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

Main interface to connect applications to driver. More...

#include "pch.h"

Functions

VOID SetTextMessageCallback (PVOID Handler)
 Set the function callback that will be called if any message needs to be shown.
 
PVOID SetTextMessageCallbackUsingSharedBuffer (PVOID Handler)
 Set the function callback that will be called if any message needs to be shown.
 
VOID UnsetTextMessageCallback ()
 Unset the function callback that will be called if any message needs to be shown.
 
VOID ShowMessages (const char *Fmt,...)
 Show messages.
 
VOID ReadIrpBasedBuffer ()
 Read kernel buffers using IRP Pending.
 
DWORD WINAPI IrpBasedBufferThread (void *data)
 Create a thread for pending buffers.
 
INT HyperDbgInstallVmmDriver ()
 Install VMM driver.
 
int HyperDbgStopDriver (LPCTSTR DriverName)
 Stop the driver.
 
INT HyperDbgStopVmmDriver ()
 Stop VMM driver.
 
int HyperDbgUninstallDriver (LPCTSTR DriverName)
 Remove the driver.
 
INT HyperDbgUninstallVmmDriver ()
 Remove the VMM driver.
 
INT HyperDbgCreateHandleFromVmmModule ()
 Create handle from VMM module.
 
INT HyperDbgUnloadVmm ()
 Unload VMM driver.
 
INT HyperDbgLoadVmmModule ()
 load vmm module
 

Variables

HANDLE g_DeviceHandle
 Holds the global handle of device which is used to send the request to the kernel by IOCTL, this handle is not used for IRP Pending of message tracing this handle is used in KD VMM.
 
HANDLE g_IsDriverLoadedSuccessfully
 Handle to show that if the debugger is loaded successfully.
 
BOOLEAN g_IsVmxOffProcessStart
 Shows whether the vmxoff process start or not.
 
PVOID g_MessageHandler
 The handler for ShowMessages function this is because the user might choose not to use printf and instead use his/her handler for showing messages.
 
PVOID g_MessageHandlerSharedBuffer
 The shared buffer for the handler of ShowMessages function.
 
TCHAR g_DriverLocation [MAX_PATH]
 Holds the location driver to install it.
 
TCHAR g_DriverName [MAX_PATH]
 Holds the name of the driver to install it.
 
BOOLEAN g_UseCustomDriverLocation
 Whether the user wants to use a custom driver location or not.
 
LIST_ENTRY g_EventTrace
 Holds a list of events in kernel and the state of events and the commands to show the state of each command (disabled/enabled)
 
BOOLEAN g_LogOpened
 Shows whether the '.logopen' command is executed and the log file is open or not.
 
BOOLEAN g_BreakPrintingOutput
 Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
 
BOOLEAN g_IsConnectedToRemoteDebugger
 Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this system.
 
BOOLEAN g_OutputSourcesInitialized
 it shows whether the debugger started using output sources or not or in other words, is g_OutputSources initialized with a variable or it is empty
 
BOOLEAN g_IsSerialConnectedToRemoteDebugger
 Shows if the debugger was connected to remote debugger (A remote host)
 
BOOLEAN g_IsDebuggerModulesLoaded
 this variable is used to indicate that modules are loaded so we make sure to later use a trace of loading in 'unload' command (used in Debugger VMM)
 
BOOLEAN g_IsReversingMachineModulesLoaded
 
LIST_ENTRY g_OutputSources
 Holds a list of output sources created by output command.
 

Detailed Description

Main interface to connect applications to driver.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-04-11

Function Documentation

◆ HyperDbgCreateHandleFromVmmModule()

INT HyperDbgCreateHandleFromVmmModule ( )

Create handle from VMM module.

Returns
INT return zero if it was successful or non-zero if there was error

lpSecurityAttirbutes

lpTemplateFile

