OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_WIN32_H_ | 5 #ifndef COURGETTE_DISASSEMBLER_WIN32_H_ |
6 #define COURGETTE_DISASSEMBLER_WIN32_H_ | 6 #define COURGETTE_DISASSEMBLER_WIN32_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 class InstructionReceptor; | 24 class InstructionReceptor; |
25 | 25 |
26 class DisassemblerWin32 : public Disassembler { | 26 class DisassemblerWin32 : public Disassembler { |
27 public: | 27 public: |
28 virtual ~DisassemblerWin32() = default; | 28 virtual ~DisassemblerWin32() = default; |
29 | 29 |
30 // Disassembler interfaces. | 30 // Disassembler interfaces. |
31 RVA FileOffsetToRVA(FileOffset file_offset) const override; | 31 RVA FileOffsetToRVA(FileOffset file_offset) const override; |
32 FileOffset RVAToFileOffset(RVA rva) const override; | 32 FileOffset RVAToFileOffset(RVA rva) const override; |
33 ExecutableType kind() const override = 0; | 33 ExecutableType kind() const override = 0; |
| 34 uint64_t image_base() const override { return image_base_; } |
34 RVA PointerToTargetRVA(const uint8_t* p) const override = 0; | 35 RVA PointerToTargetRVA(const uint8_t* p) const override = 0; |
35 bool ParseHeader() override; | 36 bool ParseHeader() override; |
36 bool Disassemble(AssemblyProgram* target) override; | 37 bool Disassemble(AssemblyProgram* program) override; |
37 | 38 |
38 // Exposed for test purposes | 39 // Exposed for test purposes |
39 bool has_text_section() const { return has_text_section_; } | 40 bool has_text_section() const { return has_text_section_; } |
40 uint32_t size_of_code() const { return size_of_code_; } | 41 uint32_t size_of_code() const { return size_of_code_; } |
41 | 42 |
42 // Returns 'true' if the base relocation table can be parsed. | 43 // Returns 'true' if the base relocation table can be parsed. |
43 // Output is a vector of the RVAs corresponding to locations within executable | 44 // Output is a vector of the RVAs corresponding to locations within executable |
44 // that are listed in the base relocation table. | 45 // that are listed in the base relocation table. |
45 bool ParseRelocs(std::vector<RVA>* addresses); | 46 bool ParseRelocs(std::vector<RVA>* addresses); |
46 | 47 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 virtual CheckBool EmitAbs(Label* label, | 86 virtual CheckBool EmitAbs(Label* label, |
86 InstructionReceptor* receptor) const = 0; | 87 InstructionReceptor* receptor) const = 0; |
87 // Returns true if type is recognized. | 88 // Returns true if type is recognized. |
88 virtual bool SupportsRelTableType(int type) const = 0; | 89 virtual bool SupportsRelTableType(int type) const = 0; |
89 virtual uint16_t OffsetOfDataDirectories() const = 0; | 90 virtual uint16_t OffsetOfDataDirectories() const = 0; |
90 | 91 |
91 #if COURGETTE_HISTOGRAM_TARGETS | 92 #if COURGETTE_HISTOGRAM_TARGETS |
92 void HistogramTargets(const char* kind, const std::map<RVA, int>& map) const; | 93 void HistogramTargets(const char* kind, const std::map<RVA, int>& map) const; |
93 #endif | 94 #endif |
94 | 95 |
95 // Most addresses are represented as 32-bit RVAs. The one address we can't | |
96 // do this with is the image base address. | |
97 uint64_t image_base() const { return image_base_; } | |
98 | |
99 const ImageDataDirectory& base_relocation_table() const { | 96 const ImageDataDirectory& base_relocation_table() const { |
100 return base_relocation_table_; | 97 return base_relocation_table_; |
101 } | 98 } |
102 | 99 |
103 // Returns description of the RVA, e.g. ".text+0x1243". For debugging only. | 100 // Returns description of the RVA, e.g. ".text+0x1243". For debugging only. |
104 std::string DescribeRVA(RVA rva) const; | 101 std::string DescribeRVA(RVA rva) const; |
105 | 102 |
106 // Finds the first section at file_offset or above. Does not return sections | 103 // Finds the first section at file_offset or above. Does not return sections |
107 // that have no raw bytes in the file. | 104 // that have no raw bytes in the file. |
108 const Section* FindNextSection(FileOffset file_offset) const; | 105 const Section* FindNextSection(FileOffset file_offset) const; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 std::map<RVA, int> rel32_target_rvas_; | 146 std::map<RVA, int> rel32_target_rvas_; |
150 #endif | 147 #endif |
151 | 148 |
152 private: | 149 private: |
153 DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32); | 150 DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32); |
154 }; | 151 }; |
155 | 152 |
156 } // namespace courgette | 153 } // namespace courgette |
157 | 154 |
158 #endif // COURGETTE_DISASSEMBLER_WIN32_H_ | 155 #endif // COURGETTE_DISASSEMBLER_WIN32_H_ |
OLD | NEW |