ResourceTraitsCapstone.hpp 726 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include <capstone/capstone.h>
  3. struct CapstoneHandleTraits {
  4. using HandleType = csh;
  5. static inline const HandleType InvalidValue = NULL;
  6. [[nodiscard]]
  7. static bool IsValid(const HandleType& Handle) noexcept {
  8. return Handle != InvalidValue;
  9. }
  10. static void Releasor(HandleType& Handle) noexcept {
  11. cs_close(&Handle);
  12. }
  13. };
  14. struct CapstoneInsnTraits {
  15. using HandleType = cs_insn*;
  16. static inline const HandleType InvalidValue = nullptr;
  17. [[nodiscard]]
  18. static bool IsValid(const HandleType& Handle) noexcept {
  19. return Handle != InvalidValue;
  20. }
  21. static void Releasor(const HandleType& Handle) noexcept {
  22. cs_free(Handle, 1);
  23. }
  24. };