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

routines to kernel debugging More...

#include "pch.h"

Functions

BOOLEAN KdCheckForTheEndOfTheBuffer (PUINT32 CurrentLoopIndex, BYTE *Buffer)
 compares the buffer with a string
BOOLEAN KdCompareBufferWithString (CHAR *Buffer, const CHAR *CompareBuffer)
 compares the buffer with a string
BYTE KdComputeDataChecksum (PVOID Buffer, UINT32 Length)
 calculate the checksum of received buffer from debugger
VOID KdInterpretPausedDebuggee ()
 Interpret the packets from debuggee in the case of paused.
BOOLEAN KdSendContinuePacketToDebuggee ()
 Sends a continue or 'g' command packet to the debuggee.
BOOLEAN KdSendSwitchCorePacketToDebuggee (UINT32 NewCore)
 Sends a change core or '~ x' command packet to the debuggee.
BOOLEAN KdSendShortCircuitingEventToDebuggee (BOOLEAN IsEnabled)
 Sends a short-circuiting event request to debuggee.
BOOLEAN KdSendEventQueryAndModifyPacketToDebuggee (UINT64 Tag, DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction, BOOLEAN *IsEnabled)
 Sends a query or request to enable/disable/clear for event.
BOOLEAN KdSendFlushPacketToDebuggee ()
 Send a flush request to the debuggee.
BOOLEAN KdSendCallStackPacketToDebuggee (UINT64 BaseAddress, UINT32 Size, DEBUGGER_CALLSTACK_DISPLAY_METHOD DisplayMethod, BOOLEAN Is32Bit)
 Send a callstack request to the debuggee.
BOOLEAN KdSendTestQueryPacketToDebuggee (DEBUGGER_TEST_QUERY_STATE Type)
 Send a test query request to the debuggee.
BOOLEAN KdSendTestQueryPacketWithContextToDebuggee (DEBUGGER_TEST_QUERY_STATE Type, UINT64 Context)
 Send a test query request to the debuggee with the specified context.
BOOLEAN KdSendSymbolReloadPacketToDebuggee (UINT32 ProcessId)
 Send symbol reload packet to the debuggee.
BOOLEAN KdSendReadRegisterPacketToDebuggee (PDEBUGGEE_REGISTER_READ_DESCRIPTION RegDes, UINT32 RegBuffSize)
 Send a read register packet to the debuggee.
BOOLEAN KdSendWriteRegisterPacketToDebuggee (PDEBUGGEE_REGISTER_WRITE_DESCRIPTION RegDes)
 Send a write register packet to the debuggee.
BOOLEAN KdSendReadMemoryPacketToDebuggee (PDEBUGGER_READ_MEMORY ReadMem, UINT32 RequestSize)
 Send a Read memory packet to the debuggee.
BOOLEAN KdSendEditMemoryPacketToDebuggee (PDEBUGGER_EDIT_MEMORY EditMem, UINT32 Size)
 Send an Edit memory packet to the debuggee.
PDEBUGGER_EVENT_AND_ACTION_RESULT KdSendRegisterEventPacketToDebuggee (PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
 Send a register event request to the debuggee.
PDEBUGGER_EVENT_AND_ACTION_RESULT KdSendAddActionToEventPacketToDebuggee (PDEBUGGER_GENERAL_ACTION GeneralAction, UINT32 GeneralActionLength)
 Send an add action to event request to the debuggee.
BOOLEAN KdSendSwitchProcessPacketToDebuggee (DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_TYPE ActionType, UINT32 NewPid, UINT64 NewProcess, BOOLEAN SetChangeByClockInterrupt, PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS SymDetailsForProcessList)
 Sends a change process or show process details packet to the debuggee.
BOOLEAN KdSendSwitchThreadPacketToDebuggee (DEBUGGEE_DETAILS_AND_SWITCH_THREAD_TYPE ActionType, UINT32 NewTid, UINT64 NewThread, BOOLEAN CheckByClockInterrupt, PDEBUGGEE_THREAD_LIST_NEEDED_DETAILS SymDetailsForThreadList)
 Sends a change thread or show threads detail packet to the debuggee.
BOOLEAN KdSendPtePacketToDebuggee (PDEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS PtePacket)
 Sends a PTE or '!pte' command packet to the debuggee.
BOOLEAN KdSendPageinPacketToDebuggee (PDEBUGGER_PAGE_IN_REQUEST PageinPacket)
 Sends a page-in or '.pagein' command packet to the debuggee.
BOOLEAN KdSendVa2paAndPa2vaPacketToDebuggee (PDEBUGGER_VA2PA_AND_PA2VA_COMMANDS Va2paAndPa2vaPacket)
 Sends VA2PA and PA2VA packest, or '!va2pa' and '!pa2va' commands packet to the debuggee.
BOOLEAN KdSendApicActionPacketsToDebuggee (PDEBUGGER_APIC_REQUEST ApicRequest, UINT32 ExpectedRequestSize)
 Send requests for APIC packet to the debuggee.
BOOLEAN KdSendSmiPacketsToDebuggee (PSMI_OPERATION_PACKETS SmiOperationRequest, UINT32 ExpectedRequestSize)
 Send requests for SMI operation packet to the debuggee.
BOOLEAN KdSendHyperTraceLbrdumpPacketsToDebuggee (PHYPERTRACE_LBR_DUMP_PACKETS HyperTraceLbrdumpRequest, UINT32 ExpectedRequestSize)
 Send requests for HyperTrace LBR dump packet to the debuggee.
BOOLEAN KdSendHyperTracePtPacketsToDebuggee (PHYPERTRACE_PT_OPERATION_PACKETS HyperTracePtOperationRequest, UINT32 ExpectedRequestSize)
 Send requests for HyperTrace PT operation packet to the debuggee.
BOOLEAN KdSendQueryIdtPacketsToDebuggee (PINTERRUPT_DESCRIPTOR_TABLE_ENTRIES_PACKETS IdtRequest)
 Send requests for IDT packet to the debuggee.
BOOLEAN KdSendBpPacketToDebuggee (PDEBUGGEE_BP_PACKET BpPacket)
 Sends a breakpoint set or 'bp' command packet to the debuggee.
BOOLEAN KdSendListOrModifyPacketToDebuggee (PDEBUGGEE_BP_LIST_OR_MODIFY_PACKET ListOrModifyPacket)
 Sends a breakpoint list or modification packet to the debuggee.
BOOLEAN KdSendScriptPacketToDebuggee (UINT64 BufferAddress, UINT32 BufferLength, UINT32 Pointer, BOOLEAN IsFormat)
 Sends a script packet to the debuggee.
BOOLEAN KdSendUserInputPacketToDebuggee (const CHAR *Sendbuf, INT Len, BOOLEAN IgnoreBreakingAgain)
 Sends user input packet to the debuggee.
BOOLEAN KdSendSearchRequestPacketToDebuggee (UINT64 *SearchRequestBuffer, UINT32 SearchRequestBufferSize)
 Sends search query request packet to the debuggee.
BOOLEAN KdSendStepPacketToDebuggee (DEBUGGER_REMOTE_STEPPING_REQUEST StepRequestType)
 Sends p (step out) and t (step in) packet to the debuggee.
BOOLEAN KdSendPausePacketToDebuggee ()
 Sends a PAUSE packet to the debuggee.
BOOLEAN KdGetWindowVersion (CHAR *BufferToSave)
 Get Windows name, version and build to send to debugger.
BOOLEAN KdReceivePacketFromDebuggee (CHAR *BufferToSave, UINT32 *LengthReceived)
 Receive packet from the debuggee.
BOOLEAN KdReceivePacketFromDebugger (CHAR *BufferToSave, UINT32 *LengthReceived)
 Receive packet from the debugger.
BOOLEAN KdSendPacketToDebuggee (const CHAR *Buffer, UINT32 Length, BOOLEAN SendEndOfBuffer)
 Sends a special packet to the debuggee.
BOOLEAN KdCommandPacketToDebuggee (DEBUGGER_REMOTE_PACKET_TYPE PacketType, DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction)
 Sends a HyperDbg packet to the debuggee.
BOOLEAN KdCommandPacketAndBufferToDebuggee (DEBUGGER_REMOTE_PACKET_TYPE PacketType, DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction, CHAR *Buffer, UINT32 BufferLength)
 Sends a HyperDbg packet + a buffer to the debuggee.
VOID KdBreakControlCheckAndPauseDebugger (BOOLEAN SignalRunningFlag)
 check if the debuggee needs to be paused
VOID KdSetStatusAndWaitForPause ()
 Set the status of the debuggee to wait for the pause.
VOID KdBreakControlCheckAndContinueDebugger ()
 check if the debuggee needs to be continued
BOOLEAN KdSendResponseOfThePingPacket ()
 Respond to the debuggee with the version and build date of the debugger.
VOID KdTheRemoteSystemIsRunning ()
 wait for a event to be triggered and if the debuggee is running it just halts the system
BOOLEAN KdPrepareSerialConnectionToRemoteSystem (HANDLE SerialHandle, BOOLEAN IsNamedPipe, BOOLEAN PauseAfterConnection)
 Prepare serial to connect to the remote server.
BOOLEAN KdCheckIfDebuggerIsListening (HANDLE ComPortHandle)
 Check and handshake to make sure if the remote debugger is listening.
BOOLEAN KdPrepareAndConnectDebugPort (const CHAR *PortName, DWORD Baudrate, UINT32 Port, BOOLEAN IsPreparing, BOOLEAN IsNamedPipe, BOOLEAN PauseAfterConnection)
 Prepare and initialize COM port.
BOOLEAN KdSendGeneralBuffersFromDebuggeeToDebugger (DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction, PVOID Buffer, UINT32 BufferLength, BOOLEAN PauseDebuggeeWhenSent)
 Send general buffer from debuggee to debugger.
BOOLEAN KdReloadSymbolsInDebuggee (BOOLEAN PauseDebuggee, UINT32 UserProcessId)
 Send the packets of reloading symbols to build a new symbol table to the debugger and send the finished packet to the debugger.
BOOLEAN KdCloseConnection ()
 Send close packet to the debuggee and debugger.
BOOLEAN KdRegisterEventInDebuggee (PDEBUGGER_GENERAL_EVENT_DETAIL EventRegBuffer, UINT32 Length)
 Register an event in the debuggee.
BOOLEAN KdAddActionToEventInDebuggee (PDEBUGGER_GENERAL_ACTION ActionAddingBuffer, UINT32 Length)
 Add action to an event in the debuggee.
BOOLEAN KdSendModifyEventInDebuggee (PDEBUGGER_MODIFY_EVENTS ModifyEvent, BOOLEAN SendTheResultBackToDebugger)
 Modify the event ioctl in the debuggee.
VOID KdHandleUserInputInDebuggee (DEBUGGEE_USER_INPUT_PACKET *Descriptor)
 Handle user-input in debuggee.
VOID KdSendUsermodePrints (CHAR *Input, UINT32 Length)
 Send result of user-mode ShowMessages to debuggee.
VOID KdSendSymbolDetailPacket (PMODULE_SYMBOL_DETAIL SymbolDetailPacket, UINT32 CurrentSymbolInfoIndex, UINT32 TotalSymbols)
 Send each packet of debugging information (PDB) to the debugger.
VOID KdUninitializeConnection ()
 Uninitialize everything in both debuggee and debugger.
BOOLEAN KdSendPcitreePacketToDebuggee (PDEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET PcitreePacket)
 Sends '!pcitree' command, including buffer, to the debuggee.
BOOLEAN KdSendPcidevinfoPacketToDebuggee (PDEBUGGEE_PCIDEVINFO_REQUEST_RESPONSE_PACKET PciepinfoPacket)
 Request PCI device info (CAM). Current consumers include '!pcicam'.

Variables

HANDLE g_SerialListeningThreadHandle
 In debuggee and debugger, we save the handle of the user-mode listening thread for pauses here.
HANDLE g_SerialRemoteComPortHandle
 In debugger (not debuggee), we save the handle of the user-mode listening thread for remote system here.
HANDLE g_DebuggeeStopCommandEventHandle
 An event to make sure that the user won't give any command in debuggee and all the commands are coming from just the debugger.
DEBUGGER_SYNCRONIZATION_EVENTS_STATE g_KernelSyncronizationObjectsHandleTable [DEBUGGER_MAXIMUM_SYNCRONIZATION_KERNEL_DEBUGGER_OBJECTS]
 In debugger (not debuggee), we save the handle of the user-mode listening thread for pauses here for kernel debugger.
BYTE g_CurrentRunningInstruction [MAXIMUM_INSTR_SIZE]
 Current executing instructions.
BOOLEAN g_IsConnectedToHyperDbgLocally
 Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machine introspection) mode.
DEBUGGER_EVENT_AND_ACTION_RESULT g_DebuggeeResultOfRegisteringEvent
 Holds the result of registering events from the remote debuggee.
DEBUGGER_EVENT_AND_ACTION_RESULT g_DebuggeeResultOfAddingActionsToEvent
 Holds the result of adding action to events from the remote debuggee.
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
BOOLEAN g_IsSerialConnectedToRemoteDebugger
 Shows if the debugger was connected to remote debugger (A remote host).
BOOLEAN g_IsDebuggerConntectedToNamedPipe
 Shows if the debugger is connected to the guest using named pipe.
BOOLEAN g_IsDebuggeeRunning
 Shows if the debuggee is running or not.
BOOLEAN g_IsKdModuleLoaded
 shows whether the kernel debugger (KD) module is loaded or not
BOOLEAN g_IsVmmModuleLoaded
 shows whether the VMM module is loaded or not
BOOLEAN g_SerialConnectionAlreadyClosed
 In both debuggee and debugger we save the state of the closed connection to avoid double close.
BOOLEAN g_IgnoreNewLoggingMessages
 Shows if the debugger should show debuggee's messages or not.
BOOLEAN g_SharedEventStatus
 This is an OVERLAPPED structure for managing simultaneous read and writes for debugger (in current design debuggee is not needed to write simultaneously but it's needed for write).
BOOLEAN g_IsRunningInstruction32Bit
 whether the Current executing instructions is 32-bit or 64 bit
BOOLEAN g_IgnorePauseRequests
 Show whether the pause request (CTRL+C or CTRL+BREAK) should be ignored or not.
BOOLEAN g_IsDebuggeeInHandshakingPhase
 Shows if the debuggee is in the handshake phase or not.
BOOLEAN g_ShouldPreviousCommandBeContinued
 Shows whether the previous command should be continued or not.
BYTE g_EndOfBufferCheckSerial [4]
 the buffer that we set at the end of buffers for serial
ULONG g_CurrentRemoteCore
 Current core that the debuggee is debugging.

Detailed Description

routines to kernel debugging

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

Function Documentation

◆ KdAddActionToEventInDebuggee()

BOOLEAN KdAddActionToEventInDebuggee ( PDEBUGGER_GENERAL_ACTION ActionAddingBuffer,
UINT32 Length )

Add action to an event in the debuggee.

Parameters
ActionAddingBuffer
Length
Returns
BOOLEAN
3200{
3201 BOOL Status;
3202 ULONG ReturnedLength;
3203 DEBUGGER_EVENT_AND_ACTION_RESULT ReturnedBuffer = {0};
3204
3206
3207 Status =
3208 DeviceIoControl(g_DeviceHandle, // Handle to device
3209 IOCTL_DEBUGGER_ADD_ACTION_TO_EVENT, // IO Control Code (IOCTL)
3210 ActionAddingBuffer, // Input Buffer to driver.
3211 Length, // Input buffer length
3212 &ReturnedBuffer, // Output Buffer from driver.
3213 sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT), // Length
3214 // of
3215 // output
3216 // buffer
3217 // in
3218 // bytes.
3219 &ReturnedLength, // Bytes placed in buffer.
3220 NULL // synchronous call
3221 );
3222
3223 if (!Status)
3224 {
3225 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
3226 return FALSE;
3227 }
3228
3229 //
3230 // Now that we added the action to the event, we should send the
3231 // results to the debugger
3232 //
3235 &ReturnedBuffer,
3237 TRUE);
3238}
int BOOL
Definition BasicTypes.h:25
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
unsigned long ULONG
Definition BasicTypes.h:31
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_DEBUGGEE_RESULT_OF_ADDING_ACTION_TO_EVENT
Definition Connection.h:123
struct _DEBUGGER_EVENT_AND_ACTION_RESULT DEBUGGER_EVENT_AND_ACTION_RESULT
Status of register buffers.
#define IOCTL_DEBUGGER_ADD_ACTION_TO_EVENT
ioctl, add action to event
Definition Ioctls.h:171
BOOLEAN KdSendGeneralBuffersFromDebuggeeToDebugger(DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction, PVOID Buffer, UINT32 BufferLength, BOOLEAN PauseDebuggeeWhenSent)
Send general buffer from debuggee to debugger.
Definition kd.cpp:2911
#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

◆ KdBreakControlCheckAndContinueDebugger()

VOID KdBreakControlCheckAndContinueDebugger ( )

check if the debuggee needs to be continued

Returns
VOID
2092{
2093 //
2094 // Check if debuggee is paused or not
2095 //
2097 {
2098 //
2099 // Send the continue request to the remote computer
2100 //
2102 {
2103 //
2104 // Set the debuggee to show that it's running
2105 //
2107 }
2108 else
2109 {
2110 ShowMessages("err, unable to continue the debuggee\n");
2111 }
2112 }
2113}
BOOLEAN KdSendContinuePacketToDebuggee()
Sends a continue or 'g' command packet to the debuggee.
Definition kd.cpp:155
BOOLEAN g_IsDebuggeeRunning
Shows if the debuggee is running or not.
Definition globals.h:272
VOID KdSetStatusAndWaitForPause()
Set the status of the debuggee to wait for the pause.
Definition kd.cpp:2072

