diff --git a/src/include/hyperhook.h b/src/include/hyperhook.h new file mode 100644 index 0000000..5893ad7 --- /dev/null +++ b/src/include/hyperhook.h @@ -0,0 +1,18 @@ +#ifndef EXTERN_C +#ifdef __cplusplus +#define EXTERN_C extern "C" +#else +#define EXTERN_C +#endif +#endif + +#ifndef DLL_IMPORT +#define DLL_IMPORT __declspec(dllimport) +#endif + +EXTERN_C DLL_IMPORT +int hyperhook_initialize(); + +EXTERN_C DLL_IMPORT +int hyperhook_write(unsigned int process_id, unsigned long long address, const void* data, + unsigned long long size); diff --git a/src/library/CMakeLists.txt b/src/library/CMakeLists.txt index faf1cef..fdb9cb8 100644 --- a/src/library/CMakeLists.txt +++ b/src/library/CMakeLists.txt @@ -15,6 +15,10 @@ target_link_libraries(library PRIVATE driver_file ) +target_include_directories(library PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/../include +) + set_source_files_properties(resource.rc PROPERTIES LANGUAGE RC) target_sources(library PRIVATE resource.rc diff --git a/src/library/main.cpp b/src/library/main.cpp index 53262f6..6159cd2 100644 --- a/src/library/main.cpp +++ b/src/library/main.cpp @@ -1,63 +1,64 @@ #include "std_include.hpp" -#include -#include -#include - #include "driver.hpp" #include "driver_device.hpp" #include #include -#include "resource.hpp" #include "utils/io.hpp" -void patch_data(const driver_device& driver_device, const uint32_t pid, const uint64_t address, const uint8_t* buffer, - const size_t length) +#define DLL_IMPORT __declspec(dllexport) +#include + +namespace { - hook_request hook_request{}; - hook_request.process_id = pid; - hook_request.target_address = reinterpret_cast(address); - - hook_request.source_data = buffer; - hook_request.source_data_size = length; - - driver_device::data input{}; - input.assign(reinterpret_cast(&hook_request), - reinterpret_cast(&hook_request) + sizeof(hook_request)); - - (void)driver_device.send(HOOK_DRV_IOCTL, input); -} - -driver_device create_driver_device() -{ - return driver_device{R"(\\.\HyperHook)"}; -} - -driver create_driver() -{ - return driver{std::filesystem::absolute(DRIVER_NAME), "HyperHook"}; -} - -driver_device& get_driver_device() -{ - static driver hypervisor{}; - static driver_device device{}; - - if (!hypervisor) + void patch_data(const driver_device& driver_device, const uint32_t pid, const uint64_t address, + const uint8_t* buffer, + const size_t length) { - hypervisor = create_driver(); + hook_request hook_request{}; + hook_request.process_id = pid; + hook_request.target_address = reinterpret_cast(address); + + hook_request.source_data = buffer; + hook_request.source_data_size = length; + + driver_device::data input{}; + input.assign(reinterpret_cast(&hook_request), + reinterpret_cast(&hook_request) + sizeof(hook_request)); + + (void)driver_device.send(HOOK_DRV_IOCTL, input); } - if (!device) + driver_device create_driver_device() { - device = create_driver_device(); + return driver_device{R"(\\.\HyperHook)"}; } - return device; + driver create_driver() + { + return driver{std::filesystem::absolute(DRIVER_NAME), "HyperHook"}; + } + + driver_device& get_driver_device() + { + static driver hypervisor{}; + static driver_device device{}; + + if (!hypervisor) + { + hypervisor = create_driver(); + } + + if (!device) + { + device = create_driver_device(); + } + + return device; + } } -extern "C" __declspec(dllexport) int hyperhook_initialize() { try @@ -76,8 +77,6 @@ int hyperhook_initialize() 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) { diff --git a/src/library/resource.hpp b/src/library/resource.hpp deleted file mode 100644 index 6f70f09..0000000 --- a/src/library/resource.hpp +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/src/library/resource.rc b/src/library/resource.rc index ebe8d4f..e11499b 100644 --- a/src/library/resource.rc +++ b/src/library/resource.rc @@ -8,7 +8,6 @@ // Generated from the TEXTINCLUDE 2 resource. // #include "windows.h" -#include "resource.hpp" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS diff --git a/src/library/std_include.hpp b/src/library/std_include.hpp index f9bd296..1d2a631 100644 --- a/src/library/std_include.hpp +++ b/src/library/std_include.hpp @@ -5,10 +5,13 @@ #include #include #include +#include +#include #include #include #include #include +#include #pragma comment(lib, "Shlwapi.lib") diff --git a/src/runner/CMakeLists.txt b/src/runner/CMakeLists.txt index 438d80f..e5db6ae 100644 --- a/src/runner/CMakeLists.txt +++ b/src/runner/CMakeLists.txt @@ -6,10 +6,6 @@ add_executable(runner #WIN32 ${runner_headers} ) -target_precompile_headers(runner PRIVATE - std_include.hpp -) - set_property(TARGET runner APPEND_STRING PROPERTY LINK_FLAGS " /MANIFESTUAC:\"level='requireAdministrator'\"") target_link_libraries(runner PRIVATE diff --git a/src/runner/main.cpp b/src/runner/main.cpp index 7562363..26444f7 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -1,17 +1,13 @@ -#include "std_include.hpp" - -#include +#include #include -#include +#include +#include -#include "resource.hpp" +#define WIN32_LEAN_AND_MEAN +#include -extern "C" __declspec(dllimport) -int hyperhook_initialize(); +#include -extern "C" __declspec(dllimport) -int hyperhook_write(unsigned int process_id, unsigned long long address, const void* data, - unsigned long long size); bool patch_data(const uint32_t process_id, const uint64_t address, const void* buffer, const size_t length) diff --git a/src/runner/resource.hpp b/src/runner/resource.hpp deleted file mode 100644 index 6f70f09..0000000 --- a/src/runner/resource.hpp +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/src/runner/resource.rc b/src/runner/resource.rc index 6755767..5444da7 100644 --- a/src/runner/resource.rc +++ b/src/runner/resource.rc @@ -8,7 +8,6 @@ // Generated from the TEXTINCLUDE 2 resource. // #include "windows.h" -#include "resource.hpp" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS diff --git a/src/runner/std_include.hpp b/src/runner/std_include.hpp deleted file mode 100644 index f9bd296..0000000 --- a/src/runner/std_include.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#pragma comment(lib, "Shlwapi.lib")