diff --git a/common/exceptions/index_exception.hpp b/common/exceptions/index_exception.hpp index f49d1c1..568aa30 100644 --- a/common/exceptions/index_exception.hpp +++ b/common/exceptions/index_exception.hpp @@ -4,9 +4,7 @@ namespace nkg::exceptions { class index_exception : public ::nkg::exception { - public: - index_exception(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} + using ::nkg::exception::exception; }; } diff --git a/common/exceptions/key_exception.hpp b/common/exceptions/key_exception.hpp index 6809748..933f8e1 100644 --- a/common/exceptions/key_exception.hpp +++ b/common/exceptions/key_exception.hpp @@ -4,9 +4,7 @@ namespace nkg::exceptions { class key_exception : public ::nkg::exception { - public: - key_exception(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} + using ::nkg::exception::exception; }; } diff --git a/common/exceptions/operation_canceled_exception.hpp b/common/exceptions/operation_canceled_exception.hpp index 5a1053c..b395175 100644 --- a/common/exceptions/operation_canceled_exception.hpp +++ b/common/exceptions/operation_canceled_exception.hpp @@ -4,9 +4,7 @@ namespace nkg::exceptions { class operation_canceled_exception : public ::nkg::exception { - public: - operation_canceled_exception(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} + using ::nkg::exception::exception; }; } diff --git a/common/rsa_cipher.hpp b/common/rsa_cipher.hpp index 8f0c212..df13e9d 100644 --- a/common/rsa_cipher.hpp +++ b/common/rsa_cipher.hpp @@ -17,42 +17,8 @@ namespace nkg { class rsa_cipher { public: - class no_key_assigned_error : public ::nkg::exception { - public: - no_key_assigned_error(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; - - class backend_error : public ::nkg::exception { - public: - using error_code_t = decltype(ERR_get_error()); - - private: - std::optional m_error_code; - std::string m_error_string; - - public: - backend_error(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - - backend_error(std::string_view file, int line, error_code_t openssl_errno, std::string_view message) noexcept : - ::nkg::exception(file, line, message), m_error_code(openssl_errno) {} - - [[nodiscard]] - virtual bool error_code_exists() const noexcept override { - return m_error_code.has_value(); - } - - [[nodiscard]] - virtual intptr_t error_code() const noexcept override { - if (error_code_exists()) { return m_error_code.value(); } else { trap_then_terminate(); } - } - - [[nodiscard]] - virtual const std::string& error_string() const noexcept override { - if (error_code_exists()) { return m_error_string; } else { trap_then_terminate(); } - } - }; + class backend_error; + class no_key_assigned_error; private: resource_wrapper m_rsa; @@ -73,7 +39,6 @@ namespace nkg { static void _write_public_key_pkcs1_to_bio(RSA* p_rsa, BIO* p_bio); public: - rsa_cipher(); [[nodiscard]] @@ -117,6 +82,41 @@ namespace nkg { size_t private_decrypt(const void* ciphertext, size_t ciphertext_size, void* plaintext, int padding) const; }; + class rsa_cipher::backend_error : public ::nkg::exception { + public: + using error_code_t = decltype(ERR_get_error()); + + private: + std::optional m_error_code; + std::string m_error_string; + + public: + backend_error(std::string_view file, int line, std::string_view message) noexcept : + ::nkg::exception(file, line, message) {} + + backend_error(std::string_view file, int line, error_code_t openssl_errno, std::string_view message) noexcept : + ::nkg::exception(file, line, message), m_error_code(openssl_errno) {} + + [[nodiscard]] + virtual bool error_code_exists() const noexcept override { + return m_error_code.has_value(); + } + + [[nodiscard]] + virtual intptr_t error_code() const noexcept override { + if (error_code_exists()) { return m_error_code.value(); } else { trap_then_terminate(); } + } + + [[nodiscard]] + virtual const std::string& error_string() const noexcept override { + if (error_code_exists()) { return m_error_string; } else { trap_then_terminate(); } + } + }; + + class rsa_cipher::no_key_assigned_error : public ::nkg::exception { + using ::nkg::exception::exception; + }; + } #undef NKG_CURRENT_SOURCE_FILE diff --git a/navicat-keygen/base32_rfc4648.hpp b/navicat-keygen/base32_rfc4648.hpp index 530c0d9..f00d846 100644 --- a/navicat-keygen/base32_rfc4648.hpp +++ b/navicat-keygen/base32_rfc4648.hpp @@ -11,11 +11,7 @@ namespace nkg { static constexpr const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; static constexpr const char padding_character = '='; - class decoding_error : public ::nkg::exception { - public: - decoding_error(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; + class decoding_error; static char symbol(alphabet_index_t idx); @@ -28,4 +24,8 @@ namespace nkg { static std::vector decode(std::string_view b32_string); }; + class base32_rfc4648::decoding_error : public ::nkg::exception { + using ::nkg::exception::exception; + }; + } diff --git a/navicat-keygen/base64_rfc4648.hpp b/navicat-keygen/base64_rfc4648.hpp index a67b435..8f7e0de 100644 --- a/navicat-keygen/base64_rfc4648.hpp +++ b/navicat-keygen/base64_rfc4648.hpp @@ -6,15 +6,15 @@ namespace nkg { struct base64_rfc4648 { - class backend_error : public ::nkg::exception { - public: - backend_error(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; + class backend_error; static std::string encode(const std::vector& data); static std::vector decode(std::string_view str_b64); }; + class base64_rfc4648::backend_error : public ::nkg::exception { + using ::nkg::exception::exception; + }; + } diff --git a/navicat-keygen/navicat_serial_generator.hpp b/navicat-keygen/navicat_serial_generator.hpp index d086132..75e6a06 100644 --- a/navicat-keygen/navicat_serial_generator.hpp +++ b/navicat-keygen/navicat_serial_generator.hpp @@ -35,11 +35,7 @@ namespace nkg { class navicat_serial_generator { public: - class version_error : public ::nkg::exception { - public: - version_error(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; + class version_error; private: static inline const DES_cblock s_des_key0 = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 }; @@ -72,4 +68,8 @@ namespace nkg { const std::string& serial_number_formatted() const noexcept; }; + class navicat_serial_generator::version_error : public ::nkg::exception { + using ::nkg::exception::exception; + }; + } diff --git a/navicat-patcher/elf64_interpreter.hpp b/navicat-patcher/elf64_interpreter.hpp index 377f0d3..7ef73b8 100644 --- a/navicat-patcher/elf64_interpreter.hpp +++ b/navicat-patcher/elf64_interpreter.hpp @@ -18,23 +18,9 @@ namespace nkg { using rva_t = uintptr_t; using va_t = uintptr_t; - class parse_error : public ::nkg::exception { - public: - parse_error(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; - - class bad_fo_exception : public ::nkg::exception { - public: - bad_fo_exception(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; - - class bad_va_exception : public ::nkg::exception { - public: - bad_va_exception(std::string_view file, int line, std::string_view message) noexcept : - ::nkg::exception(file, line, message) {} - }; + class parse_error; + class bad_fo_exception; + class bad_va_exception; private: size_t m_elf_size; @@ -236,4 +222,16 @@ namespace nkg { const std::map& relocation_distribute() const; }; + class elf64_interpreter::parse_error : public ::nkg::exception { + using ::nkg::exception::exception; + }; + + class elf64_interpreter::bad_fo_exception : public ::nkg::exception { + using ::nkg::exception::exception; + }; + + class elf64_interpreter::bad_va_exception : public ::nkg::exception { + using ::nkg::exception::exception; + }; + } diff --git a/navicat-patcher/keystone_assembler.hpp b/navicat-patcher/keystone_assembler.hpp index 60a910c..9f7ab6a 100644 --- a/navicat-patcher/keystone_assembler.hpp +++ b/navicat-patcher/keystone_assembler.hpp @@ -12,33 +12,7 @@ namespace nkg { class keystone_assembler { public: - class backend_error : public ::nkg::exception { - public: - using error_code_t = ks_err; - - private: - error_code_t m_error_code; - std::string m_error_string; - - public: - backend_error(std::string_view file, int line, error_code_t keystone_err, std::string_view message) noexcept : - ::nkg::exception(file, line, message), m_error_code(keystone_err), m_error_string(ks_strerror(keystone_err)) {} - - [[nodiscard]] - virtual bool error_code_exists() const noexcept override { - return true; - } - - [[nodiscard]] - virtual intptr_t error_code() const noexcept override { - return m_error_code; - } - - [[nodiscard]] - virtual const std::string& error_string() const noexcept override { - return m_error_string; - } - }; + class backend_error; private: resource_wrapper m_keystone_engine; @@ -52,4 +26,32 @@ namespace nkg { std::vector assemble(std::string_view asm_string, uint64_t asm_address = 0) const; }; + class keystone_assembler::backend_error : public ::nkg::exception { + public: + using error_code_t = ks_err; + + private: + error_code_t m_error_code; + std::string m_error_string; + + public: + backend_error(std::string_view file, int line, error_code_t keystone_err, std::string_view message) noexcept : + ::nkg::exception(file, line, message), m_error_code(keystone_err), m_error_string(ks_strerror(keystone_err)) {} + + [[nodiscard]] + virtual bool error_code_exists() const noexcept override { + return true; + } + + [[nodiscard]] + virtual intptr_t error_code() const noexcept override { + return m_error_code; + } + + [[nodiscard]] + virtual const std::string& error_string() const noexcept override { + return m_error_string; + } + }; + }