From 2d3941a43e56faefb8dba839f25264a2aaa48307 Mon Sep 17 00:00:00 2001 From: maxraulea Date: Tue, 16 Jun 2026 15:17:13 +0200 Subject: [PATCH] signal handler platform independent API --- hyperdbg/CMakeLists.txt | 3 ++- .../include/platform/general/header/Environment.h | 15 +++++++++++++++ hyperdbg/libhyperdbg/CMakeLists.txt | 2 ++ .../code/debugger/core/interpreter.cpp | 2 +- hyperdbg/libhyperdbg/libhyperdbg.vcxproj | 2 ++ hyperdbg/libhyperdbg/libhyperdbg.vcxproj.filters | 6 ++++++ hyperdbg/libhyperdbg/pch.h | 5 +++++ 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/hyperdbg/CMakeLists.txt b/hyperdbg/CMakeLists.txt index bf2267a7..ba5b3855 100644 --- a/hyperdbg/CMakeLists.txt +++ b/hyperdbg/CMakeLists.txt @@ -74,7 +74,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") add_subdirectory(script-engine) link_directories(libraries/zydis/user libraries/keystone/release-lib) add_subdirectory(libhyperdbg) -target_link_libraries(libhyperdbg Zycore Zydis script-engine keystone) +find_package(Threads REQUIRED) +target_link_libraries(libhyperdbg Zycore Zydis script-engine keystone Threads::Threads) add_subdirectory(hyperdbg-cli) target_link_libraries(hyperdbg-cli libhyperdbg) diff --git a/hyperdbg/include/platform/general/header/Environment.h b/hyperdbg/include/platform/general/header/Environment.h index 59619c1c..4abf4d21 100644 --- a/hyperdbg/include/platform/general/header/Environment.h +++ b/hyperdbg/include/platform/general/header/Environment.h @@ -47,6 +47,9 @@ // wchar_t is a C++ built-in but needs this header in C # include +// POSIX sleep primitives (usleep) backing the Win32 Sleep() shim below +# include + // Windows string/char types typedef char TCHAR; typedef char * LPTSTR; @@ -78,4 +81,16 @@ typedef void * HMODULE; // Win32 invalid handle sentinel (returned by the cross-platform file/serial wrappers) # define INVALID_HANDLE_VALUE ((HANDLE)(SIZE_T)-1) +// Win32 console-control event codes (kept at their Windows values so the +// shared BreakController() switch compiles unchanged). On Linux these are +// produced by the platform-signal layer from POSIX signals. +# define CTRL_C_EVENT 0 +# define CTRL_BREAK_EVENT 1 +# define CTRL_CLOSE_EVENT 2 +# define CTRL_LOGOFF_EVENT 5 +# define CTRL_SHUTDOWN_EVENT 6 + +// Win32 Sleep(milliseconds) -> POSIX usleep(microseconds) +# define Sleep(Milliseconds) usleep((useconds_t)(Milliseconds) * 1000) + #endif // HYPERDBG_ENV_LINUX diff --git a/hyperdbg/libhyperdbg/CMakeLists.txt b/hyperdbg/libhyperdbg/CMakeLists.txt index a0bfa2df..fac7603f 100644 --- a/hyperdbg/libhyperdbg/CMakeLists.txt +++ b/hyperdbg/libhyperdbg/CMakeLists.txt @@ -31,6 +31,7 @@ set(SourceFiles "../include/platform/user/code/platform-lib-calls.c" "../include/platform/user/code/platform-serial.c" "../include/platform/user/code/platform-ioctl.c" + "../include/platform/user/code/platform-signal.c" "../script-eval/code/Functions.c" "../script-eval/code/Keywords.c" "../script-eval/code/PseudoRegisters.c" @@ -175,6 +176,7 @@ set_source_files_properties( "../include/platform/user/code/platform-lib-calls.c" "../include/platform/user/code/platform-serial.c" "../include/platform/user/code/platform-ioctl.c" + "../include/platform/user/code/platform-signal.c" "../script-eval/code/Functions.c" "../script-eval/code/Keywords.c" "../script-eval/code/PseudoRegisters.c" diff --git a/hyperdbg/libhyperdbg/code/debugger/core/interpreter.cpp b/hyperdbg/libhyperdbg/code/debugger/core/interpreter.cpp index 5d8055e2..62938326 100644 --- a/hyperdbg/libhyperdbg/code/debugger/core/interpreter.cpp +++ b/hyperdbg/libhyperdbg/code/debugger/core/interpreter.cpp @@ -1300,7 +1300,7 @@ InitializeDebugger() // // Register the CTRL+C and CTRL+BREAK Signals handler // - if (!SetConsoleCtrlHandler(BreakController, TRUE)) + if (!PlatformInstallCtrlHandler(BreakController)) { ShowMessages("err, when registering CTRL+C and CTRL+BREAK Signals " "handler\n"); diff --git a/hyperdbg/libhyperdbg/libhyperdbg.vcxproj b/hyperdbg/libhyperdbg/libhyperdbg.vcxproj index 309a9efa..e1a15be8 100644 --- a/hyperdbg/libhyperdbg/libhyperdbg.vcxproj +++ b/hyperdbg/libhyperdbg/libhyperdbg.vcxproj @@ -136,6 +136,7 @@ msbuild "$(SolutionDir)dependencies\zydis\msvc\Zydis.sln" /m /p:Configuration="R + @@ -175,6 +176,7 @@ msbuild "$(SolutionDir)dependencies\zydis\msvc\Zydis.sln" /m /p:Configuration="R + diff --git a/hyperdbg/libhyperdbg/libhyperdbg.vcxproj.filters b/hyperdbg/libhyperdbg/libhyperdbg.vcxproj.filters index ad369cec..4e3ef59f 100644 --- a/hyperdbg/libhyperdbg/libhyperdbg.vcxproj.filters +++ b/hyperdbg/libhyperdbg/libhyperdbg.vcxproj.filters @@ -203,6 +203,9 @@ header\platform + + header\platform + header @@ -658,6 +661,9 @@ code\platform + + code\platform + code\app diff --git a/hyperdbg/libhyperdbg/pch.h b/hyperdbg/libhyperdbg/pch.h index 5b9d0c1c..b78b022d 100644 --- a/hyperdbg/libhyperdbg/pch.h +++ b/hyperdbg/libhyperdbg/pch.h @@ -166,6 +166,11 @@ typedef const wchar_t *LPCWCHAR, *PCWCHAR; // #include "platform/user/header/platform-ioctl.h" +// +// Platform signal (cross-platform console-control / CTRL+C handler registration) +// +#include "platform/user/header/platform-signal.h" + // // Platform-specific intrinsics //