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

bp command More...

#include "pch.h"

Functions

VOID CommandBpHelp ()
 help of the bp command
BOOLEAN CommandBpPerformApplyingBreakpointOnUserDebugger (DEBUGGEE_BP_PACKET *BpPacket)
 Apply breakpoint on the user debugger.
BOOLEAN CommandBpRequest (UINT64 Address, UINT32 Pid, UINT32 Tid, UINT32 CoreNumer)
 request breakpoint
VOID CommandBp (vector< CommandToken > CommandTokens, string Command)
 bp command handler

Variables

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
BOOLEAN g_IsVmmModuleLoaded
 shows whether the VMM module is loaded or not
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
 State of active debugging thread.

Detailed Description

bp command

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

Function Documentation

◆ CommandBp()

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

bp command handler

Parameters
CommandTokens
Command
Returns
VOID
169{
170 BOOL IsNextCoreId = FALSE;
171 BOOL IsNextPid = FALSE;
172 BOOL IsNextTid = FALSE;
173
174 BOOLEAN SetCoreId = FALSE;
175 BOOLEAN SetPid = FALSE;
176 BOOLEAN SetTid = FALSE;
177 BOOLEAN SetAddress = FALSE;
178
182 UINT64 Address = NULL;
183 BOOLEAN IsFirstCommand = TRUE;
184
185 if (CommandTokens.size() >= 9)
186 {
187 ShowMessages("incorrect use of the '%s'\n\n",
188 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
190 return;
191 }
192
193 //
194// Disable user-mode debugger in this version
195//
196#if ActivateUserModeDebugger == FALSE
197
199 {
200 ShowMessages("the user-mode debugger in VMI Mode is still in the beta version and not stable. "
201 "we decided to exclude it from this release and release it in future versions. "
202 "if you want to test the user-mode debugger in VMI Mode, you should build "
203 "HyperDbg with special instructions. But starting processes is fully supported "
204 "in the Debugger Mode.\n"
205 "(it's not recommended to use it in VMI Mode yet!)\n");
206 return;
207 }
208
209#endif // !ActivateUserModeDebugger
210
211 //
212 // If the user is debugging a process, use its pid
213 //
215 {
216 Pid = g_ActiveProcessDebuggingState.ProcessId;
217 }
218
219 for (auto Section : CommandTokens)
220 {
221 //
222 // Ignore the first argument as it's the command string itself (bp)
223 //
224 if (IsFirstCommand == TRUE)
225 {
226 IsFirstCommand = FALSE;
227 continue;
228 }
229
230 if (IsNextCoreId)
231 {
232 if (!ConvertTokenToUInt32(Section, &CoreNumer))
233 {
234 ShowMessages("please specify a correct hex value for core id\n\n");
236 return;
237 }
238 IsNextCoreId = FALSE;
239 continue;
240 }
241 if (IsNextPid)
242 {
243 if (!ConvertTokenToUInt32(Section, &Pid))
244 {
245 ShowMessages("please specify a correct hex value for process id\n\n");
247 return;
248 }
249 IsNextPid = FALSE;
250 continue;
251 }
252
253 if (IsNextTid)
254 {
255 if (!ConvertTokenToUInt32(Section, &Tid))
256 {
257 ShowMessages("please specify a correct hex value for thread id\n\n");
259 return;
260 }
261 IsNextTid = FALSE;
262 continue;
263 }
264
265 if (CompareLowerCaseStrings(Section, "pid"))
266 {
267 IsNextPid = TRUE;
268 continue;
269 }
270 if (CompareLowerCaseStrings(Section, "tid"))
271 {
272 IsNextTid = TRUE;
273 continue;
274 }
275 if (CompareLowerCaseStrings(Section, "core"))
276 {
277 IsNextCoreId = TRUE;
278 continue;
279 }
280
281 if (!SetAddress)
282 {
284 {
285 //
286 // Couldn't resolve or unknown parameter
287 //
288 ShowMessages("err, couldn't resolve error at '%s'\n\n",
291 return;
292 }
293 else
294 {
295 //
296 // Means that address is received
297 //
298 SetAddress = TRUE;
299 continue;
300 }
301 }
302 }
303
304 //
305 // Check if address is set or not
306 //
307 if (!SetAddress)
308 {
309 ShowMessages("please specify a correct hex value as the breakpoint address\n\n");
311 return;
312 }
313 if (IsNextPid)
314 {
315 ShowMessages("please specify a correct hex value for process id\n\n");
317 return;
318 }
319 if (IsNextCoreId)
320 {
321 ShowMessages("please specify a correct hex value for core\n\n");
323 return;
324 }
325 if (IsNextTid)
326 {
327 ShowMessages("please specify a correct hex value for thread id\n\n");
329 return;
330 }
331
333 {
334 ShowMessages("setting breakpoints is not possible when you're not connected "
335 "to a target debuggee (kernel debugger or user debugger)\n");
336 return;
337 }
338
339 //
340 // Request breakpoint the bp packet
341 //
342 if (!CommandBpRequest(Address, Pid, Tid, CoreNumer))
343 {
344 ShowMessages("err, couldn't set breakpoint\n");
345 }
346}
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
VOID CommandBpHelp()
help of the bp command
Definition bp.cpp:27
BOOLEAN CommandBpRequest(UINT64 Address, UINT32 Pid, UINT32 Tid, UINT32 CoreNumer)
request breakpoint
Definition bp.cpp:119
int BOOL
Definition BasicTypes.h:25
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
#define DEBUGGEE_BP_APPLY_TO_ALL_PROCESSES
The constant to apply to all processes for bp command.
Definition Constants.h:781
#define DEBUGGEE_BP_APPLY_TO_ALL_THREADS
The constant to apply to all threads for bp command.
Definition Constants.h:787
#define DEBUGGEE_BP_APPLY_TO_ALL_CORES
The constant to apply to all cores for bp command.
Definition Constants.h:775
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
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

◆ CommandBpHelp()

VOID CommandBpHelp ( )

help of the bp command

Returns
VOID
28{
29 ShowMessages("bp : puts a breakpoint (0xcc).\n");
30
31 ShowMessages(
32 "Note : 'bp' is not an event, if you want to use an event version "
33 "of breakpoints use !epthook or !epthook2 instead. See "
34 "documentation for more information.\n\n");
35
36 ShowMessages("syntax : \tbp [Address (hex)] [pid ProcessId (hex)] [tid ThreadId (hex)] [core CoreId (hex)]\n");
37
38 ShowMessages("\n");
39 ShowMessages("\t\te.g : bp nt!ExAllocatePoolWithTag\n");
40 ShowMessages("\t\te.g : bp nt!ExAllocatePoolWithTag+5\n");
41 ShowMessages("\t\te.g : bp nt!ExAllocatePoolWithTag+@rcx+rbx\n");
42 ShowMessages("\t\te.g : bp fffff8077356f010\n");
43 ShowMessages("\t\te.g : bp fffff8077356f010 pid 0x4\n");
44 ShowMessages("\t\te.g : bp fffff8077356f010 tid 0x1000\n");
45 ShowMessages("\t\te.g : bp fffff8077356f010 pid 0x4 core 2\n");
46}

◆ CommandBpPerformApplyingBreakpointOnUserDebugger()

BOOLEAN CommandBpPerformApplyingBreakpointOnUserDebugger ( DEBUGGEE_BP_PACKET * BpPacket)

Apply breakpoint on the user debugger.

Parameters
BpPacket
Returns
BOOLEAN
56{
57 BOOL Status;
58 ULONG ReturnedLength;
59
61 {
62 //
63 // Check if the debugger is connected to a remote debuggee, this request
64 // is not for the kernel debugger
65 //
66 return FALSE;
67 }
68 else
69 {
71
72 //
73 // Send IOCTL
74 //
75 Status = DeviceIoControl(
76 g_DeviceHandle, // Handle to device
77 IOCTL_SET_BREAKPOINT_USER_DEBUGGER, // IO Control Code (IOCTL)
78 BpPacket, // Input Buffer to driver.
79 SIZEOF_DEBUGGEE_BP_PACKET, // Input buffer length (not used in this case)
80 BpPacket, // Output Buffer from driver.
81 SIZEOF_DEBUGGEE_BP_PACKET, // Length of output buffer in bytes.
82 &ReturnedLength, // Bytes placed in buffer.
83 NULL // synchronous call
84 );
85
86 if (!Status)
87 {
88 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
89
90 return FALSE;
91 }
92
94 {
95 return TRUE;
96 }
97 else
98 {
99 //
100 // An err occurred, no results
101 //
102 ShowErrorMessage(BpPacket->Result);
103 return FALSE;
104 }
105 }
106}
unsigned long ULONG
Definition BasicTypes.h:31
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
#define IOCTL_SET_BREAKPOINT_USER_DEBUGGER
ioctl, to set breakpoint for the user debugger
Definition Ioctls.h:382
#define SIZEOF_DEBUGGEE_BP_PACKET
Debugger size of DEBUGGEE_BP_PACKET.
Definition RequestStructures.h:1531
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:40
#define AssertShowMessageReturnStmt(expr1, expr2, message1, message2, rc)
Definition common.h:59
#define ASSERT_MESSAGE_VMM_NOT_LOADED
Definition common.h:31
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:27
#define AssertReturnFalse
Definition common.h:21
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:481
BOOLEAN g_IsVmmModuleLoaded
shows whether the VMM module is loaded or not
Definition globals.h:28
UINT32 Result
Definition RequestStructures.h:1523

◆ CommandBpRequest()

BOOLEAN CommandBpRequest ( UINT64 Address,
UINT32 Pid,
UINT32 Tid,
UINT32 CoreNumer )

request breakpoint

Parameters
AddressAddress
PidProcess Id
TidThread Id
CoreNumerCore Number
Returns
BOOLEAN
120{
121 DEBUGGEE_BP_PACKET BpPacket = {0};
122
123 //
124 // Check if the debugger is connected to a remote debuggee or a user-debugger is active
125 //
127 {
128 return FALSE;
129 }
130
131 //
132 // Set the details for the remote packet
133 //
134 BpPacket.Address = Address;
135 BpPacket.Core = CoreNumer;
136 BpPacket.Pid = Pid;
137 BpPacket.Tid = Tid;
138
139 //
140 // Send the bp packet either to the user debugger or the kernel debugger
141 //
143 {
145 }
147 {
148 return KdSendBpPacketToDebuggee(&BpPacket);
149 }
150 else
151 {
152 //
153 // couldn't set breakpoint, no active process or remote debuggee
154 //
155 return FALSE;
156 }
157}
BOOLEAN CommandBpPerformApplyingBreakpointOnUserDebugger(DEBUGGEE_BP_PACKET *BpPacket)
Apply breakpoint on the user debugger.
Definition bp.cpp:55
struct _DEBUGGEE_BP_PACKET DEBUGGEE_BP_PACKET
The structure of bp command packet in HyperDbg.
BOOLEAN KdSendBpPacketToDebuggee(PDEBUGGEE_BP_PACKET BpPacket)
Sends a breakpoint set or 'bp' command packet to the debuggee.
Definition kd.cpp:1169
UINT32 Tid
Definition RequestStructures.h:1519
UINT32 Core
Definition RequestStructures.h:1520
UINT64 Address
Definition RequestStructures.h:1517
UINT32 Pid
Definition RequestStructures.h:1518

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

372{0};

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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

◆ g_IsVmmModuleLoaded

BOOLEAN g_IsVmmModuleLoaded
extern

shows whether the VMM module is loaded or not