◆ KdBreakControlCheckAndPauseDebugger()

VOID KdBreakControlCheckAndPauseDebugger ( BOOLEAN SignalRunningFlag)

check if the debuggee needs to be paused

Parameters
SignalRunningFlag
Returns
VOID
2041{
2042 //
2043 // Check if debuggee is running, otherwise the user
2044 // pressed CTRL+C multiple times
2045 //
2047 {
2048 //
2049 // Send the pause request to the remote computer
2050 //
2052 {
2053 ShowMessages("err, unable to pause the debuggee\n");
2054 }
2055
2056 //
2057 // Signal the event
2058 //
2059 if (SignalRunningFlag)
2060 {
2062 }
2063 }
2064}
BOOLEAN KdSendPausePacketToDebuggee()
Sends a PAUSE packet to the debuggee.
Definition kd.cpp:1462
#define DbgReceivedKernelResponse(KernelSyncObjectId)
Definition common.h:168
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_IS_DEBUGGER_RUNNING
An event to show whether the debugger is running or not in kernel-debugger.
Definition debugger.h:33

◆ KdCheckForTheEndOfTheBuffer()

BOOLEAN KdCheckForTheEndOfTheBuffer ( PUINT32 CurrentLoopIndex,
BYTE * Buffer )

compares the buffer with a string

Parameters
CurrentLoopIndexNumber of previously read bytes
Buffer
Returns
BOOLEAN
57{
58 UINT32 ActualBufferLength;
59
60 ActualBufferLength = *CurrentLoopIndex;
61
62 //
63 // End of buffer is 4 character long
64 //
65 if (*CurrentLoopIndex <= 3)
66 {
67 return FALSE;
68 }
69
70 if (Buffer[ActualBufferLength] == SERIAL_END_OF_BUFFER_CHAR_4 &&
71 Buffer[ActualBufferLength - 1] == SERIAL_END_OF_BUFFER_CHAR_3 &&
72 Buffer[ActualBufferLength - 2] == SERIAL_END_OF_BUFFER_CHAR_2 &&
73 Buffer[ActualBufferLength - 3] == SERIAL_END_OF_BUFFER_CHAR_1)
74 {
75 //
76 // Clear the end character
77 //
78 Buffer[ActualBufferLength - 3] = NULL;
79 Buffer[ActualBufferLength - 2] = NULL;
80 Buffer[ActualBufferLength - 1] = NULL;
81 Buffer[ActualBufferLength] = NULL;
82
83 //
84 // Set the new length
85 //
86 *CurrentLoopIndex = ActualBufferLength - 3;
87
88 return TRUE;
89 }
90 return FALSE;
91}
unsigned int UINT32
Definition BasicTypes.h:54
#define SERIAL_END_OF_BUFFER_CHAR_4
Definition Constants.h:437
#define SERIAL_END_OF_BUFFER_CHAR_2
Definition Constants.h:435
#define SERIAL_END_OF_BUFFER_CHAR_1
characters of the buffer that we set at the end of buffers for serial
Definition Constants.h:434
#define SERIAL_END_OF_BUFFER_CHAR_3
Definition Constants.h:436
NULL()
Definition test-case-generator.py:530

◆ KdCheckIfDebuggerIsListening()

BOOLEAN KdCheckIfDebuggerIsListening ( HANDLE ComPortHandle)

Check and handshake to make sure if the remote debugger is listening.

Parameters
ComPortHandle
Returns
BOOLEAN
2325{
2326 CHAR BufferToReceive[MaxSerialPacketSize] = {0};
2327 CHAR * ReceivedPingBuildVersionBuffer = NULL;
2328 PDEBUGGER_REMOTE_PACKET TheActualPacket = NULL;
2329 UINT32 LengthReceived = 0;
2330 BOOLEAN Result = FALSE;
2331
2332 //
2333 // For logging purposes
2334 //
2335 // ShowMessages("the ping request is received\n");
2336
2337StartAgain:
2338
2339 //
2340 // Send the ping packet and request the version of the debugger
2341 //
2345 {
2346 }
2347
2348 //
2349 // Wait for handshake to complete or in other words
2350 // get the receive packet
2351 //
2352 if (!KdReceivePacketFromDebugger(BufferToReceive, &LengthReceived))
2353 {
2354 if (LengthReceived == 0 && BufferToReceive[0] == NULL)
2355 {
2356 //
2357 // The remote computer (debuggee) closed the connection
2358 //
2359 ShowMessages("err, the remote connection is closed\n");
2360
2361 return FALSE;
2362 }
2363 else
2364 {
2365 ShowMessages("err, invalid buffer received\n");
2366 goto StartAgain;
2367 }
2368 }
2369
2370 //
2371 // Check for invalid close packets
2372 //
2373 if (LengthReceived == 1 && BufferToReceive[0] == NULL)
2374 {
2375 ShowMessages("is the debugger listening? retry handshaking with the debugger... (timeout: 5 seconds)\n");
2376 goto StartAgain;
2377 }
2378
2379 //
2380 // Check the handshaking packet
2381 //
2382 TheActualPacket = (PDEBUGGER_REMOTE_PACKET)BufferToReceive;
2383
2384 if (TheActualPacket->Indicator == INDICATOR_OF_HYPERDBG_PACKET)
2385 {
2386 //
2387 // Check checksum
2388 //
2389 if (KdComputeDataChecksum((PVOID)&TheActualPacket->Indicator,
2390 LengthReceived - sizeof(BYTE)) != TheActualPacket->Checksum)
2391 {
2392 ShowMessages("err, checksum is invalid\n");
2393 goto StartAgain;
2394 }
2395
2396 //
2397 // Check if the packet type is correct
2398 //
2400 {
2401 //
2402 // sth wrong happened, the packet is not belonging to use
2403 // nothing to do, just wait again
2404 //
2405 ShowMessages("err, unknown packet received from the debuggee\n");
2406 goto StartAgain;
2407 }
2408
2409 //
2410 // It's a HyperDbg packet
2411 //
2412 switch (TheActualPacket->RequestedActionOfThePacket)
2413 {
2415
2416 ReceivedPingBuildVersionBuffer = (CHAR *)(((CHAR *)TheActualPacket) + sizeof(DEBUGGER_REMOTE_PACKET));
2417
2418 // ShowMessages("the answer to the PING request is received: %s\n", ReceivedPingBuildVersionBuffer);
2419
2420 if (strcmp((const CHAR *)BuildSignature, ReceivedPingBuildVersionBuffer) == 0)
2421 {
2422 //
2423 // Build version matched
2424 //
2425 Result = TRUE;
2426 }
2427 else
2428 {
2429 //
2430 // Build version doesn't match
2431 //
2433
2434 Result = FALSE;
2435 }
2436
2437 break;
2438
2439 default:
2440
2441 Result = FALSE;
2442 ShowMessages("err, invalid packet is received. did you connect to an instance of HyperDbg?\n"
2443 "maybe an incorrect COM source is specified\n");
2444
2445 break;
2446 }
2447 }
2448
2449 //
2450 // By default, we prevent the connection
2451 //
2452 return Result;
2453}
UCHAR BOOLEAN
Definition BasicTypes.h:35
void * PVOID
Definition BasicTypes.h:56
unsigned char BYTE
Definition BasicTypes.h:40
char CHAR
Definition BasicTypes.h:33
struct _DEBUGGER_REMOTE_PACKET * PDEBUGGER_REMOTE_PACKET
@ DEBUGGER_REMOTE_PACKET_TYPE_DEBUGGER_TO_DEBUGGEE_EXECUTE_ON_USER_MODE
Definition Connection.h:173
@ DEBUGGER_REMOTE_PACKET_TYPE_DEBUGGEE_TO_DEBUGGER
Definition Connection.h:178
@ DEBUGGER_REMOTE_PACKET_PING_AND_SEND_SUPPORTED_VERSION
Definition Connection.h:68
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_USER_MODE_DEBUGGER_VERSION
Definition Connection.h:63
struct _DEBUGGER_REMOTE_PACKET DEBUGGER_REMOTE_PACKET
The structure of remote packets in HyperDbg.
#define INDICATOR_OF_HYPERDBG_PACKET
constant indicator of a HyperDbg packet
Definition Constants.h:504
const UCHAR BuildSignature[]
Definition Constants.h:138
#define MaxSerialPacketSize
size of buffer for serial
Definition Constants.h:202
BYTE KdComputeDataChecksum(PVOID Buffer, UINT32 Length)
calculate the checksum of received buffer from debugger
Definition kd.cpp:121
BOOLEAN KdReceivePacketFromDebugger(CHAR *BufferToSave, UINT32 *LengthReceived)
Receive packet from the debugger.
Definition kd.cpp:1661
BOOLEAN KdCommandPacketToDebuggee(DEBUGGER_REMOTE_PACKET_TYPE PacketType, DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction)
Sends a HyperDbg packet to the debuggee.
Definition kd.cpp:1923
#define ASSERT_MESSAGE_BUILD_SIGNATURE_DOESNT_MATCH
Definition common.h:35
DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedActionOfThePacket
Definition Connection.h:201
DEBUGGER_REMOTE_PACKET_TYPE TypeOfThePacket
Definition Connection.h:200
BYTE Checksum
Definition Connection.h:198
UINT64 Indicator
Definition Connection.h:199

◆ KdCloseConnection()

BOOLEAN KdCloseConnection ( )

Send close packet to the debuggee and debugger.

This function close the connection in both debuggee and debugger both of the debuggee and debugger can use this function

Returns
BOOLEAN
3057{
3058 //
3059 // The process of closing connection already started
3060 //
3062 {
3063 return TRUE;
3064 }
3065 else
3066 {
3068 }
3069
3070 //
3071 // Unload the VMM driver if it's debuggee
3072 //
3074 {
3076 {
3077 //
3078 // The messages (and outputs) should no longer be passed
3079 // to the debugger, so we'll indicate that debugger is not
3080 // connected anymore
3081 //
3083
3084 //
3085 // Unload VMM
3086 //
3088 }
3089 }
3091 {
3092 //
3093 // Send close & unload packet to debuggee (vmx-root)
3094 //
3098 {
3099 //
3100 // It's a debugger, we should send the close packet to debuggee
3101 //
3102 ShowMessages("unloading debugger vmm module on debuggee...");
3103
3104 //
3105 // Send another packet so the user-mode is not waiting for new packet
3106 //
3110 }
3111 }
3112 else
3113 {
3114 //
3115 // If we're here, probably the connection started but the debuggee is closed
3116 // without sending the start packet; thus, the debugger has no idea about
3117 // connection but we should uninitialize everything
3118 //
3119 ShowMessages("err, start packet not received but the target machine closed the "
3120 "connection\n");
3121
3122 //
3123 // Not waiting for start packet
3124 //
3126 }
3127
3128 //
3129 // Close handle and uninitialize everything
3130 //
3132
3133 return TRUE;
3134}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
@ DEBUGGER_REMOTE_PACKET_TYPE_DEBUGGER_TO_DEBUGGEE_EXECUTE_ON_VMX_ROOT
Definition Connection.h:168
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_CLOSE_AND_UNLOAD_DEBUGGEE
Definition Connection.h:75
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_USER_MODE_DO_NOT_READ_ANY_PACKET
Definition Connection.h:62
BOOLEAN g_IsConnectedToHyperDbgLocally
Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machi...
Definition globals.h:89
BOOLEAN g_SerialConnectionAlreadyClosed
In both debuggee and debugger we save the state of the closed connection to avoid double close.
Definition globals.h:173
VOID KdUninitializeConnection()
Uninitialize everything in both debuggee and debugger.
Definition kd.cpp:3474
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_STARTED_PACKET_RECEIVED
Definition debugger.h:34
INT HyperDbgUnloadVmm()
Unload VMM module.
Definition libhyperdbg.cpp:388
BOOLEAN g_IsKdModuleLoaded
shows whether the kernel debugger (KD) module is loaded or not
Definition globals.h:22
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host).
Definition rev.cpp:18

◆ KdCommandPacketAndBufferToDebuggee()

BOOLEAN KdCommandPacketAndBufferToDebuggee ( DEBUGGER_REMOTE_PACKET_TYPE PacketType,
DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction,
CHAR * Buffer,
UINT32 BufferLength )

Sends a HyperDbg packet + a buffer to the debuggee.

Parameters
RequestedAction
Buffer
BufferLength
Returns
BOOLEAN
1975{
1976 DEBUGGER_REMOTE_PACKET Packet = {0};
1977
1978 //
1979 // Check if buffer not pass the boundary
1980 //
1981 if (sizeof(DEBUGGER_REMOTE_PACKET) + BufferLength + SERIAL_END_OF_BUFFER_CHARS_COUNT >
1983 {
1984 ShowMessages("err, buffer is above the maximum buffer size that can be sent to debuggee (%d > %d), "
1985 "for more information, please visit https://docs.hyperdbg.org/tips-and-tricks/misc/customize-build/increase-communication-buffer-size",
1988
1989 return FALSE;
1990 }
1991
1992 //
1993 // Make the packet's structure
1994 //
1996 Packet.TypeOfThePacket = PacketType;
1997
1998 //
1999 // Set the requested action
2000 //
2001 Packet.RequestedActionOfThePacket = RequestedAction;
2002
2003 //
2004 // calculate checksum of the packet
2005 //
2006 Packet.Checksum =
2007 KdComputeDataChecksum((PVOID)((UINT64)&Packet + 1),
2008 sizeof(DEBUGGER_REMOTE_PACKET) - sizeof(BYTE));
2009
2010 Packet.Checksum += KdComputeDataChecksum((PVOID)Buffer, BufferLength);
2011
2012 //
2013 // Send the first buffer (without ending buffer indication)
2014 //
2015 if (!KdSendPacketToDebuggee((const CHAR *)&Packet,
2016 sizeof(DEBUGGER_REMOTE_PACKET),
2017 FALSE))
2018 {
2019 return FALSE;
2020 }
2021
2022 //
2023 // Send the second buffer (with ending buffer indication)
2024 //
2025 if (!KdSendPacketToDebuggee((const CHAR *)Buffer, BufferLength, TRUE))
2026 {
2027 return FALSE;
2028 }
2029
2030 return TRUE;
2031}
#define SERIAL_END_OF_BUFFER_CHARS_COUNT
count of characters for serial end of buffer
Definition Constants.h:428
BOOLEAN KdSendPacketToDebuggee(const CHAR *Buffer, UINT32 Length, BOOLEAN SendEndOfBuffer)
Sends a special packet to the debuggee.
Definition kd.cpp:1783

◆ KdCommandPacketToDebuggee()

BOOLEAN KdCommandPacketToDebuggee ( DEBUGGER_REMOTE_PACKET_TYPE PacketType,
DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction )

Sends a HyperDbg packet to the debuggee.

Parameters
RequestedAction
Returns
BOOLEAN
1926{
1927 DEBUGGER_REMOTE_PACKET Packet = {0};
1928
1929 //
1930 // There is no check for boundary here as it's fixed to
1931 // sizeof(DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION) + sizeof(DEBUGGER_REMOTE_PACKET)
1932 //
1933
1934 //
1935 // Make the packet's structure
1936 //
1938 Packet.TypeOfThePacket = PacketType;
1939
1940 //
1941 // Set the requested action
1942 //
1943 Packet.RequestedActionOfThePacket = RequestedAction;
1944
1945 //
1946 // calculate checksum of the packet
1947 //
1948 Packet.Checksum =
1949 KdComputeDataChecksum((PVOID)((UINT64)&Packet + 1),
1950 sizeof(DEBUGGER_REMOTE_PACKET) - sizeof(BYTE));
1951
1952 if (!KdSendPacketToDebuggee((const CHAR *)&Packet,
1953 sizeof(DEBUGGER_REMOTE_PACKET),
1954 TRUE))
1955 {
1956 return FALSE;
1957 }
1958 return TRUE;
1959}

◆ KdCompareBufferWithString()

BOOLEAN KdCompareBufferWithString ( CHAR * Buffer,
const CHAR * CompareBuffer )

compares the buffer with a string

Parameters
Buffer
CompareBuffer
Returns
BOOLEAN
102{
103 INT Result;
104
105 Result = strcmp(Buffer, CompareBuffer);
106
107 if (Result == 0)
108 return TRUE;
109 else
110 return FALSE;
111}
int INT
Definition BasicTypes.h:43

◆ KdComputeDataChecksum()

BYTE KdComputeDataChecksum ( PVOID Buffer,
UINT32 Length )

calculate the checksum of received buffer from debugger

Parameters
Buffer
LengthReceived
Returns
BYTE
122{
123 BYTE CalculatedCheckSum = 0;
124 BYTE Temp = 0;
125 while (Length--)
126 {
127 Temp = *(BYTE *)Buffer;
128 CalculatedCheckSum = CalculatedCheckSum + Temp;
129 Buffer = (PVOID)((UINT64)Buffer + 1);
130 }
131 return CalculatedCheckSum;
132}

◆ KdGetWindowVersion()

BOOLEAN KdGetWindowVersion ( CHAR * BufferToSave)

Get Windows name, version and build to send to debugger.

Parameters
BufferToSave
Returns
BOOLEAN
1491{
1492 HKeyHolder currentVersion;
1493 DWORD valueType;
1494 CHAR bufferResult[MAXIMUM_CHARACTER_FOR_OS_NAME] = {0};
1495 BYTE bufferProductName[MAXIMUM_CHARACTER_FOR_OS_NAME] = {0};
1496 BYTE bufferCurrentBuild[MAXIMUM_CHARACTER_FOR_OS_NAME] = {0};
1497 BYTE bufferDisplayVersion[MAXIMUM_CHARACTER_FOR_OS_NAME] = {0};
1499
1500 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1501 LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)",
1502 0,
1503 KEY_QUERY_VALUE,
1504 &currentVersion) != ERROR_SUCCESS)
1505 {
1506 // return FALSE;
1507 }
1508
1509 if (RegQueryValueExA(currentVersion, "ProductName", nullptr, &valueType, bufferProductName, &bufferSize) != ERROR_SUCCESS)
1510 {
1511 // return FALSE;
1512 }
1513
1514 if (valueType != REG_SZ)
1515 {
1516 // return FALSE;
1517 }
1518
1519 bufferSize = MAXIMUM_CHARACTER_FOR_OS_NAME;
1520
1521 if (RegQueryValueExA(currentVersion, "DisplayVersion", nullptr, &valueType, bufferDisplayVersion, &bufferSize) != ERROR_SUCCESS)
1522 {
1523 // return FALSE;
1524 }
1525
1526 if (valueType != REG_SZ)
1527 {
1528 // return FALSE;
1529 }
1530 bufferSize = MAXIMUM_CHARACTER_FOR_OS_NAME;
1531
1532 if (RegQueryValueExA(currentVersion, "CurrentBuild", nullptr, &valueType, bufferCurrentBuild, &bufferSize) != ERROR_SUCCESS)
1533 {
1534 // return FALSE;
1535 }
1536
1537 if (valueType != REG_SZ)
1538 {
1539 // return FALSE;
1540 }
1541
1542 sprintf_s(bufferResult, "%s %s %s (OS Build %s)", bufferProductName, IsWindowsServer() ? "- Server" : "- Client", bufferDisplayVersion, bufferCurrentBuild);
1543
1544 memcpy(BufferToSave, bufferResult, MAXIMUM_CHARACTER_FOR_OS_NAME);
1545
1546 return TRUE;
1547}
unsigned long DWORD
Definition BasicTypes.h:38
#define MAXIMUM_CHARACTER_FOR_OS_NAME
maximum name for OS name buffer
Definition Constants.h:461

