diff --git a/hyperdbg/hyperkd/code/debugger/kernel-level/Kd.c b/hyperdbg/hyperkd/code/debugger/kernel-level/Kd.c index 085c6b48..02eed173 100644 --- a/hyperdbg/hyperkd/code/debugger/kernel-level/Kd.c +++ b/hyperdbg/hyperkd/code/debugger/kernel-level/Kd.c @@ -836,7 +836,7 @@ KdNotifyDebuggeeForUserInput(DEBUGGEE_USER_INPUT_PACKET * Descriptor, UINT32 Len } /** - * @brief Notify user-mode to unload the debuggee and close the connections + * @brief Send the result of formats command to the kernel debugger * @param Value * * @return VOID diff --git a/hyperdbg/hyperkd/code/debugger/user-level/Ud.c b/hyperdbg/hyperkd/code/debugger/user-level/Ud.c index 439a243d..ed50f048 100644 --- a/hyperdbg/hyperkd/code/debugger/user-level/Ud.c +++ b/hyperdbg/hyperkd/code/debugger/user-level/Ud.c @@ -185,6 +185,19 @@ UdApplyHardwareDebugRegister(PVOID TargetAddress) (UINT64)TargetAddress); } +/** + * @brief Send the result of formats command to the user debugger + * @param Value + * + * @return VOID + */ +VOID +UdSendFormatsFunctionResult(UINT64 Value) +{ + g_UserDebuggerFormatsResultPacket.Result = DEBUGGER_OPERATION_WAS_SUCCESSFUL; + g_UserDebuggerFormatsResultPacket.Value = Value; +} + /** * @brief routines to broadcast setting hardware debug registers on all cores * @param TargetAddress @@ -423,9 +436,25 @@ UdRunScript(PROCESSOR_DEBUGGING_STATE * DbgState) &g_EventTriggerDetail)) { // - // Set status + // Check if we need to format the output or not // - ScriptPacket->Result = DEBUGGER_OPERATION_WAS_SUCCESSFUL; + if (ScriptPacket->IsFormat) + { + // + // For the format, we need to get the result from the script engine + // through global variables, we store the result of format into + // optional parameters + // + ScriptPacket->Result = g_UserDebuggerFormatsResultPacket.Result; + ScriptPacket->FormatValue = g_UserDebuggerFormatsResultPacket.Value; + } + else + { + // + // Set status + // + ScriptPacket->Result = DEBUGGER_OPERATION_WAS_SUCCESSFUL; + } } else { diff --git a/hyperdbg/hyperkd/header/debugger/user-level/Ud.h b/hyperdbg/hyperkd/header/debugger/user-level/Ud.h index bf825e9e..b9134e0f 100644 --- a/hyperdbg/hyperkd/header/debugger/user-level/Ud.h +++ b/hyperdbg/hyperkd/header/debugger/user-level/Ud.h @@ -76,3 +76,6 @@ UdCheckForCommand(PROCESSOR_DEBUGGING_STATE * DbgState, BOOLEAN UdHandleDebugEventsWhenUserDebuggerIsAttached(PROCESSOR_DEBUGGING_STATE * DbgState, BOOLEAN TrapSetByDebugger); + +VOID +UdSendFormatsFunctionResult(UINT64 Value); diff --git a/hyperdbg/hyperkd/header/globals/Global.h b/hyperdbg/hyperkd/header/globals/Global.h index 78df67be..d887f0f6 100644 --- a/hyperdbg/hyperkd/header/globals/Global.h +++ b/hyperdbg/hyperkd/header/globals/Global.h @@ -84,6 +84,12 @@ DEBUGGEE_REQUEST_TO_IGNORE_BREAKS_UNTIL_AN_EVENT g_IgnoreBreaksToDebugger; */ HARDWARE_DEBUG_REGISTER_DETAILS g_HardwareDebugRegisterDetailsForStepOver; +/** + * @brief Holds the result of user debugger formats command + * + */ +DEBUGGEE_FORMATS_PACKET g_UserDebuggerFormatsResultPacket; + /** * @brief Process switch to EPROCESS or Process ID * diff --git a/hyperdbg/include/SDK/headers/RequestStructures.h b/hyperdbg/include/SDK/headers/RequestStructures.h index dd0821e5..d5033bb6 100644 --- a/hyperdbg/include/SDK/headers/RequestStructures.h +++ b/hyperdbg/include/SDK/headers/RequestStructures.h @@ -1403,6 +1403,7 @@ typedef struct _DEBUGGEE_SCRIPT_PACKET UINT32 ScriptBufferSize; UINT32 ScriptBufferPointer; BOOLEAN IsFormat; + UINT64 FormatValue; UINT32 Result; // diff --git a/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp b/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp index ee015a28..73b07f71 100644 --- a/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp +++ b/hyperdbg/libhyperdbg/code/debugger/script-engine/script-engine.cpp @@ -43,7 +43,7 @@ ScriptEngineEvalSingleExpression(string Expr, PBOOLEAN HasError) // // Send data to the target user debugger or kernel debugger // - if (!ScriptEngineExecuteSingleExpression((CHAR *)Expr.c_str(), TRUE, FALSE)) + if (!ScriptEngineExecuteSingleExpression((CHAR *)Expr.c_str(), TRUE, TRUE)) { *HasError = TRUE; return NULL; diff --git a/hyperdbg/libhyperdbg/code/debugger/user-level/ud.cpp b/hyperdbg/libhyperdbg/code/debugger/user-level/ud.cpp index 050aad97..9b032cc4 100644 --- a/hyperdbg/libhyperdbg/code/debugger/user-level/ud.cpp +++ b/hyperdbg/libhyperdbg/code/debugger/user-level/ud.cpp @@ -17,6 +17,8 @@ extern UINT32 g_ProcessIdOfLatestStartingProcess; extern ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState; extern BOOLEAN g_IsUserDebuggerInitialized; +extern UINT64 g_ResultOfEvaluatedExpression; +extern UINT32 g_ErrorStateOfResultOfEvaluatedExpression; extern CommandType g_CommandsList; extern DEBUGGER_SYNCRONIZATION_EVENTS_STATE g_UserSyncronizationObjectsHandleTable[DEBUGGER_MAXIMUM_SYNCRONIZATION_USER_DEBUGGER_OBJECTS]; @@ -1218,6 +1220,15 @@ UdSendScriptBufferToProcess(UINT64 ProcessDetailToken, NULL, NULL); + // + // Check if it's a format expression and if there was an error or not + // + if (IsFormat && Result) + { + g_ErrorStateOfResultOfEvaluatedExpression = DEBUGGER_OPERATION_WAS_SUCCESSFUL; + g_ResultOfEvaluatedExpression = ScriptPacket->FormatValue; + } + free(ScriptPacket); return Result; diff --git a/hyperdbg/script-eval/code/Functions.c b/hyperdbg/script-eval/code/Functions.c index e44c61fe..6e2be2ff 100644 --- a/hyperdbg/script-eval/code/Functions.c +++ b/hyperdbg/script-eval/code/Functions.c @@ -1225,6 +1225,10 @@ ScriptEngineFunctionFormats(UINT64 Tag, BOOLEAN ImmediateMessagePassing, UINT64 { KdSendFormatsFunctionResult(Value); } + else if (g_UserDebuggerState) + { + UdSendFormatsFunctionResult(Value); + } else { //