ExceptionCapstone.hpp 942 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <Exception.hpp>
  3. #include <capstone/capstone.h>
  4. namespace nkg {
  5. class CapstoneError final : public Exception {
  6. private:
  7. cs_err _ErrorCode;
  8. std::xstring _ErrorString;
  9. public:
  10. CapstoneError(PCTSTR SourceFile, SIZE_T SourceLine, cs_err CapstoneErrorCode, PCTSTR CustomMessage) noexcept :
  11. Exception(SourceFile, SourceLine, CustomMessage),
  12. _ErrorCode(CapstoneErrorCode),
  13. _ErrorString(std::xstring_extension{}, cs_strerror(CapstoneErrorCode), CP_UTF8) {}
  14. [[nodiscard]]
  15. virtual bool HasErrorCode() const noexcept override {
  16. return true;
  17. }
  18. [[nodiscard]]
  19. virtual ULONG_PTR ErrorCode() const noexcept override {
  20. return _ErrorCode;
  21. }
  22. [[nodiscard]]
  23. virtual PCTSTR ErrorString() const noexcept override {
  24. return _ErrorString.c_str();
  25. }
  26. };
  27. }