◆ KdHandleUserInputInDebuggee()

VOID KdHandleUserInputInDebuggee ( DEBUGGEE_USER_INPUT_PACKET * Descriptor)

Handle user-input in debuggee.

Parameters
Descriptor
Returns
VOID
3309{
3310 BOOL Status;
3311 ULONG ReturnedLength;
3312 CHAR * Input;
3313 DEBUGGER_SEND_COMMAND_EXECUTION_FINISHED_SIGNAL FinishExecutionRequest = {0};
3314
3315 Input = (CHAR *)Descriptor + sizeof(DEBUGGEE_USER_INPUT_PACKET);
3316
3317 //
3318 // Run the command
3319 //
3320 HyperDbgInterpreter(Input);
3321
3322 //
3323 // Check if it needs to send a signal to indicate that the execution of
3324 // command finished
3325 //
3326
3327 if (!Descriptor->IgnoreFinishedSignal)
3328 {
3329 //
3330 // By the way, we don't need to send an input buffer
3331 // to the kernel, but let's keep it like this, if we
3332 // want to pass some other arguments to the kernel in
3333 // the future
3334 //
3335 Status = DeviceIoControl(
3336 g_DeviceHandle, // Handle to device
3337 IOCTL_SEND_SIGNAL_EXECUTION_IN_DEBUGGEE_FINISHED, // IO Control Code (IOCTL)
3338 &FinishExecutionRequest, // Input Buffer to driver.
3340 // length
3341 &FinishExecutionRequest, // Output Buffer from driver.
3343 // output buffer
3344 // in bytes.
3345 &ReturnedLength, // Bytes placed in buffer.
3346 NULL // synchronous call
3347 );
3348
3349 if (!Status)
3350 {
3351 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
3352 return;
3353 }
3354 }
3355}
struct _DEBUGGEE_USER_INPUT_PACKET DEBUGGEE_USER_INPUT_PACKET
The structure of user-input packet in HyperDbg.
#define IOCTL_SEND_SIGNAL_EXECUTION_IN_DEBUGGEE_FINISHED
ioctl, send a signal that execution of command finished
Definition Ioctls.h:249
struct _DEBUGGER_SEND_COMMAND_EXECUTION_FINISHED_SIGNAL DEBUGGER_SEND_COMMAND_EXECUTION_FINISHED_SIGNAL
request for send a signal that command execution finished
#define SIZEOF_DEBUGGER_SEND_COMMAND_EXECUTION_FINISHED_SIGNAL
Definition RequestStructures.h:381
INT HyperDbgInterpreter(CHAR *Command)
Interpret commands.
Definition interpreter.cpp:800
BOOLEAN IgnoreFinishedSignal
Definition DataTypes.h:175

◆ KdInterpretPausedDebuggee()

VOID KdInterpretPausedDebuggee ( )

Interpret the packets from debuggee in the case of paused.

Returns
VOID
141{
142 //
143 // Wait for handshake to complete or in other words
144 // get the receive packet
145 //
147}
#define DbgWaitForKernelResponse(KernelSyncObjectId)
Definition common.h:98
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAUSED_DEBUGGEE_DETAILS
Definition debugger.h:35

◆ KdPrepareAndConnectDebugPort()

BOOLEAN KdPrepareAndConnectDebugPort ( const CHAR * PortName,
DWORD Baudrate,
UINT32 Port,
BOOLEAN IsPreparing,
BOOLEAN IsNamedPipe,
BOOLEAN PauseAfterConnection )

Prepare and initialize COM port.

