OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_H_ | 5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_H_ |
6 #define COURGETTE_DISASSEMBLER_ELF_32_H_ | 6 #define COURGETTE_DISASSEMBLER_ELF_32_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0; | 54 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0; |
55 | 55 |
56 // Emits the courgette instruction corresponding to the RVA type. | 56 // Emits the courgette instruction corresponding to the RVA type. |
57 virtual CheckBool EmitInstruction(AssemblyProgram* program, | 57 virtual CheckBool EmitInstruction(AssemblyProgram* program, |
58 RVA target_rva) = 0; | 58 RVA target_rva) = 0; |
59 | 59 |
60 // Returns the size of the instruction containing the RVA. | 60 // Returns the size of the instruction containing the RVA. |
61 virtual uint16_t op_size() const = 0; | 61 virtual uint16_t op_size() const = 0; |
62 | 62 |
63 // Comparator for sorting, which assumes uniqueness of RVAs. | 63 // Comparator for sorting, which assumes uniqueness of RVAs. |
64 static bool IsLessThan(TypedRVA* a, TypedRVA* b) { | 64 static bool IsLessThanByRVA(TypedRVA* a, TypedRVA* b) { |
65 return a->rva() < b->rva(); | 65 return a->rva() < b->rva(); |
66 } | 66 } |
67 | 67 |
| 68 // Comparator for sorting, which assumes uniqueness of file offsets. |
| 69 static bool IsLessThanByFileOffset(TypedRVA* a, TypedRVA* b) { |
| 70 return a->file_offset() < b->file_offset(); |
| 71 } |
| 72 |
68 private: | 73 private: |
69 const RVA rva_; | 74 const RVA rva_; |
70 RVA relative_target_ = kNoRVA; | 75 RVA relative_target_ = kNoRVA; |
71 FileOffset file_offset_ = kNoFileOffset; | 76 FileOffset file_offset_ = kNoFileOffset; |
72 }; | 77 }; |
73 | 78 |
74 public: | 79 public: |
75 DisassemblerElf32(const void* start, size_t length); | 80 DisassemblerElf32(const void* start, size_t length); |
76 | 81 |
77 ~DisassemblerElf32() override { } | 82 ~DisassemblerElf32() override { } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 AssemblyProgram* program) WARN_UNUSED_RESULT; | 161 AssemblyProgram* program) WARN_UNUSED_RESULT; |
157 | 162 |
158 CheckBool ParseSimpleRegion(FileOffset start_file_offset, | 163 CheckBool ParseSimpleRegion(FileOffset start_file_offset, |
159 FileOffset end_file_offset, | 164 FileOffset end_file_offset, |
160 AssemblyProgram* program) WARN_UNUSED_RESULT; | 165 AssemblyProgram* program) WARN_UNUSED_RESULT; |
161 | 166 |
162 CheckBool ParseAbs32Relocs() WARN_UNUSED_RESULT; | 167 CheckBool ParseAbs32Relocs() WARN_UNUSED_RESULT; |
163 | 168 |
164 CheckBool CheckSection(RVA rva) WARN_UNUSED_RESULT; | 169 CheckBool CheckSection(RVA rva) WARN_UNUSED_RESULT; |
165 | 170 |
| 171 // Extracts all rel32 TypedRVAs. Does not sort the result. |
166 CheckBool ParseRel32RelocsFromSections() WARN_UNUSED_RESULT; | 172 CheckBool ParseRel32RelocsFromSections() WARN_UNUSED_RESULT; |
167 | 173 |
168 const Elf32_Ehdr* header_; | 174 const Elf32_Ehdr* header_; |
169 | 175 |
170 Elf32_Half section_header_table_size_; | 176 Elf32_Half section_header_table_size_; |
171 | 177 |
172 // Section header table, ordered by section id. | 178 // Section header table, ordered by section id. |
173 std::vector<Elf32_Shdr> section_header_table_; | 179 std::vector<Elf32_Shdr> section_header_table_; |
174 | 180 |
175 // An ordering of |section_header_table_|, sorted by file offset. | 181 // An ordering of |section_header_table_|, sorted by file offset. |
176 std::vector<Elf32_Half> section_header_file_offset_order_; | 182 std::vector<Elf32_Half> section_header_file_offset_order_; |
177 | 183 |
178 const Elf32_Phdr* program_header_table_; | 184 const Elf32_Phdr* program_header_table_; |
179 Elf32_Half program_header_table_size_; | 185 Elf32_Half program_header_table_size_; |
180 | 186 |
181 // Pointer to string table containing section names. | 187 // Pointer to string table containing section names. |
182 const char* default_string_section_; | 188 const char* default_string_section_; |
183 size_t default_string_section_size_; | 189 size_t default_string_section_size_; |
184 | 190 |
185 std::vector<RVA> abs32_locations_; | 191 std::vector<RVA> abs32_locations_; |
186 ScopedVector<TypedRVA> rel32_locations_; | 192 ScopedVector<TypedRVA> rel32_locations_; |
187 | 193 |
188 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); | 194 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); |
189 }; | 195 }; |
190 | 196 |
191 } // namespace courgette | 197 } // namespace courgette |
192 | 198 |
193 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ | 199 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ |
OLD | NEW |