| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_X86_H_ | 5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_X86_H_ |
| 6 #define COURGETTE_DISASSEMBLER_ELF_32_X86_H_ | 6 #define COURGETTE_DISASSEMBLER_ELF_32_X86_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 19 matching lines...) Expand all Loading... |
| 30 // Public for unittests only | 30 // Public for unittests only |
| 31 std::vector<RVA> &Abs32Locations() { return abs32_locations_; } | 31 std::vector<RVA> &Abs32Locations() { return abs32_locations_; } |
| 32 std::vector<RVA> &Rel32Locations() { return rel32_locations_; } | 32 std::vector<RVA> &Rel32Locations() { return rel32_locations_; } |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 | 35 |
| 36 uint32 DiscoverLength(); | 36 uint32 DiscoverLength(); |
| 37 | 37 |
| 38 // Misc Section Helpers | 38 // Misc Section Helpers |
| 39 | 39 |
| 40 const Elf32_Half SectionHeaderCount() const { | 40 Elf32_Half SectionHeaderCount() const { |
| 41 return section_header_table_size_; | 41 return section_header_table_size_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 const Elf32_Shdr *SectionHeader(int id) const { | 44 const Elf32_Shdr *SectionHeader(int id) const { |
| 45 assert(id >= 0 && id < SectionHeaderCount()); | 45 assert(id >= 0 && id < SectionHeaderCount()); |
| 46 return section_header_table_ + id; | 46 return section_header_table_ + id; |
| 47 } | 47 } |
| 48 | 48 |
| 49 const uint8 *SectionBody(int id) const { | 49 const uint8 *SectionBody(int id) const { |
| 50 return OffsetToPointer(SectionHeader(id)->sh_offset); | 50 return OffsetToPointer(SectionHeader(id)->sh_offset); |
| 51 } | 51 } |
| 52 | 52 |
| 53 const Elf32_Word SectionBodySize(int id) const { | 53 Elf32_Word SectionBodySize(int id) const { |
| 54 return SectionHeader(id)->sh_size; | 54 return SectionHeader(id)->sh_size; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Misc Segment Helpers | 57 // Misc Segment Helpers |
| 58 | 58 |
| 59 const Elf32_Half ProgramSegmentHeaderCount() const { | 59 Elf32_Half ProgramSegmentHeaderCount() const { |
| 60 return program_header_table_size_; | 60 return program_header_table_size_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 const Elf32_Phdr *ProgramSegmentHeader(int id) const { | 63 const Elf32_Phdr *ProgramSegmentHeader(int id) const { |
| 64 assert(id >= 0 && id < ProgramSegmentHeaderCount()); | 64 assert(id >= 0 && id < ProgramSegmentHeaderCount()); |
| 65 return program_header_table_ + id; | 65 return program_header_table_ + id; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // The virtual memory address at which this program segment will be loaded | 68 // The virtual memory address at which this program segment will be loaded |
| 69 const Elf32_Addr ProgramSegmentMemoryBegin(int id) const { | 69 Elf32_Addr ProgramSegmentMemoryBegin(int id) const { |
| 70 return ProgramSegmentHeader(id)->p_vaddr; | 70 return ProgramSegmentHeader(id)->p_vaddr; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // The number of virtual memory bytes for this program segment | 73 // The number of virtual memory bytes for this program segment |
| 74 const Elf32_Word ProgramSegmentMemorySize(int id) const { | 74 Elf32_Word ProgramSegmentMemorySize(int id) const { |
| 75 return ProgramSegmentHeader(id)->p_memsz; | 75 return ProgramSegmentHeader(id)->p_memsz; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Pointer into the source file for this program segment | 78 // Pointer into the source file for this program segment |
| 79 const Elf32_Addr ProgramSegmentFileOffset(int id) const { | 79 Elf32_Addr ProgramSegmentFileOffset(int id) const { |
| 80 return ProgramSegmentHeader(id)->p_offset; | 80 return ProgramSegmentHeader(id)->p_offset; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Number of file bytes for this program segment. Is <= ProgramMemorySize. | 83 // Number of file bytes for this program segment. Is <= ProgramMemorySize. |
| 84 const Elf32_Word ProgramSegmentFileSize(int id) const { | 84 Elf32_Word ProgramSegmentFileSize(int id) const { |
| 85 return ProgramSegmentHeader(id)->p_filesz; | 85 return ProgramSegmentHeader(id)->p_filesz; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Misc address space helpers | 88 // Misc address space helpers |
| 89 | 89 |
| 90 CheckBool IsValidRVA(RVA rva) const WARN_UNUSED_RESULT; | 90 CheckBool IsValidRVA(RVA rva) const WARN_UNUSED_RESULT; |
| 91 | 91 |
| 92 // Convert an ELF relocation struction into an RVA | 92 // Convert an ELF relocation struction into an RVA |
| 93 CheckBool RelToRVA(Elf32_Rel rel, RVA* result) const WARN_UNUSED_RESULT; | 93 CheckBool RelToRVA(Elf32_Rel rel, RVA* result) const WARN_UNUSED_RESULT; |
| 94 | 94 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 std::vector<RVA> abs32_locations_; | 135 std::vector<RVA> abs32_locations_; |
| 136 std::vector<RVA> rel32_locations_; | 136 std::vector<RVA> rel32_locations_; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); | 138 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 } // namespace courgette | 141 } // namespace courgette |
| 142 | 142 |
| 143 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ | 143 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ |
| OLD | NEW |