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< string > SplitCommand, 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< string > SplitCommand,
string Command )

k command handler

Parameters
SplitCommand
Command
Returns
VOID
56{
57 UINT64 BaseAddress = NULL; // Null base address means current RSP register
58 UINT32 Length = 0x100; // Default length
59 vector<string> SplitCommandCaseSensitive {Split(Command, ' ')};
60 UINT32 IndexInCommandCaseSensitive = 0;
61 BOOLEAN IsFirstCommand = TRUE;
62 BOOLEAN IsNextBase = FALSE;
63 BOOLEAN IsNextLength = FALSE;
64
65 string FirstCommand = SplitCommand.front();
66
67 if (SplitCommand.size() >= 6)
68 {
69 ShowMessages("incorrect use of the '%s'\n\n", FirstCommand.c_str());
71 return;
72 }
73
75 {
76 ShowMessages("err, tracing callstack is not possible when you're not "
77 "connected to a debuggee\n");
78 return;
79 }
80
81 //
82 // Set the default length
83 //
85 {
86 Length = 0x100;
87 }
88 else
89 {
90 Length = 0x200;
91 }
92
93 for (auto Section : SplitCommand)
94 {
95 IndexInCommandCaseSensitive++;
96
97 if (IsFirstCommand)
98 {
99 IsFirstCommand = FALSE;
100 continue;
101 }
102 if (IsNextBase == TRUE)
103 {
104 if (!SymbolConvertNameOrExprToAddress(SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1),
105 &BaseAddress))
106 {
107 //
108 // Couldn't resolve or unknown parameter
109 //
110 ShowMessages("err, couldn't resolve error at '%s'\n",
111 SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1).c_str());
112 return;
113 }
114
115 IsNextBase = FALSE;
116 continue;
117 }
118
119 if (IsNextLength == TRUE)
120 {
121 if (!ConvertStringToUInt32(Section, &Length))
122 {
123 ShowMessages("err, you should enter a valid length\n\n");
124 return;
125 }
126 IsNextLength = FALSE;
127 continue;
128 }
129
130 if (!Section.compare("l"))
131 {
132 IsNextLength = TRUE;
133 continue;
134 }
135
136 if (!Section.compare("base"))
137 {
138 IsNextBase = TRUE;
139 continue;
140 }
141
142 //
143 // User inserts unexpected input
144 //
145 ShowMessages("err, incorrect use of the '%s' command\n\n",
146 FirstCommand.c_str());
147 CommandKHelp();
148
149 return;
150 }
151
152 if (IsNextLength || IsNextBase)
153 {
154 ShowMessages("incorrect use of the '%s' command\n\n", FirstCommand.c_str());
155 CommandKHelp();
156 return;
157 }
158
159 //
160 // Send callstack request
161 //
162
163 if (!FirstCommand.compare("k"))
164 {
166 Length,
169 }
170 else if (!FirstCommand.compare("kq"))
171 {
173 Length,
175 FALSE);
176 }
177 else if (!FirstCommand.compare("kd"))
178 {
180 Length,
182 TRUE);
183 }
184}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
@ DEBUGGER_CALLSTACK_DISPLAY_METHOD_WITHOUT_PARAMS
Definition RequestStructures.h:779
@ DEBUGGER_CALLSTACK_DISPLAY_METHOD_WITH_PARAMS
Definition RequestStructures.h:780
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
BOOLEAN g_IsRunningInstruction32Bit
whether the Current executing instructions is 32-bit or 64 bit
Definition globals.h:210
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
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
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
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:360

◆ CommandKHelp()

VOID CommandKHelp ( )

help of the k command

Returns
VOID
27{
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)