disassembler_elf_32_x86.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  3. // found in the LICENSE file.
  4. #ifndef COURGETTE_DISASSEMBLER_ELF_32_X86_H_
  5. #define COURGETTE_DISASSEMBLER_ELF_32_X86_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <map>
  9. #include "courgette/disassembler_elf_32.h"
  10. #include "courgette/types_elf.h"
  11. namespace courgette {
  12. class InstructionReceptor;
  13. class DisassemblerElf32X86 : public DisassemblerElf32 {
  14. public:
  15. // Returns true if a valid executable is detected using only quick checks.
  16. static bool QuickDetect(const uint8_t* start, size_t length) {
  17. return DisassemblerElf32::QuickDetect(start, length, EM_386);
  18. }
  19. class TypedRVAX86 : public TypedRVA {
  20. public:
  21. explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { }
  22. ~TypedRVAX86() override { }
  23. // TypedRVA interfaces.
  24. CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override;
  25. CheckBool EmitInstruction(Label* label,
  26. InstructionReceptor* receptor) override;
  27. uint16_t op_size() const override;
  28. };
  29. DisassemblerElf32X86(const uint8_t* start, size_t length);
  30. DisassemblerElf32X86(const DisassemblerElf32X86&) = delete;
  31. DisassemblerElf32X86& operator=(const DisassemblerElf32X86&) = delete;
  32. ~DisassemblerElf32X86() override { }
  33. // DisassemblerElf32 interfaces.
  34. ExecutableType kind() const override { return EXE_ELF_32_X86; }
  35. e_machine_values ElfEM() const override { return EM_386; }
  36. protected:
  37. // DisassemblerElf32 interfaces.
  38. [[nodiscard]] CheckBool RelToRVA(Elf32_Rel rel, RVA* result) const override;
  39. [[nodiscard]] CheckBool ParseRelocationSection(
  40. const Elf32_Shdr* section_header,
  41. InstructionReceptor* receptor) const override;
  42. [[nodiscard]] CheckBool ParseRel32RelocsFromSection(
  43. const Elf32_Shdr* section) override;
  44. #if COURGETTE_HISTOGRAM_TARGETS
  45. std::map<RVA, int> rel32_target_rvas_;
  46. #endif
  47. };
  48. } // namespace courgette
  49. #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_