| 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 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "courgette/disassembler.h" | 16 #include "courgette/disassembler.h" |
| 17 #include "courgette/image_utils.h" | 17 #include "courgette/image_utils.h" |
| 18 #include "courgette/memory_allocator.h" | 18 #include "courgette/memory_allocator.h" |
| 19 #include "courgette/types_win_pe.h" | 19 #include "courgette/types_win_pe.h" |
| 20 | 20 |
| 21 namespace courgette { | 21 namespace courgette { |
| 22 | 22 |
| 23 class AssemblyProgram; | 23 class AssemblyProgram; |
| 24 class InstructionReceptor; |
| 24 | 25 |
| 25 class DisassemblerWin32 : public Disassembler { | 26 class DisassemblerWin32 : public Disassembler { |
| 26 public: | 27 public: |
| 27 virtual ~DisassemblerWin32() = default; | 28 virtual ~DisassemblerWin32() = default; |
| 28 | 29 |
| 29 // Disassembler interfaces. | 30 // Disassembler interfaces. |
| 30 RVA FileOffsetToRVA(FileOffset file_offset) const override; | 31 RVA FileOffsetToRVA(FileOffset file_offset) const override; |
| 31 FileOffset RVAToFileOffset(RVA rva) const override; | 32 FileOffset RVAToFileOffset(RVA rva) const override; |
| 32 virtual ExecutableType kind() const override = 0; | 33 ExecutableType kind() const override = 0; |
| 33 virtual RVA PointerToTargetRVA(const uint8_t* p) const override = 0; | 34 RVA PointerToTargetRVA(const uint8_t* p) const override = 0; |
| 34 bool ParseHeader() override; | 35 bool ParseHeader() override; |
| 35 bool Disassemble(AssemblyProgram* target) override; | 36 bool Disassemble(AssemblyProgram* target) override; |
| 36 | 37 |
| 37 // Exposed for test purposes | 38 // Exposed for test purposes |
| 38 bool has_text_section() const { return has_text_section_; } | 39 bool has_text_section() const { return has_text_section_; } |
| 39 uint32_t size_of_code() const { return size_of_code_; } | 40 uint32_t size_of_code() const { return size_of_code_; } |
| 40 | 41 |
| 41 // Returns 'true' if the base relocation table can be parsed. | 42 // Returns 'true' if the base relocation table can be parsed. |
| 42 // Output is a vector of the RVAs corresponding to locations within executable | 43 // Output is a vector of the RVAs corresponding to locations within executable |
| 43 // that are listed in the base relocation table. | 44 // that are listed in the base relocation table. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 // which will be checked against the detected one. | 55 // which will be checked against the detected one. |
| 55 static bool QuickDetect(const uint8_t* start, size_t length, uint16_t magic); | 56 static bool QuickDetect(const uint8_t* start, size_t length, uint16_t magic); |
| 56 | 57 |
| 57 // Disassembler interfaces. | 58 // Disassembler interfaces. |
| 58 RvaVisitor* CreateAbs32TargetRvaVisitor() override; | 59 RvaVisitor* CreateAbs32TargetRvaVisitor() override; |
| 59 RvaVisitor* CreateRel32TargetRvaVisitor() override; | 60 RvaVisitor* CreateRel32TargetRvaVisitor() override; |
| 60 void RemoveUnusedRel32Locations(AssemblyProgram* program) override; | 61 void RemoveUnusedRel32Locations(AssemblyProgram* program) override; |
| 61 | 62 |
| 62 DisassemblerWin32(const uint8_t* start, size_t length); | 63 DisassemblerWin32(const uint8_t* start, size_t length); |
| 63 | 64 |
| 64 CheckBool ParseFile(AssemblyProgram* target) WARN_UNUSED_RESULT; | 65 CheckBool ParseFile(AssemblyProgram* target, |
| 66 InstructionReceptor* receptor) const WARN_UNUSED_RESULT; |
| 65 bool ParseAbs32Relocs(); | 67 bool ParseAbs32Relocs(); |
| 66 void ParseRel32RelocsFromSections(); | 68 void ParseRel32RelocsFromSections(); |
| 67 virtual void ParseRel32RelocsFromSection(const Section* section) = 0; | 69 virtual void ParseRel32RelocsFromSection(const Section* section) = 0; |
| 68 | 70 |
| 69 CheckBool ParseNonSectionFileRegion(FileOffset start_file_offset, | 71 CheckBool ParseNonSectionFileRegion(FileOffset start_file_offset, |
| 70 FileOffset end_file_offset, | 72 FileOffset end_file_offset, |
| 71 AssemblyProgram* program) | 73 InstructionReceptor* receptor) const |
| 72 WARN_UNUSED_RESULT; | 74 WARN_UNUSED_RESULT; |
| 73 CheckBool ParseFileRegion(const Section* section, | 75 CheckBool ParseFileRegion(const Section* section, |
| 74 FileOffset start_file_offset, | 76 FileOffset start_file_offset, |
| 75 FileOffset end_file_offset, | 77 FileOffset end_file_offset, |
| 76 AssemblyProgram* program) WARN_UNUSED_RESULT; | 78 AssemblyProgram* program, |
| 79 InstructionReceptor* receptor) const |
| 80 WARN_UNUSED_RESULT; |
| 77 | 81 |
| 78 // Returns address width in byte count. | 82 // Returns address width in byte count. |
| 79 virtual int AbsVAWidth() const = 0; | 83 virtual int AbsVAWidth() const = 0; |
| 80 // Emits Abs 32/64 |label| to the |program|. | 84 // Emits Abs 32/64 |label| to the |receptor|. |
| 81 virtual CheckBool EmitAbs(Label* label, AssemblyProgram* program) = 0; | 85 virtual CheckBool EmitAbs(Label* label, |
| 86 InstructionReceptor* receptor) const = 0; |
| 82 // Returns true if type is recognized. | 87 // Returns true if type is recognized. |
| 83 virtual bool SupportsRelTableType(int type) const = 0; | 88 virtual bool SupportsRelTableType(int type) const = 0; |
| 84 virtual uint16_t OffsetOfDataDirectories() const = 0; | 89 virtual uint16_t OffsetOfDataDirectories() const = 0; |
| 85 | 90 |
| 86 #if COURGETTE_HISTOGRAM_TARGETS | 91 #if COURGETTE_HISTOGRAM_TARGETS |
| 87 void HistogramTargets(const char* kind, const std::map<RVA, int>& map); | 92 void HistogramTargets(const char* kind, const std::map<RVA, int>& map) const; |
| 88 #endif | 93 #endif |
| 89 | 94 |
| 90 // Most addresses are represented as 32-bit RVAs. The one address we can't | 95 // Most addresses are represented as 32-bit RVAs. The one address we can't |
| 91 // do this with is the image base address. | 96 // do this with is the image base address. |
| 92 uint64_t image_base() const { return image_base_; } | 97 uint64_t image_base() const { return image_base_; } |
| 93 | 98 |
| 94 const ImageDataDirectory& base_relocation_table() const { | 99 const ImageDataDirectory& base_relocation_table() const { |
| 95 return base_relocation_table_; | 100 return base_relocation_table_; |
| 96 } | 101 } |
| 97 | 102 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 std::map<RVA, int> rel32_target_rvas_; | 149 std::map<RVA, int> rel32_target_rvas_; |
| 145 #endif | 150 #endif |
| 146 | 151 |
| 147 private: | 152 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32); | 153 DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32); |
| 149 }; | 154 }; |
| 150 | 155 |
| 151 } // namespace courgette | 156 } // namespace courgette |
| 152 | 157 |
| 153 #endif // COURGETTE_DISASSEMBLER_WIN32_H_ | 158 #endif // COURGETTE_DISASSEMBLER_WIN32_H_ |
| OLD | NEW |