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 "base/basictypes.h" |
9 #include "courgette/disassembler.h" | 9 #include "courgette/disassembler.h" |
10 #include "courgette/memory_allocator.h" | 10 #include "courgette/memory_allocator.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Public for unittests only | 40 // Public for unittests only |
41 std::vector<RVA> &Abs32Locations() { return abs32_locations_; } | 41 std::vector<RVA> &Abs32Locations() { return abs32_locations_; } |
42 std::vector<RVA> &Rel32Locations() { return rel32_locations_; } | 42 std::vector<RVA> &Rel32Locations() { return rel32_locations_; } |
43 | 43 |
44 protected: | 44 protected: |
45 | 45 |
46 uint32 DiscoverLength(); | 46 uint32 DiscoverLength(); |
47 | 47 |
48 // Misc Section Helpers | 48 // Misc Section Helpers |
49 | 49 |
50 const Elf32_Half SectionHeaderCount() const { | 50 Elf32_Half SectionHeaderCount() const { |
51 return section_header_table_size_; | 51 return section_header_table_size_; |
52 } | 52 } |
53 | 53 |
54 const Elf32_Shdr *SectionHeader(int id) const { | 54 const Elf32_Shdr *SectionHeader(int id) const { |
55 assert(id >= 0 && id < SectionHeaderCount()); | 55 assert(id >= 0 && id < SectionHeaderCount()); |
56 return section_header_table_ + id; | 56 return section_header_table_ + id; |
57 } | 57 } |
58 | 58 |
59 const uint8 *SectionBody(int id) const { | 59 const uint8 *SectionBody(int id) const { |
60 return OffsetToPointer(SectionHeader(id)->sh_offset); | 60 return OffsetToPointer(SectionHeader(id)->sh_offset); |
61 } | 61 } |
62 | 62 |
63 const Elf32_Word SectionBodySize(int id) const { | 63 Elf32_Word SectionBodySize(int id) const { |
64 return SectionHeader(id)->sh_size; | 64 return SectionHeader(id)->sh_size; |
65 } | 65 } |
66 | 66 |
67 // Misc Segment Helpers | 67 // Misc Segment Helpers |
68 | 68 |
69 const Elf32_Half ProgramSegmentHeaderCount() const { | 69 Elf32_Half ProgramSegmentHeaderCount() const { |
70 return program_header_table_size_; | 70 return program_header_table_size_; |
71 } | 71 } |
72 | 72 |
73 const Elf32_Phdr *ProgramSegmentHeader(int id) const { | 73 const Elf32_Phdr *ProgramSegmentHeader(int id) const { |
74 assert(id >= 0 && id < ProgramSegmentHeaderCount()); | 74 assert(id >= 0 && id < ProgramSegmentHeaderCount()); |
75 return program_header_table_ + id; | 75 return program_header_table_ + id; |
76 } | 76 } |
77 | 77 |
78 // The virtual memory address at which this program segment will be loaded | 78 // The virtual memory address at which this program segment will be loaded |
79 const Elf32_Addr ProgramSegmentMemoryBegin(int id) const { | 79 Elf32_Addr ProgramSegmentMemoryBegin(int id) const { |
80 return ProgramSegmentHeader(id)->p_vaddr; | 80 return ProgramSegmentHeader(id)->p_vaddr; |
81 } | 81 } |
82 | 82 |
83 // The number of virtual memory bytes for this program segment | 83 // The number of virtual memory bytes for this program segment |
84 const Elf32_Word ProgramSegmentMemorySize(int id) const { | 84 Elf32_Word ProgramSegmentMemorySize(int id) const { |
85 return ProgramSegmentHeader(id)->p_memsz; | 85 return ProgramSegmentHeader(id)->p_memsz; |
86 } | 86 } |
87 | 87 |
88 // Pointer into the source file for this program segment | 88 // Pointer into the source file for this program segment |
89 const Elf32_Addr ProgramSegmentFileOffset(int id) const { | 89 Elf32_Addr ProgramSegmentFileOffset(int id) const { |
90 return ProgramSegmentHeader(id)->p_offset; | 90 return ProgramSegmentHeader(id)->p_offset; |
91 } | 91 } |
92 | 92 |
93 // Number of file bytes for this program segment. Is <= ProgramMemorySize. | 93 // Number of file bytes for this program segment. Is <= ProgramMemorySize. |
94 const Elf32_Word ProgramSegmentFileSize(int id) const { | 94 Elf32_Word ProgramSegmentFileSize(int id) const { |
95 return ProgramSegmentHeader(id)->p_filesz; | 95 return ProgramSegmentHeader(id)->p_filesz; |
96 } | 96 } |
97 | 97 |
98 // Misc address space helpers | 98 // Misc address space helpers |
99 | 99 |
100 CheckBool IsValidRVA(RVA rva) const WARN_UNUSED_RESULT; | 100 CheckBool IsValidRVA(RVA rva) const WARN_UNUSED_RESULT; |
101 | 101 |
102 // Convert an ELF relocation struction into an RVA | 102 // Convert an ELF relocation struction into an RVA |
103 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) | 103 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) |
104 const WARN_UNUSED_RESULT = 0; | 104 const WARN_UNUSED_RESULT = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 std::vector<RVA> abs32_locations_; | 146 std::vector<RVA> abs32_locations_; |
147 std::vector<RVA> rel32_locations_; | 147 std::vector<RVA> rel32_locations_; |
148 | 148 |
149 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); | 149 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); |
150 }; | 150 }; |
151 | 151 |
152 } // namespace courgette | 152 } // namespace courgette |
153 | 153 |
154 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ | 154 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ |
OLD | NEW |