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

Side by Side Diff: courgette/disassembler_win32.h

Issue 2583373002: [Courgette] Simple AssemblyProgram and Disassembler cleanups. (Closed)
Patch Set: Tune up header inclusion. Created 3 years, 11 months 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
« no previous file with comments | « courgette/disassembler_elf_32_x86_unittest.cc ('k') | courgette/disassembler_win32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 14 matching lines...) Expand all
123 uint16_t number_of_sections_ = 0; 120 uint16_t number_of_sections_ = 0;
124 const Section* sections_ = nullptr; 121 const Section* sections_ = nullptr;
125 bool has_text_section_ = false; 122 bool has_text_section_ = false;
126 123
127 uint32_t size_of_code_ = 0; 124 uint32_t size_of_code_ = 0;
128 uint32_t size_of_initialized_data_ = 0; 125 uint32_t size_of_initialized_data_ = 0;
129 uint32_t size_of_uninitialized_data_ = 0; 126 uint32_t size_of_uninitialized_data_ = 0;
130 RVA base_of_code_ = 0; 127 RVA base_of_code_ = 0;
131 RVA base_of_data_ = 0; 128 RVA base_of_data_ = 0;
132 129
133 uint64_t image_base_ = 0; // Range limited to 32 bits for 32 bit executable 130 uint64_t image_base_ = 0; // Range limited to 32 bits for 32 bit executable.
134 uint32_t size_of_image_ = 0; 131 uint32_t size_of_image_ = 0;
135 int number_of_data_directories_ = 0; 132 int number_of_data_directories_ = 0;
136 133
137 ImageDataDirectory export_table_; 134 ImageDataDirectory export_table_;
138 ImageDataDirectory import_table_; 135 ImageDataDirectory import_table_;
139 ImageDataDirectory resource_table_; 136 ImageDataDirectory resource_table_;
140 ImageDataDirectory exception_table_; 137 ImageDataDirectory exception_table_;
141 ImageDataDirectory base_relocation_table_; 138 ImageDataDirectory base_relocation_table_;
142 ImageDataDirectory bound_import_table_; 139 ImageDataDirectory bound_import_table_;
143 ImageDataDirectory import_address_table_; 140 ImageDataDirectory import_address_table_;
144 ImageDataDirectory delay_import_descriptor_; 141 ImageDataDirectory delay_import_descriptor_;
145 ImageDataDirectory clr_runtime_header_; 142 ImageDataDirectory clr_runtime_header_;
146 143
147 #if COURGETTE_HISTOGRAM_TARGETS 144 #if COURGETTE_HISTOGRAM_TARGETS
148 std::map<RVA, int> abs32_target_rvas_; 145 std::map<RVA, int> abs32_target_rvas_;
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_
OLDNEW
« no previous file with comments | « courgette/disassembler_elf_32_x86_unittest.cc ('k') | courgette/disassembler_win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698