617{
618 DWORD ErrorNum;
619 DWORD ThreadId;
620
621 if (g_DeviceHandle)
622 {
623 ShowMessages("handle of the driver found, if you use 'load' before, please "
624 "unload it using 'unload'\n");
625 return 1;
626 }
627
628 //
629 // Make sure that this variable is false, because it might be set to
630 // true as the result of a previous load
631 //
633
634 //
635 // Init entering vmx
636 //
637 g_DeviceHandle = CreateFileA(
638 "\\\\.\\HyperDbgDebuggerDevice",
639 GENERIC_READ | GENERIC_WRITE,
640 FILE_SHARE_READ | FILE_SHARE_WRITE,
641 NULL,
642 OPEN_EXISTING,
643 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
644 NULL);
645
646 if (g_DeviceHandle == INVALID_HANDLE_VALUE)
647 {
648 ErrorNum = GetLastError();
649 if (ErrorNum == ERROR_ACCESS_DENIED)
650 {
651 ShowMessages("err, access denied\nare you sure you have administrator "
652 "rights?\n");
653 }
654 else if (ErrorNum == ERROR_GEN_FAILURE)
655 {
656 ShowMessages("err, a device attached to the system is not functioning\n"
657 "vmx feature might be disabled from BIOS or VBS/HVCI is active\n");
658 }
659 else
660 {
661 ShowMessages("err, CreateFile failed (%x)\n", ErrorNum);
662 }
663
665 return 1;
666 }
667
668 //
669 // Initialize the list of events
670 //
672
673#if !UseDbgPrintInsteadOfUsermodeMessageTracking
674 HANDLE Thread = CreateThread(NULL, 0, IrpBasedBufferThread, NULL, 0, &ThreadId);
675
676 // if (Thread)
677 // {
678 // ShowMessages("thread Created successfully\n");
679 // }
680
681#endif
682
683 return 0;
684}
#define FALSE
Definition BasicTypes.h:54
unsigned long DWORD
Definition BasicTypes.h:22
FORCEINLINE VOID InitializeListHead(_Out_ PLIST_ENTRY ListHead)
Definition Windows.h:41
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:471
DWORD WINAPI IrpBasedBufferThread(void *data)
Create a thread for pending buffers.
Definition libhyperdbg.cpp:483
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
BOOLEAN g_IsVmxOffProcessStart
Shows whether the vmxoff process start or not.
Definition globals.h:462
LIST_ENTRY g_EventTrace
Holds a list of events in kernel and the state of events and the commands to show the state of each c...
Definition globals.h:400
NULL()
Definition test-case-generator.py:530

◆ HyperDbgInstallVmmDriver()

INT HyperDbgInstallVmmDriver ( )

Install VMM driver.

Returns
INT return zero if it was successful or non-zero if there was error
503{
504 //
505 // The driver is not started yet so let us the install driver
506 // First setup full path to driver name
507 //
508
509 //
510 // If the user has not specified a custom driver location, then we
511 // need to find the driver in the same directory as the executable
512 //
514 {
516 {
517 return 1;
518 }
519
520 //
521 // Use default driver name
522 //
524 }
525
527 {
528 ShowMessages("unable to install VMM driver\n");
529
530 //
531 // Error - remove driver
532 //
534
535 return 1;
536 }
537
538 return 0;
539}
#define TRUE
Definition BasicTypes.h:55
#define KERNEL_DEBUGGER_DRIVER_NAME
name of HyperDbg's debugger driver
Definition Definition.h:40
#define KERNEL_DEBUGGER_DRIVER_NAME_AND_EXTENSION
name of HyperDbg's debugger driver + extension
Definition Definition.h:46
BOOLEAN SetupPathForFileName(const CHAR *FileName, _Inout_updates_bytes_all_(BufferLength) PCHAR FileLocation, ULONG BufferLength, BOOLEAN CheckFileExists)
Setup file name.
Definition install.cpp:440
BOOLEAN ManageDriver(LPCTSTR DriverName, LPCTSTR ServiceName, UINT16 Function)
Manage Driver.
Definition install.cpp:121
#define DRIVER_FUNC_REMOVE
Definition install.h:36
#define DRIVER_FUNC_INSTALL
Definition install.h:34
TCHAR g_DriverLocation[MAX_PATH]
Holds the location driver to install it.
Definition globals.h:423
TCHAR g_DriverName[MAX_PATH]
Holds the name of the driver to install it.
Definition globals.h:429
BOOLEAN g_UseCustomDriverLocation
Whether the user wants to use a custom driver location or not.
Definition globals.h:435

◆ HyperDbgLoadVmmModule()

INT HyperDbgLoadVmmModule ( )

load vmm module

