OLD | NEW |
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 "base/basictypes.h" | 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include "base/macros.h" |
9 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
10 #include "courgette/assembly_program.h" | 13 #include "courgette/assembly_program.h" |
11 #include "courgette/disassembler.h" | 14 #include "courgette/disassembler.h" |
12 #include "courgette/memory_allocator.h" | 15 #include "courgette/memory_allocator.h" |
13 #include "courgette/types_elf.h" | 16 #include "courgette/types_elf.h" |
14 | 17 |
15 namespace courgette { | 18 namespace courgette { |
16 | 19 |
17 class AssemblyProgram; | 20 class AssemblyProgram; |
18 | 21 |
(...skipping 30 matching lines...) Expand all Loading... |
49 | 52 |
50 size_t get_offset() { | 53 size_t get_offset() { |
51 return offset_; | 54 return offset_; |
52 } | 55 } |
53 | 56 |
54 void set_offset(size_t offset) { | 57 void set_offset(size_t offset) { |
55 offset_ = offset; | 58 offset_ = offset; |
56 } | 59 } |
57 | 60 |
58 // Computes the relative jump's offset from the op in p. | 61 // Computes the relative jump's offset from the op in p. |
59 virtual CheckBool ComputeRelativeTarget(const uint8* op_pointer) = 0; | 62 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0; |
60 | 63 |
61 // Emits the courgette instruction corresponding to the RVA type. | 64 // Emits the courgette instruction corresponding to the RVA type. |
62 virtual CheckBool EmitInstruction(AssemblyProgram* program, | 65 virtual CheckBool EmitInstruction(AssemblyProgram* program, |
63 RVA target_rva) = 0; | 66 RVA target_rva) = 0; |
64 | 67 |
65 virtual uint16 op_size() const = 0; | 68 virtual uint16_t op_size() const = 0; |
66 | 69 |
67 static bool IsLessThan(TypedRVA *a, TypedRVA *b) { | 70 static bool IsLessThan(TypedRVA *a, TypedRVA *b) { |
68 return a->rva() < b->rva(); | 71 return a->rva() < b->rva(); |
69 } | 72 } |
70 | 73 |
71 private: | 74 private: |
72 const RVA rva_; | 75 const RVA rva_; |
73 RVA relative_target_; | 76 RVA relative_target_; |
74 size_t offset_; | 77 size_t offset_; |
75 }; | 78 }; |
(...skipping 26 matching lines...) Expand all Loading... |
102 | 105 |
103 Elf32_Half SectionHeaderCount() const { | 106 Elf32_Half SectionHeaderCount() const { |
104 return section_header_table_size_; | 107 return section_header_table_size_; |
105 } | 108 } |
106 | 109 |
107 const Elf32_Shdr *SectionHeader(int id) const { | 110 const Elf32_Shdr *SectionHeader(int id) const { |
108 assert(id >= 0 && id < SectionHeaderCount()); | 111 assert(id >= 0 && id < SectionHeaderCount()); |
109 return section_header_table_ + id; | 112 return section_header_table_ + id; |
110 } | 113 } |
111 | 114 |
112 const uint8 *SectionBody(int id) const { | 115 const uint8_t* SectionBody(int id) const { |
113 return OffsetToPointer(SectionHeader(id)->sh_offset); | 116 return OffsetToPointer(SectionHeader(id)->sh_offset); |
114 } | 117 } |
115 | 118 |
116 Elf32_Word SectionBodySize(int id) const { | 119 Elf32_Word SectionBodySize(int id) const { |
117 return SectionHeader(id)->sh_size; | 120 return SectionHeader(id)->sh_size; |
118 } | 121 } |
119 | 122 |
120 // Misc Segment Helpers | 123 // Misc Segment Helpers |
121 | 124 |
122 Elf32_Half ProgramSegmentHeaderCount() const { | 125 Elf32_Half ProgramSegmentHeaderCount() const { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 204 |
202 std::vector<RVA> abs32_locations_; | 205 std::vector<RVA> abs32_locations_; |
203 ScopedVector<TypedRVA> rel32_locations_; | 206 ScopedVector<TypedRVA> rel32_locations_; |
204 | 207 |
205 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); | 208 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); |
206 }; | 209 }; |
207 | 210 |
208 } // namespace courgette | 211 } // namespace courgette |
209 | 212 |
210 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ | 213 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ |
OLD | NEW |