Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: snapshot/win/pe_image_reader.h

Issue 1475023004: Get module versions and types from in-memory images (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with 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 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 }; 44 };
45 45
46 } // namespace process_types 46 } // namespace process_types
47 47
48 //! \brief A reader for PE images mapped into another process. 48 //! \brief A reader for PE images mapped into another process.
49 //! 49 //!
50 //! This class is capable of reading both 32-bit and 64-bit images based on the 50 //! This class is capable of reading both 32-bit and 64-bit images based on the
51 //! bitness of the remote process. 51 //! bitness of the remote process.
52 //! 52 //!
53 //! \sa PEImageAnnotationsReader 53 //! \sa PEImageAnnotationsReader
54 //! \sa PEImageResourceReader
54 class PEImageReader { 55 class PEImageReader {
55 public: 56 public:
56 PEImageReader(); 57 PEImageReader();
57 ~PEImageReader(); 58 ~PEImageReader();
58 59
59 //! \brief Initializes the reader. 60 //! \brief Initializes the reader.
60 //! 61 //!
61 //! This method must be called only once on an object. This method must be 62 //! This method must be called only once on an object. This method must be
62 //! called successfully before any other method in this class may be called. 63 //! called successfully before any other method in this class may be called.
63 //! 64 //!
(...skipping 29 matching lines...) Expand all
93 template <class Traits> 94 template <class Traits>
94 bool GetCrashpadInfo( 95 bool GetCrashpadInfo(
95 process_types::CrashpadInfo<Traits>* crashpad_info) const; 96 process_types::CrashpadInfo<Traits>* crashpad_info) const;
96 97
97 //! \brief Obtains information from the module's debug directory, if any. 98 //! \brief Obtains information from the module's debug directory, if any.
98 //! 99 //!
99 //! \param[out] uuid The unique identifier of the executable/PDB. 100 //! \param[out] uuid The unique identifier of the executable/PDB.
100 //! \param[out] age The age field for the pdb (the number of times it's been 101 //! \param[out] age The age field for the pdb (the number of times it's been
101 //! relinked). 102 //! relinked).
102 //! \param[out] pdbname Name of the pdb file. 103 //! \param[out] pdbname Name of the pdb file.
103 //! \return `true` on success, or `false` if the module has no debug directory
104 //! entry.
105 bool DebugDirectoryInformation(UUID* uuid,
106 DWORD* age,
107 std::string* pdbname) const;
108
109 private:
110 //! \brief Implementation helper for DebugDirectoryInformation() templated by
111 //! `IMAGE_NT_HEADERS` type for different bitnesses.
112 //! 104 //!
113 //! \return `true` on success, with the parameters set appropriately. `false` 105 //! \return `true` on success, with the parameters set appropriately. `false`
114 //! on failure. This method may return `false` without logging anything in 106 //! on failure. This method may return `false` without logging anything in
115 //! the case of a module that does not contain relevant debugging 107 //! the case of a module that does not contain relevant debugging
116 //! information but is otherwise properly structured. 108 //! information but is otherwise properly structured.
117 template <class NtHeadersType> 109 bool DebugDirectoryInformation(UUID* uuid,
118 bool ReadDebugDirectoryInformation(UUID* uuid, 110 DWORD* age,
119 DWORD* age, 111 std::string* pdbname) const;
120 std::string* pdbname) const;
121 112
113 //! \brief Obtains the module’s `VS_FIXEDFILEINFO`, containing its version and
114 //! type information.
115 //!
116 //! The data obtained from this method should be equivalent to what could be
117 //! obtained by calling GetModuleVersionAndType(). Avoiding that function
118 //! ensures that the data in the module loaded into the remote process will be
119 //! used as-is, without the risks associated with loading the module into the
120 //! reading process.
121 //!
122 //! \param[out] vs_fixed_file_info The VS_FIXEDFILEINFO on success.
123 //! VS_FIXEDFILEINFO::dwFileFlags will have been masked with
124 //! VS_FIXEDFILEINFO::dwFileFlagsMask already.
125 //!
126 //! \return `true` on success. `false` if the module does not contain this
127 //! information, without logging any messages. `false` on failure, with
128 //! a message logged.
129 bool VSFixedFileInfo(VS_FIXEDFILEINFO* vs_fixed_file_info) const;
130
131 private:
122 //! \brief Reads the `IMAGE_NT_HEADERS` from the beginning of the image. 132 //! \brief Reads the `IMAGE_NT_HEADERS` from the beginning of the image.
123 //! 133 //!
124 //! \param[out] nt_headers The contents of the templated NtHeadersType 134 //! \param[out] nt_headers The contents of the templated NtHeadersType
125 //! structure read from the remote process. 135 //! structure read from the remote process.
126 //! \param[out] nt_headers_address The address of the templated NtHeadersType 136 //! \param[out] nt_headers_address The address of the templated NtHeadersType
127 //! structure in the remote process’ address space. If this information is 137 //! structure in the remote process’ address space. If this information is
128 //! not needed, this parameter may be `nullptr`. 138 //! not needed, this parameter may be `nullptr`.
129 //! 139 //!
130 //! \return `true` on success, with \a nt_headers and optionally \a 140 //! \return `true` on success, with \a nt_headers and optionally \a
131 //! nt_headers_address set appropriately. `false` on failure, with a 141 //! nt_headers_address set appropriately. `false` on failure, with a
132 //! message logged. 142 //! message logged.
133 template <class NtHeadersType> 143 template <class NtHeadersType>
134 bool ReadNtHeaders(NtHeadersType* nt_headers, 144 bool ReadNtHeaders(NtHeadersType* nt_headers,
135 WinVMAddress* nt_headers_address) const; 145 WinVMAddress* nt_headers_address) const;
136 146
137 //! \brief Finds a given section by name in the image. 147 //! \brief Finds a given section by name in the image.
138 template <class NtHeadersType> 148 template <class NtHeadersType>
139 bool GetSectionByName(const std::string& name, 149 bool GetSectionByName(const std::string& name,
140 IMAGE_SECTION_HEADER* section) const; 150 IMAGE_SECTION_HEADER* section) const;
141 151
142 //! \brief Reads memory from target process, first checking whether the range 152 //! \brief Finds the `IMAGE_DATA_DIRECTORY` in
143 //! requested falls inside module_range_. 153 //! `IMAGE_OPTIONAL_HEADER::DataDirectory` at the specified \a index.
144 //! 154 //!
145 //! \return `true` on success, with \a into filled out, otherwise `false` and 155 //! \param[in] index An `IMAGE_DIRECTORY_ENTRY_*` constant specifying the
146 //! a message will be logged. 156 //! data to be returned.
157 //! \param[out] entry The `IMAGE_DATA_DIRECTORY` found within the module.
158 //!
159 //! \return `true` on success, with \a entry set appropriately. `false` if the
160 //! module does not contain the specified information, without logging a
161 //! message. `false` on failure, with a message logged.
162 bool ImageDataDirectoryEntry(size_t index, IMAGE_DATA_DIRECTORY* entry) const;
163
164 //! \brief A templatized helper for ImageDataDirectoryEntry() to account for
165 //! differences in \a NtHeadersType.
166 template <class NtHeadersType>
167 bool ImageDataDirectoryEntryT(size_t index,
168 IMAGE_DATA_DIRECTORY* entry) const;
169
170 //! \brief Reads memory from the target process, first checking whether the
171 //! range requested falls inside module_range_.
172 //!
173 //! \return `true` on success, with \a into filled out, otherwise `false` with
174 //! a message logged.
147 bool CheckedReadMemory(WinVMAddress address, 175 bool CheckedReadMemory(WinVMAddress address,
148 WinVMSize size, 176 WinVMSize size,
149 void* into) const; 177 void* into) const;
150 178
151 ProcessReaderWin* process_reader_; // weak 179 ProcessReaderWin* process_reader_; // weak
152 CheckedWinAddressRange module_range_; 180 CheckedWinAddressRange module_range_;
153 std::string module_name_; 181 std::string module_name_;
154 InitializationStateDcheck initialized_; 182 InitializationStateDcheck initialized_;
155 183
156 DISALLOW_COPY_AND_ASSIGN(PEImageReader); 184 DISALLOW_COPY_AND_ASSIGN(PEImageReader);
157 }; 185 };
158 186
159 } // namespace crashpad 187 } // namespace crashpad
160 188
161 #endif // CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_ 189 #endif // CRASHPAD_SNAPSHOT_WIN_PE_IMAGE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698