HyperDbg/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/p.cpp

158 lines
3.8 KiB
C++
Raw Permalink Normal View History

2020-12-29 15:03:45 -08:00
/**
* @file p.cpp
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
2020-12-29 15:03:45 -08:00
* @brief p command
* @details
* @version 0.1
* @date 2020-12-29
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
2020-12-29 15:03:45 -08:00
//
// Global Variables
//
extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee;
extern BOOLEAN g_IsInstrumentingInstructions;
extern ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState;
2020-12-29 15:03:45 -08:00
/**
2023-07-13 16:05:42 +09:00
* @brief help of the p command
2020-12-29 15:03:45 -08:00
*
* @return VOID
*/
2021-03-22 18:19:39 +04:30
VOID
CommandPHelp()
{
ShowMessages(
"p : executes a single instruction (step) and optionally displays the "
"resulting values of all registers and flags.\n\n");
ShowMessages("syntax : \tp\n");
ShowMessages("syntax : \tp [Count (hex)]\n");
ShowMessages("syntax : \tpr\n");
ShowMessages("syntax : \tpr [Count (hex)]\n");
ShowMessages("\n");
2021-03-22 18:19:39 +04:30
ShowMessages("\t\te.g : p\n");
ShowMessages("\t\te.g : pr\n");
ShowMessages("\t\te.g : pr 1f\n");
2020-12-29 15:03:45 -08:00
}
/**
* @brief handler of p command
*
2024-07-30 14:17:06 +09:00
* @param CommandTokens
* @param Command
2024-07-30 14:17:06 +09:00
*
2020-12-29 15:03:45 -08:00
* @return VOID
*/
2021-03-22 18:19:39 +04:30
VOID
CommandP(vector<CommandToken> CommandTokens, string Command)
2021-03-22 18:19:39 +04:30
{
UINT32 StepCount;
DEBUGGER_REMOTE_STEPPING_REQUEST RequestFormat;
2020-12-29 15:03:45 -08:00
2021-03-22 18:19:39 +04:30
//
// Validate the commands
//
2024-07-30 14:17:06 +09:00
if (CommandTokens.size() != 1 && CommandTokens.size() != 2)
2021-03-22 18:19:39 +04:30
{
ShowMessages("incorrect use of the '%s'\n\n",
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
2021-03-22 18:19:39 +04:30
CommandPHelp();
return;
2020-12-29 15:03:45 -08:00
}
2021-03-22 18:19:39 +04:30
//
// Set type of request
//
RequestFormat = DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_OVER;
2020-12-29 15:03:45 -08:00
2021-03-22 18:19:39 +04:30
//
// Check if the command has a counter parameter
//
2024-07-30 14:17:06 +09:00
if (CommandTokens.size() == 2)
2021-03-22 18:19:39 +04:30
{
2024-07-30 14:17:06 +09:00
if (!ConvertTokenToUInt32(CommandTokens.at(1), &StepCount))
2021-03-22 18:19:39 +04:30
{
ShowMessages("please specify a correct hex value for [count]\n\n");
CommandPHelp();
return;
}
}
else
{
StepCount = 1;
}
2021-03-22 18:19:39 +04:30
//
2022-01-13 17:54:03 +03:30
// Check if the remote serial debuggee or user debugger are paused or not
2021-03-22 18:19:39 +04:30
//
if (g_IsSerialConnectedToRemoteDebuggee || g_ActiveProcessDebuggingState.IsActive)
2021-03-22 18:19:39 +04:30
{
//
// Check if the thread is paused or not
//
if (g_ActiveProcessDebuggingState.IsActive && !g_ActiveProcessDebuggingState.IsPaused)
{
ShowMessages("the target process is running, use the "
"'pause' command or press CTRL+C to pause the process\n");
return;
}
//
// Indicate that we're instrumenting
//
g_IsInstrumentingInstructions = TRUE;
for (SIZE_T i = 0; i < StepCount; i++)
2021-03-22 18:19:39 +04:30
{
//
// For logging purpose
//
// ShowMessages("percentage : %f %% (%x)\n", 100.0 * (i /
// (float)StepCount), i);
//
2021-03-10 00:21:04 +03:30
//
// Perform Step-over
//
SteppingStepOver();
2021-03-19 12:36:03 +03:30
2024-07-30 14:17:06 +09:00
if (CompareLowerCaseStrings(CommandTokens.at(0), "pr"))
2021-03-22 18:19:39 +04:30
{
//
// Show registers
//
2024-07-07 19:50:01 +09:00
HyperDbgRegisterShowAll();
2021-03-22 18:19:39 +04:30
if (i != StepCount - 1)
{
ShowMessages("\n");
}
}
//
// Check if user pressed CTRL+C
//
if (!g_IsInstrumentingInstructions)
{
break;
}
}
//
// We're not instrumenting instructions anymore
//
g_IsInstrumentingInstructions = FALSE;
2020-12-29 15:03:45 -08:00
}
2021-03-22 18:19:39 +04:30
else
{
ShowMessages("err, stepping (p) is not valid in the current context, you "
"should connect to a debuggee\n");
}
2020-12-29 15:03:45 -08:00
}