2020-09-08 13:53:27 -07:00
|
|
|
/**
|
|
|
|
|
* @file t.cpp
|
2022-01-18 22:38:56 +03:30
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
2020-09-08 13:53:27 -07:00
|
|
|
* @brief t command
|
|
|
|
|
* @details
|
|
|
|
|
* @version 0.1
|
2020-12-29 15:03:45 -08:00
|
|
|
* @date 2020-12-29
|
2020-09-08 13:53:27 -07:00
|
|
|
*
|
|
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#include "pch.h"
|
2020-09-08 13:53:27 -07:00
|
|
|
|
2020-12-29 15:03:45 -08:00
|
|
|
//
|
|
|
|
|
// Global Variables
|
|
|
|
|
//
|
2022-01-16 03:16:15 +03:30
|
|
|
extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee;
|
|
|
|
|
extern BOOLEAN g_IsInstrumentingInstructions;
|
|
|
|
|
extern ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState;
|
2020-12-29 15:03:45 -08:00
|
|
|
|
2020-09-08 13:53:27 -07:00
|
|
|
/**
|
2023-07-13 16:05:42 +09:00
|
|
|
* @brief help of the t command
|
2020-09-08 13:53:27 -07:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
|
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
|
|
|
|
CommandTHelp()
|
|
|
|
|
{
|
|
|
|
|
ShowMessages(
|
|
|
|
|
"t : executes a single instruction (step-in) and optionally displays the "
|
|
|
|
|
"resulting values of all registers and flags.\n\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
2022-02-08 16:06:26 +03:30
|
|
|
ShowMessages("syntax : \tt\n");
|
|
|
|
|
ShowMessages("syntax : \tt [Count (hex)]\n");
|
|
|
|
|
ShowMessages("syntax : \ttr\n");
|
|
|
|
|
ShowMessages("syntax : \ttr [Count (hex)]\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
|
|
|
|
ShowMessages("\n");
|
2021-03-22 18:19:39 +04:30
|
|
|
ShowMessages("\t\te.g : t\n");
|
|
|
|
|
ShowMessages("\t\te.g : tr\n");
|
|
|
|
|
ShowMessages("\t\te.g : tr 1f\n");
|
2020-09-08 13:53:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-29 15:03:45 -08:00
|
|
|
* @brief handler of t command
|
2020-09-08 13:53:27 -07:00
|
|
|
*
|
2024-07-30 14:17:06 +09:00
|
|
|
* @param CommandTokens
|
2024-07-31 14:08:14 +09:00
|
|
|
* @param Command
|
2024-07-30 14:17:06 +09:00
|
|
|
*
|
2020-09-08 13:53:27 -07:00
|
|
|
* @return VOID
|
|
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
2024-07-31 14:08:14 +09:00
|
|
|
CommandT(vector<CommandToken> CommandTokens, string Command)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2024-09-06 12:42:55 +02:00
|
|
|
UINT32 StepCount;
|
2020-09-08 13:53:27 -07: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
|
|
|
{
|
2024-07-31 18:21:23 +09:00
|
|
|
ShowMessages("incorrect use of the '%s'\n\n",
|
|
|
|
|
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
|
2021-03-22 18:19:39 +04:30
|
|
|
CommandTHelp();
|
|
|
|
|
return;
|
2020-12-29 15:03:45 -08:00
|
|
|
}
|
2020-09-08 13:53:27 -07: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");
|
|
|
|
|
CommandTHelp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StepCount = 1;
|
|
|
|
|
}
|
2021-03-10 00:21:04 +03:30
|
|
|
|
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
|
|
|
//
|
2022-01-16 03:16:15 +03:30
|
|
|
if (g_IsSerialConnectedToRemoteDebuggee || g_ActiveProcessDebuggingState.IsActive)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2022-01-28 21:19:20 +03:30
|
|
|
//
|
|
|
|
|
// Check if the thread is paused or not
|
|
|
|
|
//
|
|
|
|
|
if (g_ActiveProcessDebuggingState.IsActive && !g_ActiveProcessDebuggingState.IsPaused)
|
|
|
|
|
{
|
|
|
|
|
ShowMessages("the target process is running, use the "
|
2025-08-23 01:30:12 +02:00
|
|
|
"'pause' command to pause the process\n");
|
2022-01-28 21:19:20 +03:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 18:27:33 +03:30
|
|
|
//
|
|
|
|
|
// Indicate that we're instrumenting
|
|
|
|
|
//
|
|
|
|
|
g_IsInstrumentingInstructions = TRUE;
|
|
|
|
|
|
2026-05-31 18:34:03 +02:00
|
|
|
for (SIZE_T i = 0; i < StepCount; i++)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2022-01-13 17:54:03 +03:30
|
|
|
//
|
|
|
|
|
// For logging purpose
|
|
|
|
|
//
|
|
|
|
|
// ShowMessages("percentage : %f %% (%x)\n", 100.0 * (i /
|
|
|
|
|
// (float)StepCount), i);
|
|
|
|
|
//
|
|
|
|
|
|
2024-09-06 12:42:55 +02:00
|
|
|
//
|
|
|
|
|
// Instrument (regular) the instruction
|
|
|
|
|
//
|
|
|
|
|
SteppingRegularStepIn();
|
2021-03-19 12:36:03 +03:30
|
|
|
|
2024-07-30 14:17:06 +09:00
|
|
|
if (CompareLowerCaseStrings(CommandTokens.at(0), "tr"))
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-18 18:27:33 +03:30
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Check if user pressed CTRL+C
|
|
|
|
|
//
|
|
|
|
|
if (!g_IsInstrumentingInstructions)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-03-19 12:52:57 +03:30
|
|
|
}
|
2021-11-18 18:27:33 +03:30
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 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 (t) is not valid in the current context, you "
|
|
|
|
|
"should connect to a debuggee\n");
|
|
|
|
|
}
|
2020-09-08 13:53:27 -07:00
|
|
|
}
|