HyperDbg Debugger
Loading...
Searching...
No Matches
track.cpp File Reference

!track command More...

#include "pch.h"

Functions

VOID CommandTrackHelp ()
 help of the !track command
VOID CommandTrack (vector< CommandToken > CommandTokens, string Command)
 handler of !track command
VOID CommandTrackHandleReceivedInstructions (UCHAR *BufferToDisassemble, UINT32 BuffLength, BOOLEAN Isx86_64, UINT64 RipAddress)
 Handle received 'call' or 'ret'.
VOID CommandTrackHandleReceivedCallInstructions (const CHAR *NameOfFunctionFromSymbols, UINT64 ComputedAbsoluteAddress)
 Handle received 'call'.
VOID CommandTrackHandleReceivedRetInstructions (UINT64 CurrentRip)
 Handle received 'ret'.

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
BOOLEAN g_IsInstrumentingInstructions
 Shows whether the user is running 't', 'p', or 'i' command.
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
 State of active debugging thread.
BOOLEAN g_AddressConversion
 Whether converting addresses to object names or not.
UINT32 NumberOfCallsIdentation = 0
BOOLEAN IsCallInstructionVisited = FALSE
BOOLEAN ShowRegs = FALSE
volatile BOOLEAN RequestShowingRegs = FALSE

Detailed Description

!track command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.3
Date
2023-05-05

Function Documentation

◆ CommandTrack()

VOID CommandTrack ( vector< CommandToken > CommandTokens,
string Command )

handler of !track command