Parameters
PortName
Baudrate
Port
IsPreparing
IsNamedPipe
PauseAfterConnection
Returns
BOOLEAN
2474{
2475 HANDLE Comm; /* Handle to the Serial port */
2476 BOOL Status; /* Status */
2477 DCB SerialParams = {0}; /* Initializing DCB structure */
2478 COMMTIMEOUTS Timeouts = {0}; /* Initializing timeouts structure */
2479 CHAR PortNo[20] = {0}; /* contain friendly name */
2480 BOOLEAN StatusIoctl;
2481 ULONG ReturnedLength;
2482 PDEBUGGER_PREPARE_DEBUGGEE DebuggeeRequest;
2483
2484 //
2485 // Check if the debugger or debuggee is already active
2486 //
2488 {
2489 return FALSE;
2490 }
2491
2492 if (IsPreparing && IsNamedPipe)
2493 {
2494 ShowMessages("err, cannot used named pipe for debuggee");
2495 return FALSE;
2496 }
2497
2498 if (!IsNamedPipe)
2499 {
2500 //
2501 // It's a serial
2502 //
2503
2504 //
2505 // Append name to make a Windows understandable format
2506 //
2507 sprintf_s(PortNo, 20, "\\\\.\\%s", PortName);
2508
2509 //
2510 // Open the serial com port (if it's the debugger (not debuggee)) then
2511 // open with Overlapped I/O
2512 //
2513
2514 if (IsPreparing)
2515 {
2516 //
2517 // It's debuggee (Non-overlapped I/O)
2518 //
2519 Comm = CreateFile(PortNo, // Friendly name
2520 GENERIC_READ | GENERIC_WRITE, // Read/Write Access
2521 0, // No Sharing, ports can't be shared
2522 NULL, // No Security
2523 OPEN_EXISTING, // Open existing port only
2524 0, // Non Overlapped I/O
2525 NULL); // Null for Comm Devices
2526
2527 //
2528 // Create event for overlapped I/O (Read)
2529 //
2530 g_OverlappedIoStructureForReadDebuggee.hEvent =
2531 CreateEvent(NULL, TRUE, FALSE, NULL);
2532 }
2533 else
2534 {
2535 //
2536 // It's debugger (Overlapped I/O)
2537 //
2538 Comm = CreateFile(PortNo, // Friendly name
2539 GENERIC_READ | GENERIC_WRITE, // Read/Write Access
2540 0, // No Sharing, ports can't be shared
2541 NULL, // No Security
2542 OPEN_EXISTING, // Open existing port only
2543 FILE_FLAG_OVERLAPPED, // Overlapped I/O
2544 NULL); // Null for Comm Devices
2545
2546 //
2547 // Create event for overlapped I/O (Read)
2548 //
2550 CreateEvent(NULL, TRUE, FALSE, NULL);
2551
2552 //
2553 // Create event for overlapped I/O (Write)
2554 //
2556 CreateEvent(NULL, TRUE, FALSE, NULL);
2557 }
2558
2559 if (Comm == INVALID_HANDLE_VALUE)
2560 {
2561 ShowMessages("err, port can't be opened\n");
2562 return FALSE;
2563 }
2564
2565 //
2566 // Purge the serial port
2567 //
2568 PurgeComm(Comm,
2569 PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
2570
2571 //
2572 // Setting the Parameters for the SerialPort
2573 //
2574 SerialParams.DCBlength = sizeof(SerialParams);
2575
2576 //
2577 // retrieves the current settings
2578 //
2579 Status = GetCommState(Comm, &SerialParams);
2580
2581 if (Status == FALSE)
2582 {
2583 CloseHandle(Comm);
2584 ShowMessages("err, to Get the COM state\n");
2585 return FALSE;
2586 }
2587
2588 SerialParams.BaudRate =
2589 Baudrate; // BaudRate = 9600 (Based on user selection)
2590 SerialParams.ByteSize = 8; // ByteSize = 8
2591 SerialParams.StopBits = ONESTOPBIT; // StopBits = 1
2592 SerialParams.Parity = NOPARITY; // Parity = None
2593 Status = SetCommState(Comm, &SerialParams);
2594
2595 if (Status == FALSE)
2596 {
2597 CloseHandle(Comm);
2598 ShowMessages("err, to Setting DCB Structure\n");
2599 return FALSE;
2600 }
2601
2602 //
2603 // Setting Timeouts (not use it anymore as we use special signature for
2604 // ending buffer)
2605 // (no need anymore as we use end buffer detection mechanism)
2606 //
2607
2608 /*
2609 Timeouts.ReadIntervalTimeout = 50;
2610 Timeouts.ReadTotalTimeoutConstant = 50;
2611 Timeouts.ReadTotalTimeoutMultiplier = 10;
2612 Timeouts.WriteTotalTimeoutConstant = 50;
2613 Timeouts.WriteTotalTimeoutMultiplier = 10;
2614
2615 if (SetCommTimeouts(Comm, &Timeouts) == FALSE) {
2616 ShowMessages("err, to Setting Time outs (%x).\n", GetLastError());
2617 return FALSE;
2618 }
2619 */
2620 }
2621 else
2622 {
2623 //
2624 // It's a namedpipe
2625 //
2627
2628 if (!Comm)
2629 {
2630 //
2631 // Unable to create handle
2632 //
2633 ShowMessages("is the virtual machine running?\n");
2634 return FALSE;
2635 }
2636 }
2637
2638 if (IsPreparing)
2639 {
2640 //
2641 // It's a debuggee request
2642 //
2643
2644 //
2645 // We entered the handshaking phase
2646 //
2648
2649 //
2650 // Set handle to serial device
2651 //
2653
2654 //
2655 // Check if debuggee is listening before loading module
2656 //
2658 {
2659 CloseHandle(Comm);
2662
2663 return FALSE;
2664 }
2665 else
2666 {
2667 //
2668 // Not in handshaking phase anymore (The handshaking phase was successful)
2669 //
2671 }
2672
2673 //
2674 // First, connect to local machine and we load the VMM module as it's a
2675 // module that is responsible for working on debugger
2676 //
2678
2679 //
2680 // Load the VMM
2681 //
2683 {
2684 CloseHandle(Comm);
2687
2688 ShowMessages("failed to install or load the driver\n");
2689 return FALSE;
2690 }
2691
2692 //
2693 // Check if driver is loaded or not, in the case
2694 // of connecting to a remote machine as debuggee
2695 //
2696 if (!g_DeviceHandle)
2697 {
2698 CloseHandle(Comm);
2701
2703 }
2704
2705 //
2706 // Allocate buffer
2707 //
2708 DebuggeeRequest =
2710
2711 if (DebuggeeRequest == NULL)
2712 {
2713 CloseHandle(Comm);
2716
2717 ShowMessages("err, unable to allocate memory for request packet");
2718 return FALSE;
2719 }
2720
2721 RtlZeroMemory(DebuggeeRequest, SIZEOF_DEBUGGER_PREPARE_DEBUGGEE);
2722
2723 //
2724 // Prepare the details structure
2725 //
2726 DebuggeeRequest->PortAddress = Port;
2727 DebuggeeRequest->Baudrate = Baudrate;
2728
2729 //
2730 // Get base address of ntoskrnl
2731 //
2732 DebuggeeRequest->KernelBaseAddress = DebuggerGetNtoskrnlBase();
2733
2734 //
2735 // Set the debuggee name, version, and build number
2736 //
2737 if (!KdGetWindowVersion(DebuggeeRequest->OsName))
2738 {
2739 //
2740 // It's not an error if it returned null (we could ignore it)
2741 //
2742 // return FALSE;
2743 }
2744
2745 //
2746 // Send the request to the kernel
2747 //
2748 StatusIoctl =
2749 DeviceIoControl(g_DeviceHandle, // Handle to device
2750 IOCTL_PREPARE_DEBUGGEE, // IO Control Code (IOCTL)
2751 DebuggeeRequest, // Input Buffer to driver.
2752 SIZEOF_DEBUGGER_PREPARE_DEBUGGEE, // Input buffer
2753 // length
2754 DebuggeeRequest, // Output Buffer from driver.
2755 SIZEOF_DEBUGGER_PREPARE_DEBUGGEE, // Length of output
2756 // buffer in bytes.
2757 &ReturnedLength, // Bytes placed in buffer.
2758 NULL // synchronous call
2759 );
2760
2761 if (!StatusIoctl)
2762 {
2763 CloseHandle(Comm);
2766
2767 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
2768
2769 //
2770 // Free the buffer
2771 //
2772 free(DebuggeeRequest);
2773
2774 return FALSE;
2775 }
2776
2777 if (DebuggeeRequest->Result == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
2778 {
2779 //
2780 // Ignore handling CTRL+C breaks
2781 //
2783
2784 //
2785 // initialize and load symbols (pdb) and send the details to the debugger
2786 //
2787 ShowMessages("synchronizing modules' symbol details\n");
2788
2789 //
2790 // Do not pause debugger after finish
2791 //
2792 KdReloadSymbolsInDebuggee(FALSE, GetCurrentProcessId());
2793 }
2794 else
2795 {
2796 CloseHandle(Comm);
2799
2800 ShowErrorMessage(DebuggeeRequest->Result);
2801
2802 //
2803 // Free the buffer
2804 //
2805 free(DebuggeeRequest);
2806
2807 return FALSE;
2808 }
2809
2810 //
2811 // show the message that the operation was successful,
2812 // we show it here because if we set the next variables
2813 // to true, then it will be sent to the debugger instead
2814 // of showing the message in debuggee
2815 //
2816 ShowMessages("the operation was successful\n");
2817
2818 //
2819 // Serial connection is not already closed
2820 //
2822
2823 //
2824 // Indicate that we connected to the debugger
2825 //
2827
2828 //
2829 // Free the buffer
2830 //
2831 free(DebuggeeRequest);
2832
2833 //
2834 // Wait here so the user can't give new commands
2835 // Create an event (manually. no signal)
2836 //
2837 g_DebuggeeStopCommandEventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
2838
2839 //
2840 // Create a thread to listen for pauses from the remote debugger
2841 //
2842
2843 g_SerialListeningThreadHandle = CreateThread(
2844 NULL,
2845 0,
2847 NULL,
2848 0,
2849 NULL);
2850
2851 //
2852 // Test should be removed
2853 //
2854 // HyperDbgInterpreter("!syscall script { print(@rax); }");
2855 // HyperDbgInterpreter("!epthook fffff801`639b1030 script { print(@rax);
2856 // }"); HyperDbgInterpreter("!msrwrite script { print(@rax); }");
2857 //
2858
2859 //
2860 // Now we should wait on this state until the user closes the connection to
2861 // debuggee from debugger
2862 //
2863 WaitForSingleObject(g_DebuggeeStopCommandEventHandle, INFINITE);
2864
2865 //
2866 // Close the event's handle
2867 //
2870
2871 //
2872 // Handle CTRL+C breaks again
2873 //
2875
2876 //
2877 // Finish it here
2878 //
2879 return TRUE;
2880 }
2881 else
2882 {
2883 //
2884 // Save the handler
2885 //
2887
2888 //
2889 // If we are here, then it's a debugger (not debuggee)
2890 // let's prepare the debuggee
2891 //
2892 KdPrepareSerialConnectionToRemoteSystem(Comm, IsNamedPipe, PauseAfterConnection);
2893 }
2894
2895 //
2896 // everything was done
2897 //
2898 return TRUE;
2899}
BOOLEAN g_IgnorePauseRequests
Show whether the pause request (CTRL+C or CTRL+BREAK) should be ignored or not.
Definition globals.h:180
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
#define IOCTL_PREPARE_DEBUGGEE
ioctl, prepare debuggee
Definition Ioctls.h:235
#define SIZEOF_DEBUGGER_PREPARE_DEBUGGEE
Definition RequestStructures.h:624
struct _DEBUGGER_PREPARE_DEBUGGEE * PDEBUGGER_PREPARE_DEBUGGEE
UINT64 DebuggerGetNtoskrnlBase()
Get ntoskrnl.exe base in the kernel.
Definition debugger.cpp:657
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:40
BOOLEAN IsConnectedToAnyInstanceOfDebuggerOrDebuggee()
Shows whether the debugger is connected to a debugger or debuggee connected to a debugger.
Definition debugger.cpp:773
HANDLE g_DebuggeeStopCommandEventHandle
An event to make sure that the user won't give any command in debuggee and all the commands are comin...
Definition globals.h:299
BOOLEAN KdCheckIfDebuggerIsListening(HANDLE ComPortHandle)
Check and handshake to make sure if the remote debugger is listening.
Definition kd.cpp:2324
HANDLE g_SerialRemoteComPortHandle
In debugger (not debuggee), we save the handle of the user-mode listening thread for remote system he...
Definition globals.h:246
BOOLEAN KdGetWindowVersion(CHAR *BufferToSave)
Get Windows name, version and build to send to debugger.
Definition kd.cpp:1490
HANDLE g_SerialListeningThreadHandle
In debuggee and debugger, we save the handle of the user-mode listening thread for pauses here.
Definition globals.h:239
BOOLEAN KdReloadSymbolsInDebuggee(BOOLEAN PauseDebuggee, UINT32 UserProcessId)
Send the packets of reloading symbols to build a new symbol table to the debugger and send the finish...
Definition kd.cpp:3015
BOOLEAN g_IsDebuggeeInHandshakingPhase
Shows if the debuggee is in the handshake phase or not.
Definition globals.h:266
BOOLEAN KdPrepareSerialConnectionToRemoteSystem(HANDLE SerialHandle, BOOLEAN IsNamedPipe, BOOLEAN PauseAfterConnection)
Prepare serial to connect to the remote server.
Definition kd.cpp:2175
DWORD WINAPI ListeningSerialPauseDebuggeeThread(PVOID Param)
Check if the remote debugger needs to pause the system.
Definition kernel-listening.cpp:1627
HANDLE NamedPipeClientCreatePipeOverlappedIo(LPCSTR PipeName)
Create a client named pipe through overlapped I/O.
Definition namedpipe.cpp:234
OVERLAPPED g_OverlappedIoStructureForWriteDebugger
OVERLAPPED g_OverlappedIoStructureForReadDebugger
#define ASSERT_MESSAGE_KD_NOT_LOADED
Definition common.h:29
INT HyperDbgInstallKdDriver()
Install KD (Kernel Debugger) driver.
Definition libhyperdbg.cpp:81
INT HyperDbgLoadVmmModule()
load vmm module
Definition libhyperdbg.cpp:749
UINT64 KernelBaseAddress
Definition RequestStructures.h:634
UINT32 Result
Definition RequestStructures.h:635
UINT32 Baudrate
Definition RequestStructures.h:633
UINT32 PortAddress
Definition RequestStructures.h:632
CHAR OsName[MAXIMUM_CHARACTER_FOR_OS_NAME]
Definition RequestStructures.h:636

◆ KdPrepareSerialConnectionToRemoteSystem()

BOOLEAN KdPrepareSerialConnectionToRemoteSystem ( HANDLE SerialHandle,
BOOLEAN IsNamedPipe,
BOOLEAN PauseAfterConnection )

Prepare serial to connect to the remote server.

wait to connect to debuggee (this is debugger)

Parameters
SerialHandle
IsNamedPipe
PauseAfterConnection
Returns
BOOLEAN
2178{
2179 BOOL Status; /* Status */
2180 DWORD EventMask = 0; /* Event mask to trigger */
2181
2182 //
2183 // Show an indication to connect the debugger
2184 //
2185 ShowMessages("waiting for debuggee to connect...\n");
2186
2187 if (!IsNamedPipe)
2188 {
2189 //
2190 // Setting Receive Mask
2191 //
2192 Status = SetCommMask(SerialHandle, EV_RXCHAR);
2193 if (Status == FALSE)
2194 {
2195 //
2196 // Can be ignored
2197 //
2198 // ShowMessages("err, in setting CommMask\n");
2199 // return FALSE;
2200 }
2201
2202 //
2203 // Setting WaitComm() Event
2204 //
2205 Status = WaitCommEvent(SerialHandle, &EventMask, NULL); /* Wait for the character to be received */
2206
2207 if (Status == FALSE)
2208 {
2209 //
2210 // Can be ignored
2211 //
2212 // ShowMessages("err, in setting WaitCommEvent\n");
2213 // return FALSE;
2214 }
2215 }
2216
2217 //
2218 // Initialize the handle table
2219 //
2221 {
2222 g_KernelSyncronizationObjectsHandleTable[i].IsOnWaitingState = FALSE;
2224 CreateEvent(NULL, FALSE, FALSE, NULL);
2225 }
2226
2227 //
2228 // the debuggee is not already closed the connection
2229 //
2231
2232 //
2233 // Create the listening thread in debugger
2234 //
2235
2237 CreateThread(NULL, 0, ListeningSerialPauseDebuggerThread, NULL, 0, NULL);
2238
2239 //
2240 // Wait for the 'Start' packet on the listener side
2241 //
2243
2244 //
2245 // Check to make sure the connection not close before starting a session
2246 //
2248 {
2249 //
2250 // Ignore handling breaks
2251 //
2253
2254 //
2255 // The next step is getting symbol details
2256 //
2257 ShowMessages("getting symbol details...\n");
2258
2259 //
2260 // Wait to receive symbol details
2261 //
2263
2264 //
2265 // Connected to the debuggee
2266 //
2268
2269 //
2270 // And debuggee is running
2271 //
2273
2274 //
2275 // Save the handler
2276 //
2277 g_SerialRemoteComPortHandle = SerialHandle;
2278
2279 //
2280 // Is serial handle for a named pipe
2281 //
2283
2284 //
2285 // Process CTRL+C breaks again
2286 //
2288
2289 //
2290 // Now, the user can press ctrl+c to pause the debuggee
2291 //
2292 ShowMessages("press CTRL+C to pause the debuggee\n");
2293
2294 //
2295 // If the user wants to pause after connection
2296 //
2297 if (PauseAfterConnection)
2298 {
2299 //
2300 // Pause the target debuggee after connection
2301 //
2303 }
2304 else
2305 {
2306 //
2307 // Wait for event on this thread
2308 //
2310 }
2311 }
2312
2313 return TRUE;
2314}
VOID KdBreakControlCheckAndPauseDebugger(BOOLEAN SignalRunningFlag)
check if the debuggee needs to be paused
Definition kd.cpp:2040
VOID KdTheRemoteSystemIsRunning()
wait for a event to be triggered and if the debuggee is running it just halts the system
Definition kd.cpp:2151
DEBUGGER_SYNCRONIZATION_EVENTS_STATE g_KernelSyncronizationObjectsHandleTable[DEBUGGER_MAXIMUM_SYNCRONIZATION_KERNEL_DEBUGGER_OBJECTS]
In debugger (not debuggee), we save the handle of the user-mode listening thread for pauses here for ...
Definition globals.h:220
BOOLEAN g_IsDebuggerConntectedToNamedPipe
Shows if the debugger is connected to the guest using named pipe.
Definition globals.h:292
DWORD WINAPI ListeningSerialPauseDebuggerThread(PVOID Param)
Check if the remote debuggee needs to pause the system.
Definition kernel-listening.cpp:1610
#define DEBUGGER_MAXIMUM_SYNCRONIZATION_KERNEL_DEBUGGER_OBJECTS
maximum number of event handles in kernel-debugger
Definition debugger.h:22
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SYMBOL_RELOAD
Definition debugger.h:51

◆ KdReceivePacketFromDebuggee()

BOOLEAN KdReceivePacketFromDebuggee ( CHAR * BufferToSave,
UINT32 * LengthReceived )

Receive packet from the debuggee.

Parameters
BufferToSave
LengthReceived
Returns
BOOLEAN
1560{
1561 CHAR ReadData = NULL; /* temperory Character */
1562 DWORD NoBytesRead = 0; /* Bytes read by ReadFile() */
1563 UINT32 Loop = 0;
1564
1565 //
1566 // Read data and store in a buffer
1567 //
1568 do
1569 {
1570#ifdef _WIN32
1571 //
1572 // It's in the debugger
1573 //
1574
1575 //
1576 // Try to read one byte in overlapped I/O (in debugger)
1577 //
1578 if (!ReadFile(g_SerialRemoteComPortHandle, &ReadData, sizeof(ReadData), NULL, &g_OverlappedIoStructureForReadDebugger))
1579 {
1580 DWORD e = GetLastError();
1581
1582 if (e != ERROR_IO_PENDING)
1583 {
1584 return FALSE;
1585 }
1586 }
1587
1588 //
1589 // Wait till one packet becomes available
1590 //
1591 WaitForSingleObject(g_OverlappedIoStructureForReadDebugger.hEvent,
1592 INFINITE);
1593
1594 //
1595 // Get the result
1596 //
1597 GetOverlappedResult(g_SerialRemoteComPortHandle,
1599 &NoBytesRead,
1600 FALSE);
1601
1602 //
1603 // Reset event for next try
1604 //
1605 ResetEvent(g_OverlappedIoStructureForReadDebugger.hEvent);
1606#else
1607 //
1608 // Linux: read one byte through the cross-platform serial transport
1609 //
1611 &ReadData,
1612 &NoBytesRead,
1614 {
1615 return FALSE;
1616 }
1617#endif
1618
1619 //
1620 // We already now that the maximum packet size is MaxSerialPacketSize
1621 // Check to make sure that we don't pass the boundaries
1622 //
1623 if (!(MaxSerialPacketSize > Loop))
1624 {
1625 //
1626 // Invalid buffer
1627 //
1628 ShowMessages("err, a buffer received in which exceeds the "
1629 "buffer limitation\n");
1630 return FALSE;
1631 }
1632
1633 BufferToSave[Loop] = ReadData;
1634
1635 if (KdCheckForTheEndOfTheBuffer(&Loop, (BYTE *)BufferToSave))
1636 {
1637 break;
1638 }
1639
1640 Loop++;
1641
1642 } while (NoBytesRead > 0);
1643
1644 //
1645 // Set the length
1646 //
1647 *LengthReceived = Loop;
1648
1649 return TRUE;
1650}
BOOLEAN KdCheckForTheEndOfTheBuffer(PUINT32 CurrentLoopIndex, BYTE *Buffer)
compares the buffer with a string
Definition kd.cpp:56
@ PLATFORM_SERIAL_IO_DEBUGGER
Definition platform-serial.h:31
BOOLEAN PlatformSerialReadByte(HANDLE Handle, CHAR *OutByte, DWORD *BytesRead, PLATFORM_SERIAL_IO_ROLE Role)

◆ KdReceivePacketFromDebugger()

BOOLEAN KdReceivePacketFromDebugger ( CHAR * BufferToSave,
UINT32 * LengthReceived )

Receive packet from the debugger.

Parameters
BufferToSave
LengthReceived
Returns
BOOLEAN
1663{
1664 CHAR ReadData = NULL; /* temperory Character */
1665 DWORD NoBytesRead = 0; /* Bytes read by ReadFile() */
1666 UINT32 Loop = 0;
1667
1668#ifdef _WIN32
1669 //
1670 // Set the timeout in milliseconds (e.g., 5000 ms = 5 seconds)
1671 //
1672 DWORD ReadTimeout = 5000;
1673
1674 //
1675 // Set the read timeout using SetCommTimeouts
1676 //
1677 COMMTIMEOUTS Timeouts;
1678 GetCommTimeouts(g_SerialRemoteComPortHandle, &Timeouts);
1679 Timeouts.ReadIntervalTimeout = MAXDWORD;
1680 Timeouts.ReadTotalTimeoutConstant = ReadTimeout;
1681 Timeouts.ReadTotalTimeoutMultiplier = 0;
1682 Timeouts.WriteTotalTimeoutConstant = 0;
1683 Timeouts.WriteTotalTimeoutMultiplier = 0;
1684 SetCommTimeouts(g_SerialRemoteComPortHandle, &Timeouts);
1685#endif
1686
1687 //
1688 // Read data and store in a buffer
1689 //
1690 do
1691 {
1692#ifdef _WIN32
1693 //
1694 // It's in the debuggee
1695 //
1696
1697 //
1698 // Try to read one byte in overlapped I/O (in debugger)
1699 //
1700 if (!ReadFile(g_SerialRemoteComPortHandle, &ReadData, sizeof(ReadData), NULL, &g_OverlappedIoStructureForReadDebuggee))
1701 {
1702 DWORD e = GetLastError();
1703
1704 if (e != ERROR_IO_PENDING)
1705 {
1706 return FALSE;
1707 }
1708 }
1709
1710 //
1711 // Wait till one packet becomes available
1712 //
1713 WaitForSingleObject(g_OverlappedIoStructureForReadDebuggee.hEvent,
1714 INFINITE);
1715
1716 //
1717 // Get the result
1718 //
1719 GetOverlappedResult(g_SerialRemoteComPortHandle,
1720 &g_OverlappedIoStructureForReadDebuggee,
1721 &NoBytesRead,
1722 FALSE);
1723
1724 //
1725 // Reset event for next try
1726 //
1727 ResetEvent(g_OverlappedIoStructureForReadDebuggee.hEvent);
1728#else
1729 //
1730 // Linux: read one byte through the cross-platform serial transport
1731 // (the 5s read timeout is applied inside the platform layer)
1732 //
1734 &ReadData,
1735 &NoBytesRead,
1737 {
1738 return FALSE;
1739 }
1740#endif
1741
1742 //
1743 // We already now that the maximum packet size is MaxSerialPacketSize
1744 // Check to make sure that we don't pass the boundaries
1745 //
1746 if (!(MaxSerialPacketSize > Loop))
1747 {
1748 //
1749 // Invalid buffer
1750 //
1751 ShowMessages("err, a buffer received in which exceeds the "
1752 "buffer limitation\n");
1753 return FALSE;
1754 }
1755
1756 BufferToSave[Loop] = ReadData;
1757
1758 if (KdCheckForTheEndOfTheBuffer(&Loop, (BYTE *)BufferToSave))
1759 {
1760 break;
1761 }
1762
1763 Loop++;
1764
1765 } while (NoBytesRead > 0);
1766
1767 //
1768 // Set the length
1769 //
1770 *LengthReceived = Loop;
1771
1772 return TRUE;
1773}
@ PLATFORM_SERIAL_IO_DEBUGGEE
Definition platform-serial.h:32

◆ KdRegisterEventInDebuggee()

BOOLEAN KdRegisterEventInDebuggee ( PDEBUGGER_GENERAL_EVENT_DETAIL EventRegBuffer,
UINT32 Length )

Register an event in the debuggee.

Parameters
EventRegBuffer
Length
Returns
BOOLEAN
3146{
3147 BOOL Status;
3148 ULONG ReturnedLength;
3149 DEBUGGER_EVENT_AND_ACTION_RESULT ReturnedBuffer = {0};
3150
3152
3153 //
3154 // Send IOCTL
3155 //
3156 Status =
3157 DeviceIoControl(g_DeviceHandle, // Handle to device
3158 IOCTL_DEBUGGER_REGISTER_EVENT, // IO Control Code (IOCTL)
3159 EventRegBuffer,
3160 Length // Input Buffer to driver.
3161 , // Input buffer length
3162 &ReturnedBuffer, // Output Buffer from driver.
3163 sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT), // Length
3164 // of
3165 // output
3166 // buffer
3167 // in
3168 // bytes.
3169 &ReturnedLength, // Bytes placed in buffer.
3170 NULL // synchronous call
3171 );
3172
3173 if (!Status)
3174 {
3175 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
3176 return FALSE;
3177 }
3178
3179 //
3180 // Now that we registered the event (with or without error),
3181 // we should send the results back to the debugger
3182 //
3185 &ReturnedBuffer,
3187 TRUE);
3188}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_DEBUGGEE_RESULT_OF_REGISTERING_EVENT
Definition Connection.h:122
#define IOCTL_DEBUGGER_REGISTER_EVENT
ioctl, register an event
Definition Ioctls.h:164

◆ KdReloadSymbolsInDebuggee()

BOOLEAN KdReloadSymbolsInDebuggee ( BOOLEAN PauseDebuggee,
UINT32 UserProcessId )

Send the packets of reloading symbols to build a new symbol table to the debugger and send the finished packet to the debugger.

Parameters
PauseDebuggee
UserProcessId
Returns
BOOLEAN
3016{
3017 DEBUGGEE_SYMBOL_UPDATE_RESULT SymReload = {0};
3018
3019 //
3020 // In kernel debugger, if the process id is not specified
3021 // we choose the HyperDbg's process to load its modules
3022 //
3023 if (UserProcessId == NULL)
3024 {
3025 UserProcessId = GetCurrentProcessId();
3026 }
3027
3028 //
3029 // Request debuggee to send new symbol packets
3030 //
3032
3033 //
3034 // Set the status
3035 //
3037
3038 //
3039 // Send the finished request packet
3040 //
3043 &SymReload,
3045 PauseDebuggee);
3046}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_DEBUGGEE_RELOAD_SYMBOL_FINISHED
Definition Connection.h:133
struct _DEBUGGEE_SYMBOL_UPDATE_RESULT DEBUGGEE_SYMBOL_UPDATE_RESULT
request that shows, symbol reload process is finished
UINT64 KernelStatus
Definition Symbols.h:92
VOID SymbolPrepareDebuggerWithSymbolInfo(UINT32 UserProcessId)
Initial and send the results of serial for the debugger in the case of debugger mode.
Definition symbol.cpp:69

