OLD | NEW |
1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. 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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #ifndef SYZYGY_PE_PE_UTILS_H_ | 15 #ifndef SYZYGY_PE_PE_UTILS_H_ |
16 #define SYZYGY_PE_PE_UTILS_H_ | 16 #define SYZYGY_PE_PE_UTILS_H_ |
17 | 17 |
18 #include <windows.h> | 18 #include <windows.h> |
19 #include <winnt.h> | 19 #include <winnt.h> |
20 | 20 |
21 #include "syzygy/block_graph/block_graph.h" | 21 #include "syzygy/block_graph/block_graph.h" |
| 22 #include "syzygy/core/address.h" |
| 23 #include "syzygy/pe/pe_file_writer.h" |
22 | 24 |
23 namespace pe { | 25 namespace pe { |
24 | 26 |
25 // @name Operations on PE/COFF headers. | 27 // @name Operations on PE/COFF headers. |
26 // @{ | 28 // @{ |
27 // Known section types. | 29 // Known section types. |
28 enum SectionType { | 30 enum SectionType { |
29 kSectionCode, | 31 kSectionCode, |
30 kSectionData, | 32 kSectionData, |
31 kSectionUnknown | 33 kSectionUnknown |
32 }; | 34 }; |
33 | 35 |
| 36 // The file ranges of each section. This is populated by |
| 37 // CalculateSectionRanges and is a map from section index (as ordered in |
| 38 // the image layout) to section ranges on disk. |
| 39 typedef core::AddressRange<core::FileOffsetAddress, size_t> FileRange; |
| 40 typedef std::map<size_t, FileRange> SectionIndexFileRangeMap; |
| 41 |
| 42 // This stores an address-space from RVAs to section indices and is populated |
| 43 // by CalculateSectionRanges. This can be used to map from a block's |
| 44 // address to the index of its section. This is needed for finalizing |
| 45 // references. |
| 46 typedef core::AddressSpace<core::RelativeAddress, size_t, size_t> |
| 47 SectionIndexSpace; |
| 48 |
34 // Typical section names. | 49 // Typical section names. |
35 extern const char kCodeSectionName[]; | 50 extern const char kCodeSectionName[]; |
36 extern const char kReadOnlyDataSectionName[]; | 51 extern const char kReadOnlyDataSectionName[]; |
37 extern const char kReadWriteDataSectionName[]; | 52 extern const char kReadWriteDataSectionName[]; |
38 extern const char kRelocSectionName[]; | 53 extern const char kRelocSectionName[]; |
39 extern const char kResourceSectionName[]; | 54 extern const char kResourceSectionName[]; |
40 extern const char kTlsSectionName[]; | 55 extern const char kTlsSectionName[]; |
41 | 56 |
42 // Typical section characteristics. | 57 // Typical section characteristics. |
43 extern const DWORD kCodeCharacteristics; | 58 extern const DWORD kCodeCharacteristics; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 199 |
185 // Redirect references in a block-graph, except for references originating from | 200 // Redirect references in a block-graph, except for references originating from |
186 // PE structures. Any non-PE-structure block in src_blocks will have its | 201 // PE structures. Any non-PE-structure block in src_blocks will have its |
187 // references examined. Any reference found as a key in @p redirects will be | 202 // references examined. Any reference found as a key in @p redirects will be |
188 // remapped to its corresponding value. | 203 // remapped to its corresponding value. |
189 // @param src The original referred destination that is to be redirected. | 204 // @param src The original referred destination that is to be redirected. |
190 // @param dst The redirected destination to be referred to. | 205 // @param dst The redirected destination to be referred to. |
191 // @param redirects A map of original to redirected destinations. | 206 // @param redirects A map of original to redirected destinations. |
192 void RedirectReferences(const ReferenceMap& redirects); | 207 void RedirectReferences(const ReferenceMap& redirects); |
193 | 208 |
| 209 template <class Type> |
| 210 bool UpdateReference(size_t start, Type new_value, std::vector<uint8_t>* data); |
| 211 |
| 212 bool ResolveReferences(core::AbsoluteAddress image_base, |
| 213 const block_graph::BlockGraph::Block* block, |
| 214 core::RelativeAddress addr, |
| 215 const core::FileOffsetAddress file_offs, |
| 216 SectionIndexFileRangeMap section_file_range_map, |
| 217 SectionIndexSpace section_index_space, |
| 218 bool write_references_in_place, |
| 219 std::vector<uint8_t>* buffer, |
| 220 const ImageLayout& image_layout); |
| 221 |
194 } // namespace pe | 222 } // namespace pe |
195 | 223 |
196 #include "syzygy/pe/pe_utils_impl.h" | 224 #include "syzygy/pe/pe_utils_impl.h" |
197 | 225 |
198 #endif // SYZYGY_PE_PE_UTILS_H_ | 226 #endif // SYZYGY_PE_PE_UTILS_H_ |
OLD | NEW |