| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 const Elf32_Shdr *SectionHeader(int id) const { | 110 const Elf32_Shdr *SectionHeader(int id) const { |
| 111 assert(id >= 0 && id < SectionHeaderCount()); | 111 assert(id >= 0 && id < SectionHeaderCount()); |
| 112 return section_header_table_ + id; | 112 return section_header_table_ + id; |
| 113 } | 113 } |
| 114 | 114 |
| 115 const uint8_t* SectionBody(int id) const { | 115 const uint8_t* SectionBody(int id) const { |
| 116 return OffsetToPointer(SectionHeader(id)->sh_offset); | 116 return OffsetToPointer(SectionHeader(id)->sh_offset); |
| 117 } | 117 } |
| 118 | 118 |
| 119 Elf32_Word SectionBodySize(int id) const { | |
| 120 return SectionHeader(id)->sh_size; | |
| 121 } | |
| 122 | |
| 123 // Misc Segment Helpers | 119 // Misc Segment Helpers |
| 124 | 120 |
| 125 Elf32_Half ProgramSegmentHeaderCount() const { | 121 Elf32_Half ProgramSegmentHeaderCount() const { |
| 126 return program_header_table_size_; | 122 return program_header_table_size_; |
| 127 } | 123 } |
| 128 | 124 |
| 129 const Elf32_Phdr *ProgramSegmentHeader(int id) const { | 125 const Elf32_Phdr *ProgramSegmentHeader(int id) const { |
| 130 assert(id >= 0 && id < ProgramSegmentHeaderCount()); | 126 assert(id >= 0 && id < ProgramSegmentHeaderCount()); |
| 131 return program_header_table_ + id; | 127 return program_header_table_ + id; |
| 132 } | 128 } |
| 133 | 129 |
| 134 // The virtual memory address at which this program segment will be loaded | |
| 135 Elf32_Addr ProgramSegmentMemoryBegin(int id) const { | |
| 136 return ProgramSegmentHeader(id)->p_vaddr; | |
| 137 } | |
| 138 | |
| 139 // The number of virtual memory bytes for this program segment | |
| 140 Elf32_Word ProgramSegmentMemorySize(int id) const { | |
| 141 return ProgramSegmentHeader(id)->p_memsz; | |
| 142 } | |
| 143 | |
| 144 // Pointer into the source file for this program segment | |
| 145 Elf32_Addr ProgramSegmentFileOffset(int id) const { | |
| 146 return ProgramSegmentHeader(id)->p_offset; | |
| 147 } | |
| 148 | |
| 149 // Number of file bytes for this program segment. Is <= ProgramMemorySize. | |
| 150 Elf32_Word ProgramSegmentFileSize(int id) const { | |
| 151 return ProgramSegmentHeader(id)->p_filesz; | |
| 152 } | |
| 153 | |
| 154 // Misc address space helpers | 130 // Misc address space helpers |
| 155 | 131 |
| 156 CheckBool IsValidRVA(RVA rva) const WARN_UNUSED_RESULT; | 132 CheckBool IsValidRVA(RVA rva) const WARN_UNUSED_RESULT; |
| 157 | 133 |
| 158 // Convert an ELF relocation struction into an RVA | 134 // Convert an ELF relocation struction into an RVA |
| 159 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) | 135 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) |
| 160 const WARN_UNUSED_RESULT = 0; | 136 const WARN_UNUSED_RESULT = 0; |
| 161 | 137 |
| 162 // Returns kNoOffset if there is no file offset corresponding to 'rva'. | 138 // Returns kNoOffset if there is no file offset corresponding to 'rva'. |
| 163 CheckBool RVAToFileOffset(RVA rva, size_t* result) const WARN_UNUSED_RESULT; | 139 CheckBool RVAToFileOffset(RVA rva, size_t* result) const WARN_UNUSED_RESULT; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 180 |
| 205 std::vector<RVA> abs32_locations_; | 181 std::vector<RVA> abs32_locations_; |
| 206 ScopedVector<TypedRVA> rel32_locations_; | 182 ScopedVector<TypedRVA> rel32_locations_; |
| 207 | 183 |
| 208 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); | 184 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32); |
| 209 }; | 185 }; |
| 210 | 186 |
| 211 } // namespace courgette | 187 } // namespace courgette |
| 212 | 188 |
| 213 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ | 189 #endif // COURGETTE_DISASSEMBLER_ELF_32_H_ |
| OLD | NEW |