◆ KdSendAddActionToEventPacketToDebuggee()

PDEBUGGER_EVENT_AND_ACTION_RESULT KdSendAddActionToEventPacketToDebuggee ( PDEBUGGER_GENERAL_ACTION GeneralAction,
UINT32 GeneralActionLength )

Send an add action to event request to the debuggee.

as this command uses one global variable to transfer the buffers so should not be called simultaneously

Parameters
GeneralAction
GeneralActionLength
Returns
PDEBUGGER_EVENT_AND_ACTION_RESULT
739{
741 UINT32 Len;
742
743 Len = GeneralActionLength +
745
747
748 if (Header == NULL)
749 {
750 return NULL;
751 }
752
753 RtlZeroMemory(Header, Len);
754
755 //
756 // Set length in header
757 //
758 Header->Length = GeneralActionLength;
759
760 //
761 // Move buffer
762 //
763 memcpy((PVOID)((UINT64)Header +
765 (PVOID)GeneralAction,
766 GeneralActionLength);
767
770
771 //
772 // Send add action to event packet
773 //
777 (CHAR *)Header,
778 Len))
779 {
780 free(Header);
781 return NULL;
782 }
783
784 //
785 // Wait until the result of adding action to event received
786 //
788
789 free(Header);
790
792}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_ADD_ACTION_TO_EVENT
Definition Connection.h:86
struct _DEBUGGEE_EVENT_AND_ACTION_HEADER_FOR_REMOTE_PACKET DEBUGGEE_EVENT_AND_ACTION_HEADER_FOR_REMOTE_PACKET
The structure of user-input packet in HyperDbg.
struct _DEBUGGEE_EVENT_AND_ACTION_HEADER_FOR_REMOTE_PACKET * PDEBUGGEE_EVENT_AND_ACTION_HEADER_FOR_REMOTE_PACKET
DEBUGGER_EVENT_AND_ACTION_RESULT g_DebuggeeResultOfAddingActionsToEvent
Holds the result of adding action to events from the remote debuggee.
Definition globals.h:311
BOOLEAN KdCommandPacketAndBufferToDebuggee(DEBUGGER_REMOTE_PACKET_TYPE PacketType, DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction, CHAR *Buffer, UINT32 BufferLength)
Sends a HyperDbg packet + a buffer to the debuggee.
Definition kd.cpp:1970
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_ADD_ACTION_TO_EVENT
Definition debugger.h:44

◆ KdSendApicActionPacketsToDebuggee()

BOOLEAN KdSendApicActionPacketsToDebuggee ( PDEBUGGER_APIC_REQUEST ApicRequest,
UINT32 ExpectedRequestSize )

Send requests for APIC packet to the debuggee.

Parameters
ApicPage
ExpectedRequestSize
Returns
BOOLEAN
996{
997 //
998 // Set the request data
999 //
1001
1002 //
1003 // Send the APIC request packets
1004 //
1008 (CHAR *)ApicRequest,
1009 sizeof(DEBUGGER_APIC_REQUEST) // only sending the request header
1010 ))
1011 {
1012 return FALSE;
1013 }
1014
1015 //
1016 // Wait until the result of actions to APIC is received
1017 //
1019
1020 return TRUE;
1021}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_PERFORM_ACTIONS_ON_APIC
Definition Connection.h:100
struct _DEBUGGER_APIC_REQUEST DEBUGGER_APIC_REQUEST
The structure of actions for APIC.
#define DbgWaitSetKernelRequestData(KernelSyncObjectId, ReqData, ReqSize)
Definition common.h:120
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_APIC_ACTIONS
Definition debugger.h:61

◆ KdSendBpPacketToDebuggee()

BOOLEAN KdSendBpPacketToDebuggee ( PDEBUGGEE_BP_PACKET BpPacket)

Sends a breakpoint set or 'bp' command packet to the debuggee.

Parameters
BpPacket
Returns
BOOLEAN
1170{
1171 //
1172 // Send 'bp' as a breakpoint packet
1173 //
1177 (CHAR *)BpPacket,
1178 sizeof(DEBUGGEE_BP_PACKET)))
1179 {
1180 return FALSE;
1181 }
1182
1183 //
1184 // Wait until the result of putting breakpoint is received
1185 //
1187
1188 return TRUE;
1189}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_BP
Definition Connection.h:91
struct _DEBUGGEE_BP_PACKET DEBUGGEE_BP_PACKET
The structure of bp command packet in HyperDbg.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_BP
Definition debugger.h:47

◆ KdSendCallStackPacketToDebuggee()

BOOLEAN KdSendCallStackPacketToDebuggee ( UINT64 BaseAddress,
UINT32 Size,
DEBUGGER_CALLSTACK_DISPLAY_METHOD DisplayMethod,
BOOLEAN Is32Bit )

Send a callstack request to the debuggee.

Parameters
BaseAddress
Size
DisplayMethod
Is32Bit
Returns
BOOLEAN
352{
353 UINT32 FrameCount;
354 UINT32 CallstackRequestSize = 0;
355 PDEBUGGER_CALLSTACK_REQUEST CallstackPacket = NULL;
356
357 if (Size == 0)
358 {
359 return FALSE;
360 }
361
362 if (Is32Bit)
363 {
364 FrameCount = Size / sizeof(UINT32);
365 }
366 else
367 {
368 FrameCount = Size / sizeof(UINT64);
369 }
370
371 CallstackRequestSize = sizeof(DEBUGGER_CALLSTACK_REQUEST) + (sizeof(DEBUGGER_SINGLE_CALLSTACK_FRAME) * FrameCount);
372
373 //
374 // Allocate buffer for request
375 //
376 CallstackPacket = (PDEBUGGER_CALLSTACK_REQUEST)malloc(CallstackRequestSize);
377
378 if (CallstackPacket == NULL)
379 {
380 return FALSE;
381 }
382
383 RtlZeroMemory(CallstackPacket, CallstackRequestSize);
384
385 //
386 // Set the details
387 //
388 CallstackPacket->BaseAddress = BaseAddress;
389 CallstackPacket->Is32Bit = Is32Bit;
390 CallstackPacket->Size = Size;
391 CallstackPacket->BufferSize = CallstackRequestSize;
392 CallstackPacket->FrameCount = FrameCount;
393 CallstackPacket->DisplayMethod = DisplayMethod;
394
395 //
396 // Send 'k' command as callstack request packet
397 //
401 (CHAR *)CallstackPacket,
402 CallstackRequestSize))
403 {
404 free(CallstackPacket);
405 return FALSE;
406 }
407
408 //
409 // Wait until the result of callstack is received
410 //
412
413 free(CallstackPacket);
414 return TRUE;
415}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_CALLSTACK
Definition Connection.h:78
struct _DEBUGGER_CALLSTACK_REQUEST * PDEBUGGER_CALLSTACK_REQUEST
struct _DEBUGGER_CALLSTACK_REQUEST DEBUGGER_CALLSTACK_REQUEST
request for callstack frames
struct _DEBUGGER_SINGLE_CALLSTACK_FRAME DEBUGGER_SINGLE_CALLSTACK_FRAME
The structure for saving the callstack frame of one parameter.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CALLSTACK_RESULT
Definition debugger.h:53
UINT32 Size
Definition RequestStructures.h:847
UINT32 FrameCount
Definition RequestStructures.h:848
UINT64 BufferSize
Definition RequestStructures.h:850
BOOLEAN Is32Bit
Definition RequestStructures.h:844
DEBUGGER_CALLSTACK_DISPLAY_METHOD DisplayMethod
Definition RequestStructures.h:846
UINT64 BaseAddress
Definition RequestStructures.h:849

◆ KdSendContinuePacketToDebuggee()

BOOLEAN KdSendContinuePacketToDebuggee ( )

Sends a continue or 'g' command packet to the debuggee.

Returns
BOOLEAN
156{
157 //
158 // No core
159 //
161
162 //
163 // Send 'g' as continue packet
164 //
168 {
169 return FALSE;
170 }
171
172 return TRUE;
173}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_CONTINUE
Definition Connection.h:74
#define DEBUGGER_DEBUGGEE_IS_RUNNING_NO_CORE
Apply the event to all the cores.
Definition Constants.h:733
ULONG g_CurrentRemoteCore
Current core that the debuggee is debugging.
Definition globals.h:285

◆ KdSendEditMemoryPacketToDebuggee()

BOOLEAN KdSendEditMemoryPacketToDebuggee ( PDEBUGGER_EDIT_MEMORY EditMem,
UINT32 Size )

Send an Edit memory packet to the debuggee.

Parameters
EditMem
Size
Returns
BOOLEAN
634{
635 //
636 // Set the request data
637 //
639
640 //
641 // Send d command as read memory packet
642 //
646 (CHAR *)EditMem,
647 Size))
648 {
649 return FALSE;
650 }
651
652 //
653 // Wait until the result of read registers received
654 //
656
657 return TRUE;
658}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_EDIT_MEMORY
Definition Connection.h:90
struct _DEBUGGER_EDIT_MEMORY DEBUGGER_EDIT_MEMORY
request for edit virtual and physical memory
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_EDIT_MEMORY
Definition debugger.h:50

◆ KdSendEventQueryAndModifyPacketToDebuggee()

BOOLEAN KdSendEventQueryAndModifyPacketToDebuggee ( UINT64 Tag,
DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction,
BOOLEAN * IsEnabled )

Sends a query or request to enable/disable/clear for event.

if IsQueryState is TRUE then TypeOfAction is ignored

