diff --git a/src/library/driver.hpp b/src/library/driver.hpp index 4513a6e..406b2b6 100644 --- a/src/library/driver.hpp +++ b/src/library/driver.hpp @@ -14,6 +14,11 @@ public: driver(driver&& obj) noexcept = default;; driver& operator=(driver&& obj) noexcept = default; + operator bool() const + { + return this->service_; + } + private: service_handle manager_{}; service_handle service_{}; diff --git a/src/library/main.cpp b/src/library/main.cpp index 4e59398..53262f6 100644 --- a/src/library/main.cpp +++ b/src/library/main.cpp @@ -44,28 +44,48 @@ driver_device& get_driver_device() static driver hypervisor{}; static driver_device device{}; - if (device) - { - return device; - } - - try - { - device = create_driver_device(); - } - catch (...) + if (!hypervisor) { hypervisor = create_driver(); + } + + if (!device) + { device = create_driver_device(); } return device; } +extern "C" __declspec(dllexport) +int hyperhook_initialize() +{ + try + { + const auto& device = get_driver_device(); + if (device) + { + return 1; + } + } + catch (const std::exception& e) + { + printf("%s\n", e.what()); + } + + return 0; +} + + extern "C" __declspec(dllexport) int hyperhook_write(const unsigned int process_id, const unsigned long long address, const void* data, const unsigned long long size) { + if (hyperhook_initialize() == 0) + { + return 0; + } + try { const auto& device = get_driver_device(); diff --git a/src/runner/main.cpp b/src/runner/main.cpp index 1caf653..7562363 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -6,6 +6,9 @@ #include "resource.hpp" +extern "C" __declspec(dllimport) +int hyperhook_initialize(); + extern "C" __declspec(dllimport) int hyperhook_write(unsigned int process_id, unsigned long long address, const void* data, unsigned long long size); @@ -99,6 +102,11 @@ void try_patch_t6() int safe_main(const int /*argc*/, char* /*argv*/[]) { + if (hyperhook_initialize() == 0) + { + throw std::runtime_error("Failed to initialize HyperHook"); + } + while (true) { try_patch_iw5();