From 65cbdc95e662cd4a96940fb5a3d888ca665618cf Mon Sep 17 00:00:00 2001 From: SinaKarvandi Date: Sat, 24 Apr 2021 16:50:12 +0430 Subject: [PATCH] fixs related to testing phase. --- hyperdbg/hprdbgctrl/breakcontrol.cpp | 12 ++++++---- hyperdbg/hprdbgctrl/connect.cpp | 2 +- hyperdbg/hprdbgctrl/hprdbgctrl.cpp | 10 ++++----- hyperdbg/hprdbgctrl/interpreter.cpp | 31 +++++++++++++++++++++++++- hyperdbg/hprdbgctrl/load.cpp | 2 +- hyperdbg/hprdbgctrl/script.cpp | 7 +++++- hyperdbg/hprdbgctrl/status.cpp | 5 ++--- hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp | 8 +++---- 8 files changed, 57 insertions(+), 20 deletions(-) diff --git a/hyperdbg/hprdbgctrl/breakcontrol.cpp b/hyperdbg/hprdbgctrl/breakcontrol.cpp index 11704087..3c929241 100644 --- a/hyperdbg/hprdbgctrl/breakcontrol.cpp +++ b/hyperdbg/hprdbgctrl/breakcontrol.cpp @@ -70,7 +70,8 @@ BreakController(DWORD CtrlType) "pause\npausing debugger...\nauto-unpause mode is enabled, " "debugger will automatically continue when you run a new " "event command, if you want to change this behaviour then " - "run run 'settings autounpause off'\n\nHyperDbg> "); + "run run 'settings autounpause off'\n\n"); + HyperdbgShowSignature(); } else { @@ -78,7 +79,8 @@ BreakController(DWORD CtrlType) "pause\npausing debugger...\nauto-unpause mode is disabled, you " "should run 'g' when you want to continue, otherwise run " "'settings " - "autounpause on'\n\nHyperDbg> "); + "autounpause on'\n\n"); + HyperdbgShowSignature(); } } } @@ -130,7 +132,8 @@ BreakController(DWORD CtrlType) "pause\npausing debugger...\nauto-unpause mode is enabled, " "debugger will automatically continue when you run a new " "event command, if you want to change this behaviour then " - "run run 'settings autounpause off'\n\nHyperDbg> "); + "run run 'settings autounpause off'\n\n"); + HyperdbgShowSignature(); } else { @@ -138,7 +141,8 @@ BreakController(DWORD CtrlType) "pause\npausing debugger...\nauto-unpause mode is disabled, you " "should run 'g' when you want to continue, otherwise run " "'settings " - "autounpause on'\n\nHyperDbg> "); + "autounpause on'\n\n"); + HyperdbgShowSignature(); } } } diff --git a/hyperdbg/hprdbgctrl/connect.cpp b/hyperdbg/hprdbgctrl/connect.cpp index b66e6fe9..b2e9e9b7 100644 --- a/hyperdbg/hprdbgctrl/connect.cpp +++ b/hyperdbg/hprdbgctrl/connect.cpp @@ -87,7 +87,7 @@ CommandConnect(vector SplittedCommand, string Command) // // connect to local debugger // - ShowMessages("local debuging (vmi-mode)\n"); + ShowMessages("local debugging (vmi-mode)\n"); g_IsConnectedToHyperDbgLocally = TRUE; return; } diff --git a/hyperdbg/hprdbgctrl/hprdbgctrl.cpp b/hyperdbg/hprdbgctrl/hprdbgctrl.cpp index d73c8429..6fd963ff 100644 --- a/hyperdbg/hprdbgctrl/hprdbgctrl.cpp +++ b/hyperdbg/hprdbgctrl/hprdbgctrl.cpp @@ -193,16 +193,16 @@ ReadIrpBasedBuffer() if (!Status) { + // + // Error occured for second time, and we show the error message + // + //ShowMessages("ioctl failed with code 0x%x\n", GetLastError()); + // // if we reach here, the packet is probably failed, it might // be because of using flush command // continue; - - // - // Error occured for second time, and we show the error message - // - //ShowMessages("ioctl failed with code 0x%x\n", GetLastError()); } // diff --git a/hyperdbg/hprdbgctrl/interpreter.cpp b/hyperdbg/hprdbgctrl/interpreter.cpp index 5e9762d3..90cb5f7f 100644 --- a/hyperdbg/hprdbgctrl/interpreter.cpp +++ b/hyperdbg/hprdbgctrl/interpreter.cpp @@ -28,6 +28,8 @@ extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee; extern BOOLEAN g_IsDebuggeeRunning; extern BOOLEAN g_BreakPrintingOutput; +extern ULONG g_CurrentRemoteCore; + extern string g_ServerPort; extern string g_ServerIp; @@ -58,12 +60,12 @@ HyperdbgInterpreter(const char * Command) g_IsCommandListInitialized = TRUE; } + // // Save the command into log open file // if (g_LogOpened && !g_ExecutingScript) { - LogopenSaveToFile("HyperDbg> "); LogopenSaveToFile(Command); LogopenSaveToFile("\n"); } @@ -190,19 +192,41 @@ HyperdbgInterpreter(const char * Command) return 0; } +/** + * @brief Show signature of HyperDbg + * + * @return VOID + */ VOID HyperdbgShowSignature() { if (g_IsConnectedToRemoteDebuggee) { + // + // Remote debugging over tcp (vmi-mode) + // ShowMessages("[%s:%s] HyperDbg> ", g_ServerIp.c_str(), g_ServerPort.c_str()); } else if (g_DebuggingState.IsAttachedToUsermodeProcess) { + // + // Debugging a special process + // ShowMessages("(%x:%x) HyperDbg> ", g_DebuggingState.ConnectedProcessId, g_DebuggingState.ConnectedThreadId); } + else if (g_IsSerialConnectedToRemoteDebuggee) + { + // + // Remote debugging over serial (debugger-mode) + // + ShowMessages("%x: kHyperDbg> ", g_CurrentRemoteCore); + } else { + // + // Anything other than above scenarios including local debugging + // in vmi-mode + // ShowMessages("HyperDbg> "); } } @@ -241,6 +265,11 @@ GetCommandAttributes(string FirstCommand) return NULL; } +/** + * @brief Initialize commands and attributes + * + * @return VOID + */ VOID InitializeCommandsDictionary() { diff --git a/hyperdbg/hprdbgctrl/load.cpp b/hyperdbg/hprdbgctrl/load.cpp index 0eac0aa6..530916d7 100644 --- a/hyperdbg/hprdbgctrl/load.cpp +++ b/hyperdbg/hprdbgctrl/load.cpp @@ -148,7 +148,7 @@ CommandLoad(vector SplittedCommand, string Command) // // Load VMM Module // - ShowMessages("trying to install and load the vmm driver\n"); + ShowMessages("loading the vmm driver\n"); if (!CommandLoadVmmModule()) { diff --git a/hyperdbg/hprdbgctrl/script.cpp b/hyperdbg/hprdbgctrl/script.cpp index c09afb28..b28e92f6 100644 --- a/hyperdbg/hprdbgctrl/script.cpp +++ b/hyperdbg/hprdbgctrl/script.cpp @@ -82,7 +82,12 @@ CommandScript(vector SplittedCommand, string Command) while (std::getline(File, Line)) { - ShowMessages("HyperDbg> %s\n", Line.c_str()); + // + // Show current running command + // + HyperdbgShowSignature(); + ShowMessages("%s\n", Line.c_str()); + CommandExecutionResult = HyperdbgInterpreter(Line.c_str()); ShowMessages("\n"); diff --git a/hyperdbg/hprdbgctrl/status.cpp b/hyperdbg/hprdbgctrl/status.cpp index 0b6bfdf2..23f2b116 100644 --- a/hyperdbg/hprdbgctrl/status.cpp +++ b/hyperdbg/hprdbgctrl/status.cpp @@ -60,7 +60,6 @@ CommandStatus(vector SplittedCommand, string Command) // // Connected to a remote debuggee (serial port) // - ShowMessages("g_BreakPrintingOutput : %s\n", g_BreakPrintingOutput ? "true" : "false"); ShowMessages("remote debugging ('debugger mode')\n"); } else if (g_IsConnectedToRemoteDebuggee) @@ -77,13 +76,13 @@ CommandStatus(vector SplittedCommand, string Command) // // Connected to a local system // - ShowMessages("g_BreakPrintingOutput : %s\n", g_BreakPrintingOutput ? "true" : "false"); ShowMessages("local debugging ('vmi mode')\n"); } else if (g_IsConnectedToRemoteDebugger) { // - // It's computer connect to a remote machine + // It's computer connect to a remote machine (this + // message shouldn't be showed) // ShowMessages("a remote debugger connected to this system in ('vmi " "mode'), ip : %s:%s \n", diff --git a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp index 3299f2f7..3c908a63 100644 --- a/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp +++ b/hyperdbg/hyperdbg-cli/hyperdbg-cli.cpp @@ -48,6 +48,10 @@ main(int argc, char * argv[]) { bool ExitFromDebugger = false; + printf("HyperDbg Debugger [core version: v%s]\n", Version); + printf("Please visit https://docs.hyperdbg.com for more information...\n"); + printf("HyperDbg is released under the GNU Public License v3 (GPLv3).\n\n"); + if (argc != 1) { // @@ -71,10 +75,6 @@ main(int argc, char * argv[]) } } - printf("HyperDbg Debugger [core version: v%s]\n", Version); - printf("Please visit https://docs.hyperdbg.com for more information...\n"); - printf("HyperDbg is released under the GNU Public License v3 (GPLv3).\n\n"); - while (!ExitFromDebugger) { HyperdbgShowSignature();