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

k command More...

#include "pch.h"

Functions

VOID CommandKHelp ()
 help of the k command
VOID CommandK (vector< CommandToken > CommandTokens, string Command)
 k command handler

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
BOOLEAN g_IsRunningInstruction32Bit
 whether the Current executing instructions is 32-bit or 64 bit

Detailed Description

k command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2021-12-13

Function Documentation

◆ CommandK()

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

k command handler

Parameters
CommandTokens
Command
Returns
VOID
57{
58 UINT64 BaseAddress = NULL; // Null base address means current RSP register
59 UINT32 Length = PAGE_SIZE; // Default length
60 BOOLEAN IsFirstCommand = TRUE;
61 BOOLEAN IsNextBase = FALSE;
62 BOOLEAN IsNextLength = FALSE;
63
64 if (CommandTokens.size() >= 6)
65 {
66 ShowMessages("incorrect use of the '%s'\n\n",
67 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
69 return;
70 }
71
73 {
74 ShowMessages("err, tracing callstack is not possible when you're not "
75 "connected to a debuggee\n");
76 return;
77 }
78
79 //
80 // Set the default length
81 //
83 {
84 Length = PAGE_SIZE;
85 }
86 else
87 {
88 Length = PAGE_SIZE * 2;
89 }
90
91 for (auto Section : CommandTokens)
92 {
93 if (IsFirstCommand)
94 {
95 IsFirstCommand = FALSE;
96 continue;
97 }
98 if (IsNextBase == TRUE)
99 {
101 &BaseAddress))
102 {
103 //
104 // Couldn't resolve or unknown parameter
105 //
106 ShowMessages("err, couldn't resolve error at '%s'\n",
108 return;
109 }
110
111 IsNextBase = FALSE;
112 continue;
113 }
114
115 if (IsNextLength == TRUE)
116 {
117 if (!ConvertTokenToUInt32(Section, &Length))
118 {
119 ShowMessages("err, you should enter a valid length\n\n");
120 return;
121 }
122 IsNextLength = FALSE;
123 continue;
124 }
125
126 if (CompareLowerCaseStrings(Section, "l"))
127 {
128 IsNextLength = TRUE;
129 continue;
130 }
131
132 if (CompareLowerCaseStrings(Section, "base"))
133 {
134 IsNextBase = TRUE;
135 continue;
136 }
137
138 //
139 // User inserts unexpected input
140 //
141 ShowMessages("err, incorrect use of the '%s' command\n\n",
142 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
143 CommandKHelp();
144
145 return;
146 }
147
148 if (IsNextLength || IsNextBase)
149 {
150 ShowMessages("incorrect use of the '%s' command\n\n",
151 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
152 CommandKHelp();
153 return;
154 }
155
156 //
157 // Send callstack request
158 //
159
160 if (CompareLowerCaseStrings(CommandTokens.at(0), "k"))
161 {
163 Length,
166 }
167 else if (CompareLowerCaseStrings(CommandTokens.at(0), "kq"))
168 {
170 Length,
172 FALSE);
173 }
174 else if (CompareLowerCaseStrings(CommandTokens.at(0), "kd"))
175 {
177 Length,
179 TRUE);
180 }
181}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned int UINT32
Definition BasicTypes.h:54
@ DEBUGGER_CALLSTACK_DISPLAY_METHOD_WITHOUT_PARAMS
Definition RequestStructures.h:833
@ DEBUGGER_CALLSTACK_DISPLAY_METHOD_WITH_PARAMS
Definition RequestStructures.h:834
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_IsRunningInstruction32Bit
whether the Current executing instructions is 32-bit or 64 bit
Definition globals.h:232
VOID CommandKHelp()
help of the k command
Definition k.cpp:26
BOOLEAN KdSendCallStackPacketToDebuggee(UINT64 BaseAddress, UINT32 Size, DEBUGGER_CALLSTACK_DISPLAY_METHOD DisplayMethod, BOOLEAN Is32Bit)
Send a callstack request to the debuggee.
Definition kd.cpp:348
#define PAGE_SIZE
Size of each page (4096 bytes).
Definition common.h:80
NULL()
Definition test-case-generator.py:530
BOOLEAN SymbolConvertNameOrExprToAddress(const string &TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for symbol object names and eval...
Definition symbol.cpp:359

◆ CommandKHelp()

VOID CommandKHelp ( )

help of the k command

Returns
VOID
27{
28 ShowMessages(
29 "k, kd, kq : shows the callstack of the thread.\n\n");
30
31 ShowMessages("syntax : \tk\n");
32 ShowMessages("syntax : \tkd\n");
33 ShowMessages("syntax : \tkq\n");
34 ShowMessages("syntax : \tk [base StackAddress (hex)] [l Length (hex)]\n");
35 ShowMessages("syntax : \tkd [base StackAddress (hex)] [l Length (hex)]\n");
36 ShowMessages("syntax : \tkq [base StackAddress (hex)] [l Length (hex)]\n");
37
38 ShowMessages("\n");
39 ShowMessages("\t\te.g : k\n");
40 ShowMessages("\t\te.g : k l 100\n");
41 ShowMessages("\t\te.g : kd base 0x77356f010\n");
42 ShowMessages("\t\te.g : kq base fffff8077356f010\n");
43 ShowMessages("\t\te.g : kq base @rbx-10\n");
44 ShowMessages("\t\te.g : kq base fffff8077356f010 l 100\n");
45}

Variable Documentation

◆ g_IsRunningInstruction32Bit

BOOLEAN g_IsRunningInstruction32Bit
extern

whether the Current executing instructions is 32-bit or 64 bit

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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