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

Side by Side Diff: courgette/disassembler_win32.h

Issue 2771753004: [Courgette] Refactor: Unify Disassembler::Disassemble() and instantiate AssemblyProgram there. (Closed)
Patch Set: Fix signed/unsigned comparison issue in test. Created 3 years, 9 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
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/instruction_utils.h"
18 #include "courgette/memory_allocator.h" 19 #include "courgette/memory_allocator.h"
19 #include "courgette/types_win_pe.h" 20 #include "courgette/types_win_pe.h"
20 21
21 namespace courgette { 22 namespace courgette {
22 23
23 class AssemblyProgram; 24 class AssemblyProgram;
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 uint64_t image_base() const override { return image_base_; }
35 RVA PointerToTargetRVA(const uint8_t* p) const override = 0; 35 RVA PointerToTargetRVA(const uint8_t* p) const override = 0;
36 bool ParseHeader() override; 36 bool ParseHeader() override;
37 bool Disassemble(AssemblyProgram* program) override;
38 37
39 // Exposed for test purposes 38 // Exposed for test purposes
40 bool has_text_section() const { return has_text_section_; } 39 bool has_text_section() const { return has_text_section_; }
41 uint32_t size_of_code() const { return size_of_code_; } 40 uint32_t size_of_code() const { return size_of_code_; }
42 41
43 // Returns 'true' if the base relocation table can be parsed. 42 // Returns 'true' if the base relocation table can be parsed.
44 // 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
45 // that are listed in the base relocation table. 44 // that are listed in the base relocation table.
46 bool ParseRelocs(std::vector<RVA>* addresses); 45 bool ParseRelocs(std::vector<RVA>* addresses);
47 46
48 // Returns Section containing the relative virtual address, or null if none. 47 // Returns Section containing the relative virtual address, or null if none.
49 const Section* RVAToSection(RVA rva) const; 48 const Section* RVAToSection(RVA rva) const;
50 49
51 static std::string SectionName(const Section* section); 50 static std::string SectionName(const Section* section);
52 51
53 protected: 52 protected:
54 // Returns true if a valid executable is detected using only quick checks. 53 // Returns true if a valid executable is detected using only quick checks.
55 // Derived classes should inject |magic| corresponding to their architecture, 54 // Derived classes should inject |magic| corresponding to their architecture,
56 // which will be checked against the detected one. 55 // which will be checked against the detected one.
57 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);
58 57
59 bool ParseAbs32Relocs(); 58 bool ParseAbs32Relocs();
60 void ParseRel32RelocsFromSections(); 59 void ParseRel32RelocsFromSections();
61 60
62 // Disassembler interfaces. 61 // Disassembler interfaces.
62 bool ExtractAbs32Locations() override;
63 bool ExtractRel32Locations() override;
63 RvaVisitor* CreateAbs32TargetRvaVisitor() override; 64 RvaVisitor* CreateAbs32TargetRvaVisitor() override;
64 RvaVisitor* CreateRel32TargetRvaVisitor() override; 65 RvaVisitor* CreateRel32TargetRvaVisitor() override;
65 void RemoveUnusedRel32Locations(AssemblyProgram* program) override; 66 void RemoveUnusedRel32Locations(AssemblyProgram* program) override;
67 InstructionGenerator GetInstructionGenerator(
68 AssemblyProgram* program) override;
66 69
67 DisassemblerWin32(const uint8_t* start, size_t length); 70 DisassemblerWin32(const uint8_t* start, size_t length);
68 71
69 CheckBool ParseFile(AssemblyProgram* target, 72 CheckBool ParseFile(AssemblyProgram* target,
70 InstructionReceptor* receptor) const WARN_UNUSED_RESULT; 73 InstructionReceptor* receptor) const WARN_UNUSED_RESULT;
71 virtual void ParseRel32RelocsFromSection(const Section* section) = 0; 74 virtual void ParseRel32RelocsFromSection(const Section* section) = 0;
72 75
73 CheckBool ParseNonSectionFileRegion(FileOffset start_file_offset, 76 CheckBool ParseNonSectionFileRegion(FileOffset start_file_offset,
74 FileOffset end_file_offset, 77 FileOffset end_file_offset,
75 InstructionReceptor* receptor) const 78 InstructionReceptor* receptor) const
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 std::map<RVA, int> rel32_target_rvas_; 150 std::map<RVA, int> rel32_target_rvas_;
148 #endif 151 #endif
149 152
150 private: 153 private:
151 DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32); 154 DISALLOW_COPY_AND_ASSIGN(DisassemblerWin32);
152 }; 155 };
153 156
154 } // namespace courgette 157 } // namespace courgette
155 158
156 #endif // COURGETTE_DISASSEMBLER_WIN32_H_ 159 #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