CapstoneDisassembler.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "ExceptionCapstone.hpp"
  3. #include <ResourceOwned.hpp>
  4. #include "ResourceTraitsCapstone.hpp"
  5. namespace nkg {
  6. struct CapstoneContext {
  7. const void* lpMachineCode;
  8. size_t cbMachineCode;
  9. uint64_t Address;
  10. };
  11. class CapstoneEngine;
  12. class CapstoneDisassembler : private ResourceOwned<CapstoneInsnTraits> {
  13. friend class CapstoneEngine;
  14. private:
  15. const CapstoneEngine& _Engine;
  16. CapstoneContext _CurrentState;
  17. CapstoneContext _NextState;
  18. cs_insn* _lpCurrentInsn;
  19. CapstoneDisassembler(const CapstoneEngine& Engine);
  20. public:
  21. CapstoneDisassembler(CapstoneDisassembler&& Other) noexcept;
  22. CapstoneDisassembler& SetContext(const CapstoneContext& Ctx) noexcept;
  23. [[nodiscard]]
  24. const CapstoneContext& GetContext() const noexcept;
  25. [[nodiscard]]
  26. bool Next() noexcept;
  27. [[nodiscard]]
  28. const cs_insn* GetInstruction() const noexcept;
  29. [[nodiscard]]
  30. const CapstoneContext& GetInstructionContext() const noexcept;
  31. };
  32. class CapstoneEngine : private ResourceOwned<CapstoneHandleTraits> {
  33. friend class CapstoneDisassembler;
  34. public:
  35. CapstoneEngine(cs_arch ArchType, cs_mode Mode);
  36. void Option(cs_opt_type Type, cs_opt_value Value);
  37. const char* GetRegisterName(unsigned int reg_id) const noexcept;
  38. [[nodiscard]]
  39. CapstoneDisassembler CreateDisassembler() const;
  40. };
  41. }