| 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_ARM_H_ | 5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ |
| 6 #define COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ | 6 #define COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include "base/macros.h" |
| 9 #include "courgette/disassembler_elf_32.h" | 12 #include "courgette/disassembler_elf_32.h" |
| 10 #include "courgette/memory_allocator.h" | 13 #include "courgette/memory_allocator.h" |
| 11 #include "courgette/types_elf.h" | 14 #include "courgette/types_elf.h" |
| 12 | 15 |
| 13 namespace courgette { | 16 namespace courgette { |
| 14 | 17 |
| 15 class AssemblyProgram; | 18 class AssemblyProgram; |
| 16 | 19 |
| 17 enum ARM_RVA { | 20 enum ARM_RVA { |
| 18 ARM_OFF8, | 21 ARM_OFF8, |
| 19 ARM_OFF11, | 22 ARM_OFF11, |
| 20 ARM_OFF24, | 23 ARM_OFF24, |
| 21 ARM_OFF25, | 24 ARM_OFF25, |
| 22 ARM_OFF21, | 25 ARM_OFF21, |
| 23 }; | 26 }; |
| 24 | 27 |
| 25 class DisassemblerElf32ARM : public DisassemblerElf32 { | 28 class DisassemblerElf32ARM : public DisassemblerElf32 { |
| 26 public: | 29 public: |
| 27 class TypedRVAARM : public TypedRVA { | 30 class TypedRVAARM : public TypedRVA { |
| 28 public: | 31 public: |
| 29 TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { } | 32 TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { } |
| 30 | 33 |
| 31 uint16 c_op() const { | 34 uint16_t c_op() const { return c_op_; } |
| 32 return c_op_; | |
| 33 } | |
| 34 | 35 |
| 35 virtual CheckBool ComputeRelativeTarget(const uint8* op_pointer); | 36 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer); |
| 36 | 37 |
| 37 virtual CheckBool EmitInstruction(AssemblyProgram* program, | 38 virtual CheckBool EmitInstruction(AssemblyProgram* program, |
| 38 RVA target_rva); | 39 RVA target_rva); |
| 39 | 40 |
| 40 virtual uint16 op_size() const; | 41 virtual uint16_t op_size() const; |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 ARM_RVA type_; | 44 ARM_RVA type_; |
| 44 | 45 |
| 45 uint16 c_op_; // set by ComputeRelativeTarget() | 46 uint16_t c_op_; // set by ComputeRelativeTarget() |
| 46 const uint8* arm_op_; | 47 const uint8_t* arm_op_; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 explicit DisassemblerElf32ARM(const void* start, size_t length); | 50 explicit DisassemblerElf32ARM(const void* start, size_t length); |
| 50 | 51 |
| 51 virtual ExecutableType kind() { return EXE_ELF_32_ARM; } | 52 virtual ExecutableType kind() { return EXE_ELF_32_ARM; } |
| 52 | 53 |
| 53 virtual e_machine_values ElfEM() { return EM_ARM; } | 54 virtual e_machine_values ElfEM() { return EM_ARM; } |
| 54 | 55 |
| 55 static CheckBool Compress(ARM_RVA type, uint32 arm_op, RVA rva, | 56 static CheckBool Compress(ARM_RVA type, |
| 56 uint16* c_op /* out */, uint32* addr /* out */); | 57 uint32_t arm_op, |
| 58 RVA rva, |
| 59 uint16_t* c_op /* out */, |
| 60 uint32_t* addr /* out */); |
| 57 | 61 |
| 58 static CheckBool Decompress(ARM_RVA type, uint16 c_op, uint32 addr, | 62 static CheckBool Decompress(ARM_RVA type, |
| 59 uint32* arm_op /* out */); | 63 uint16_t c_op, |
| 64 uint32_t addr, |
| 65 uint32_t* arm_op /* out */); |
| 60 | 66 |
| 61 protected: | 67 protected: |
| 62 | 68 |
| 63 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) | 69 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) |
| 64 const WARN_UNUSED_RESULT; | 70 const WARN_UNUSED_RESULT; |
| 65 | 71 |
| 66 virtual CheckBool ParseRelocationSection( | 72 virtual CheckBool ParseRelocationSection( |
| 67 const Elf32_Shdr *section_header, | 73 const Elf32_Shdr *section_header, |
| 68 AssemblyProgram* program) WARN_UNUSED_RESULT; | 74 AssemblyProgram* program) WARN_UNUSED_RESULT; |
| 69 | 75 |
| 70 virtual CheckBool ParseRel32RelocsFromSection( | 76 virtual CheckBool ParseRel32RelocsFromSection( |
| 71 const Elf32_Shdr* section) WARN_UNUSED_RESULT; | 77 const Elf32_Shdr* section) WARN_UNUSED_RESULT; |
| 72 | 78 |
| 73 #if COURGETTE_HISTOGRAM_TARGETS | 79 #if COURGETTE_HISTOGRAM_TARGETS |
| 74 std::map<RVA, int> rel32_target_rvas_; | 80 std::map<RVA, int> rel32_target_rvas_; |
| 75 #endif | 81 #endif |
| 76 | 82 |
| 77 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM); | 83 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM); |
| 78 }; | 84 }; |
| 79 | 85 |
| 80 } // namespace courgette | 86 } // namespace courgette |
| 81 | 87 |
| 82 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ | 88 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ |
| OLD | NEW |