Parameters
Tag
TypeOfAction
IsEnabledIf it's a query state then this argument can be used
Returns
BOOLEAN
269{
270 DEBUGGER_MODIFY_EVENTS ModifyAndQueryEventPacket = {0};
271
273
274 //
275 // Fill the structure of packet
276 //
277 ModifyAndQueryEventPacket.Tag = Tag;
278 ModifyAndQueryEventPacket.TypeOfAction = TypeOfAction;
279
280 //
281 // Send modify and query event packet
282 //
286 (CHAR *)&ModifyAndQueryEventPacket,
287 sizeof(DEBUGGER_MODIFY_EVENTS)))
288 {
289 return FALSE;
290 }
291
292 //
293 // Wait until the result of query and modify event is received
294 //
296
297 if (TypeOfAction == DEBUGGER_MODIFY_EVENTS_QUERY_STATE)
298 {
299 //
300 // We should read the results to set IsEnabled variable
301 //
302 *IsEnabled = g_SharedEventStatus;
303 }
304
305 return TRUE;
306}
POOL_TYPE SIZE_T ULONG Tag
Definition Hooks.h:89
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_QUERY_AND_MODIFY_EVENT
Definition Connection.h:87
@ DEBUGGER_MODIFY_EVENTS_QUERY_STATE
Definition Events.h:234
struct _DEBUGGER_MODIFY_EVENTS DEBUGGER_MODIFY_EVENTS
request for modifying events (enable/disable/clear)
BOOLEAN g_SharedEventStatus
This is an OVERLAPPED structure for managing simultaneous read and writes for debugger (in current de...
Definition globals.h:331
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_MODIFY_AND_QUERY_EVENT
Definition debugger.h:45
DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction
Definition Events.h:249
UINT64 Tag
Definition Events.h:246

◆ KdSendFlushPacketToDebuggee()

BOOLEAN KdSendFlushPacketToDebuggee ( )

Send a flush request to the debuggee.

Returns
BOOLEAN
315{
316 DEBUGGER_FLUSH_LOGGING_BUFFERS FlushPacket = {0};
317
318 //
319 // Send 'flush' command as flush packet
320 //
324 (CHAR *)&FlushPacket,
326 {
327 return FALSE;
328 }
329
330 //
331 // Wait until the result of flushing received
332 //
334
335 return TRUE;
336}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_FLUSH_BUFFERS
Definition Connection.h:77
struct _DEBUGGER_FLUSH_LOGGING_BUFFERS DEBUGGER_FLUSH_LOGGING_BUFFERS
request for flushing buffers
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_FLUSH_RESULT
Definition debugger.h:42

◆ KdSendGeneralBuffersFromDebuggeeToDebugger()

BOOLEAN KdSendGeneralBuffersFromDebuggeeToDebugger ( DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction,
PVOID Buffer,
UINT32 BufferLength,
BOOLEAN PauseDebuggeeWhenSent )

Send general buffer from debuggee to debugger.

Parameters
RequestedAction
Buffer
Length
PauseDebuggeeWhenSent
Returns
BOOLEAN
2916{
2917 BOOL Status;
2918 ULONG ReturnedLength;
2920 GeneralPacketFromDebuggeeToDebuggerRequest;
2921 UINT32 Length;
2922
2923 //
2924 // Compute the length of the packet (add to header )
2925 //
2927 BufferLength;
2928
2929 //
2930 // Allocate the target buffer
2931 //
2932 GeneralPacketFromDebuggeeToDebuggerRequest =
2934
2935 if (GeneralPacketFromDebuggeeToDebuggerRequest == NULL)
2936 {
2937 //
2938 // err, allocating buffer
2939 //
2940 return FALSE;
2941 }
2942
2943 RtlZeroMemory(GeneralPacketFromDebuggeeToDebuggerRequest, Length);
2944
2945 //
2946 // Fill the header structure
2947 //
2948 GeneralPacketFromDebuggeeToDebuggerRequest->RequestedAction = RequestedAction;
2949 GeneralPacketFromDebuggeeToDebuggerRequest->LengthOfBuffer = BufferLength;
2950 GeneralPacketFromDebuggeeToDebuggerRequest->PauseDebuggeeWhenSent =
2951 PauseDebuggeeWhenSent;
2952
2953 //
2954 // Move the memory to the bottom of the structure
2955 //
2956 memcpy(
2957 (PVOID)((UINT64)GeneralPacketFromDebuggeeToDebuggerRequest +
2959 (PVOID)Buffer,
2960 BufferLength);
2961
2962 //
2963 // Send Ioctl to the kernel
2964 //
2965 Status = DeviceIoControl(
2966 g_DeviceHandle, // Handle to device
2967 IOCTL_SEND_GENERAL_BUFFER_FROM_DEBUGGEE_TO_DEBUGGER, // IO Control Code (IOCTL)
2968 GeneralPacketFromDebuggeeToDebuggerRequest, // Input Buffer to driver.
2969 Length, // Input buffer
2970 // length
2971 GeneralPacketFromDebuggeeToDebuggerRequest, // Output Buffer from driver.
2973 // of
2974 // output
2975 // buffer
2976 // in
2977 // bytes.
2978 &ReturnedLength, // Bytes placed in buffer.
2979 NULL // synchronous call
2980 );
2981
2982 if (!Status)
2983 {
2984 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
2985 free(GeneralPacketFromDebuggeeToDebuggerRequest);
2986 return FALSE;
2987 }
2988
2989 if (GeneralPacketFromDebuggeeToDebuggerRequest->KernelResult !=
2991 {
2992 ShowErrorMessage(GeneralPacketFromDebuggeeToDebuggerRequest->KernelResult);
2993
2994 //
2995 // Free the buffer
2996 //
2997 free(GeneralPacketFromDebuggeeToDebuggerRequest);
2998 return FALSE;
2999 }
3000
3001 free(GeneralPacketFromDebuggeeToDebuggerRequest);
3002 return TRUE;
3003}
#define IOCTL_SEND_GENERAL_BUFFER_FROM_DEBUGGEE_TO_DEBUGGER
ioctl, send general buffer from debuggee to debugger
Definition Ioctls.h:263
#define SIZEOF_DEBUGGEE_SEND_GENERAL_PACKET_FROM_DEBUGGEE_TO_DEBUGGER
Definition RequestStructures.h:397
struct _DEBUGGEE_SEND_GENERAL_PACKET_FROM_DEBUGGEE_TO_DEBUGGER * PDEBUGGEE_SEND_GENERAL_PACKET_FROM_DEBUGGEE_TO_DEBUGGER
struct _DEBUGGEE_SEND_GENERAL_PACKET_FROM_DEBUGGEE_TO_DEBUGGER DEBUGGEE_SEND_GENERAL_PACKET_FROM_DEBUGGEE_TO_DEBUGGER
request for send general packets from debuggee to debugger
BOOLEAN PauseDebuggeeWhenSent
Definition RequestStructures.h:408
DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION RequestedAction
Definition RequestStructures.h:406
UINT32 LengthOfBuffer
Definition RequestStructures.h:407
UINT32 KernelResult
Definition RequestStructures.h:409

◆ KdSendHyperTraceLbrdumpPacketsToDebuggee()

BOOLEAN KdSendHyperTraceLbrdumpPacketsToDebuggee ( PHYPERTRACE_LBR_DUMP_PACKETS HyperTraceLbrdumpRequest,
UINT32 ExpectedRequestSize )

Send requests for HyperTrace LBR dump packet to the debuggee.

Parameters
HyperTraceLbrdumpRequest
Returns
BOOLEAN
1067{
1068 //
1069 // Set the request data
1070 //
1072
1073 //
1074 // Send the LBR request packets
1075 //
1079 (CHAR *)HyperTraceLbrdumpRequest,
1081 {
1082 return FALSE;
1083 }
1084
1085 //
1086 // Wait until the result of actions to HyperTrace LBR is received
1087 //
1089
1090 return TRUE;
1091}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_PERFORM_HYPERTRACE_LBR_DUMP
Definition Connection.h:104
#define SIZEOF_HYPERTRACE_LBR_DUMP_PACKETS
Debugger size of HYPERTRACE_LBR_DUMP_PACKETS.
Definition RequestStructures.h:1343
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_HYPERTRACE_LBR_DUMP_RESULT
Definition debugger.h:65

◆ KdSendHyperTracePtPacketsToDebuggee()

BOOLEAN KdSendHyperTracePtPacketsToDebuggee ( PHYPERTRACE_PT_OPERATION_PACKETS HyperTracePtOperationRequest,
UINT32 ExpectedRequestSize )

Send requests for HyperTrace PT operation packet to the debuggee.

Parameters
HyperTracePtOperationRequest
Returns
BOOLEAN
1102{
1103 //
1104 // Set the request data
1105 //
1107
1108 //
1109 // Send the PT request packets
1110 //
1114 (CHAR *)HyperTracePtOperationRequest,
1116 {
1117 return FALSE;
1118 }
1119
1120 //
1121 // Wait until the result of actions to HyperTrace PT is received
1122 //
1124
1125 return TRUE;
1126}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_PERFORM_HYPERTRACE_PT_OPERATION
Definition Connection.h:105
#define SIZEOF_HYPERTRACE_PT_OPERATION_PACKETS
Debugger size of HYPERTRACE_PT_OPERATION_PACKETS.
Definition RequestStructures.h:1412
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_HYPERTRACE_PT_OPERATION_RESULT
Definition debugger.h:66

◆ KdSendListOrModifyPacketToDebuggee()

BOOLEAN KdSendListOrModifyPacketToDebuggee ( PDEBUGGEE_BP_LIST_OR_MODIFY_PACKET ListOrModifyPacket)

Sends a breakpoint list or modification packet to the debuggee.

Parameters
ListOrModifyPacket
Returns
BOOLEAN
1200{
1201 //
1202 // Send list or modify breakpoint packet
1203 //
1207 (CHAR *)ListOrModifyPacket,
1209 {
1210 return FALSE;
1211 }
1212
1213 //
1214 // Wait until the result of listing or modifying breakpoints is received
1215 //
1217
1218 return TRUE;
1219}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_LIST_OR_MODIFY_BREAKPOINTS
Definition Connection.h:92
struct _DEBUGGEE_BP_LIST_OR_MODIFY_PACKET DEBUGGEE_BP_LIST_OR_MODIFY_PACKET
The structure of breakpoint modification requests packet in HyperDbg.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_LIST_OR_MODIFY_BREAKPOINTS
Definition debugger.h:48

◆ KdSendModifyEventInDebuggee()

BOOLEAN KdSendModifyEventInDebuggee ( PDEBUGGER_MODIFY_EVENTS ModifyEvent,
BOOLEAN SendTheResultBackToDebugger )

Modify the event ioctl in the debuggee.

Parameters
ModifyEvent
SendTheResultBackToDebugger
Returns
BOOLEAN
3249{
3250 BOOLEAN Status;
3251 ULONG ReturnedLength;
3252
3253 //
3254 // This mechanism is only used for clear event,
3255 // it is because we apply enable/disable in kernel
3256 // directly
3257 //
3258
3259 //
3260 // Check if debugger is loaded or not
3261 //
3263
3264 //
3265 // Send the request to the kernel
3266 //
3267
3268 Status = DeviceIoControl(g_DeviceHandle, // Handle to device
3269 IOCTL_DEBUGGER_MODIFY_EVENTS, // IO Control Code (IOCTL)
3270 ModifyEvent, // Input Buffer to driver.
3271 SIZEOF_DEBUGGER_MODIFY_EVENTS, // Input buffer length
3272 ModifyEvent, // Output Buffer from driver.
3273 SIZEOF_DEBUGGER_MODIFY_EVENTS, // Length of output
3274 // buffer in bytes.
3275 &ReturnedLength, // Bytes placed in buffer.
3276 NULL // synchronous call
3277 );
3278
3279 if (!Status)
3280 {
3281 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
3282 return FALSE;
3283 }
3284
3285 //
3286 // Send the buffer back to debugger
3287 //
3288 if (SendTheResultBackToDebugger)
3289 {
3292 ModifyEvent,
3293 sizeof(DEBUGGER_MODIFY_EVENTS),
3294 TRUE);
3295 }
3296 else
3297 {
3298 return TRUE;
3299 }
3300}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_DEBUGGEE_RESULT_OF_QUERY_AND_MODIFY_EVENT
Definition Connection.h:124
#define SIZEOF_DEBUGGER_MODIFY_EVENTS
Definition Events.h:254
#define IOCTL_DEBUGGER_MODIFY_EVENTS
ioctl, request to modify an event (enable/disable/clear)
Definition Ioctls.h:206

◆ KdSendPacketToDebuggee()

BOOLEAN KdSendPacketToDebuggee ( const CHAR * Buffer,
UINT32 Length,
BOOLEAN SendEndOfBuffer )

Sends a special packet to the debuggee.

Parameters
Buffer
Length
Returns
BOOLEAN
1784{
1785 BOOL Status;
1786 DWORD BytesWritten = 0;
1787 DWORD LastErrorCode = 0;
1788
1789 //
1790 // Start getting debuggee messages again
1791 //
1793
1794 //
1795 // Double check if buffer not pass the boundary
1796 //
1798 {
1799 ShowMessages("err, buffer is above the maximum buffer size that can be sent to debuggee (%d > %d), "
1800 "for more information, please visit https://docs.hyperdbg.org/tips-and-tricks/misc/customize-build/increase-communication-buffer-size\n",
1803 return FALSE;
1804 }
1805
1806 //
1807 // Check if the remote code's handle found or not
1808 //
1809 if (g_SerialRemoteComPortHandle == NULL)
1810 {
1811 ShowMessages("err, handle to remote debuggee's com port is not found\n");
1812 return FALSE;
1813 }
1814
1815#ifdef _WIN32
1817 {
1818 //
1819 // It's for a debuggee
1820 //
1821 Status = WriteFile(g_SerialRemoteComPortHandle, // Handle to the Serialport
1822 Buffer, // Data to be written to the port
1823 Length, // No of bytes to write into the port
1824 &BytesWritten, // No of bytes written to the port
1825 NULL);
1826
1827 if (Status == FALSE)
1828 {
1829 ShowMessages("err, fail to write to com port or named pipe (error %x).\n",
1830 GetLastError());
1831 return FALSE;
1832 }
1833
1834 //
1835 // Check if message delivered successfully
1836 //
1837 if (BytesWritten != Length)
1838 {
1839 return FALSE;
1840 }
1841 }
1842 else
1843 {
1844 //
1845 // It's a debugger
1846 //
1847
1848 if (WriteFile(g_SerialRemoteComPortHandle, Buffer, Length, NULL, &g_OverlappedIoStructureForWriteDebugger))
1849 {
1850 //
1851 // Write Completed
1852 //
1853 goto Out;
1854 }
1855
1856 LastErrorCode = GetLastError();
1857 if (LastErrorCode != ERROR_IO_PENDING)
1858 {
1859 //
1860 // Error
1861 //
1862 // ShowMessages("err, on sending serial packets (%x)", LastErrorCode);
1863 return FALSE;
1864 }
1865
1866 //
1867 // Wait until write completed
1868 //
1869 if (WaitForSingleObject(g_OverlappedIoStructureForWriteDebugger.hEvent,
1870 INFINITE) != WAIT_OBJECT_0)
1871 {
1872 // ShowMessages("err, on sending serial packets (signal error)");
1873 return FALSE;
1874 }
1875
1876 //
1877 // Reset event
1878 //
1879 ResetEvent(g_OverlappedIoStructureForWriteDebugger.hEvent);
1880 }
1881#else
1882 //
1883 // Linux: write through the cross-platform serial transport. The debuggee /
1884 // handshaking path is synchronous; the debugger path is overlapped (handled
1885 // inside the platform layer).
1886 //
1887 {
1889 if (!PlatformSerialWrite(g_SerialRemoteComPortHandle, Buffer, Length, Synchronous))
1890 {
1891 return FALSE;
1892 }
1893 }
1894#endif
1895
1896Out:
1897 if (SendEndOfBuffer)
1898 {
1899 //
1900 // Send End of Buffer Packet
1901 //
1904 FALSE))
1905 {
1906 return FALSE;
1907 }
1908 }
1909
1910 //
1911 // All the bytes are sent
1912 //
1913 return TRUE;
1914}
BYTE g_EndOfBufferCheckSerial[4]
the buffer that we set at the end of buffers for serial
Definition globals.h:207
BOOLEAN g_IgnoreNewLoggingMessages
Shows if the debugger should show debuggee's messages or not.
Definition globals.h:279
BOOLEAN PlatformSerialWrite(HANDLE Handle, const void *Buffer, UINT32 Length, BOOLEAN Synchronous)

◆ KdSendPageinPacketToDebuggee()

BOOLEAN KdSendPageinPacketToDebuggee ( PDEBUGGER_PAGE_IN_REQUEST PageinPacket)

Sends a page-in or '.pagein' command packet to the debuggee.

Parameters
PageinPacket
Returns
BOOLEAN
937{
938 //
939 // Send the '.pagein' packet
940 //
944 (CHAR *)PageinPacket,
946 {
947 return FALSE;
948 }
949
950 //
951 // Wait until the result of page-in packet is received
952 //
954
955 return TRUE;
956}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_INJECT_PAGE_FAULT
Definition Connection.h:97
struct _DEBUGGER_PAGE_IN_REQUEST DEBUGGER_PAGE_IN_REQUEST
requests for the '.pagein' command
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAGE_IN_STATE
Definition debugger.h:58

◆ KdSendPausePacketToDebuggee()

BOOLEAN KdSendPausePacketToDebuggee ( )

Sends a PAUSE packet to the debuggee.

Returns
BOOLEAN
1463{
1464 //
1465 // Send the pause packet to debuggee
1466 //
1470 {
1471 return FALSE;
1472 }
1473
1474 //
1475 // Handle the paused state (show rip, instructions, etc.)
1476 //
1478
1479 return TRUE;
1480}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_USER_MODE_PAUSE
Definition Connection.h:61
VOID KdInterpretPausedDebuggee()
Interpret the packets from debuggee in the case of paused.
Definition kd.cpp:140

◆ KdSendPcidevinfoPacketToDebuggee()

BOOLEAN KdSendPcidevinfoPacketToDebuggee ( PDEBUGGEE_PCIDEVINFO_REQUEST_RESPONSE_PACKET PciepinfoPacket)

Request PCI device info (CAM). Current consumers include '!pcicam'.

Parameters
PciepinfoPacket
Returns
BOOLEAN
3622{
3623 //
3624 // Send Pciepinfo packet
3625 //
3629 (CHAR *)PciepinfoPacket,
3631 {
3632 return FALSE;
3633 }
3634
3635 //
3636 // Wait until the result of Pcitree packet is received
3637 //
3639
3640 return TRUE;
3641}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_QUERY_PCIDEVINFO
Definition Connection.h:101
struct _DEBUGGEE_PCIDEVINFO_REQUEST_RESPONSE_PACKET DEBUGGEE_PCIDEVINFO_REQUEST_RESPONSE_PACKET
PCI device info Request-Response Packet, used by !pcicam and future PCI-related commands....
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PCIDEVINFO_RESULT
Definition debugger.h:62

◆ KdSendPcitreePacketToDebuggee()

BOOLEAN KdSendPcitreePacketToDebuggee ( PDEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET PcitreePacket)

Sends '!pcitree' command, including buffer, to the debuggee.

Parameters
PcitreePacket
Returns
BOOLEAN
3593{
3594 //
3595 // Send '!pcitree' packet
3596 //
3600 (CHAR *)PcitreePacket,
3602 {
3603 return FALSE;
3604 }
3605
3606 //
3607 // Wait until the result of Pcitree packet is received
3608 //
3610
3611 return TRUE;
3612}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_QUERY_PCITREE
Definition Connection.h:99
struct _DEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET DEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET
Pcitree Request-Response Packet. Represents PCI device tree.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PCITREE_RESULT
Definition debugger.h:60

◆ KdSendPtePacketToDebuggee()

BOOLEAN KdSendPtePacketToDebuggee ( PDEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS PtePacket)

Sends a PTE or '!pte' command packet to the debuggee.

Parameters
PtePacket
Returns
BOOLEAN
908{
909 //
910 // Send the '!pte' packet
911 //
915 (CHAR *)PtePacket,
917 {
918 return FALSE;
919 }
920
921 //
922 // Wait until the result of PTE packet is received
923 //
925
926 return TRUE;
927}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_SYMBOL_QUERY_PTE
Definition Connection.h:95
struct _DEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS DEBUGGER_READ_PAGE_TABLE_ENTRIES_DETAILS
request for !pte command
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PTE_RESULT
Definition debugger.h:56

◆ KdSendQueryIdtPacketsToDebuggee()

BOOLEAN KdSendQueryIdtPacketsToDebuggee ( PINTERRUPT_DESCRIPTOR_TABLE_ENTRIES_PACKETS IdtRequest)

Send requests for IDT packet to the debuggee.

Parameters
IdtRequest
Returns
BOOLEAN
1136{
1137 //
1138 // Set the request data
1139 //
1141 IdtRequest,
1143
1144 //
1145 // Send the IDT request packets
1146 //
1150 {
1151 return FALSE;
1152 }
1153
1154 //
1155 // Wait until the result of actions to IDT is received
1156 //
1158
1159 return TRUE;
1160}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_READ_IDT_ENTRIES
Definition Connection.h:102
struct _INTERRUPT_DESCRIPTOR_TABLE_ENTRIES_PACKETS INTERRUPT_DESCRIPTOR_TABLE_ENTRIES_PACKETS
The structure of IDT entries result packet in HyperDbg.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_IDT_ENTRIES
Definition debugger.h:63

◆ KdSendReadMemoryPacketToDebuggee()

BOOLEAN KdSendReadMemoryPacketToDebuggee ( PDEBUGGER_READ_MEMORY ReadMem,
UINT32 RequestSize )

Send a Read memory packet to the debuggee.

Parameters
ReadMem
Size
Returns
BOOLEAN
598{
599 //
600 // Set the request data
601 //
603
604 //
605 // Send u-d command as read memory packet
606 //
610 (CHAR *)ReadMem,
611 sizeof(DEBUGGER_READ_MEMORY) // only the header is enough, no need to send the entire buffer
612 ))
613 {
614 return FALSE;
615 }
616
617 //
618 // Wait until the result of read registers received
619 //
621
622 return TRUE;
623}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_READ_MEMORY
Definition Connection.h:89
struct _DEBUGGER_READ_MEMORY DEBUGGER_READ_MEMORY
request for reading virtual and physical memory
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_MEMORY
Definition debugger.h:49

◆ KdSendReadRegisterPacketToDebuggee()

BOOLEAN KdSendReadRegisterPacketToDebuggee ( PDEBUGGEE_REGISTER_READ_DESCRIPTION RegDes,
UINT32 RegBuffSize )

Send a read register packet to the debuggee.

Parameters
RegDes
RegBuffSize
Returns
BOOLEAN
528{
529 //
530 // Set the request data
531 //
533
534 //
535 // Send the 'r' command as read register packet
536 //
540 (CHAR *)RegDes,
541 sizeof(DEBUGGEE_REGISTER_READ_DESCRIPTION) // only the header is enough, no need to send the entire buffer
542 ))
543 {
544 return FALSE;
545 }
546
547 //
548 // Wait until the result of read registers received
549 //
551
552 return TRUE;
553}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_READ_REGISTERS
Definition Connection.h:88
struct _DEBUGGEE_REGISTER_READ_DESCRIPTION DEBUGGEE_REGISTER_READ_DESCRIPTION
Register Descriptor Structure to use in r command.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_REGISTERS
Definition debugger.h:46

◆ KdSendRegisterEventPacketToDebuggee()

PDEBUGGER_EVENT_AND_ACTION_RESULT KdSendRegisterEventPacketToDebuggee ( PDEBUGGER_GENERAL_EVENT_DETAIL Event,
UINT32 EventBufferLength )

Send a register event request to the debuggee.

as this command uses one global variable to transfer the buffers so should not be called simultaneously

Parameters
Event
EventBufferLength
Returns
PDEBUGGER_EVENT_AND_ACTION_RESULT
672{
674 UINT32 Len;
675
676 Len = EventBufferLength +
678
680
681 if (Header == NULL)
682 {
683 return NULL;
684 }
685
686 RtlZeroMemory(Header, Len);
687
688 //
689 // Set length in header
690 //
691 Header->Length = EventBufferLength;
692
693 //
694 // Move buffer
695 //
696 memcpy((PVOID)((UINT64)Header +
698 (PVOID)Event,
699 EventBufferLength);
700
703
704 //
705 // Send register event packet
706 //
710 (CHAR *)Header,
711 Len))
712 {
713 free(Header);
714 return NULL;
715 }
716
717 //
718 // Wait until the result of registering received
719 //
721
722 free(Header);
723
725}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_REGISTER_EVENT
Definition Connection.h:85
DEBUGGER_EVENT_AND_ACTION_RESULT g_DebuggeeResultOfRegisteringEvent
Holds the result of registering events from the remote debuggee.
Definition globals.h:305
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_REGISTER_EVENT
Definition debugger.h:43

