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_elf_32.h

Issue 1969543002: Unified usage of vector<unique_ptr<T>> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | courgette/disassembler_elf_32.cc » ('j') | courgette/disassembler_elf_32.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include <memory>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h"
15 #include "courgette/disassembler.h" 15 #include "courgette/disassembler.h"
16 #include "courgette/image_utils.h" 16 #include "courgette/image_utils.h"
17 #include "courgette/memory_allocator.h" 17 #include "courgette/memory_allocator.h"
18 #include "courgette/types_elf.h" 18 #include "courgette/types_elf.h"
19 19
20 namespace courgette { 20 namespace courgette {
21 21
22 class AssemblyProgram; 22 class AssemblyProgram;
23 23
24 // A Courgette disassembler for 32-bit ELF files. This is only a partial 24 // A Courgette disassembler for 32-bit ELF files. This is only a partial
(...skipping 29 matching lines...) Expand all
54 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0; 54 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0;
55 55
56 // Emits the courgette instruction corresponding to the RVA type. 56 // Emits the courgette instruction corresponding to the RVA type.
57 virtual CheckBool EmitInstruction(AssemblyProgram* program, 57 virtual CheckBool EmitInstruction(AssemblyProgram* program,
58 RVA target_rva) = 0; 58 RVA target_rva) = 0;
59 59
60 // Returns the size of the instruction containing the RVA. 60 // Returns the size of the instruction containing the RVA.
61 virtual uint16_t op_size() const = 0; 61 virtual uint16_t op_size() const = 0;
62 62
63 // Comparator for sorting, which assumes uniqueness of RVAs. 63 // Comparator for sorting, which assumes uniqueness of RVAs.
64 static bool IsLessThanByRVA(TypedRVA* a, TypedRVA* b) { 64 static bool IsLessThanByRVA(const std::unique_ptr<TypedRVA>& a,
65 const std::unique_ptr<TypedRVA>& b) {
huangs 2016/05/11 04:49:23 NIT: Align to "(" like function_name(int param1,
etiennep 2016/05/11 18:19:13 Done.
65 return a->rva() < b->rva(); 66 return a->rva() < b->rva();
66 } 67 }
67 68
68 // Comparator for sorting, which assumes uniqueness of file offsets. 69 // Comparator for sorting, which assumes uniqueness of file offsets.
69 static bool IsLessThanByFileOffset(TypedRVA* a, TypedRVA* b) { 70 static bool IsLessThanByFileOffset(const std::unique_ptr<TypedRVA>& a,
71 const std::unique_ptr<TypedRVA>& b) {
huangs 2016/05/11 04:49:23 Same as above.
etiennep 2016/05/11 18:19:13 Done.
70 return a->file_offset() < b->file_offset(); 72 return a->file_offset() < b->file_offset();
71 } 73 }
72 74
73 private: 75 private:
74 const RVA rva_; 76 const RVA rva_;
75 RVA relative_target_ = kNoRVA; 77 RVA relative_target_ = kNoRVA;
76 FileOffset file_offset_ = kNoFileOffset; 78 FileOffset file_offset_ = kNoFileOffset;
77 }; 79 };
78 80
79 public: 81 public:
80 DisassemblerElf32(const void* start, size_t length); 82 DisassemblerElf32(const void* start, size_t length);
81 83
82 ~DisassemblerElf32() override { } 84 ~DisassemblerElf32() override { }
83 85
84 // Disassembler interfaces. 86 // Disassembler interfaces.
85 RVA FileOffsetToRVA(FileOffset file_offset) const override; 87 RVA FileOffsetToRVA(FileOffset file_offset) const override;
86 FileOffset RVAToFileOffset(RVA rva) const override; 88 FileOffset RVAToFileOffset(RVA rva) const override;
87 RVA PointerToTargetRVA(const uint8_t* p) const override; 89 RVA PointerToTargetRVA(const uint8_t* p) const override;
88 virtual ExecutableType kind() const override = 0; 90 virtual ExecutableType kind() const override = 0;
89 bool ParseHeader() override; 91 bool ParseHeader() override;
90 bool Disassemble(AssemblyProgram* target) override; 92 bool Disassemble(AssemblyProgram* target) override;
91 93
92 virtual e_machine_values ElfEM() const = 0; 94 virtual e_machine_values ElfEM() const = 0;
93 95
94 // Public for unittests only 96 // Public for unittests only
95 std::vector<RVA> &Abs32Locations() { return abs32_locations_; } 97 std::vector<RVA> &Abs32Locations() { return abs32_locations_; }
huangs 2016/05/11 04:49:23 Please group '&' with type (fixes earlier mistake)
etiennep 2016/05/11 18:19:12 Done.
96 ScopedVector<TypedRVA> &Rel32Locations() { return rel32_locations_; } 98 std::vector<std::unique_ptr<TypedRVA>> &Rel32Locations() {
99 return rel32_locations_;
100 }
97 101
98 protected: 102 protected:
99 bool UpdateLength(); 103 bool UpdateLength();
100 104
101 // Misc Section Helpers 105 // Misc Section Helpers
102 106
103 Elf32_Half SectionHeaderCount() const { 107 Elf32_Half SectionHeaderCount() const {
104 return section_header_table_size_; 108 return section_header_table_size_;
105 } 109 }
106 110
(...skipping 25 matching lines...) Expand all
132 136
133 CheckBool IsValidTargetRVA(RVA rva) const WARN_UNUSED_RESULT; 137 CheckBool IsValidTargetRVA(RVA rva) const WARN_UNUSED_RESULT;
134 138
135 // Converts an ELF relocation instruction into an RVA. 139 // Converts an ELF relocation instruction into an RVA.
136 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) 140 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
137 const WARN_UNUSED_RESULT = 0; 141 const WARN_UNUSED_RESULT = 0;
138 142
139 CheckBool RVAsToFileOffsets(const std::vector<RVA>& rvas, 143 CheckBool RVAsToFileOffsets(const std::vector<RVA>& rvas,
140 std::vector<FileOffset>* file_offsets); 144 std::vector<FileOffset>* file_offsets);
141 145
142 CheckBool RVAsToFileOffsets(ScopedVector<TypedRVA>* typed_rvas); 146 CheckBool RVAsToFileOffsets(
147 std::vector<std::unique_ptr<TypedRVA>>* typed_rvas);
143 148
144 // Parsing code for Disassemble(). 149 // Parsing code for Disassemble().
145 150
146 virtual CheckBool ParseRelocationSection(const Elf32_Shdr* section_header, 151 virtual CheckBool ParseRelocationSection(const Elf32_Shdr* section_header,
147 AssemblyProgram* program) 152 AssemblyProgram* program)
148 WARN_UNUSED_RESULT = 0; 153 WARN_UNUSED_RESULT = 0;
149 154
150 virtual CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section) 155 virtual CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section)
151 WARN_UNUSED_RESULT = 0; 156 WARN_UNUSED_RESULT = 0;
152 157
153 CheckBool ParseFile(AssemblyProgram* target) WARN_UNUSED_RESULT; 158 CheckBool ParseFile(AssemblyProgram* target) WARN_UNUSED_RESULT;
154 159
155 CheckBool ParseProgbitsSection( 160 CheckBool ParseProgbitsSection(
156 const Elf32_Shdr* section_header, 161 const Elf32_Shdr* section_header,
157 std::vector<FileOffset>::iterator* current_abs_offset, 162 std::vector<FileOffset>::iterator* current_abs_offset,
158 std::vector<FileOffset>::iterator end_abs_offset, 163 std::vector<FileOffset>::iterator end_abs_offset,
159 ScopedVector<TypedRVA>::iterator* current_rel, 164 std::vector<std::unique_ptr<TypedRVA>>::iterator* current_rel,
160 ScopedVector<TypedRVA>::iterator end_rel, 165 std::vector<std::unique_ptr<TypedRVA>>::iterator end_rel,
161 AssemblyProgram* program) WARN_UNUSED_RESULT; 166 AssemblyProgram* program) WARN_UNUSED_RESULT;
162 167
163 CheckBool ParseSimpleRegion(FileOffset start_file_offset, 168 CheckBool ParseSimpleRegion(FileOffset start_file_offset,
164 FileOffset end_file_offset, 169 FileOffset end_file_offset,
165 AssemblyProgram* program) WARN_UNUSED_RESULT; 170 AssemblyProgram* program) WARN_UNUSED_RESULT;
166 171
167 CheckBool ParseAbs32Relocs() WARN_UNUSED_RESULT; 172 CheckBool ParseAbs32Relocs() WARN_UNUSED_RESULT;
168 173
169 CheckBool CheckSection(RVA rva) WARN_UNUSED_RESULT; 174 CheckBool CheckSection(RVA rva) WARN_UNUSED_RESULT;
170 175
(...skipping 11 matching lines...) Expand all
182 std::vector<Elf32_Half> section_header_file_offset_order_; 187 std::vector<Elf32_Half> section_header_file_offset_order_;
183 188
184 const Elf32_Phdr* program_header_table_; 189 const Elf32_Phdr* program_header_table_;
185 Elf32_Half program_header_table_size_; 190 Elf32_Half program_header_table_size_;
186 191
187 // Pointer to string table containing section names. 192 // Pointer to string table containing section names.
188 const char* default_string_section_; 193 const char* default_string_section_;
189 size_t default_string_section_size_; 194 size_t default_string_section_size_;
190 195
191 std::vector<RVA> abs32_locations_; 196 std::vector<RVA> abs32_locations_;
192 ScopedVector<TypedRVA> rel32_locations_; 197 std::vector<std::unique_ptr<TypedRVA>> rel32_locations_;
193 198
194 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); 199 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32);
195 }; 200 };
196 201
197 } // namespace courgette 202 } // namespace courgette
198 203
199 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ 204 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_
OLDNEW
« no previous file with comments | « no previous file | courgette/disassembler_elf_32.cc » ('j') | courgette/disassembler_elf_32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698