Returns
int return zero if it was successful or non-zero if there
799{
800 BOOL Status;
801 HANDLE hToken;
802 char CpuId[13] = {0};
803
804 //
805 // Enable Debug privilege
806 //
807 Status = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
808 if (!Status)
809 {
810 ShowMessages("err, OpenProcessToken failed (%x)\n", GetLastError());
811 return 1;
812 }
813
814 Status = SetPrivilege(hToken, SE_DEBUG_NAME, TRUE);
815 if (!Status)
816 {
817 CloseHandle(hToken);
818 return 1;
819 }
820
821 //
822 // Read the vendor string
823 //
824 CpuReadVendorString(CpuId);
825
826 ShowMessages("current processor vendor is : %s\n", CpuId);
827
828 if (strcmp(CpuId, "GenuineIntel") == 0)
829 {
830 ShowMessages("virtualization technology is vt-x\n");
831 }
832 else
833 {
834 ShowMessages("this program is not designed to run in a non-VT-x "
835 "environment !\n");
836 return 1;
837 }
838
840 {
841 ShowMessages("vmx operation is supported by your processor\n");
842 }
843 else
844 {
845 ShowMessages("vmx operation is not supported by your processor\n");
846 return 1;
847 }
848
849 //
850 // Create event to show if the hypervisor is loaded or not
851 //
852 g_IsDriverLoadedSuccessfully = CreateEvent(NULL, FALSE, FALSE, NULL);
853
855 {
856 //
857 // No need to handle anymore
858 //
859 CloseHandle(g_IsDriverLoadedSuccessfully);
860 return 1;
861 }
862
863 //
864 // Vmm module (Hypervisor) is loaded
865 //
866
867 //
868 // We wait for the first message from the kernel debugger to continue
869 //
870 WaitForSingleObject(
872 INFINITE);
873
874 //
875 // No need to handle anymore
876 //
877 CloseHandle(g_IsDriverLoadedSuccessfully);
878
879 //
880 // If we reach here so the module are loaded
881 //
883
884 ShowMessages("vmm module is running...\n");
885
886 return 0;
887}
int BOOL
Definition BasicTypes.h:23
BOOLEAN VmxSupportDetection()
Detect whether the VMX is supported or not.
Definition common.cpp:505
BOOL SetPrivilege(HANDLE Token, LPCTSTR Privilege, BOOL EnablePrivilege)
SetPrivilege enables/disables process token privilege.
Definition common.cpp:522
VOID CpuReadVendorString(CHAR *Result)
Reads the CPU vendor string.
Definition cpu.cpp:249
HANDLE g_IsDriverLoadedSuccessfully
Handle to show that if the debugger is loaded successfully.
Definition globals.h:130
BOOLEAN g_IsDebuggerModulesLoaded
this variable is used to indicate that modules are loaded so we make sure to later use a trace of loa...
Definition globals.h:356
INT HyperDbgCreateHandleFromVmmModule()
Create handle from VMM module.
Definition libhyperdbg.cpp:616

◆ HyperDbgStopDriver()

int HyperDbgStopDriver ( LPCTSTR DriverName)

Stop the driver.

Returns
int return zero if it was successful or non-zero if there was error
549{
550 //
551 // Unload the driver if loaded
552 //
553 if (g_DriverLocation[0] != (TCHAR)0 && ManageDriver(DriverName, g_DriverLocation, DRIVER_FUNC_STOP))
554 {
555 return 0;
556 }
557 else
558 {
559 return 1;
560 }
561}
#define DRIVER_FUNC_STOP
Definition install.h:35

◆ HyperDbgStopVmmDriver()

INT HyperDbgStopVmmDriver ( )

Stop VMM driver.

Returns
INT return zero if it was successful or non-zero if there was error
571{
573}
int HyperDbgStopDriver(LPCTSTR DriverName)
Stop the driver.
Definition libhyperdbg.cpp:548

◆ HyperDbgUninstallDriver()

int HyperDbgUninstallDriver ( LPCTSTR DriverName)

Remove the driver.

Returns
int return zero if it was successful or non-zero if there was error
583{
584 //
585 // Unload the driver if loaded. Ignore any errors
586 //
587 if (g_DriverLocation[0] != (TCHAR)0 && ManageDriver(DriverName, g_DriverLocation, DRIVER_FUNC_REMOVE))
588 {
589 return 0;
590 }
591 else
592 {
593 return 1;
594 }
595}

◆ HyperDbgUninstallVmmDriver()

INT HyperDbgUninstallVmmDriver ( )

Remove the VMM driver.

Returns
INT return zero if it was successful or non-zero if there was error
605{
607}
int HyperDbgUninstallDriver(LPCTSTR DriverName)
Remove the driver.
Definition libhyperdbg.cpp:582

