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

bp command More...

#include "pch.h"

Functions

VOID CommandBpHelp ()
 help of the bp command
 
VOID CommandBpRequest (UINT64 Address, UINT32 Pid, UINT32 Tid, UINT32 CoreNumer)
 request breakpoint
 
VOID CommandBp (vector< string > SplitCommand, string Command)
 bp command handler
 

Variables

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

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

bp command handler

Parameters
SplitCommand
Command
Returns
VOID
84{
85 BOOL IsNextCoreId = FALSE;
86 BOOL IsNextPid = FALSE;
87 BOOL IsNextTid = FALSE;
88
89 BOOLEAN SetCoreId = FALSE;
90 BOOLEAN SetPid = FALSE;
91 BOOLEAN SetTid = FALSE;
92 BOOLEAN SetAddress = FALSE;
93
98 vector<string> SplitCommandCaseSensitive {Split(Command, ' ')};
99 UINT32 IndexInCommandCaseSensitive = 0;
100 BOOLEAN IsFirstCommand = TRUE;
101
102 if (SplitCommand.size() >= 9)
103 {
104 ShowMessages("incorrect use of the 'bp'\n\n");
106 return;
107 }
108
109 for (auto Section : SplitCommand)
110 {
111 IndexInCommandCaseSensitive++;
112
113 //
114 // Ignore the first argument as it's the command string itself (bp)
115 //
116 if (IsFirstCommand == TRUE)
117 {
118 IsFirstCommand = FALSE;
119 continue;
120 }
121
122 if (IsNextCoreId)
123 {
124 if (!ConvertStringToUInt32(Section, &CoreNumer))
125 {
126 ShowMessages("please specify a correct hex value for core id\n\n");
128 return;
129 }
130 IsNextCoreId = FALSE;
131 continue;
132 }
133 if (IsNextPid)
134 {
135 if (!ConvertStringToUInt32(Section, &Pid))
136 {
137 ShowMessages("please specify a correct hex value for process id\n\n");
139 return;
140 }
141 IsNextPid = FALSE;
142 continue;
143 }
144
145 if (IsNextTid)
146 {
147 if (!ConvertStringToUInt32(Section, &Tid))
148 {
149 ShowMessages("please specify a correct hex value for thread id\n\n");
151 return;
152 }
153 IsNextTid = FALSE;
154 continue;
155 }
156
157 if (!Section.compare("pid"))
158 {
159 IsNextPid = TRUE;
160 continue;
161 }
162 if (!Section.compare("tid"))
163 {
164 IsNextTid = TRUE;
165 continue;
166 }
167 if (!Section.compare("core"))
168 {
169 IsNextCoreId = TRUE;
170 continue;
171 }
172
173 if (!SetAddress)
174 {
175 if (!SymbolConvertNameOrExprToAddress(SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1), &Address))
176 {
177 //
178 // Couldn't resolve or unknown parameter
179 //
180 ShowMessages("err, couldn't resolve error at '%s'\n\n",
181 SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1).c_str());
183 return;
184 }
185 else
186 {
187 //
188 // Means that address is received
189 //
190 SetAddress = TRUE;
191 continue;
192 }
193 }
194 }
195
196 //
197 // Check if address is set or not
198 //
199 if (!SetAddress)
200 {
202 "please specify a correct hex value as the breakpoint address\n\n");
204 return;
205 }
206 if (IsNextPid)
207 {
208 ShowMessages("please specify a correct hex value for process id\n\n");
210 return;
211 }
212 if (IsNextCoreId)
213 {
214 ShowMessages("please specify a correct hex value for core\n\n");
216 return;
217 }
218 if (IsNextTid)
219 {
220 ShowMessages("please specify a correct hex value for thread id\n\n");
222 return;
223 }
224
226 {
227 ShowMessages("err, setting breakpoints is not possible when you're not "
228 "connected to a debuggee\n");
229 return;
230 }
231
232 //
233 // Request breakpoint the bp packet
234 //
235 CommandBpRequest(Address, Pid, Tid, CoreNumer);
236}
int BOOL
Definition BasicTypes.h:23
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
#define DEBUGGEE_BP_APPLY_TO_ALL_PROCESSES
The constant to apply to all processes for bp command.
Definition Constants.h:653
#define DEBUGGEE_BP_APPLY_TO_ALL_THREADS
The constant to apply to all threads for bp command.
Definition Constants.h:659
#define DEBUGGEE_BP_APPLY_TO_ALL_CORES
The constant to apply to all cores for bp command.
Definition Constants.h:647
UINT64 Address
Definition HyperDbgScriptImports.h:67
VOID CommandBpRequest(UINT64 Address, UINT32 Pid, UINT32 Tid, UINT32 CoreNumer)
request breakpoint
Definition bp.cpp:57
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
VOID CommandBpHelp()
help of the bp command
Definition bp.cpp:25
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
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

◆ CommandBpHelp()

VOID CommandBpHelp ( )

help of the bp command

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

◆ CommandBpRequest()

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

request breakpoint

Parameters
AddressAddress
PidProcess Id
TidThread Id
CoreNumerCore Number
Returns
VOID
58{
59 DEBUGGEE_BP_PACKET BpPacket = {0};
60
61 //
62 // Set the details for the remote packet
63 //
64 BpPacket.Address = Address;
65 BpPacket.Core = CoreNumer;
66 BpPacket.Pid = Pid;
67 BpPacket.Tid = Tid;
68
69 //
70 // Send the bp packet
71 //
72 KdSendBpPacketToDebuggee(&BpPacket);
73}
BOOLEAN KdSendBpPacketToDebuggee(PDEBUGGEE_BP_PACKET BpPacket)
Sends a breakpoint set or 'bp' command packet to the debuggee.
Definition kd.cpp:994
The structure of bp command packet in HyperDbg.
Definition RequestStructures.h:1060
UINT32 Tid
Definition RequestStructures.h:1063
UINT32 Core
Definition RequestStructures.h:1064
UINT64 Address
Definition RequestStructures.h:1061
UINT32 Pid
Definition RequestStructures.h:1062

Variable Documentation

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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