| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | |
| 12 | |
| 13 #include "base/macros.h" | 11 #include "base/macros.h" |
| 14 #include "courgette/disassembler_elf_32.h" | 12 #include "courgette/disassembler_elf_32.h" |
| 13 #include "courgette/memory_allocator.h" |
| 15 #include "courgette/types_elf.h" | 14 #include "courgette/types_elf.h" |
| 16 | 15 |
| 17 namespace courgette { | 16 namespace courgette { |
| 18 | 17 |
| 19 class AssemblyProgram; | 18 class AssemblyProgram; |
| 20 | 19 |
| 21 class DisassemblerElf32X86 : public DisassemblerElf32 { | 20 class DisassemblerElf32X86 : public DisassemblerElf32 { |
| 22 public: | 21 public: |
| 23 class TypedRVAX86 : public TypedRVA { | 22 class TypedRVAX86 : public TypedRVA { |
| 24 public: | 23 public: |
| 25 explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { } | 24 explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { |
| 26 ~TypedRVAX86() override { } | 25 } |
| 27 | 26 |
| 28 // TypedRVA interfaces. | 27 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override { |
| 29 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override; | 28 set_relative_target(Read32LittleEndian(op_pointer) + 4); |
| 29 return true; |
| 30 } |
| 31 |
| 30 CheckBool EmitInstruction(AssemblyProgram* program, | 32 CheckBool EmitInstruction(AssemblyProgram* program, |
| 31 RVA target_rva) override; | 33 RVA target_rva) override { |
| 32 uint16_t op_size() const override; | 34 return program->EmitRel32(program->FindOrMakeRel32Label(target_rva)); |
| 35 } |
| 36 |
| 37 uint16_t op_size() const override { return 4; } |
| 33 }; | 38 }; |
| 34 | 39 |
| 35 DisassemblerElf32X86(const void* start, size_t length); | 40 explicit DisassemblerElf32X86(const void* start, size_t length); |
| 36 | 41 |
| 37 ~DisassemblerElf32X86() override { } | 42 virtual ExecutableType kind() { return EXE_ELF_32_X86; } |
| 38 | 43 |
| 39 // DisassemblerElf32 interfaces. | 44 virtual e_machine_values ElfEM() { return EM_386; } |
| 40 ExecutableType kind() const override { return EXE_ELF_32_X86; } | |
| 41 e_machine_values ElfEM() const override { return EM_386; } | |
| 42 | 45 |
| 43 protected: | 46 protected: |
| 44 // DisassemblerElf32 interfaces. | 47 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) |
| 45 CheckBool RelToRVA(Elf32_Rel rel, | 48 const WARN_UNUSED_RESULT; |
| 46 RVA* result) const override WARN_UNUSED_RESULT; | 49 |
| 47 CheckBool ParseRelocationSection(const Elf32_Shdr* section_header, | 50 virtual CheckBool ParseRelocationSection( |
| 48 AssemblyProgram* program) | 51 const Elf32_Shdr *section_header, |
| 49 override WARN_UNUSED_RESULT; | 52 AssemblyProgram* program) WARN_UNUSED_RESULT; |
| 50 CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section) | 53 |
| 51 override WARN_UNUSED_RESULT; | 54 virtual CheckBool ParseRel32RelocsFromSection( |
| 55 const Elf32_Shdr* section) WARN_UNUSED_RESULT; |
| 52 | 56 |
| 53 #if COURGETTE_HISTOGRAM_TARGETS | 57 #if COURGETTE_HISTOGRAM_TARGETS |
| 54 std::map<RVA, int> rel32_target_rvas_; | 58 std::map<RVA, int> rel32_target_rvas_; |
| 55 #endif | 59 #endif |
| 56 | 60 |
| 57 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); | 61 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 } // namespace courgette | 64 } // namespace courgette |
| 61 | 65 |
| 62 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ | 66 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ |
| OLD | NEW |