◆ HyperDbgUnloadVmm()

INT HyperDbgUnloadVmm ( )

Unload VMM driver.

Returns
INT return zero if it was successful or non-zero if there was error
694{
695 BOOL Status;
696
698
699 ShowMessages("start terminating...\n");
700
701 //
702 // Uninitialize the user debugger if it's initialized
703 //
705
706 //
707 // Send IOCTL to mark complete all IRP Pending
708 //
709 Status = DeviceIoControl(g_DeviceHandle, // Handle to device
710 IOCTL_TERMINATE_VMX, // IO Control Code (IOCTL)
711 NULL, // Input Buffer to driver.
712 0, // Length of input buffer in bytes. (x 2 is bcuz
713 // as the driver is x64 and has 64 bit values)
714 NULL, // Output Buffer from driver.
715 0, // Length of output buffer in bytes.
716 NULL, // Bytes placed in buffer.
717 NULL // synchronous call
718 );
719
720 //
721 // wait to make sure we don't use an invalid handle in another Ioctl
722 //
723 if (!Status)
724 {
725 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
726 return 1;
727 }
728
729 //
730 // Send IOCTL to mark complete all IRP Pending
731 //
732 Status = DeviceIoControl(
733 g_DeviceHandle, // Handle to device
735 // Control
736 // code
737 NULL, // Input Buffer to driver.
738 0, // Length of input buffer in bytes. (x 2 is bcuz as the
739 // driver is x64 and has 64 bit values)
740 NULL, // Output Buffer from driver.
741 0, // Length of output buffer in bytes.
742 NULL, // Bytes placed in buffer.
743 NULL // synchronous call
744 );
745
746 //
747 // wait to make sure we don't use an invalid handle in another Ioctl
748 //
749 if (!Status)
750 {
751 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
752 return 1;
753 }
754
755 //
756 // Indicate that the finish process start or not
757 //
759
760 Sleep(1000); // Wait so next thread can return from IRP Pending
761
762 //
763 // Send IRP_MJ_CLOSE to driver to terminate Vmxs
764 //
765 if (!CloseHandle(g_DeviceHandle))
766 {
767 ShowMessages("err, closing handle 0x%x\n", GetLastError());
768 return 1;
769 };
770
771 //
772 // Null the handle to indicate that the driver's device is not ready
773 // to use
774 //
776
777 //
778 // Debugger module is not loaded anymore
779 //
781
782 //
783 // Check if we found an already built symbol table
784 //
786
787 ShowMessages("you're not on HyperDbg's hypervisor anymore!\n");
788
789 return 0;
790}
#define IOCTL_RETURN_IRP_PENDING_PACKETS_AND_DISALLOW_IOCTL
ioctl, irp pending mechanism for reading from message tracing buffers
Definition Ioctls.h:71
#define IOCTL_TERMINATE_VMX
ioctl, to terminate vmx and exit form debugger
Definition Ioctls.h:78
VOID UdUninitializeUserDebugger()
uninitialize user debugger
Definition Ud.c:77
#define AssertShowMessageReturnStmt(expr, message, rc)
Definition common.h:51
#define AssertReturnOne
Definition common.h:23
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:25
BOOLEAN SymbolDeleteSymTable()
Delete and free structures and variables related to the symbols.
Definition symbol.cpp:433

◆ IrpBasedBufferThread()

DWORD WINAPI IrpBasedBufferThread ( void * data)

Create a thread for pending buffers.

Parameters
Data
Returns
DWORD Device Handle
484{
485 //
486 // Do stuff. This will be the first function called on the new
487 // thread. When this function returns, the thread goes away. See
488 // MSDN for more details. Test Irp Based Notifications
489 //
491
492 return 0;
493}
VOID ReadIrpBasedBuffer()
Read kernel buffers using IRP Pending.
Definition libhyperdbg.cpp:170

◆ ReadIrpBasedBuffer()

VOID ReadIrpBasedBuffer ( )

Read kernel buffers using IRP Pending.

Parameters
DeviceDriver handle
Returns
VOID

lpSecurityAttirbutes

lpTemplateFile

