OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_ |
| 16 #define CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_ |
| 17 |
| 18 #include <windows.h> |
| 19 |
| 20 #include <string> |
| 21 |
| 22 #include "base/basictypes.h" |
| 23 #include "util/misc/initialization_state_dcheck.h" |
| 24 #include "util/win/address_types.h" |
| 25 #include "util/win/checked_win_address_range.h" |
| 26 |
| 27 namespace crashpad { |
| 28 |
| 29 class ProcessReaderWin; |
| 30 |
| 31 namespace process_types { |
| 32 |
| 33 // TODO(scottmg): Genericize and/or? move process_types out of mac/. |
| 34 struct CrashpadInfo { |
| 35 uint32_t signature; |
| 36 uint32_t size; |
| 37 uint32_t version; |
| 38 uint8_t crashpad_handler_behavior; // TriState. |
| 39 uint8_t system_crash_reporter_forwarding; // TriState. |
| 40 uint16_t padding_0; |
| 41 uint64_t simple_annotations; // TODO(scottmg): x86/64. |
| 42 }; |
| 43 |
| 44 struct Section { |
| 45 }; |
| 46 |
| 47 } // namespace process_types |
| 48 |
| 49 //! \brief A reader for PE images mapped into another process. |
| 50 //! |
| 51 //! This class is capable of reading both 32-bit and 64-bit images based on the |
| 52 //! bitness of the remote process. |
| 53 //! |
| 54 //! \sa PEImageAnnotationsReader |
| 55 class PEImageReader { |
| 56 public: |
| 57 PEImageReader(); |
| 58 ~PEImageReader(); |
| 59 |
| 60 //! \brief Initializes the reader. |
| 61 //! |
| 62 //! This method must be called only once on an object. This method must be |
| 63 //! called successfully before any other method in this class may be called. |
| 64 //! |
| 65 //! \param[in] process_reader The reader for the remote process. |
| 66 //! \param[in] address The address, in the remote process' address space, |
| 67 //! where the `IMAGE_DOS_HEADER` is located. |
| 68 //! \param[in] size The size of the image. |
| 69 //! \param[in] name The module's name, a string to be used in logged messages. |
| 70 //! This string is for diagnostic purposes. |
| 71 //! |
| 72 //! \return `true` if the image was read successfully, `false` otherwise, with |
| 73 //! an appropriate message logged. |
| 74 bool Initialize(ProcessReaderWin* process_reader, |
| 75 WinVMAddress address, |
| 76 WinVMSize size, |
| 77 const std::string& module_name); |
| 78 |
| 79 //! \brief Returns the image's load address. |
| 80 //! |
| 81 //! This is the value passed as \a address to Initialize(). |
| 82 WinVMAddress Address() const { return module_range_.Base(); } |
| 83 |
| 84 //! \brief Returns the image's size. |
| 85 //! |
| 86 //! This is the value passed as \a size to Initialize(). |
| 87 WinVMSize Size() const { return module_range_.Size(); } |
| 88 |
| 89 //! \brief Obtains the module's CrashpadInfo structure. |
| 90 //! |
| 91 //! \return `true` on success, `false` on failure. If the module does not have |
| 92 //! a `CPADinfo` section, this will return `false` without logging any |
| 93 //! messages. Other failures will result in messages being logged. |
| 94 bool GetCrashpadInfo(process_types::CrashpadInfo* crashpad_info) const; |
| 95 |
| 96 private: |
| 97 //! \brief Finds a given section by name in the image. |
| 98 bool GetSectionByName(const std::string& name, |
| 99 IMAGE_SECTION_HEADER* section) const; |
| 100 |
| 101 //! \brief Reads memory from target process, first checking whether the range |
| 102 //! requested falls inside module_range_. |
| 103 //! |
| 104 //! \return `true` on success, with \a into filled out, otherwise `false` and |
| 105 //! a message will be logged. |
| 106 bool CheckedReadMemory(WinVMAddress address, |
| 107 WinVMSize size, |
| 108 void* into) const; |
| 109 |
| 110 ProcessReaderWin* process_reader_; // weak |
| 111 CheckedWinAddressRange module_range_; |
| 112 std::string module_name_; |
| 113 InitializationStateDcheck initialized_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(PEImageReader); |
| 116 }; |
| 117 |
| 118 } // namespace crashpad |
| 119 |
| 120 #endif // CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_ |
OLD | NEW |