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

Side by Side Diff: courgette/disassembler_elf_32.h

Issue 2055343002: Courgette: Add static method QuickDetect() to optimize program detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Propagate uint8_t* to unittests and Nits Created 4 years, 6 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
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ~Elf32RvaVisitor_Rel32() override { } 87 ~Elf32RvaVisitor_Rel32() override { }
88 88
89 // VectorRvaVisitor<TypedRVA*> interfaces. 89 // VectorRvaVisitor<TypedRVA*> interfaces.
90 RVA Get() const override; 90 RVA Get() const override;
91 91
92 private: 92 private:
93 DISALLOW_COPY_AND_ASSIGN(Elf32RvaVisitor_Rel32); 93 DISALLOW_COPY_AND_ASSIGN(Elf32RvaVisitor_Rel32);
94 }; 94 };
95 95
96 public: 96 public:
97 DisassemblerElf32(const void* start, size_t length); 97 DisassemblerElf32(const uint8_t* start, size_t length);
98 98
99 ~DisassemblerElf32() override { } 99 ~DisassemblerElf32() override { }
100 100
101 // Disassembler interfaces. 101 // Disassembler interfaces.
102 RVA FileOffsetToRVA(FileOffset file_offset) const override; 102 RVA FileOffsetToRVA(FileOffset file_offset) const override;
103 FileOffset RVAToFileOffset(RVA rva) const override; 103 FileOffset RVAToFileOffset(RVA rva) const override;
104 RVA PointerToTargetRVA(const uint8_t* p) const override; 104 RVA PointerToTargetRVA(const uint8_t* p) const override;
105 virtual ExecutableType kind() const override = 0; 105 virtual ExecutableType kind() const override = 0;
106 bool ParseHeader() override; 106 bool ParseHeader() override;
107 bool Disassemble(AssemblyProgram* target) override; 107 bool Disassemble(AssemblyProgram* target) override;
108 108
109 virtual e_machine_values ElfEM() const = 0; 109 virtual e_machine_values ElfEM() const = 0;
110 110
111 CheckBool IsValidTargetRVA(RVA rva) const WARN_UNUSED_RESULT; 111 CheckBool IsValidTargetRVA(RVA rva) const WARN_UNUSED_RESULT;
112 112
113 // Converts an ELF relocation instruction into an RVA. 113 // Converts an ELF relocation instruction into an RVA.
114 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) 114 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
115 const WARN_UNUSED_RESULT = 0; 115 const WARN_UNUSED_RESULT = 0;
116 116
117 // Public for unittests only 117 // Public for unittests only
118 std::vector<RVA>& Abs32Locations() { return abs32_locations_; } 118 std::vector<RVA>& Abs32Locations() { return abs32_locations_; }
119 std::vector<std::unique_ptr<TypedRVA>>& Rel32Locations() { 119 std::vector<std::unique_ptr<TypedRVA>>& Rel32Locations() {
120 return rel32_locations_; 120 return rel32_locations_;
121 } 121 }
122 122
123 protected: 123 protected:
124 // Returns 'true' if an valid executable is detected using only quick checks.
125 // Derived classes should inject |elf_em| corresponding to their architecture,
126 // which will be checked against the detected one.
huangs 2016/06/15 00:13:04 NIT: Extra space before "which".
etiennep 2016/06/15 20:38:06 Done.
127 static bool QuickDetect(const uint8_t* start,
128 size_t length,
129 e_machine_values elf_em);
130
124 bool UpdateLength(); 131 bool UpdateLength();
125 132
126 // Misc Section Helpers 133 // Misc Section Helpers
127 134
128 Elf32_Half SectionHeaderCount() const { 135 Elf32_Half SectionHeaderCount() const {
129 return section_header_table_size_; 136 return section_header_table_size_;
130 } 137 }
131 138
132 const Elf32_Shdr* SectionHeader(Elf32_Half id) const { 139 const Elf32_Shdr* SectionHeader(Elf32_Half id) const {
133 assert(id >= 0 && id < SectionHeaderCount()); 140 assert(id >= 0 && id < SectionHeaderCount());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 222
216 std::vector<RVA> abs32_locations_; 223 std::vector<RVA> abs32_locations_;
217 std::vector<std::unique_ptr<TypedRVA>> rel32_locations_; 224 std::vector<std::unique_ptr<TypedRVA>> rel32_locations_;
218 225
219 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); 226 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32);
220 }; 227 };
221 228
222 } // namespace courgette 229 } // namespace courgette
223 230
224 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ 231 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698