171{
172 BOOL Status;
173 ULONG ReturnedLength;
174 REGISTER_NOTIFY_BUFFER RegisterEvent;
175 UINT32 OperationCode;
176 DWORD ErrorNum;
177 HANDLE Handle;
178
179 RegisterEvent.hEvent = NULL;
180 RegisterEvent.Type = IRP_BASED;
181
182 //
183 // Create another handle to be used in for reading kernel messages,
184 // it is because I noticed that if I use a same handle for IRP Pending
185 // and other IOCTLs then if I complete that IOCTL then both of the current
186 // IOCTL and the Pending IRP are completed and return to user mode,
187 // even if it's odd but that what happens, so this way we can solve it
188 // if you know why this problem happens, then contact me !
189 //
190 Handle = CreateFileA(
191 "\\\\.\\HyperDbgDebuggerDevice",
192 GENERIC_READ | GENERIC_WRITE,
193 FILE_SHARE_READ | FILE_SHARE_WRITE,
194 NULL,
195 OPEN_EXISTING,
196 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
197 NULL);
198
199 if (Handle == INVALID_HANDLE_VALUE)
200 {
201 ErrorNum = GetLastError();
202
203 if (ErrorNum == ERROR_ACCESS_DENIED)
204 {
205 ShowMessages("err, access denied\nare you sure you have administrator "
206 "rights?\n");
207 }
208 else if (ErrorNum == ERROR_GEN_FAILURE)
209 {
210 ShowMessages("err, a device attached to the system is not functioning\n"
211 "vmx feature might be disabled from BIOS or VBS/HVCI is active\n");
212 }
213 else
214 {
215 ShowMessages("err, CreateFile failed with (%x)\n", ErrorNum);
216 }
217
219 Handle = NULL;
220
221 return;
222 }
223
224 //
225 // allocate buffer for transferring messages
226 //
227 char * OutputBuffer = (char *)malloc(UsermodeBufferSize);
228
229 try
230 {
231 while (TRUE)
232 {
234 {
235 //
236 // Clear the buffer
237 //
238 ZeroMemory(OutputBuffer, UsermodeBufferSize);
239
240 Sleep(DefaultSpeedOfReadingKernelMessages); // we're not trying to eat all of the CPU ;)
241
242 Status = DeviceIoControl(
243 Handle, // Handle to device
244 IOCTL_REGISTER_EVENT, // IO Control Code (IOCTL)
245 &RegisterEvent, // Input Buffer to driver.
246 SIZEOF_REGISTER_EVENT * 2, // Length of input buffer in bytes. (x 2 is bcuz as the
247 // driver is x64 and has 64 bit values)
248 OutputBuffer, // Output Buffer from driver.
249 UsermodeBufferSize, // Length of output buffer in bytes.
250 &ReturnedLength, // Bytes placed in buffer.
251 NULL // synchronous call
252 );
253
254 if (!Status)
255 {
256 //
257 // Error occurred for second time, and we show the error message
258 //
259 // ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
260
261 //
262 // if we reach here, the packet is probably failed, it might
263 // be because of using flush command
264 //
265 continue;
266 }
267
268 //
269 // Compute the received buffer's operation code
270 //
271 OperationCode = 0;
272 memcpy(&OperationCode, OutputBuffer, sizeof(UINT32));
273
274 /*
275 ShowMessages("Returned Length : 0x%x \n", ReturnedLength);
276 ShowMessages("Operation Code : 0x%x \n", OperationCode);
277 */
278
279 switch (OperationCode)
280 {
282
284 {
285 //
286 // means that the user asserts a CTRL+C or CTRL+BREAK Signal
287 // we shouldn't show or save anything in this case
288 //
289 continue;
290 }
291
292 ShowMessages("%s", OutputBuffer + sizeof(UINT32));
293
294 break;
296
298 {
299 //
300 // means that the user asserts a CTRL+C or CTRL+BREAK Signal
301 // we shouldn't show or save anything in this case
302 //
303 continue;
304 }
305
306 ShowMessages("%s", OutputBuffer + sizeof(UINT32));
307
308 break;
311 {
312 //
313 // means that the user asserts a CTRL+C or CTRL+BREAK Signal
314 // we shouldn't show or save anything in this case
315 //
316 continue;
317 }
318
319 ShowMessages("%s", OutputBuffer + sizeof(UINT32));
320
321 break;
323
325 {
326 //
327 // means that the user asserts a CTRL+C or CTRL+BREAK Signal
328 // we shouldn't show or save anything in this case
329 //
330 continue;
331 }
332
333 ShowMessages("%s", OutputBuffer + sizeof(UINT32));
334
335 break;
336
338
340
341 break;
342
344
346
347 break;
348
350
352 (PDEBUGGER_GENERAL_EVENT_DETAIL)(OutputBuffer + sizeof(UINT32)),
353 ReturnedLength);
354
355 break;
356
358
360 (PDEBUGGER_GENERAL_ACTION)(OutputBuffer + sizeof(UINT32)),
361 ReturnedLength);
362
363 break;
364
366
368 (PDEBUGGER_MODIFY_EVENTS)(OutputBuffer + sizeof(UINT32)),
369 TRUE);
370
371 break;
372
374
376 (PDEBUGGER_MODIFY_EVENTS)(OutputBuffer + sizeof(UINT32)),
377 FALSE);
378
379 break;
380
382
383 //
384 // Indicate that driver (Hypervisor) is loaded successfully
385 //
387
388 break;
389
391
392 //
393 // End of receiving messages (IRPs), nothing to do
394 //
395 break;
396
398
399 //
400 // Pause debugger after getting the results
401 //
403 ((PDEBUGGEE_SYMBOL_REQUEST_PACKET)(OutputBuffer + sizeof(UINT32)))->ProcessId);
404
405 break;
406
408
409 //
410 // handle pausing packet from user debugger
411 //
413 (PDEBUGGEE_UD_PAUSED_PACKET)(OutputBuffer + sizeof(UINT32)));
414
415 break;
416
417 default:
418
419 //
420 // Check if there are available output sources
421 //
423 OutputBuffer + sizeof(UINT32),
424 ReturnedLength - sizeof(UINT32) - 1))
425 {
427 {
428 //
429 // means that the user asserts a CTRL+C or CTRL+BREAK Signal
430 // we shouldn't show or save anything in this case
431 //
432 continue;
433 }
434
435 ShowMessages("%s", OutputBuffer + sizeof(UINT32));
436 }
437
438 break;
439 }
440 }
441 else
442 {
443 //
444 // the thread should not work anymore
445 //
446 free(OutputBuffer);
447
448 //
449 // closeHandle
450 //
451 if (!CloseHandle(Handle))
452 {
453 ShowMessages("err, closing handle 0x%x\n", GetLastError());
454 }
455
456 return;
457 }
458 }
459 }
460 catch (const std::exception &)
461 {
462 ShowMessages("err, exception occurred in creating handle or parsing buffer\n");
463 }
464
465 free(OutputBuffer);
466
467 //
468 // closeHandle
469 //
470 if (!CloseHandle(Handle))
471 {
472 ShowMessages("err, closing handle 0x%x\n", GetLastError());
473 };
474}
unsigned int UINT32
Definition BasicTypes.h:48
unsigned long ULONG
Definition BasicTypes.h:37
#define OPERATION_DEBUGGEE_USER_INPUT
Definition Constants.h:374
#define OPERATION_HYPERVISOR_DRIVER_END_OF_IRPS
Definition Constants.h:382
#define OPERATION_LOG_ERROR_MESSAGE
Definition Constants.h:368
#define OPERATION_COMMAND_FROM_DEBUGGER_RELOAD_SYMBOL
Definition Constants.h:384
#define UsermodeBufferSize
size of user-mode buffer
Definition Constants.h:187
#define OPERATION_DEBUGGEE_ADD_ACTION_TO_EVENT
Definition Constants.h:376
#define OPERATION_NOTIFICATION_FROM_USER_DEBUGGER_PAUSE
Definition Constants.h:387
#define OPERATION_LOG_WARNING_MESSAGE
Definition Constants.h:367
#define OPERATION_DEBUGGEE_REGISTER_EVENT
Definition Constants.h:375
#define OPERATION_HYPERVISOR_DRIVER_IS_SUCCESSFULLY_LOADED
Definition Constants.h:380
#define OPERATION_LOG_INFO_MESSAGE
Message logs id that comes from kernel-mode to user-mode.
Definition Constants.h:366
#define OPERATION_DEBUGGEE_CLEAR_EVENTS_WITHOUT_NOTIFYING_DEBUGGER
Definition Constants.h:379
#define OPERATION_DEBUGGEE_CLEAR_EVENTS
Definition Constants.h:378
#define OPERATION_LOG_NON_IMMEDIATE_MESSAGE
Definition Constants.h:369
#define OPERATION_COMMAND_FROM_DEBUGGER_CLOSE_AND_UNLOAD_VMM
Definition Constants.h:372
@ IRP_BASED
Definition DataTypes.h:255
#define DefaultSpeedOfReadingKernelMessages
The speed delay for showing messages from kernel-mode to user-mode in VMI-mode, using a lower value c...
Definition Definition.h:72
#define IOCTL_REGISTER_EVENT
ioctl, register a new event
Definition Ioctls.h:64
BOOLEAN ForwardingCheckAndPerformEventForwarding(UINT32 OperationCode, CHAR *Message, UINT32 MessageLength)
Check and send the event result to the corresponding sources.
Definition forwarding.cpp:439
#define SIZEOF_REGISTER_EVENT
Definition Events.h:429
BOOLEAN KdRegisterEventInDebuggee(PDEBUGGER_GENERAL_EVENT_DETAIL EventRegBuffer, UINT32 Length)
BOOLEAN KdSendModifyEventInDebuggee(PDEBUGGER_MODIFY_EVENTS ModifyEvent, BOOLEAN SendTheResultBackToDebugger)
BOOLEAN KdCloseConnection()
VOID KdHandleUserInputInDebuggee(DEBUGGEE_USER_INPUT_PACKET *Descriptor)
BOOLEAN KdReloadSymbolsInDebuggee(BOOLEAN PauseDebuggee, UINT32 UserProcessId)
BOOLEAN KdAddActionToEventInDebuggee(PDEBUGGER_GENERAL_ACTION ActionAddingBuffer, UINT32 Length)
BOOLEAN g_OutputSourcesInitialized
it shows whether the debugger started using output sources or not or in other words,...
Definition globals.h:408
BOOLEAN g_BreakPrintingOutput
Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
Definition globals.h:499
The structure of .sym reload packet in HyperDbg.
Definition RequestStructures.h:1047
The structure of pausing packet in uHyperDbg.
Definition DataTypes.h:229
The structure of user-input packet in HyperDbg.
Definition DataTypes.h:140
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
request for modifying events (enable/disable/clear)
Definition Events.h:242
Used to register event for transferring buffer between user-to-kernel.
Definition DataTypes.h:279
NOTIFY_TYPE Type
Definition DataTypes.h:280
HANDLE hEvent
Definition DataTypes.h:281
VOID UdHandleUserDebuggerPausing(PDEBUGGEE_UD_PAUSED_PACKET PausePacket)
Handle pause packets from user debugger.
Definition user-listening.cpp:29

