diff --git a/CHANGELOG.md b/CHANGELOG.md index 2160391c..575a23cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,16 +8,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 New release of the HyperDbg Debugger. ### Added -- The **!xsetbv** event command is added to execution of XSETBV instruction thanks to HyperDbg group members ([link](https://docs.hyperdbg.org/commands/extension-commands/xsetbv)) +- The **!xsetbv** event command is added to the execution of the XSETBV instruction thanks to HyperDbg group members ([link](https://docs.hyperdbg.org/commands/extension-commands/xsetbv)) - Number of blocked context switches in the '.switch' command ([link](https://docs.hyperdbg.org/commands/meta-commands/.switch)) - Added support to the step-in (the 't' command) for the user debugger ([link](https://docs.hyperdbg.org/commands/debugging-commands/t)) - Added support to the step-over (the 'p' command) for the user debugger ([link](https://docs.hyperdbg.org/commands/debugging-commands/p)) +- Added support to show all registers or a specific register for the user debugger ([link](https://docs.hyperdbg.org/commands/debugging-commands/r)) +- Export SDK API for running scripts in the kernel debugger or the user debugger +- Added support to modify registers or a specific register for the user debugger ([link](https://docs.hyperdbg.org/commands/debugging-commands/r)) +- Added support to evaluate (run) scripts on the target thread in the user debugger ([link](https://docs.hyperdbg.org/commands/debugging-commands/eval)) ### Changed - Non-volatile XMM registers are no longer saved/restored on VM-exit handler ([link](https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170)) - Fix grammar and spelling errors throughout HyperDbg codebase ([link](https://github.com/HyperDbg/HyperDbg/pull/546)) - Relocate extension command files into their corresponding VS directory -- Fix infinite vm-exit bug for the '!monitor x' command thanks to [@unlockable](https://github.com/unlockable) ([link](https://github.com/HyperDbg/HyperDbg/pull/545)) +- Fix infinite VM-exit bug for the '!monitor x' command thanks to [@unlockable](https://github.com/unlockable) ([link](https://github.com/HyperDbg/HyperDbg/pull/545)) ## [0.15.0.0] - 2025-08-18 New release of the HyperDbg Debugger. diff --git a/hyperdbg/include/SDK/imports/user/HyperDbgLibImports.h b/hyperdbg/include/SDK/imports/user/HyperDbgLibImports.h index 4c0bd9be..7b8b3881 100644 --- a/hyperdbg/include/SDK/imports/user/HyperDbgLibImports.h +++ b/hyperdbg/include/SDK/imports/user/HyperDbgLibImports.h @@ -289,6 +289,12 @@ hwdbg_script_run_script(const CHAR * script, VOID hwdbg_script_engine_wrapper_test_parser(const CHAR * Expr); +// +// Run script +// +BOOLEAN +hyperdbg_u_run_script(CHAR * Expr, BOOLEAN ShowErrorMessageIfAny); + #ifdef __cplusplus } #endif diff --git a/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/eval.cpp b/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/eval.cpp index f0d292b5..be6b8d68 100644 --- a/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/eval.cpp +++ b/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/eval.cpp @@ -14,7 +14,8 @@ // // Global Variables // -extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee; +extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee; +extern ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState; /** * @brief help of the ? command @@ -194,11 +195,6 @@ ErrorMessage: VOID CommandEval(vector CommandTokens, string Command) { - PVOID CodeBuffer; - UINT64 BufferAddress; - UINT32 BufferLength; - UINT32 Pointer; - if (CommandTokens.size() == 1) { ShowMessages("incorrect use of the '%s'\n\n", @@ -242,56 +238,26 @@ CommandEval(vector CommandTokens, string Command) return; } - if (g_IsSerialConnectedToRemoteDebuggee) + // + // Check if we're connected to a remote debuggee (kernel debugger) or the user debugger + // + if (g_IsSerialConnectedToRemoteDebuggee || + (g_ActiveProcessDebuggingState.IsActive && g_ActiveProcessDebuggingState.IsPaused)) { // - // Send over serial + // Send data to the target user debugger or kernel debugger // - - // - // Run script engine handler - // - CodeBuffer = ScriptEngineParseWrapper((char *)Command.c_str(), TRUE); - - if (CodeBuffer == NULL) - { - // - // return to show that this item contains an script - // - return; - } - - // - // Print symbols (test) - // - // PrintSymbolBufferWrapper(CodeBuffer); - - // - // Set the buffer and length - // - BufferAddress = ScriptEngineWrapperGetHead(CodeBuffer); - BufferLength = ScriptEngineWrapperGetSize(CodeBuffer); - Pointer = ScriptEngineWrapperGetPointer(CodeBuffer); - - // - // Send it to the remote debuggee - // - KdSendScriptPacketToDebuggee(BufferAddress, BufferLength, Pointer, FALSE); - - // - // Remove the buffer of script engine interpreted code - // - ScriptEngineWrapperRemoveSymbolBuffer(CodeBuffer); + ScriptEngineExecuteSingleExpression((CHAR *)Command.c_str(), TRUE, FALSE); } else { // - // It's a test + // It's a test (simulated) run of the script-engine // - ShowMessages("this command should not be used while you're in VMI-Mode or not in debugger-mode, " - "the results that you see is a simulated result for TESTING script-engine " - "and is not based on the status of your system. You can use this command, " - "ONLY in debugger-mode\n\n"); + ShowMessages("this command should not be used while you're in VMI-Mode (not attached to the user debugger) " + "or not in debugger-mode, the results that you see is a simulated result for TESTING script-engine " + "and is not based on the status of your system. You can use this command, either in the debugger mode " + "(kernel debugger), or when you attached to a user debugger\n\n"); ShowMessages("test expression : %s \n", Command.c_str()); ScriptEngineWrapperTestParser(Command); diff --git a/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/r.cpp b/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/r.cpp index 3161444e..da225f35 100644 --- a/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/r.cpp +++ b/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/r.cpp @@ -453,7 +453,7 @@ CommandR(vector CommandTokens, string Command) { REGS_ENUM RegKind; std::vector Tmp; - std::string SetRegValue; + std::string SetRegisterValue; // // Disable user-mode debugger in this version @@ -573,12 +573,12 @@ CommandR(vector CommandTokens, string Command) // // send the request // - SetRegValue = "@" + tmp + '=' + Tmp[1] + "; "; + SetRegisterValue = "@" + tmp + '=' + Tmp[1] + "; "; // // Send data to the target user debugger or kernel debugger // - ScriptEngineExecuteSingleExpression(SetRegValue, TRUE, FALSE); + ScriptEngineExecuteSingleExpression((CHAR *)SetRegisterValue.c_str(), TRUE, FALSE); } else { diff --git a/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp b/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp index 358f3e4e..8c5dffa4 100644 --- a/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp +++ b/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp @@ -135,7 +135,7 @@ ScriptEngineEvalSingleExpression(string Expr, PBOOLEAN HasError) * @return BOOLEAN Returns TRUE if it was successful */ BOOLEAN -ScriptEngineExecuteSingleExpression(string Expr, BOOLEAN ShowErrorMessageIfAny, BOOLEAN IsFormat) +ScriptEngineExecuteSingleExpression(CHAR * Expr, BOOLEAN ShowErrorMessageIfAny, BOOLEAN IsFormat) { PVOID CodeBuffer; UINT64 BufferAddress; @@ -146,7 +146,7 @@ ScriptEngineExecuteSingleExpression(string Expr, BOOLEAN ShowErrorMessageIfAny, // // Run script engine handler // - CodeBuffer = ScriptEngineParseWrapper((char *)Expr.c_str(), ShowErrorMessageIfAny); + CodeBuffer = ScriptEngineParseWrapper(Expr, ShowErrorMessageIfAny); if (CodeBuffer == NULL) { diff --git a/hyperdbg/libhyperdbg/code/export/export.cpp b/hyperdbg/libhyperdbg/code/export/export.cpp index dc29a1a4..99be9922 100644 --- a/hyperdbg/libhyperdbg/code/export/export.cpp +++ b/hyperdbg/libhyperdbg/code/export/export.cpp @@ -799,3 +799,17 @@ hyperdbg_u_disable_transparent_mode() { return HyperDbgDisableTransparentMode(); } + +/** + * @brief Run HyperDbg scripts in the target process (user debugger) or + * debuggee (kernel debugger) + * @param Expr The expression to run + * @param ShowErrorMessageIfAny If true, show error message if any + * + * @return BOOLEAN + */ +BOOLEAN +hyperdbg_u_run_script(CHAR * Expr, BOOLEAN ShowErrorMessageIfAny) +{ + return ScriptEngineExecuteSingleExpression(Expr, ShowErrorMessageIfAny, FALSE); +} diff --git a/hyperdbg/libhyperdbg/header/script-engine.h b/hyperdbg/libhyperdbg/header/script-engine.h index 949beaca..48341994 100644 --- a/hyperdbg/libhyperdbg/header/script-engine.h +++ b/hyperdbg/libhyperdbg/header/script-engine.h @@ -110,4 +110,4 @@ UINT64 ScriptEngineEvalSingleExpression(string Expr, PBOOLEAN HasError); BOOLEAN -ScriptEngineExecuteSingleExpression(string Expr, BOOLEAN ShowErrorMessageIfAny, BOOLEAN IsFormat); +ScriptEngineExecuteSingleExpression(CHAR * Expr, BOOLEAN ShowErrorMessageIfAny, BOOLEAN IsFormat);