Parameters
CommandTokens
Command
Returns
VOID
61{
62 UINT32 StepCount;
63 string SymbolServer;
64
65 //
66 // Validate the commands
67 //
68 if (CommandTokens.size() >= 4)
69 {
70 ShowMessages("incorrect use of the '%s'\n\n",
71 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
73 return;
74 }
75
76 //
77 // Check if we're in VMI mode
78 //
80 {
81 ShowMessages("the tracking mechanism is only supported in Debugger Mode\n");
82 return;
83 }
84
85 //
86 // Show recommendation
87 //
88 if (!CommandSettingsGetValueFromConfigFile("SymbolServer", SymbolServer))
89 {
90 ShowMessages("it is recommended to configure the symbol path '.sympath' and load "
91 "symbols before using the '!track' command command to obtain results with function "
92 "names\n");
93 }
94
95 //
96 // Reset the details of indentation and regs
97 //
100 ShowRegs = FALSE;
102
103 //
104 // Set default of stepping (tracking)
105 //
107
108 //
109 // Check parameters
110 //
111 for (auto Section : CommandTokens)
112 {
113 if (CompareLowerCaseStrings(Section, "!track") || CompareLowerCaseStrings(Section, "track"))
114 {
115 continue;
116 }
117
118 //
119 // check if the second param is a number
120 //
121 if (ConvertTokenToUInt32(Section, &StepCount))
122 {
123 continue;
124 }
125 else if (CompareLowerCaseStrings(Section, "tree"))
126 {
127 //
128 // Default
129 //
130 ShowRegs = FALSE;
131 }
132 else if (CompareLowerCaseStrings(Section, "reg"))
133 {
134 ShowRegs = TRUE;
135 }
136 else
137 {
138 ShowMessages("err, couldn't resolve error at '%s'\n\n",
140 return;
141 }
142 }
143
144 //
145 // Check if the remote serial debuggee or user debugger are paused or not
146 //
148 {
149 //
150 // Indicate that we're instrumenting
151 //
153
154 for (SIZE_T i = 0; i < StepCount; i++)
155 {
156 //
157 // For logging purpose
158 //
159 // ShowMessages("percentage : %f %% (%x)\n", 100.0 * (i /
160 // (float)StepCount), i);
161 //
162
163 //
164 // It's stepping over serial connection in kernel debugger
165 //
167
169 {
171
172 //
173 // Show registers
174 //
176
177 ShowMessages("\n");
178 }
179
180 //
181 // Check if user pressed CTRL+C
182 //
184 {
185 break;
186 }
187 }
188
189 //
190 // We're not instrumenting instructions anymore
191 //
193 }
194 else
195 {
196 ShowMessages("err, tracking is not valid in the current context, you "
197 "should connect to a debuggee\n");
198 }
199}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:372
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
#define DEBUGGER_REMOTE_TRACKING_DEFAULT_COUNT_OF_STEPPING
default number of instructions used in tracking and stepping
Definition RequestStructures.h:1077
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
BOOLEAN ConvertTokenToUInt32(CommandToken TargetToken, PUINT32 Result)
check and convert command token to a 32 bit unsigned integer
Definition common.cpp:546
BOOLEAN g_IsInstrumentingInstructions
Shows whether the user is running 't', 'p', or 'i' command.
Definition globals.h:571
BOOLEAN HyperDbgRegisterShowAll()
handler of r show all registers
Definition r.cpp:354
BOOLEAN CommandSettingsGetValueFromConfigFile(std::string OptionName, std::string &OptionValue)
Gets the setting values from config file.
Definition settings.cpp:60
BOOLEAN SteppingInstrumentationStepInForTracking()
Perform Instrumentation Step-in for Tracking.
Definition steppings.cpp:53
volatile BOOLEAN RequestShowingRegs
Definition track.cpp:28
BOOLEAN ShowRegs
Definition track.cpp:27
VOID CommandTrackHelp()
help of the !track command
Definition track.cpp:36
BOOLEAN IsCallInstructionVisited
Definition track.cpp:26
UINT32 NumberOfCallsIdentation
Definition track.cpp:25

◆ CommandTrackHandleReceivedCallInstructions()

VOID CommandTrackHandleReceivedCallInstructions ( const CHAR * NameOfFunctionFromSymbols,
UINT64 ComputedAbsoluteAddress )

Handle received 'call'.

Parameters
NameOfFunctionFromSymbols
ComputedAbsoluteAddress
Returns
VOID
237{
238 //
239 // One 'call' instruction is visited
240 //
242
243 CHAR Utf8String1[] = "\xE2\x94\x82\x20\x20";
244
245 for (SIZE_T i = 0; i < NumberOfCallsIdentation; i++)
246 {
247 PlatformWriteConsole(Utf8String1, sizeof(Utf8String1) - 1);
248 }
249
250 //
251 // Write the UTF-8 encoded character sequence to the console
252 //
253 // CHAR Utf8String[] = "\xE2\x94\x9C\xE2\x94\x80\xE2\x94\x80";
254 CHAR Utf8String[] = "\xE2\x94\x8C\xE2\x94\x80\xE2\x94\x80";
255 PlatformWriteConsole(Utf8String, sizeof(Utf8String) - 1);
256
257 if (NameOfFunctionFromSymbols != NULL)
258 {
259 ShowMessages(" %s (%s)\n", NameOfFunctionFromSymbols, SeparateTo64BitValue(ComputedAbsoluteAddress).c_str());
260 }
261 else
262 {
263 ShowMessages(" %s\n", SeparateTo64BitValue(ComputedAbsoluteAddress).c_str());
264 }
265
266 if (ShowRegs)
267 {
269 }
270
272}
char CHAR
Definition BasicTypes.h:33
string SeparateTo64BitValue(UINT64 Value)
BOOLEAN PlatformWriteConsole(const VOID *Buffer, DWORD NumberOfBytes)
Platform independent wrapper to write raw bytes to the console.
Definition platform-lib-calls.c:374

◆ CommandTrackHandleReceivedInstructions()

VOID CommandTrackHandleReceivedInstructions ( UCHAR * BufferToDisassemble,
UINT32 BuffLength,
BOOLEAN Isx86_64,
UINT64 RipAddress )

Handle received 'call' or 'ret'.

Parameters
BufferToDisassemble
BuffLength
Isx86_64
RipAddress
Returns
VOID
216{
217 BOOLEAN IsRet = FALSE;
218
219 //
220 // By calling this function, it acts as a callback that in case of the 'call' and the 'ret' instructions
221 // the callbacks will be called
222 //
223 HyperDbgCheckWhetherTheCurrentInstructionIsCallOrRet(BufferToDisassemble, RipAddress, BuffLength, Isx86_64, &IsRet);
224}
UCHAR BOOLEAN
Definition BasicTypes.h:35
BOOLEAN HyperDbgCheckWhetherTheCurrentInstructionIsCallOrRet(UCHAR *BufferToDisassemble, UINT64 CurrentRip, UINT32 BuffLength, BOOLEAN Isx86_64, PBOOLEAN IsRet)
Check whether the current instruction is a 'call' or 'ret' or not.
Definition disassembler.cpp:983

◆ CommandTrackHandleReceivedRetInstructions()

VOID CommandTrackHandleReceivedRetInstructions ( UINT64 CurrentRip)

Handle received 'ret'.

Parameters
CurrentRip
Returns
VOID
283{
284 UINT64 UsedBaseAddress = NULL;
285 BOOLEAN IsNameShowed = FALSE;
286
288 {
290 {
292 }
293 }
294
295 CHAR Utf8String1[] = "\xE2\x94\x82\x20\x20";
296
297 for (SIZE_T i = 0; i < NumberOfCallsIdentation; i++)
298 {
299 PlatformWriteConsole(Utf8String1, sizeof(Utf8String1) - 1);
300 }
301
302 //
303 // Write the UTF-8 encoded character sequence to the console
304 //
305 CHAR Utf8String[] = "\xE2\x94\x94\xE2\x94\x80\xE2\x94\x80\x20";
306 PlatformWriteConsole(Utf8String, sizeof(Utf8String) - 1);
307
308 //
309 // Apply addressconversion of settings here
310 //
312 {
313 //
314 // Showing function names here
315 //
316 if (SymbolShowFunctionNameBasedOnAddress(CurrentRip, &UsedBaseAddress))
317 {
318 //
319 // The symbol address is showed
320 //
321 IsNameShowed = TRUE;
322 ShowMessages(" (%s)\n", SeparateTo64BitValue(CurrentRip).c_str());
323 }
324 }
325
326 if (!IsNameShowed)
327 {
328 ShowMessages("%s \n", SeparateTo64BitValue(CurrentRip).c_str());
329 }
330}
NULL()
Definition test-case-generator.py:530
BOOLEAN g_AddressConversion
Whether converting addresses to object names or not.
Definition globals.h:594
BOOLEAN SymbolShowFunctionNameBasedOnAddress(UINT64 Address, PUINT64 UsedBaseAddress)
shows the functions' name for the disassembler
Definition symbol.cpp:161

◆ CommandTrackHelp()

VOID CommandTrackHelp ( )

help of the !track command

Returns
VOID
37{
38 ShowMessages(
39 "!track : tracks instructions from user-mode to kernel-mode or kernel-mode to user-mode "
40 "to create call tree. Please note that it's highly recommended to configure symbols before "
41 "using this command as it maps addresses to corresponding function names.\n\n");
42
43 ShowMessages("syntax : \t!track [tree] [Count (hex)]\n");
44 ShowMessages("syntax : \t!track [reg] [Count (hex)]\n");
45
46 ShowMessages("\n");
47 ShowMessages("\t\te.g : !track tree 10000\n");
48 ShowMessages("\t\te.g : !track reg 10000\n");
49}

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

372{0};

◆ g_AddressConversion

BOOLEAN g_AddressConversion
extern

Whether converting addresses to object names or not.

it is enabled by default

◆ g_IsInstrumentingInstructions

BOOLEAN g_IsInstrumentingInstructions
extern

Shows whether the user is running 't', 'p', or 'i' command.

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest).

◆ IsCallInstructionVisited

BOOLEAN IsCallInstructionVisited = FALSE

◆ NumberOfCallsIdentation

UINT32 NumberOfCallsIdentation = 0

◆ RequestShowingRegs

volatile BOOLEAN RequestShowingRegs = FALSE

◆ ShowRegs

BOOLEAN ShowRegs = FALSE