◆ SetTextMessageCallback()

VOID SetTextMessageCallback ( PVOID Handler)

Set the function callback that will be called if any message needs to be shown.

Parameters
HandlerFunction that handles the messages
Returns
VOID
46{
47 g_MessageHandler = Handler;
48}
PVOID g_MessageHandler
The handler for ShowMessages function this is because the user might choose not to use printf and ins...
Definition globals.h:450

◆ SetTextMessageCallbackUsingSharedBuffer()

PVOID SetTextMessageCallbackUsingSharedBuffer ( PVOID Handler)

Set the function callback that will be called if any message needs to be shown.

Parameters
HandlerFunction that handles the messages
Returns
PVOID
59{
60 g_MessageHandler = Handler;
62
64 {
66 return NULL;
67 }
68
70
72}
#define TCP_END_OF_BUFFER_CHARS_COUNT
count of characters for tcp end of buffer
Definition Constants.h:440
#define COMMUNICATION_BUFFER_SIZE
Packet size for TCP connections.
Definition Constants.h:330
PVOID g_MessageHandlerSharedBuffer
The shared buffer for the handler of ShowMessages function.
Definition globals.h:456

◆ ShowMessages()

VOID ShowMessages ( const char * Fmt,
... )

Show messages.

Parameters
Fmtformat string message
...arguments
Returns
VOID
97{
98 va_list ArgList;
99 va_list Args;
101
103 {
104 va_start(Args, Fmt);
105
106 vprintf(Fmt, Args);
107
108 va_end(Args);
109
110 if (!g_LogOpened)
111 {
112 return;
113 }
114 }
115
116 va_start(ArgList, Fmt);
117
118 int SprintfResult = vsprintf_s(TempMessage, Fmt, ArgList);
119
120 va_end(ArgList);
121
122 if (SprintfResult != -1)
123 {
125 {
126 //
127 // vsprintf_s and vswprintf_s return the number of characters written,
128 // not including the terminating null character, or a negative value
129 // if an output error occurs.
130 //
131 RemoteConnectionSendResultsToHost(TempMessage, SprintfResult);
132 }
134 {
135 KdSendUsermodePrints(TempMessage, SprintfResult);
136 }
137
138 if (g_LogOpened)
139 {
140 //
141 // .logopen command executed
142 //
143 LogopenSaveToFile(TempMessage);
144 }
145 if (g_MessageHandler != NULL)
146 {
147 //
148 // There is another handler
149 //
151 {
153 }
154 else
155 {
156 memcpy(g_MessageHandlerSharedBuffer, TempMessage, strlen(TempMessage) + 1);
158 }
159 }
160 }
161}
int(* SendMessageWWithSharedBufferCallback)()
Callback type that can be used to be used as a custom ShowMessages function (using shared buffer)
Definition DataTypes.h:129
int(* SendMessageWithParamCallback)(const char *Text)
Callback type that can be used to be used as a custom ShowMessages function (by passing message as a ...
Definition DataTypes.h:122
VOID KdSendUsermodePrints(CHAR *Input, UINT32 Length)
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host)
Definition rev.cpp:20
BOOLEAN g_LogOpened
Shows whether the '.logopen' command is executed and the log file is open or not.
Definition globals.h:478
BOOLEAN g_IsConnectedToRemoteDebugger
Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this sys...
Definition globals.h:81
VOID LogopenSaveToFile(const char *Text)
Append text to the file object.
Definition logopen.cpp:119
int RemoteConnectionSendResultsToHost(const char *sendbuf, int len)
Send the results of executing a command from deubggee (server, guest) to the debugger (client,...
Definition remote-connection.cpp:481

◆ UnsetTextMessageCallback()

VOID UnsetTextMessageCallback ( )

Unset the function callback that will be called if any message needs to be shown.

Returns
VOID

Variable Documentation

◆ g_BreakPrintingOutput

BOOLEAN g_BreakPrintingOutput
extern

Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.

◆ g_DeviceHandle

HANDLE g_DeviceHandle
extern

Holds the global handle of device which is used to send the request to the kernel by IOCTL, this handle is not used for IRP Pending of message tracing this handle is used in KD VMM.

◆ g_DriverLocation

TCHAR g_DriverLocation[MAX_PATH]
extern

Holds the location driver to install it.

423{0};

◆ g_DriverName

TCHAR g_DriverName[MAX_PATH]
extern

Holds the name of the driver to install it.

429{0};

◆ g_EventTrace

LIST_ENTRY g_EventTrace
extern

Holds a list of events in kernel and the state of events and the commands to show the state of each command (disabled/enabled)

this list is not have any relation with the things that HyperDbg holds for each event in the kernel

400{0};

◆ g_IsConnectedToRemoteDebugger

BOOLEAN g_IsConnectedToRemoteDebugger
extern

Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this system.

◆ g_IsDebuggerModulesLoaded

BOOLEAN g_IsDebuggerModulesLoaded
extern

this variable is used to indicate that modules are loaded so we make sure to later use a trace of loading in 'unload' command (used in Debugger VMM)

◆ g_IsDriverLoadedSuccessfully

HANDLE g_IsDriverLoadedSuccessfully
extern

Handle to show that if the debugger is loaded successfully.

◆ g_IsReversingMachineModulesLoaded

BOOLEAN g_IsReversingMachineModulesLoaded
extern

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

Shows if the debugger was connected to remote debugger (A remote host)

◆ g_IsVmxOffProcessStart

BOOLEAN g_IsVmxOffProcessStart
extern

Shows whether the vmxoff process start or not.

◆ g_LogOpened

BOOLEAN g_LogOpened
extern

Shows whether the '.logopen' command is executed and the log file is open or not.

◆ g_MessageHandler

PVOID g_MessageHandler
extern

The handler for ShowMessages function this is because the user might choose not to use printf and instead use his/her handler for showing messages.

◆ g_MessageHandlerSharedBuffer

PVOID g_MessageHandlerSharedBuffer
extern

The shared buffer for the handler of ShowMessages function.

◆ g_OutputSources

LIST_ENTRY g_OutputSources
extern

Holds a list of output sources created by output command.

user-mode events and output sources are two separate things in HyperDbg

417{0};

◆ g_OutputSourcesInitialized

BOOLEAN g_OutputSourcesInitialized
extern

it shows whether the debugger started using output sources or not or in other words, is g_OutputSources initialized with a variable or it is empty

◆ g_UseCustomDriverLocation

BOOLEAN g_UseCustomDriverLocation
extern

Whether the user wants to use a custom driver location or not.