◆ KdSendResponseOfThePingPacket()

BOOLEAN KdSendResponseOfThePingPacket ( )

Respond to the debuggee with the version and build date of the debugger.

Returns
BOOLEAN
2122{
2123 //
2124 // For logging purposes
2125 //
2126 // ShowMessages("the ping request is received\n");
2127
2128 //
2129 // Send the handshake packet to debuggee
2130 //
2135 sizeof(BuildSignature)))
2136 {
2137 ShowMessages("err, unable to send response to the ping packet\n");
2138 return FALSE;
2139 }
2140
2141 return TRUE;
2142}

◆ KdSendScriptPacketToDebuggee()

BOOLEAN KdSendScriptPacketToDebuggee ( UINT64 BufferAddress,
UINT32 BufferLength,
UINT32 Pointer,
BOOLEAN IsFormat )

Sends a script packet to the debuggee.

Parameters
BufferAddress
BufferLength
Pointer
IsFormat
Returns
BOOLEAN
1232{
1233 PDEBUGGEE_SCRIPT_PACKET ScriptPacket;
1234 UINT32 SizeOfStruct = 0;
1235
1236 SizeOfStruct = sizeof(DEBUGGEE_SCRIPT_PACKET) + BufferLength;
1237
1238 ScriptPacket = (DEBUGGEE_SCRIPT_PACKET *)malloc(SizeOfStruct);
1239
1240 RtlZeroMemory(ScriptPacket, SizeOfStruct);
1241
1242 //
1243 // Fill the script packet buffer
1244 //
1245 ScriptPacket->ScriptBufferSize = BufferLength;
1246 ScriptPacket->ScriptBufferPointer = Pointer;
1247 ScriptPacket->IsFormat = IsFormat;
1248
1249 //
1250 // Move the buffer at the bottom of the script packet
1251 //
1252 memcpy((PVOID)((UINT64)ScriptPacket + sizeof(DEBUGGEE_SCRIPT_PACKET)),
1253 (PVOID)BufferAddress,
1254 BufferLength);
1255
1256 //
1257 // Send script packet
1258 //
1262 (CHAR *)ScriptPacket,
1263 SizeOfStruct))
1264 {
1265 free(ScriptPacket);
1266 return FALSE;
1267 }
1268
1269 if (IsFormat)
1270 {
1271 //
1272 // Wait for formats results too
1273 //
1275 }
1276
1277 //
1278 // Wait until the result of script engine received
1279 //
1281
1282 free(ScriptPacket);
1283 return TRUE;
1284}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_RUN_SCRIPT
Definition Connection.h:82
struct _DEBUGGEE_SCRIPT_PACKET * PDEBUGGEE_SCRIPT_PACKET
struct _DEBUGGEE_SCRIPT_PACKET DEBUGGEE_SCRIPT_PACKET
The structure of script packet in HyperDbg.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_FORMATS_RESULT
Definition debugger.h:40
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_RUNNING_RESULT
Definition debugger.h:39
BOOLEAN IsFormat
Definition RequestStructures.h:1586
UINT32 ScriptBufferPointer
Definition RequestStructures.h:1585
UINT32 ScriptBufferSize
Definition RequestStructures.h:1584

◆ KdSendSearchRequestPacketToDebuggee()

BOOLEAN KdSendSearchRequestPacketToDebuggee ( UINT64 * SearchRequestBuffer,
UINT32 SearchRequestBufferSize )

Sends search query request packet to the debuggee.

Parameters
SearchRequestBuffer
SearchRequestBufferSize
Returns
BOOLEAN
1354{
1355 //
1356 // Send search request packet
1357 //
1361 (CHAR *)SearchRequestBuffer,
1362 SearchRequestBufferSize))
1363 {
1364 return FALSE;
1365 }
1366
1367 //
1368 // Wait until the result of search request received
1369 //
1371
1372 return TRUE;
1373}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_SEARCH_QUERY
Definition Connection.h:84
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SEARCH_QUERY_RESULT
Definition debugger.h:54

◆ KdSendShortCircuitingEventToDebuggee()

BOOLEAN KdSendShortCircuitingEventToDebuggee ( BOOLEAN IsEnabled)

Sends a short-circuiting event request to debuggee.

Parameters
IsEnabled
Returns
BOOLEAN
227{
228 DEBUGGER_SHORT_CIRCUITING_EVENT ShortCircuitEventPacket = {0};
229
230 //
231 // Fill the structure of the packet
232 //
233 ShortCircuitEventPacket.IsShortCircuiting = IsEnabled;
234
235 //
236 // Send modify and query event packet
237 //
241 (CHAR *)&ShortCircuitEventPacket,
243 {
244 return FALSE;
245 }
246
247 //
248 // Wait until the result of setting short-circuiting event state is received
249 //
251
252 return TRUE;
253}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_SET_SHORT_CIRCUITING_STATE
Definition Connection.h:96
struct _DEBUGGER_SHORT_CIRCUITING_EVENT DEBUGGER_SHORT_CIRCUITING_EVENT
request for performing a short-circuiting event
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SHORT_CIRCUITING_EVENT_STATE
Definition debugger.h:57
BOOLEAN IsShortCircuiting
Definition Events.h:263

◆ KdSendSmiPacketsToDebuggee()

BOOLEAN KdSendSmiPacketsToDebuggee ( PSMI_OPERATION_PACKETS SmiOperationRequest,
UINT32 ExpectedRequestSize )

Send requests for SMI operation packet to the debuggee.

Parameters
SmiOperationRequest
Returns
BOOLEAN
1032{
1033 //
1034 // Set the request data
1035 //
1037
1038 //
1039 // Send the SMI request packets
1040 //
1044 (CHAR *)SmiOperationRequest,
1046 {
1047 return FALSE;
1048 }
1049
1050 //
1051 // Wait until the result of actions to SMI is received
1052 //
1054
1055 return TRUE;
1056}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_PERFORM_SMI_OPERATION
Definition Connection.h:103
#define SIZEOF_SMI_OPERATION_PACKETS
Debugger size of SMI_OPERATION_PACKETS.
Definition RequestStructures.h:1275
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SMI_OPERATION_RESULT
Definition debugger.h:64

◆ KdSendStepPacketToDebuggee()

BOOLEAN KdSendStepPacketToDebuggee ( DEBUGGER_REMOTE_STEPPING_REQUEST StepRequestType)

Sends p (step out) and t (step in) packet to the debuggee.

Returns
BOOLEAN
1382{
1383 DEBUGGEE_STEP_PACKET StepPacket = {0};
1384 UINT32 CallInstructionSize;
1385
1386 //
1387 // Set the type of step packet
1388 //
1389 StepPacket.StepType = StepRequestType;
1390
1391 //
1392 // Check if it's a step-over
1393 //
1394 if (StepRequestType == DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_OVER ||
1396 {
1397 //
1398 // It's not needed to check for DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_OVER_FOR_GU_LAST_INSTRUCTION
1399 // as the last instruction is a 'RET' not a 'CALL'
1400 //
1401
1402 //
1403 // We should check whether the current instruction is a 'call'
1404 // instruction or not, if yes we have to compute the length of call
1405 //
1409 g_IsRunningInstruction32Bit ? FALSE : TRUE, // equals to !g_IsRunningInstruction32Bit
1410 &CallInstructionSize))
1411 {
1412 //
1413 // It's a call in step-over
1414 //
1415 StepPacket.IsCurrentInstructionACall = TRUE;
1416 StepPacket.CallLength = CallInstructionSize;
1417 }
1418 }
1419
1420 //
1421 // Set the debuggee is running after this command
1422 //
1423 if (StepRequestType == DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_OVER ||
1426 {
1427 //
1428 // The debuggee is also running after this type of command
1429 // This is because this way the debuggee is running after the step-over or step-in
1430 // so, if the program either terminates or couldn't run the next instruction, the
1431 // user could pause the debuggee again
1432 //
1434 }
1435
1436 //
1437 // Send step packet to the serial
1438 //
1442 (CHAR *)&StepPacket,
1443 sizeof(DEBUGGEE_STEP_PACKET)))
1444 {
1445 return FALSE;
1446 }
1447
1448 //
1449 // Wait until the result of user-input received
1450 //
1452
1453 return TRUE;
1454}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_STEP
Definition Connection.h:73
#define MAXIMUM_INSTR_SIZE
maximum instruction size in Intel
Definition Constants.h:470
struct _DEBUGGEE_STEP_PACKET DEBUGGEE_STEP_PACKET
The structure of stepping packet in HyperDbg.
@ DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_IN
Definition RequestStructures.h:1046
@ DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_OVER_FOR_GU
Definition RequestStructures.h:1051
@ DEBUGGER_REMOTE_STEPPING_REQUEST_STEP_OVER
Definition RequestStructures.h:1050
BOOLEAN HyperDbgCheckWhetherTheCurrentInstructionIsCall(UCHAR *BufferToDisassemble, UINT64 BuffLength, BOOLEAN Isx86_64, PUINT32 CallLength)
Check whether the current instruction is a 'call' or not.
Definition disassembler.cpp:755
BOOLEAN g_IsRunningInstruction32Bit
whether the Current executing instructions is 32-bit or 64 bit
Definition globals.h:232
BYTE g_CurrentRunningInstruction[MAXIMUM_INSTR_SIZE]
Current executing instructions.
Definition globals.h:226
BOOLEAN IsCurrentInstructionACall
Definition RequestStructures.h:1068
UINT32 CallLength
Definition RequestStructures.h:1069
DEBUGGER_REMOTE_STEPPING_REQUEST StepType
Definition RequestStructures.h:1062

◆ KdSendSwitchCorePacketToDebuggee()

BOOLEAN KdSendSwitchCorePacketToDebuggee ( UINT32 NewCore)

Sends a change core or '~ x' command packet to the debuggee.

Returns
BOOLEAN
182{
183 DEBUGGEE_CHANGE_CORE_PACKET CoreChangePacket = {0};
184
185 CoreChangePacket.NewCore = NewCore;
186
187 if (CoreChangePacket.NewCore == g_CurrentRemoteCore)
188 {
189 //
190 // We show an error message here when there is no core change (because the
191 // target core and current operating core is the same)
192 //
193 ShowMessages("the current operating core is %x (not changed)\n",
194 CoreChangePacket.NewCore);
195
196 return FALSE;
197 }
198
199 //
200 // Send '~' as switch packet
201 //
205 (CHAR *)&CoreChangePacket,
207 {
208 return FALSE;
209 }
210
211 //
212 // Wait until the result of core change received
213 //
215
216 return TRUE;
217}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_CHANGE_CORE
Definition Connection.h:76
struct _DEBUGGEE_CHANGE_CORE_PACKET DEBUGGEE_CHANGE_CORE_PACKET
The structure of changing core packet in HyperDbg.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CORE_SWITCHING_RESULT
Definition debugger.h:36
UINT32 NewCore
Definition RequestStructures.h:648

◆ KdSendSwitchProcessPacketToDebuggee()

BOOLEAN KdSendSwitchProcessPacketToDebuggee ( DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_TYPE ActionType,
UINT32 NewPid,
UINT64 NewProcess,
BOOLEAN SetChangeByClockInterrupt,
PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS SymDetailsForProcessList )

Sends a change process or show process details packet to the debuggee.

Parameters
ActionType
NewPid
NewProcess
SetChangeByClockInterrupt
SymDetailsForProcessList
Returns
BOOLEAN
810{
811 DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET ProcessChangePacket = {0};
812
813 ProcessChangePacket.ActionType = ActionType;
814 ProcessChangePacket.ProcessId = NewPid;
815 ProcessChangePacket.Process = NewProcess;
816 ProcessChangePacket.IsSwitchByClkIntr = SetChangeByClockInterrupt;
817
818 //
819 // Check if the command really needs these information or not
820 // it's because some of the command don't need symbol offset information
821 //
822 if (SymDetailsForProcessList != NULL)
823 {
824 memcpy(&ProcessChangePacket.ProcessListSymDetails, SymDetailsForProcessList, sizeof(DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS));
825 }
826
827 //
828 // Send '.process' as switch packet
829 //
833 (CHAR *)&ProcessChangePacket,
835 {
836 return FALSE;
837 }
838
839 //
840 // Wait until the result of process change received
841 //
843
844 return TRUE;
845}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_CHANGE_PROCESS
Definition Connection.h:80
struct _DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS
The structure of needed information to get the details of the process from nt!_EPROCESS and location ...
struct _DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET
The structure of changing process and show process packet in HyperDbg.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PROCESS_SWITCHING_RESULT
Definition debugger.h:37
DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS ProcessListSymDetails
Definition RequestStructures.h:986
UINT32 ProcessId
Definition RequestStructures.h:982
UINT64 Process
Definition RequestStructures.h:983
DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_TYPE ActionType
Definition RequestStructures.h:981
BOOLEAN IsSwitchByClkIntr
Definition RequestStructures.h:984

◆ KdSendSwitchThreadPacketToDebuggee()

BOOLEAN KdSendSwitchThreadPacketToDebuggee ( DEBUGGEE_DETAILS_AND_SWITCH_THREAD_TYPE ActionType,
UINT32 NewTid,
UINT64 NewThread,
BOOLEAN CheckByClockInterrupt,
PDEBUGGEE_THREAD_LIST_NEEDED_DETAILS SymDetailsForThreadList )

Sends a change thread or show threads detail packet to the debuggee.

Parameters
ActionType
NewTid
NewThread
CheckByClockInterrupt
SymDetailsForThreadList
Returns
BOOLEAN
863{
864 DEBUGGEE_DETAILS_AND_SWITCH_THREAD_PACKET ThreadChangePacket = {0};
865
866 ThreadChangePacket.ActionType = ActionType;
867 ThreadChangePacket.ThreadId = NewTid;
868 ThreadChangePacket.Thread = NewThread;
869 ThreadChangePacket.CheckByClockInterrupt = CheckByClockInterrupt;
870
871 //
872 // Check if the command really needs these information or not
873 // it's because some of the command don't need symbol offset information
874 //
875 if (SymDetailsForThreadList != NULL)
876 {
877 memcpy(&ThreadChangePacket.ThreadListSymDetails, SymDetailsForThreadList, sizeof(DEBUGGEE_THREAD_LIST_NEEDED_DETAILS));
878 }
879
880 //
881 // Send '.thread' as switch packet
882 //
886 (CHAR *)&ThreadChangePacket,
888 {
889 return FALSE;
890 }
891
892 //
893 // Wait until the result of thread change received
894 //
896
897 return TRUE;
898}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_CHANGE_THREAD
Definition Connection.h:81
struct _DEBUGGEE_DETAILS_AND_SWITCH_THREAD_PACKET DEBUGGEE_DETAILS_AND_SWITCH_THREAD_PACKET
The structure of changing thead and show thread packet in HyperDbg.
struct _DEBUGGEE_THREAD_LIST_NEEDED_DETAILS DEBUGGEE_THREAD_LIST_NEEDED_DETAILS
The structure of needed information to get the details of the thread from nt!_ETHREAD and location of...
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_THREAD_SWITCHING_RESULT
Definition debugger.h:38
DEBUGGEE_DETAILS_AND_SWITCH_THREAD_TYPE ActionType
Definition RequestStructures.h:1019
UINT64 Thread
Definition RequestStructures.h:1022
DEBUGGEE_THREAD_LIST_NEEDED_DETAILS ThreadListSymDetails
Definition RequestStructures.h:1026
UINT32 ThreadId
Definition RequestStructures.h:1020
BOOLEAN CheckByClockInterrupt
Definition RequestStructures.h:1024

◆ KdSendSymbolDetailPacket()

VOID KdSendSymbolDetailPacket ( PMODULE_SYMBOL_DETAIL SymbolDetailPacket,
UINT32 CurrentSymbolInfoIndex,
UINT32 TotalSymbols )

Send each packet of debugging information (PDB) to the debugger.

Parameters
SymbolDetailPacket
CurrentSymbolInfoIndex
TotalSymbols
Returns
VOID
3425{
3426 BOOLEAN Result;
3427 PDEBUGGER_UPDATE_SYMBOL_TABLE UsermodeSymDetailRequest;
3428
3429 UsermodeSymDetailRequest =
3431
3432 RtlZeroMemory(UsermodeSymDetailRequest, sizeof(DEBUGGER_UPDATE_SYMBOL_TABLE));
3433
3434 //
3435 // Set other parameters for the symbol details
3436 //
3437 UsermodeSymDetailRequest->CurrentSymbolIndex = CurrentSymbolInfoIndex;
3438 UsermodeSymDetailRequest->TotalSymbols = TotalSymbols;
3439
3440 //
3441 // Move the user message buffer at the bottom of the structure packet
3442 //
3443 memcpy((PVOID)((UINT64)&UsermodeSymDetailRequest->SymbolDetailPacket),
3444 (PVOID)SymbolDetailPacket,
3445 sizeof(MODULE_SYMBOL_DETAIL));
3446
3447 //
3448 // Send the symbol update buffer to the debugger
3449 //
3452 UsermodeSymDetailRequest,
3454 FALSE);
3455
3456 if (!Result)
3457 {
3458 ShowMessages("err, sending symbol packets failed in debuggee");
3459 free(UsermodeSymDetailRequest);
3460 return;
3461 }
3462
3463 free(UsermodeSymDetailRequest);
3464}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_DEBUGGEE_UPDATE_SYMBOL_INFO
Definition Connection.h:132
struct _MODULE_SYMBOL_DETAIL MODULE_SYMBOL_DETAIL
structures for sending and saving details about each module and symbols details
struct _DEBUGGER_UPDATE_SYMBOL_TABLE * PDEBUGGER_UPDATE_SYMBOL_TABLE
struct _DEBUGGER_UPDATE_SYMBOL_TABLE DEBUGGER_UPDATE_SYMBOL_TABLE
request to add new symbol detail or update a previous symbol table entry
MODULE_SYMBOL_DETAIL SymbolDetailPacket
Definition Symbols.h:78
UINT32 CurrentSymbolIndex
Definition Symbols.h:77
UINT32 TotalSymbols
Definition Symbols.h:76

