55{
59 string DetailsOfSource;
61 PLIST_ENTRY TempList = 0;
63 HANDLE SourceHandle = INVALID_HANDLE_VALUE;
65 HMODULE Module =
NULL;
66 vector<string> SplitCommandCaseSensitive {
Split(Command,
' ')};
67
68 if (SplitCommand.size() <= 2)
69 {
72 return;
73 }
74
75
76
77
78 if (SplitCommand.size() == 1)
79 {
80 IndexToShowList = 0;
81
83 {
85
87 {
88 TempList = TempList->Blink;
89
92
93
94
95
96 IndexToShowList++;
97
98 string TempStateString = "";
99 string TempTypeString = "";
100
101 if (CurrentOutputSourceDetails->
State ==
103 {
104 TempStateString = "not opened";
105 }
106 else if (CurrentOutputSourceDetails->
State ==
108 {
109 TempStateString = "opened ";
110 }
111 else if (CurrentOutputSourceDetails->
State ==
113 {
114 TempStateString = "closed ";
115 }
116
118 {
119 TempTypeString = "namedpipe";
120 }
122 {
123 TempTypeString = "file ";
124 }
126 {
127 TempTypeString = "tcp ";
128 }
130 {
131 TempTypeString = "module ";
132 }
133
134 ShowMessages(
"%x %s %s\t%s\n", IndexToShowList, TempTypeString.c_str(), TempStateString.c_str(), CurrentOutputSourceDetails->
Name);
135 }
136 }
137 else
138 {
140 }
141
142 return;
143 }
144
145
146
147
148 if (!SplitCommand.at(1).compare("create"))
149 {
150
151
152
153
154
155
156
157 if (SplitCommand.size() <= 4)
158 {
161 return;
162 }
163
164
165
166
167 if (!SplitCommand.at(3).compare("file"))
168 {
170 }
171 else if (!SplitCommand.at(3).compare("namedpipe"))
172 {
174 }
175 else if (!SplitCommand.at(3).compare("tcp"))
176 {
178 }
179 else if (!SplitCommand.at(3).compare("module"))
180 {
182 }
183 else
184 {
186 SplitCommand.at(3).c_str());
188 return;
189 }
190
191
192
193
194 if (SplitCommand.at(2).size() >=
196 {
197 ShowMessages(
"name of the output cannot exceed form %d characters\n\n",
200 return;
201 }
202
203
204
205
206
207
209 {
211
213 {
214 TempList = TempList->Flink;
215
218
219 if (strcmp(CurrentOutputSourceDetails->
Name,
220 SplitCommandCaseSensitive.at(2).c_str()) == 0)
221 {
222
223
224
225 OutputSourceFound =
TRUE;
226
227
228
229
230 break;
231 }
232 }
233
234
235
236
237 if (OutputSourceFound)
238 {
239 ShowMessages(
"err, the name you entered, already exists, please choose "
240 "another name\n");
241 return;
242 }
243 }
244
245
246
247
248 DetailsOfSource = Command.substr(Command.find(SplitCommandCaseSensitive.at(3)) +
249 SplitCommandCaseSensitive.at(3).size() + 1,
250 Command.size());
251
253
254
255
256
257 if (SourceHandle == INVALID_HANDLE_VALUE)
258 {
260 "err, invalid address or cannot open or find the address\n");
261 return;
262 }
263
264
265
266
267 EventForwardingObject =
269
270 if (EventForwardingObject == NULL)
271 {
272 ShowMessages(
"err, in allocating memory for event forwarding\n");
273 return;
274 }
275
277
278
279
280
282
283
284
285
286 EventForwardingObject->
Type = Type;
287
288
289
290
292
293
294
295
296
298 {
299 EventForwardingObject->
Socket = Socket;
300 }
302 {
303 EventForwardingObject->
Module = Module;
304
305
306
307
308 EventForwardingObject->
Handle = SourceHandle;
309 }
310 else
311 {
312 EventForwardingObject->
Handle = SourceHandle;
313 }
314
315
316
317
318 strcpy_s(EventForwardingObject->
Name, SplitCommandCaseSensitive.at(2).c_str());
319
320
321
322
324 {
327 }
328
329
330
331
334 }
335 else if (!SplitCommand.at(1).compare("open"))
336 {
337
338
339
341 {
343 return;
344 }
345
346
347
348
349
351
353 {
354 TempList = TempList->Flink;
355
357 TempList,
359 OutputSourcesList);
360
361 if (strcmp(CurrentOutputSourceDetails->
Name,
362 SplitCommandCaseSensitive.at(2).c_str()) == 0)
363 {
364
365
366
367 OutputSourceFound =
TRUE;
368
369
370
371
373
375 {
376 ShowMessages(
"err, the name you entered was already closed\n");
377 return;
378 }
380 {
381 ShowMessages(
"err, the name you entered was already opened\n");
382 return;
383 }
384 else if (Status !=
386 {
387 ShowMessages(
"err, unable to open the output source\n");
388 return;
389 }
390
391
392
393
394 break;
395 }
396 }
397
398 if (!OutputSourceFound)
399 {
401 return;
402 }
403 }
404 else if (!SplitCommand.at(1).compare("close"))
405 {
406
407
408
410 {
412 return;
413 }
414
415
416
417
418
420
422 {
423 TempList = TempList->Flink;
424
426 TempList,
428 OutputSourcesList);
429
430 if (strcmp(CurrentOutputSourceDetails->
Name,
431 SplitCommandCaseSensitive.at(2).c_str()) == 0)
432 {
433
434
435
436 OutputSourceFound =
TRUE;
437
438
439
440
442
444 {
445 ShowMessages(
"err, the name you entered was already closed\n");
446 return;
447 }
449 {
451 return;
452 }
453 else if (Status !=
455 {
457 return;
458 }
459
460
461
462
463 break;
464 }
465 }
466
467 if (!OutputSourceFound)
468 {
470 return;
471 }
472 }
473 else
474 {
475
476
477
478 ShowMessages(
"incorrect option at '%s'\n\n", SplitCommand.at(1).c_str());
480 return;
481 }
482}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
FORCEINLINE VOID InitializeListHead(_Out_ PLIST_ENTRY ListHead)
Definition Windows.h:41
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ PLIST_ENTRY Entry)
Definition Windows.h:115
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
DEBUGGER_OUTPUT_SOURCE_STATUS ForwardingCloseOutputSource(PDEBUGGER_EVENT_FORWARDING SourceDescriptor)
Closes the output source.
Definition forwarding.cpp:110
DEBUGGER_OUTPUT_SOURCE_STATUS ForwardingOpenOutputSource(PDEBUGGER_EVENT_FORWARDING SourceDescriptor)
Opens the output source.
Definition forwarding.cpp:40
VOID * ForwardingCreateOutputSource(DEBUGGER_EVENT_FORWARDING_TYPE SourceType, const string &Description, SOCKET *Socket, HMODULE *Module)
Create a new source (create handle from the source)
Definition forwarding.cpp:215
UINT64 ForwardingGetNewOutputSourceTag()
Get the output source tag and increase the global variable for tag.
Definition forwarding.cpp:28
@ EVENT_FORWARDING_STATE_OPENED
Definition forwarding.h:54
@ EVENT_FORWARDING_CLOSED
Definition forwarding.h:55
@ EVENT_FORWARDING_STATE_NOT_OPENED
Definition forwarding.h:53
enum _DEBUGGER_EVENT_FORWARDING_TYPE DEBUGGER_EVENT_FORWARDING_TYPE
event forwarding type
#define MAXIMUM_CHARACTERS_FOR_EVENT_FORWARDING_NAME
maximum characters for event forwarding source names
Definition forwarding.h:32
@ DEBUGGER_OUTPUT_SOURCE_STATUS_SUCCESSFULLY_OPENED
Definition forwarding.h:67
@ DEBUGGER_OUTPUT_SOURCE_STATUS_UNKNOWN_ERROR
Definition forwarding.h:71
@ DEBUGGER_OUTPUT_SOURCE_STATUS_ALREADY_OPENED
Definition forwarding.h:69
@ DEBUGGER_OUTPUT_SOURCE_STATUS_SUCCESSFULLY_CLOSED
Definition forwarding.h:68
@ DEBUGGER_OUTPUT_SOURCE_STATUS_ALREADY_CLOSED
Definition forwarding.h:70
enum _DEBUGGER_OUTPUT_SOURCE_STATUS DEBUGGER_OUTPUT_SOURCE_STATUS
output source status
@ EVENT_FORWARDING_TCP
Definition forwarding.h:42
@ EVENT_FORWARDING_MODULE
Definition forwarding.h:43
@ EVENT_FORWARDING_FILE
Definition forwarding.h:41
@ EVENT_FORWARDING_NAMEDPIPE
Definition forwarding.h:40
struct _DEBUGGER_EVENT_FORWARDING * PDEBUGGER_EVENT_FORWARDING
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
NULL()
Definition test-case-generator.py:530
BOOLEAN g_OutputSourcesInitialized
it shows whether the debugger started using output sources or not or in other words,...
Definition globals.h:408
VOID CommandOutputHelp()
help of the output command
Definition output.cpp:26
LIST_ENTRY g_OutputSources
Holds a list of output sources created by output command.
Definition globals.h:417
structures hold the detail of event forwarding
Definition forwarding.h:80
LIST_ENTRY OutputSourcesList
Definition forwarding.h:88
DEBUGGER_EVENT_FORWARDING_TYPE Type
Definition forwarding.h:81
DEBUGGER_EVENT_FORWARDING_STATE State
Definition forwarding.h:82
CHAR Name[MAXIMUM_CHARACTERS_FOR_EVENT_FORWARDING_NAME]
Definition forwarding.h:89
SOCKET Socket
Definition forwarding.h:84
HMODULE Module
Definition forwarding.h:85
UINT64 OutputUniqueTag
Definition forwarding.h:86
VOID * Handle
Definition forwarding.h:83