62{
68 UINT32 ActionBreakToDebuggerLength = 0;
69 UINT32 ActionCustomCodeLength = 0;
70 UINT32 ActionScriptLength = 0;
80 vector<string> SplitCommandCaseSensitive {
Split(Command,
' ')};
82 UINT32 IndexInCommandCaseSensitive = 0;
84
85 if (SplitCommand.size() < 4)
86 {
89 return;
90 }
91
92
93
94
95
96
97
98
100 &SplitCommand,
101 &SplitCommandCaseSensitive,
103 &Event,
104 &EventLength,
105 &ActionBreakToDebugger,
106 &ActionBreakToDebuggerLength,
107 &ActionCustomCode,
108 &ActionCustomCodeLength,
109 &ActionScript,
110 &ActionScriptLength,
111 &EventParsingErrorCause))
112 {
113 return;
114 }
115
116
117
118
119 for (auto Section : SplitCommand)
120 {
121 IndexInCommandCaseSensitive++;
122
123 if (!Section.compare("!monitor"))
124 {
125 continue;
126 }
127 else if (IsNextLength)
128 {
130 {
131 ShowMessages(
"err, you should enter a valid length\n\n");
132 return;
133 }
134
135 IsNextLength =
FALSE;
136 LengthAlreadySet =
TRUE;
138 }
139 else if (!Section.compare("r") && !SetAttributes)
140 {
142 SetAttributes =
TRUE;
143 }
144 else if (!Section.compare("w") && !SetAttributes)
145 {
147 SetAttributes =
TRUE;
148 }
149 else if (!Section.compare("x") && !SetAttributes)
150 {
152 SetAttributes =
TRUE;
153 }
154 else if ((!Section.compare("rw") || !Section.compare("wr")) && !SetAttributes)
155 {
157 SetAttributes =
TRUE;
158 }
159 else if ((!Section.compare("rx") || !Section.compare("xr")) &&
160 !SetAttributes)
161 {
163 SetAttributes =
TRUE;
164 }
165 else if ((!Section.compare("wx") || !Section.compare("xw")) &&
166 !SetAttributes)
167 {
169 SetAttributes =
TRUE;
170 }
171 else if ((!Section.compare("rwx") ||
172 !Section.compare("rxw") ||
173 !Section.compare("wrx") ||
174 !Section.compare("wxr") ||
175 !Section.compare("xrw") ||
176 !Section.compare("xwr")) &&
177 !SetAttributes)
178 {
180 SetAttributes =
TRUE;
181 }
182 else if (!Section.compare("l") && !SetTo && !LengthAlreadySet)
183 {
185 continue;
186 }
187 else if (!Section.compare("va") && !HookMemoryTypeSet)
188 {
190 HookMemoryTypeSet =
TRUE;
191 continue;
192 }
193 else if (!Section.compare("pa") && !HookMemoryTypeSet)
194 {
196 HookMemoryTypeSet =
TRUE;
197 continue;
198 }
199 else
200 {
201
202
203
204 if (!SetFrom)
205 {
207 SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1),
208 &OptionalParam1))
209 {
210
211
212
214 SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1).c_str());
216
218 return;
219 }
221 }
222 else if (!SetTo && !LengthAlreadySet)
223 {
225 SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1),
226 &OptionalParam2))
227 {
228
229
230
232 SplitCommandCaseSensitive.at(IndexInCommandCaseSensitive - 1).c_str());
233
235
237 return;
238 }
240 }
241 else
242 {
243
244
245
246 ShowMessages(
"unknown parameter '%s'\n\n", Section.c_str());
248
250 return;
251 }
252 }
253 }
254
255
256
257
258 if (!SetFrom || !SetTo)
259 {
260 ShowMessages(
"please choose the 'from' or 'to' values or specify the length\n");
262 return;
263 }
264
265
266
267
268 if (LengthAlreadySet)
269 {
270
271
272
273 OptionalParam2 = OptionalParam1 + HookLength - 1;
274 }
275
276
277
278
279 if (OptionalParam1 > OptionalParam2)
280 {
281
282
283
284 ShowMessages(
"please choose the 'from' value first, then choose the 'to' "
285 "value\n");
286
288 return;
289 }
290
291
292
293
294 if (!SetAttributes)
295 {
296 ShowMessages(
"please specify the attribute(s) that you want to monitor (r, w, x, rw, rx, wx, rwx)\n");
297
299 return;
300 }
301
302
303
304
308
309
310
311
313 {
314
315
316
317
318
319
321 return;
322 }
323
324
325
326
328 ActionBreakToDebugger,
329 ActionBreakToDebuggerLength,
330 ActionCustomCode,
331 ActionCustomCodeLength,
332 ActionScript,
333 ActionScriptLength))
334 {
335
336
337
338
340 return;
341 }
342}
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_MEMORY_HOOK_VIRTUAL_ADDRESS
Definition DataTypes.h:311
@ DEBUGGER_MEMORY_HOOK_PHYSICAL_ADDRESS
Definition DataTypes.h:312
enum _DEBUGGER_HOOK_MEMORY_TYPE DEBUGGER_HOOK_MEMORY_TYPE
different type of memory addresses
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 FreeEventsAndActionsMemory(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, PDEBUGGER_GENERAL_ACTION ActionCustomCode, PDEBUGGER_GENERAL_ACTION ActionScript)
Deallocate buffers relating to events and actions.
Definition debugger.cpp:2292
BOOLEAN InterpretGeneralEventAndActionsFields(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, VMM_EVENT_TYPE_ENUM EventType, PDEBUGGER_GENERAL_EVENT_DETAIL *EventDetailsToFill, PUINT32 EventBufferLength, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillBreakToDebugger, PUINT32 ActionBufferLengthBreakToDebugger, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillCustomCode, PUINT32 ActionBufferLengthCustomCode, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillScript, PUINT32 ActionBufferLengthScript, PDEBUGGER_EVENT_PARSING_ERROR_CAUSE ReasonForErrorInParsing)
Interpret general event fields.
Definition debugger.cpp:2342
BOOLEAN SendEventToKernel(PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
Register the event to the kernel.
Definition debugger.cpp:1969
BOOLEAN RegisterActionToEvent(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, UINT32 ActionBreakToDebuggerLength, PDEBUGGER_GENERAL_ACTION ActionCustomCode, UINT32 ActionCustomCodeLength, PDEBUGGER_GENERAL_ACTION ActionScript, UINT32 ActionScriptLength)
Register the action to the event.
Definition debugger.cpp:2086
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
VOID CommandMonitorHelp()
help of the !monitor command
Definition monitor.cpp:20
NULL()
Definition test-case-generator.py:530
UINT64 OptionalParam2
Definition Events.h:273
UINT64 OptionalParam3
Definition Events.h:274
UINT64 OptionalParam1
Definition Events.h:272
Each event can have multiple actions.
Definition Events.h:406
Each command is like the following struct, it also used for tracing works in user mode and sending it...
Definition Events.h:350
DEBUGGER_EVENT_OPTIONS Options
Definition Events.h:391
VMM_EVENT_TYPE_ENUM EventType
Definition Events.h:389
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