◆ KdSendSymbolReloadPacketToDebuggee()

BOOLEAN KdSendSymbolReloadPacketToDebuggee ( UINT32 ProcessId)

Send symbol reload packet to the debuggee.

Returns
BOOLEAN
494{
495 DEBUGGEE_SYMBOL_REQUEST_PACKET SymbolRequest = {0};
496
497 SymbolRequest.ProcessId = ProcessId;
498
499 //
500 // Send '.sym reload' as symbol reload packet
501 //
505 (CHAR *)&SymbolRequest,
507 {
508 return FALSE;
509 }
510
511 //
512 // Wait until all of the symbol packets are received
513 //
515
516 return TRUE;
517}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_SYMBOL_RELOAD
Definition Connection.h:93
struct _DEBUGGEE_SYMBOL_REQUEST_PACKET DEBUGGEE_SYMBOL_REQUEST_PACKET
The structure of .sym reload packet in HyperDbg.
UINT32 ProcessId
Definition RequestStructures.h:1505

◆ KdSendTestQueryPacketToDebuggee()

BOOLEAN KdSendTestQueryPacketToDebuggee ( DEBUGGER_TEST_QUERY_STATE Type)

Send a test query request to the debuggee.

Parameters
Type
Returns
BOOLEAN
426{
427 DEBUGGER_DEBUGGER_TEST_QUERY_BUFFER TestQueryPacket = {0};
428
429 TestQueryPacket.RequestType = Type;
430
431 //
432 // Send 'test query' command as query packet
433 //
437 (CHAR *)&TestQueryPacket,
439 {
440 return FALSE;
441 }
442
443 //
444 // Wait until the result of test query is received
445 //
447
448 return TRUE;
449}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_MODE_TEST_QUERY
Definition Connection.h:79
struct _DEBUGGER_DEBUGGER_TEST_QUERY_BUFFER DEBUGGER_DEBUGGER_TEST_QUERY_BUFFER
request for test query buffers
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_TEST_QUERY
Definition debugger.h:52
DEBUGGER_TEST_QUERY_STATE RequestType
Definition RequestStructures.h:358

◆ KdSendTestQueryPacketWithContextToDebuggee()

BOOLEAN KdSendTestQueryPacketWithContextToDebuggee ( DEBUGGER_TEST_QUERY_STATE Type,
UINT64 Context )

Send a test query request to the debuggee with the specified context.

Parameters
Type
Context
Returns
BOOLEAN
461{
462 DEBUGGER_DEBUGGER_TEST_QUERY_BUFFER TestQueryPacket = {0};
463
464 TestQueryPacket.RequestType = Type;
465 TestQueryPacket.Context = Context;
466
467 //
468 // Send 'test query' command as query packet
469 //
473 (CHAR *)&TestQueryPacket,
475 {
476 return FALSE;
477 }
478
479 //
480 // Wait until the result of test query is received
481 //
483
484 return TRUE;
485}
UINT64 Context
Definition RequestStructures.h:359

◆ KdSendUserInputPacketToDebuggee()

BOOLEAN KdSendUserInputPacketToDebuggee ( const CHAR * Sendbuf,
INT Len,
BOOLEAN IgnoreBreakingAgain )

Sends user input packet to the debuggee.

Parameters
Sendbuf
Len
IgnoreBreakingAgain
Returns
BOOLEAN
1296{
1297 PDEBUGGEE_USER_INPUT_PACKET UserInputPacket;
1298 UINT32 SizeOfStruct = 0;
1299
1300 SizeOfStruct = sizeof(DEBUGGEE_USER_INPUT_PACKET) + Len;
1301
1302 UserInputPacket = (DEBUGGEE_USER_INPUT_PACKET *)malloc(SizeOfStruct);
1303
1304 RtlZeroMemory(UserInputPacket, SizeOfStruct);
1305
1306 //
1307 // Fill the script packet buffer descriptors
1308 //
1309 UserInputPacket->CommandLen = Len;
1310 UserInputPacket->IgnoreFinishedSignal = IgnoreBreakingAgain;
1311
1312 //
1313 // Move the user input buffer at the bottom of the structure packet
1314 //
1315 memcpy((PVOID)((UINT64)UserInputPacket + sizeof(DEBUGGEE_USER_INPUT_PACKET)),
1316 (PVOID)Sendbuf,
1317 Len);
1318
1319 //
1320 // Send user-input packet
1321 //
1325 (CHAR *)UserInputPacket,
1326 SizeOfStruct))
1327 {
1328 free(UserInputPacket);
1329 return FALSE;
1330 }
1331
1332 //
1333 // Wait until the result of user-input received
1334 //
1335 if (!IgnoreBreakingAgain)
1336 {
1338 }
1339
1340 free(UserInputPacket);
1341
1342 return TRUE;
1343}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_USER_INPUT_BUFFER
Definition Connection.h:83
struct _DEBUGGEE_USER_INPUT_PACKET * PDEBUGGEE_USER_INPUT_PACKET
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_DEBUGGEE_FINISHED_COMMAND_EXECUTION
Definition debugger.h:41
UINT32 CommandLen
Definition DataTypes.h:174

◆ KdSendUsermodePrints()

VOID KdSendUsermodePrints ( CHAR * Input,
UINT32 Length )

Send result of user-mode ShowMessages to debuggee.

Parameters
Input
Length
Returns
VOID
3365{
3366 BOOL Status;
3367 ULONG ReturnedLength;
3368 PDEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER UsermodeMessageRequest;
3369 UINT32 SizeToSend;
3370
3371 SizeToSend = sizeof(DEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER) + Length;
3372
3373 UsermodeMessageRequest =
3374 (DEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER *)malloc(SizeToSend);
3375
3376 RtlZeroMemory(UsermodeMessageRequest, SizeToSend);
3377
3378 //
3379 // Set the length
3380 //
3381 UsermodeMessageRequest->Length = Length;
3382
3383 //
3384 // Move the user message buffer at the bottom of the structure packet
3385 //
3386 memcpy((PVOID)((UINT64)UsermodeMessageRequest +
3388 (PVOID)Input,
3389 Length);
3390
3391 Status = DeviceIoControl(
3392 g_DeviceHandle, // Handle to device
3393 IOCTL_SEND_USERMODE_MESSAGES_TO_DEBUGGER, // IO Control Code (IOCTL)
3394 UsermodeMessageRequest, // Input Buffer to driver.
3395 SizeToSend, // Input buffer
3396 // length
3397 UsermodeMessageRequest, // Output Buffer from driver.
3398 SizeToSend, // Length of
3399 // output buffer
3400 // in bytes.
3401 &ReturnedLength, // Bytes placed in buffer.
3402 NULL // synchronous call
3403 );
3404
3405 if (!Status)
3406 {
3407 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
3408 free(UsermodeMessageRequest);
3409 return;
3410 }
3411
3412 free(UsermodeMessageRequest);
3413}
#define IOCTL_SEND_USERMODE_MESSAGES_TO_DEBUGGER
ioctl, send user-mode messages to the debugger
Definition Ioctls.h:256
struct _DEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER * PDEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER
struct _DEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER DEBUGGER_SEND_USERMODE_MESSAGES_TO_DEBUGGER
request for send a user-mode message to debugger
UINT32 Length
Definition RequestStructures.h:430

◆ KdSendVa2paAndPa2vaPacketToDebuggee()

BOOLEAN KdSendVa2paAndPa2vaPacketToDebuggee ( PDEBUGGER_VA2PA_AND_PA2VA_COMMANDS Va2paAndPa2vaPacket)

Sends VA2PA and PA2VA packest, or '!va2pa' and '!pa2va' commands packet to the debuggee.

Parameters
Va2paAndPa2vaPacket
Returns
BOOLEAN
966{
967 //
968 // Send '!va2pa' or '!pa2va' as a query packet
969 //
973 (CHAR *)Va2paAndPa2vaPacket,
975 {
976 return FALSE;
977 }
978
979 //
980 // Wait until the result of VA2PA or PA2VA packet is received
981 //
983
984 return TRUE;
985}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_QUERY_PA2VA_AND_VA2PA
Definition Connection.h:94
struct _DEBUGGER_VA2PA_AND_PA2VA_COMMANDS DEBUGGER_VA2PA_AND_PA2VA_COMMANDS
requests for !va2pa and !pa2va commands
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_VA2PA_AND_PA2VA_RESULT
Definition debugger.h:55

◆ KdSendWriteRegisterPacketToDebuggee()

BOOLEAN KdSendWriteRegisterPacketToDebuggee ( PDEBUGGEE_REGISTER_WRITE_DESCRIPTION RegDes)

Send a write register packet to the debuggee.

Parameters
RegDes
Returns
BOOLEAN
563{
564 //
565 // Set the request data
566 //
568
569 //
570 // Send write register packet
571 //
575 (CHAR *)RegDes,
577 {
578 return FALSE;
579 }
580
581 //
582 // Wait until the result of write register received
583 //
585
586 return TRUE;
587}
@ DEBUGGER_REMOTE_PACKET_REQUESTED_ACTION_ON_VMX_ROOT_WRITE_REGISTER
Definition Connection.h:98
struct _DEBUGGEE_REGISTER_WRITE_DESCRIPTION DEBUGGEE_REGISTER_WRITE_DESCRIPTION
Register Descriptor Structure to write on registers.
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_WRITE_REGISTER
Definition debugger.h:59

◆ KdSetStatusAndWaitForPause()

VOID KdSetStatusAndWaitForPause ( )

Set the status of the debuggee to wait for the pause.

Returns
VOID
2073{
2074 //
2075 // Set the debuggee to show that it's running
2076 //
2078
2079 //
2080 // Halt the UI
2081 //
2083}

◆ KdTheRemoteSystemIsRunning()

VOID KdTheRemoteSystemIsRunning ( )

wait for a event to be triggered and if the debuggee is running it just halts the system

Returns
VOID
2152{
2153 //
2154 // Indicate that the debuggee is running
2155 //
2156 ShowMessages("debuggee is running...\n");
2157
2158 //
2159 // Wait until the users press CTRL+C
2160 //
2162}

◆ KdUninitializeConnection()

VOID KdUninitializeConnection ( )

Uninitialize everything in both debuggee and debugger.

This function close the connection in both debuggee and debugger both of the debuggee and debugger can use this function

Returns
VOID
3475{
3476 //
3477 // Close the handles of the listening threads
3478 //
3480 {
3481 CloseHandle(g_SerialListeningThreadHandle);
3483 }
3484
3485 if (g_OverlappedIoStructureForReadDebugger.hEvent != NULL)
3486 {
3487 CloseHandle(g_OverlappedIoStructureForReadDebugger.hEvent);
3488 }
3489
3490 if (g_OverlappedIoStructureForReadDebuggee.hEvent != NULL)
3491 {
3492 CloseHandle(g_OverlappedIoStructureForReadDebuggee.hEvent);
3493 }
3494
3495 if (g_OverlappedIoStructureForWriteDebugger.hEvent != NULL)
3496 {
3497 CloseHandle(g_OverlappedIoStructureForWriteDebugger.hEvent);
3498 }
3499
3501 {
3502 //
3503 // Signal the debuggee to get new commands
3504 //
3506 }
3507
3508 //
3509 // Unpause the debugger to get commands
3510 //
3512
3513 //
3514 // Close synchronization objects
3515 //
3517 {
3518 if (g_KernelSyncronizationObjectsHandleTable[i].EventHandle != NULL)
3519 {
3520 if (g_KernelSyncronizationObjectsHandleTable[i].IsOnWaitingState)
3521 {
3523 }
3524
3525 CloseHandle(g_KernelSyncronizationObjectsHandleTable[i].EventHandle);
3527 }
3528 }
3529
3530 //
3531 // Unallocate symbol data
3532 //
3534
3535 //
3536 // No current core
3537 //
3539
3540 //
3541 // Not in handshaking phase
3542 //
3544
3545 //
3546 // If connected to debugger
3547 //
3549
3550 //
3551 // No longer connected to the debuggee
3552 //
3554
3555 //
3556 // And debuggee is not running
3557 //
3559
3560 //
3561 // Not repeating the last command
3562 //
3564
3565 //
3566 // Clear the handler
3567 //
3568 if (g_SerialRemoteComPortHandle != NULL)
3569 {
3570 CloseHandle(g_SerialRemoteComPortHandle);
3572 }
3573
3574 //
3575 // Start getting debuggee messages on next try
3576 //
3578
3579 //
3580 // Is serial handle for a named pipe
3581 //
3583}
BOOLEAN g_ShouldPreviousCommandBeContinued
Shows whether the previous command should be continued or not.
Definition globals.h:342
BOOLEAN SymbolDeleteSymTable()
Delete and free structures and variables related to the symbols.
Definition symbol.cpp:717

Variable Documentation

◆ g_CurrentRemoteCore

ULONG g_CurrentRemoteCore
extern

Current core that the debuggee is debugging.

◆ g_CurrentRunningInstruction

BYTE g_CurrentRunningInstruction[MAXIMUM_INSTR_SIZE]
extern

Current executing instructions.

226{0};

◆ g_DebuggeeResultOfAddingActionsToEvent

DEBUGGER_EVENT_AND_ACTION_RESULT g_DebuggeeResultOfAddingActionsToEvent
extern

Holds the result of adding action to events from the remote debuggee.

311 {
312 0};

◆ g_DebuggeeResultOfRegisteringEvent

DEBUGGER_EVENT_AND_ACTION_RESULT g_DebuggeeResultOfRegisteringEvent
extern

Holds the result of registering events from the remote debuggee.

305{0};

◆ g_DebuggeeStopCommandEventHandle

HANDLE g_DebuggeeStopCommandEventHandle
extern

An event to make sure that the user won't give any command in debuggee and all the commands are coming from just the debugger.

◆ g_EndOfBufferCheckSerial

BYTE g_EndOfBufferCheckSerial[4]
extern

the buffer that we set at the end of buffers for serial

◆ g_IgnoreNewLoggingMessages

BOOLEAN g_IgnoreNewLoggingMessages
extern

Shows if the debugger should show debuggee's messages or not.

◆ g_IgnorePauseRequests

BOOLEAN g_IgnorePauseRequests
extern

Show whether the pause request (CTRL+C or CTRL+BREAK) should be ignored or not.

◆ g_IsConnectedToHyperDbgLocally

BOOLEAN g_IsConnectedToHyperDbgLocally
extern

Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machine introspection) mode.

◆ g_IsDebuggeeInHandshakingPhase

BOOLEAN g_IsDebuggeeInHandshakingPhase
extern

Shows if the debuggee is in the handshake phase or not.

◆ g_IsDebuggeeRunning

BOOLEAN g_IsDebuggeeRunning
extern

Shows if the debuggee is running or not.

◆ g_IsDebuggerConntectedToNamedPipe

BOOLEAN g_IsDebuggerConntectedToNamedPipe
extern

Shows if the debugger is connected to the guest using named pipe.

◆ g_IsKdModuleLoaded

BOOLEAN g_IsKdModuleLoaded
extern

shows whether the kernel debugger (KD) module is loaded or not

◆ g_IsRunningInstruction32Bit

BOOLEAN g_IsRunningInstruction32Bit
extern

whether the Current executing instructions is 32-bit or 64 bit

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

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

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

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

◆ g_IsVmmModuleLoaded

BOOLEAN g_IsVmmModuleLoaded
extern

shows whether the VMM module is loaded or not

◆ g_KernelSyncronizationObjectsHandleTable

In debugger (not debuggee), we save the handle of the user-mode listening thread for pauses here for kernel debugger.

220{0};

◆ g_SerialConnectionAlreadyClosed

BOOLEAN g_SerialConnectionAlreadyClosed
extern

In both debuggee and debugger we save the state of the closed connection to avoid double close.

◆ g_SerialListeningThreadHandle

HANDLE g_SerialListeningThreadHandle
extern

In debuggee and debugger, we save the handle of the user-mode listening thread for pauses here.

◆ g_SerialRemoteComPortHandle

HANDLE g_SerialRemoteComPortHandle
extern

In debugger (not debuggee), we save the handle of the user-mode listening thread for remote system here.

◆ g_SharedEventStatus

BOOLEAN g_SharedEventStatus
extern

This is an OVERLAPPED structure for managing simultaneous read and writes for debugger (in current design debuggee is not needed to write simultaneously but it's needed for write).

Shows whether the queried event is enabled or disabled

◆ g_ShouldPreviousCommandBeContinued

BOOLEAN g_ShouldPreviousCommandBeContinued
extern

Shows whether the previous command should be continued or not.