HyperDbg Debugger
Loading...
Searching...
No Matches
debugger.h File Reference

General debugger functions. More...

Go to the source code of this file.

Classes

struct  _DEBUGGER_SYNCRONIZATION_EVENTS_STATE
 In debugger holds the state of events. More...
 

Macros

#define DEBUGGER_MAXIMUM_SYNCRONIZATION_KERNEL_DEBUGGER_OBJECTS   0x40
 maximum number of event handles in kernel-debugger
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_IS_DEBUGGER_RUNNING   0x0
 An event to show whether the debugger is running or not in kernel-debugger.
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_STARTED_PACKET_RECEIVED   0x1
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAUSED_DEBUGGEE_DETAILS   0x2
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CORE_SWITCHING_RESULT   0x3
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PROCESS_SWITCHING_RESULT   0x4
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_THREAD_SWITCHING_RESULT   0x5
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_RUNNING_RESULT   0x6
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_FORMATS_RESULT   0x7
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_DEBUGGEE_FINISHED_COMMAND_EXECUTION   0x8
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_FLUSH_RESULT   0x9
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_REGISTER_EVENT   0xa
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_ADD_ACTION_TO_EVENT   0xb
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_MODIFY_AND_QUERY_EVENT   0xc
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_REGISTERS   0xd
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_BP   0xe
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_LIST_OR_MODIFY_BREAKPOINTS   0xf
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_MEMORY   0x10
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_EDIT_MEMORY   0x11
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SYMBOL_RELOAD   0x12
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_TEST_QUERY   0x13
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CALLSTACK_RESULT   0x14
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SEARCH_QUERY_RESULT   0x15
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_VA2PA_AND_PA2VA_RESULT   0x16
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PTE_RESULT   0x17
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SHORT_CIRCUITING_EVENT_STATE   0x18
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAGE_IN_STATE   0x19
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_WRITE_REGISTER   0x1a
 
#define DEBUGGER_MAXIMUM_SYNCRONIZATION_USER_DEBUGGER_OBJECTS   0x40
 Maximum number of event handles in user-debugger.
 
#define DEBUGGER_SYNCRONIZATION_OBJECT_USER_DEBUGGER_IS_DEBUGGER_RUNNING   0x30
 An event to show whether the debugger is running or not in user-debugger.
 

Typedefs

typedef enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
 Reason for error in parsing commands.
 
typedef enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSEPDEBUGGER_EVENT_PARSING_ERROR_CAUSE
 
typedef struct _DEBUGGER_SYNCRONIZATION_EVENTS_STATE DEBUGGER_SYNCRONIZATION_EVENTS_STATE
 In debugger holds the state of events.
 
typedef struct _DEBUGGER_SYNCRONIZATION_EVENTS_STATEPDEBUGGER_SYNCRONIZATION_EVENTS_STATE
 

Enumerations

enum  _DEBUGGER_EVENT_PARSING_ERROR_CAUSE {
  DEBUGGER_EVENT_PARSING_ERROR_CAUSE_SUCCESSFUL_NO_ERROR = 0 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_SCRIPT_SYNTAX_ERROR = 1 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_NO_INPUT = 2 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_MAXIMUM_INPUT_REACHED = 3 ,
  DEBUGGER_EVENT_PARSING_ERROR_CAUSE_OUTPUT_NAME_NOT_FOUND = 4 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_OUTPUT_SOURCE_ALREADY_CLOSED = 5 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ALLOCATION_ERROR = 6 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR = 7 ,
  DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ATTEMPT_TO_BREAK_ON_VMI_MODE = 8 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_IMMEDIATE_MESSAGING_IN_EVENT_FORWARDING_MODE = 9 , DEBUGGER_EVENT_PARSING_ERROR_CAUSE_USING_SHORT_CIRCUITING_IN_POST_EVENTS = 10
}
 Reason for error in parsing commands. More...
 

Functions

VOID InterpreterRemoveComments (char *CommandText)
 Remove batch comments.
 
BOOLEAN ShowErrorMessage (UINT32 Error)
 shows the error message
 
BOOLEAN IsConnectedToAnyInstanceOfDebuggerOrDebuggee ()
 Shows whether the debugger is connected to a debugger or debuggee connected to a debugger.
 
BOOLEAN IsTagExist (UINT64 Tag)
 Check whether the tag exists or not, if the tag is DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG then if we find just one event, it also means that the tag is found.
 
UINT64 DebuggerGetNtoskrnlBase ()
 Get ntoskrnl.exe base in the kernel.
 
UINT64 DebuggerGetKernelBase ()
 Get the base address of the kernel module.
 
BOOLEAN DebuggerPauseDebuggee ()
 pauses the debuggee
 
BOOLEAN InterpretConditionsAndCodes (vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, BOOLEAN IsConditionBuffer, PUINT64 BufferAddress, PUINT32 BufferLength)
 Interpret conditions (if an event has condition) and custom code.
 
VOID FreeEventsAndActionsMemory (PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, PDEBUGGER_GENERAL_ACTION ActionCustomCode, PDEBUGGER_GENERAL_ACTION ActionScript)
 Deallocate buffers relating to events and actions.
 
BOOLEAN SendEventToKernel (PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
 Register the event to the kernel.
 
BOOLEAN RegisterActionToEvent (PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, UINT32 ActionBreakToDebuggerLength, PDEBUGGER_GENERAL_ACTION ActionCustomCode, UINT32 ActionCustomCodeLength, PDEBUGGER_GENERAL_ACTION ActionScript, UINT32 ActionScriptLength)
 Register the action to the event.
 
BOOLEAN InterpretGeneralEventAndActionsFields (vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, VMM_EVENT_TYPE_ENUM EventType, PDEBUGGER_GENERAL_EVENT_DETAIL *EventDetailsToFill, PUINT32 EventBufferLength, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillBreakToDebugger, PUINT32 ActionBufferLengthBreakToDebugger, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillCustomCode, PUINT32 ActionBufferLengthCustomCode, PDEBUGGER_GENERAL_ACTION *ActionDetailsToFillScript, PUINT32 ActionBufferLengthScript, PDEBUGGER_EVENT_PARSING_ERROR_CAUSE ReasonForErrorInParsing)
 Interpret general event fields.
 
BOOLEAN CallstackReturnAddressToCallingAddress (UCHAR *ReturnAddress, PUINT32 IndexOfCallFromReturnAddress)
 Walkthrough the stack.
 
VOID CallstackShowFrames (PDEBUGGER_SINGLE_CALLSTACK_FRAME CallstackFrames, UINT32 FrameCount, DEBUGGER_CALLSTACK_DISPLAY_METHOD DisplayMethod, BOOLEAN Is32Bit)
 Show stack frames.
 
UINT64 GetNewDebuggerEventTag ()
 Get the New Debugger Event Tag object and increase the global variable for tag.
 
DWORD WINAPI ListeningSerialPauseDebuggeeThread (PVOID Param)
 Check if the remote debugger needs to pause the system.
 
DWORD WINAPI ListeningSerialPauseDebuggerThread (PVOID Param)
 Check if the remote debuggee needs to pause the system.
 
VOID LogopenSaveToFile (const char *Text)
 Append text to the file object.
 
BOOL BreakController (DWORD CtrlType)
 handle CTRL+C and CTRL+Break events
 
VOID CommandEventsShowEvents ()
 print every active and disabled events
 
BOOLEAN CommandEventsModifyAndQueryEvents (UINT64 Tag, DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction)
 modify a special event (enable/disable/clear) and send the request directly to the kernel
 
VOID CommandEventsHandleModifiedEvent (UINT64 Tag, PDEBUGGER_MODIFY_EVENTS ModifyEventRequest)
 Handle events after modification.
 
VOID CommandEventsClearAllEventsAndResetTags ()
 Clears all the events and resets the tag.
 
VOID CommandFlushRequestFlush ()
 flush command handler
 
UINT64 GetCommandAttributes (const string &FirstCommand)
 Get Command Attributes.
 
VOID DetachFromProcess ()
 perform detach from process
 
VOID CommandPauseRequest ()
 request to pause
 
VOID CommandGRequest ()
 Request to unpause.
 
VOID CommandBpRequest (UINT64 Address, UINT32 Pid, UINT32 Tid, UINT32 CoreNumer)
 request breakpoint
 
VOID CommandTrackHandleReceivedInstructions (unsigned char *BufferToDisassemble, UINT32 BuffLength, BOOLEAN Isx86_64, UINT64 RipAddress)
 Handle received 'call' or 'ret'.
 
VOID CommandTrackHandleReceivedCallInstructions (const char *NameOfFunctionFromSymbols, UINT64 ComputedAbsoluteAddress)
 Handle received 'call'.
 
VOID CommandTrackHandleReceivedRetInstructions (UINT64 CurrentRip)
 Handle received 'ret'.
 
BOOLEAN HyperDbgWriteMemory (PVOID DestinationAddress, DEBUGGER_EDIT_MEMORY_TYPE MemoryType, UINT32 ProcessId, PVOID SourceAddress, UINT32 NumberOfBytes)
 API function for writing the memory content.
 
BOOLEAN HyperDbgReadAllRegisters (GUEST_REGS *GuestRegisters, GUEST_EXTRA_REGISTERS *ExtraRegisters)
 Read all registers.
 
BOOLEAN HyperDbgReadTargetRegister (REGS_ENUM RegisterId, UINT64 *TargetRegister)
 Read target register.
 
BOOLEAN HyperDbgWriteTargetRegister (REGS_ENUM RegisterId, UINT64 Value)
 Write target register.
 
BOOLEAN HyperDbgRegisterShowAll ()
 handler of r show all registers
 
BOOLEAN HyperDbgRegisterShowTargetRegister (REGS_ENUM RegisterId)
 handler of r show the target register
 
BOOLEAN HyperDbgDebugRemoteDeviceUsingComPort (const CHAR *PortName, DWORD Baudrate)
 Connect to a remote serial device (Debugger)
 
BOOLEAN HyperDbgDebugRemoteDeviceUsingNamedPipe (const CHAR *NamedPipe)
 Connect to a remote named pipe (Debugger)
 
BOOLEAN HyperDbgDebugCurrentDeviceUsingComPort (const CHAR *PortName, DWORD Baudrate)
 Connect to a remote serial device (Debuggee)
 

Detailed Description

General debugger functions.

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

Macro Definition Documentation

◆ DEBUGGER_MAXIMUM_SYNCRONIZATION_KERNEL_DEBUGGER_OBJECTS

#define DEBUGGER_MAXIMUM_SYNCRONIZATION_KERNEL_DEBUGGER_OBJECTS   0x40

maximum number of event handles in kernel-debugger

◆ DEBUGGER_MAXIMUM_SYNCRONIZATION_USER_DEBUGGER_OBJECTS

#define DEBUGGER_MAXIMUM_SYNCRONIZATION_USER_DEBUGGER_OBJECTS   0x40

Maximum number of event handles in user-debugger.

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_ADD_ACTION_TO_EVENT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_ADD_ACTION_TO_EVENT   0xb

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_BP

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_BP   0xe

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CALLSTACK_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CALLSTACK_RESULT   0x14

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CORE_SWITCHING_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_CORE_SWITCHING_RESULT   0x3

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_DEBUGGEE_FINISHED_COMMAND_EXECUTION

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_DEBUGGEE_FINISHED_COMMAND_EXECUTION   0x8

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_EDIT_MEMORY

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_EDIT_MEMORY   0x11

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_FLUSH_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_FLUSH_RESULT   0x9

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_IS_DEBUGGER_RUNNING

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_IS_DEBUGGER_RUNNING   0x0

An event to show whether the debugger is running or not in kernel-debugger.

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_LIST_OR_MODIFY_BREAKPOINTS

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_LIST_OR_MODIFY_BREAKPOINTS   0xf

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_MODIFY_AND_QUERY_EVENT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_MODIFY_AND_QUERY_EVENT   0xc

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAGE_IN_STATE

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAGE_IN_STATE   0x19

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAUSED_DEBUGGEE_DETAILS

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PAUSED_DEBUGGEE_DETAILS   0x2

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PROCESS_SWITCHING_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PROCESS_SWITCHING_RESULT   0x4

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PTE_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_PTE_RESULT   0x17

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_MEMORY

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_MEMORY   0x10

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_REGISTERS

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_READ_REGISTERS   0xd

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_REGISTER_EVENT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_REGISTER_EVENT   0xa

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_FORMATS_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_FORMATS_RESULT   0x7

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_RUNNING_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SCRIPT_RUNNING_RESULT   0x6

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SEARCH_QUERY_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SEARCH_QUERY_RESULT   0x15

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SHORT_CIRCUITING_EVENT_STATE

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SHORT_CIRCUITING_EVENT_STATE   0x18

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_STARTED_PACKET_RECEIVED

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_STARTED_PACKET_RECEIVED   0x1

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SYMBOL_RELOAD

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_SYMBOL_RELOAD   0x12

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_TEST_QUERY

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_TEST_QUERY   0x13

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_THREAD_SWITCHING_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_THREAD_SWITCHING_RESULT   0x5

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_VA2PA_AND_PA2VA_RESULT

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_VA2PA_AND_PA2VA_RESULT   0x16

◆ DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_WRITE_REGISTER

#define DEBUGGER_SYNCRONIZATION_OBJECT_KERNEL_DEBUGGER_WRITE_REGISTER   0x1a

◆ DEBUGGER_SYNCRONIZATION_OBJECT_USER_DEBUGGER_IS_DEBUGGER_RUNNING

#define DEBUGGER_SYNCRONIZATION_OBJECT_USER_DEBUGGER_IS_DEBUGGER_RUNNING   0x30

An event to show whether the debugger is running or not in user-debugger.

Typedef Documentation

◆ DEBUGGER_EVENT_PARSING_ERROR_CAUSE

Reason for error in parsing commands.

◆ DEBUGGER_SYNCRONIZATION_EVENTS_STATE

In debugger holds the state of events.

◆ PDEBUGGER_EVENT_PARSING_ERROR_CAUSE

◆ PDEBUGGER_SYNCRONIZATION_EVENTS_STATE

Enumeration Type Documentation

◆ _DEBUGGER_EVENT_PARSING_ERROR_CAUSE

Reason for error in parsing commands.

Enumerator
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_SUCCESSFUL_NO_ERROR 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_SCRIPT_SYNTAX_ERROR 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_NO_INPUT 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_MAXIMUM_INPUT_REACHED 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_OUTPUT_NAME_NOT_FOUND 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_OUTPUT_SOURCE_ALREADY_CLOSED 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ALLOCATION_ERROR 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ATTEMPT_TO_BREAK_ON_VMI_MODE 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_IMMEDIATE_MESSAGING_IN_EVENT_FORWARDING_MODE 
DEBUGGER_EVENT_PARSING_ERROR_CAUSE_USING_SHORT_CIRCUITING_IN_POST_EVENTS 
69{
81
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_OUTPUT_NAME_NOT_FOUND
Definition debugger.h:74
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_SUCCESSFUL_NO_ERROR
Definition debugger.h:70
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_MAXIMUM_INPUT_REACHED
Definition debugger.h:73
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_USING_SHORT_CIRCUITING_IN_POST_EVENTS
Definition debugger.h:80
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_NO_INPUT
Definition debugger.h:72
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_OUTPUT_SOURCE_ALREADY_CLOSED
Definition debugger.h:75
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_SCRIPT_SYNTAX_ERROR
Definition debugger.h:71
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_IMMEDIATE_MESSAGING_IN_EVENT_FORWARDING_MODE
Definition debugger.h:79
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ALLOCATION_ERROR
Definition debugger.h:76
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ATTEMPT_TO_BREAK_ON_VMI_MODE
Definition debugger.h:78
@ DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR
Definition debugger.h:77
enum _DEBUGGER_EVENT_PARSING_ERROR_CAUSE DEBUGGER_EVENT_PARSING_ERROR_CAUSE
Reason for error in parsing commands.

Function Documentation

◆ BreakController()

BOOL BreakController ( DWORD CtrlType)

handle CTRL+C and CTRL+Break events

Parameters
CtrlType
Returns
BOOL
35{
36 switch (CtrlType)
37 {
38 //
39 // Handle the CTRL + C & CTRL + Break signal
40 //
41 case CTRL_BREAK_EVENT:
42 case CTRL_C_EVENT:
43
44 //
45 // check if we should ignore the break requests or not
46 //
48 {
49 return TRUE;
50 }
51
52 //
53 // Check for aborting symbol loading routines
54 //
56 {
57 //
58 // Avoid to calling it again
59 //
61
62 //
63 // Abort the execution
64 //
66 }
67
68 //
69 // Check if the debuggee is running because of pausing or not
70 //
72 {
74 {
76 }
77 else
78 {
80 }
81 }
83 {
84 //
85 // vmm module is not loaded here
86 //
87 }
88 else
89 {
91 {
93 }
94 else
95 {
96 //
97 // Sleep because the other thread that shows must be stopped
98 //
100
101 //
102 // Check if its a remote debuggee then we should send the 'pause' command
103 //
105 {
106 RemoteConnectionSendCommand("pause", (UINT32)strlen("pause") + 1);
107 }
108
109 Sleep(300);
110
111 //
112 // It is because we didn't query the target debuggee auto-unpause variable
113 //
115 {
116 if (g_AutoUnpause)
117 {
119 "\npausing...\nauto-unpause mode is enabled, "
120 "debugger will automatically continue when you run a new "
121 "event command, if you want to change this behaviour then "
122 "run run 'settings autounpause off'\n\n");
123 }
124 else
125 {
127 "\npausing...\nauto-unpause mode is disabled, you "
128 "should run 'g' when you want to continue, otherwise run "
129 "'settings "
130 "autounpause on'\n\n");
131 }
132
133 //
134 // Show the signature of HyperDbg
135 //
137
139 {
141 }
142 }
143 }
144 }
145
146 return TRUE;
147
148 //
149 // CTRL+CLOSE: confirm that the user wants to exit.
150 //
151 case CTRL_CLOSE_EVENT:
152 return TRUE;
153
154 case CTRL_LOGOFF_EVENT:
155 return FALSE;
156
157 case CTRL_SHUTDOWN_EVENT:
158 return FALSE;
159
160 default:
161
162 //
163 // Return TRUE if handled this message, further handler functions won't be
164 // called.
165 // Return FALSE to pass this message to further handlers until default
166 // handler calls ExitProcess().
167 //
168 return FALSE;
169 }
170}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
BOOLEAN g_IsInstrumentingInstructions
Shows whether the user is running 't', 'p', or 'i' command.
Definition globals.h:561
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN g_BreakPrintingOutput
Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
Definition globals.h:499
BOOLEAN g_IsExecutingSymbolLoadingRoutines
Executing symbol reloading or downloading routines.
Definition globals.h:506
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362
BOOLEAN g_AutoUnpause
Whether auto-unpause mode is enabled or not enabled.
Definition globals.h:577
BOOLEAN g_IsDebuggerModulesLoaded
this variable is used to indicate that modules are loaded so we make sure to later use a trace of loa...
Definition globals.h:356
BOOLEAN g_IgnorePauseRequests
Show whether the pause request (CTRL+C or CTRL+BREAK) should be ignored or not.
Definition globals.h:158
VOID HyperDbgShowSignature()
Show signature of HyperDbg.
Definition interpreter.cpp:566
VOID KdBreakControlCheckAndPauseDebugger()
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
int RemoteConnectionSendCommand(const char *sendbuf, int len)
send the command as a client (debugger, host) to the server (debuggee, guest)
Definition remote-connection.cpp:445
VOID ScriptEngineSymbolAbortLoadingWrapper()
SymbolAbortLoading wrapper.
Definition script-engine-wrapper.cpp:228
BOOLEAN IsActive
Definition ud.h:49
UINT64 ProcessDebuggingToken
Definition ud.h:50
BOOLEAN UdPauseProcess(UINT64 ProcessDebuggingToken)
Pause the target process.
Definition ud.cpp:843

◆ CallstackReturnAddressToCallingAddress()

BOOLEAN CallstackReturnAddressToCallingAddress ( UCHAR * ReturnAddress,
PUINT32 IndexOfCallFromReturnAddress )

Walkthrough the stack.

This code is borrowed from here : https://github.com/electronicarts/EAThread/blob/master/source/x86/eathread_callstack_x86.cpp

Parameters
ReturnAddress
IndexOfCallFromReturnAddress
Returns
BOOLEAN
31{
32 //
33 // While negative array indices can be considered non-idiomatic it
34 // was felt that they are semantically appropriate as this code bases
35 // its comparisons from the return address and that it would be cleaner
36 // than using *(ReturnAddress - index).
37 //
38
39 //
40 // Three op-codes are used for the call instruction, 9A, E8, and FF.
41 // For a reference on the IA32 instruction format, see:
42 // http://www.cs.princeton.edu/courses/archive/spr06/cos217/reading/ia32vol2.pdf
43 //
44
45 //
46 // 9A cp - CALL ptr16:32 (7-byte)
47 //
48 if (ReturnAddress[-7] == 0x9A)
49 {
50 *IndexOfCallFromReturnAddress = 7;
51 return TRUE;
52 }
53 // E8 cd - CALL rel32 (5-byte)
54 else if (ReturnAddress[-5] == 0xE8)
55 {
56 *IndexOfCallFromReturnAddress = 5;
57 return TRUE;
58 }
59 else
60 {
61 //
62 // The third opcode to specify "call" instructions is FF.
63 // Unfortunately this instruction also needs the succeeding ModR/M
64 // byte to fully determine instruction length. The SIB value is
65 // another byte used for extending the range of addressing modes
66 // supported by the ModR/M byte. The values of this ModR/M byte
67 // used in conjunction with the call instruction are as follows:
68 //
69 // 7-byte call:
70 // FF [ModR/M] [SIB] [4-byte displacement]
71 // * ModR/M is either 0x94 or 0x9C
72 //
73 // 6-byte call:
74 // FF [ModR/M] [4-byte displacement]
75 // * ModR/M can be:
76 // * 0x90 - 0x9F EXCLUDING 0x94 or 0x9C
77 // * 0x15 or 0x1D
78 //
79 // 4-byte call:
80 // FF [ModR/M] [SIB] [1-byte displacement]
81 // * ModR/M is either 0x54 or 0x5C
82 //
83 // 3-byte call:
84 // FF [ModR/M] [1-byte displacement]
85 // * ModR/M can be:
86 // * 0x50 - 0x5F EXCLUDING 0x54 or 0x5C
87 // FF [ModR/M] [SIB]
88 // * ModR/M is either 0x14 or 0x1C
89 //
90 // 2-byte call:
91 // FF [ModR/M]
92 // * ModR/M can be:
93 // * 0xD0 - 0xDF
94 // * 0x10 - 0x1F EXCEPT 0x14, 0x15, 0x1C, or 0x1D
95 //
96
97 //
98 // The mask of F8 is used because we want to mask out the bottom
99 // three bits (which are most often used for register selection)
100 //
101 const unsigned char RmMask = 0xF8;
102
103 //
104 // 7-byte format:
105 //
106 if (ReturnAddress[-7] == 0xFF &&
107 (ReturnAddress[-6] == 0x94 || ReturnAddress[-6] == 0x9C))
108 {
109 *IndexOfCallFromReturnAddress = 7;
110 return TRUE;
111 }
112
113 //
114 // 6-byte format:
115 // FF [ModR/M] [4-byte displacement]
116 //
117 else if (ReturnAddress[-6] == 0xFF &&
118 ((ReturnAddress[-5] & RmMask) == 0x90 || (ReturnAddress[-5] & RmMask) == 0x98) &&
119 (ReturnAddress[-5] != 0x94 && ReturnAddress[-5] != 0x9C))
120 {
121 *IndexOfCallFromReturnAddress = 6;
122 return TRUE;
123 }
124
125 //
126 // Alternate 6-byte format:
127 //
128 else if (ReturnAddress[-6] == 0xFF &&
129 (ReturnAddress[-5] == 0x15 || ReturnAddress[-5] == 0x1D))
130 {
131 *IndexOfCallFromReturnAddress = 6;
132 return TRUE;
133 }
134
135 //
136 // 4-byte format:
137 // FF [ModR/M] [SIB] [1-byte displacement]
138 //
139 else if (ReturnAddress[-4] == 0xFF &&
140 (ReturnAddress[-3] == 0x54 || ReturnAddress[-3] == 0x5C))
141 {
142 *IndexOfCallFromReturnAddress = 4;
143 return TRUE;
144 }
145
146 //
147 // 3-byte format:
148 // FF [ModR/M] [1-byte displacement]
149 //
150 else if (ReturnAddress[-3] == 0xFF &&
151 ((ReturnAddress[-2] & RmMask) == 0x50 || (ReturnAddress[-2] & RmMask) == 0x58) &&
152 (ReturnAddress[-2] != 0x54 && ReturnAddress[-2] != 0x5C))
153 {
154 *IndexOfCallFromReturnAddress = 3;
155 return TRUE;
156 }
157
158 //
159 // Alternate 3-byte format:
160 // FF [ModR/M] [SIB]
161 //
162 else if (ReturnAddress[-3] == 0xFF &&
163 (ReturnAddress[-2] == 0x14 || ReturnAddress[-2] == 0x1C))
164 {
165 *IndexOfCallFromReturnAddress = 3;
166 return TRUE;
167 }
168
169 //
170 // 2-byte calling format:
171 // FF [ModR/M]
172 //
173 else if (ReturnAddress[-2] == 0xFF &&
174 ((ReturnAddress[-1] & RmMask) == 0xD0 || (ReturnAddress[-1] & RmMask) == 0xD8))
175 {
176 *IndexOfCallFromReturnAddress = 2;
177 return TRUE;
178 }
179
180 //
181 // Alternate 2-byte calling format:
182 // FF [ModR/M]
183 //
184 else if (ReturnAddress[-2] == 0xFF &&
185 ((ReturnAddress[-1] & RmMask) == 0x10 || (ReturnAddress[-1] & RmMask) == 0x18) &&
186 (ReturnAddress[-1] != 0x14 && ReturnAddress[-1] != 0x15 &&
187 ReturnAddress[-1] != 0x1C && ReturnAddress[-1] != 0x1D))
188 {
189 *IndexOfCallFromReturnAddress = 2;
190 return TRUE;
191 }
192 else
193 {
194 return FALSE;
195 }
196 }
197
198 return FALSE;
199}

◆ CallstackShowFrames()

VOID CallstackShowFrames ( PDEBUGGER_SINGLE_CALLSTACK_FRAME CallstackFrames,
UINT32 FrameCount,
DEBUGGER_CALLSTACK_DISPLAY_METHOD DisplayMethod,
BOOLEAN Is32Bit )

Show stack frames.

Parameters
CallstackFrames
FrameCount
DisplayMethod
Is32Bit
Returns
VOID
216{
217 UINT32 CallLength;
218 UINT64 TargetAddress;
219 UINT64 UsedBaseAddress;
220 BOOLEAN IsCall = FALSE;
221 std::map<UINT64, LOCAL_FUNCTION_DESCRIPTION>::iterator Iterate;
222
223 //
224 // Print callstack frames
225 //
226 for (size_t i = 0; i < FrameCount; i++)
227 {
228 IsCall = FALSE;
229
230 if (CallstackFrames[i].IsValidAddress)
231 {
232 //
233 // Check if it's call or just a simple code address
234 //
235 if (CallstackFrames[i].IsExecutable && CallstackReturnAddressToCallingAddress(
236 (unsigned char *)&CallstackFrames[i].InstructionBytesOnRip[MAXIMUM_CALL_INSTR_SIZE],
237 &CallLength))
238 {
239 //
240 // Computer the "call" instruction address
241 //
242 TargetAddress = CallstackFrames[i].Value - CallLength;
243
244 IsCall = TRUE;
245 }
246 else
247 {
248 //
249 // Check if we wanna show the stack params
250 //
252 {
253 continue;
254 }
255
256 IsCall = FALSE;
257 TargetAddress = CallstackFrames[i].Value;
258 }
259
260 ShowMessages("[$+%03x] ", i * (Is32Bit ? sizeof(UINT32) : sizeof(UINT64)));
261
262 if (IsCall)
263 {
264 if (Is32Bit)
265 {
266 ShowMessages(" %08x (from ", TargetAddress);
267 }
268 else
269 {
270 ShowMessages(" %016llx (from ", TargetAddress);
271 }
272 }
273 else
274 {
275 if (Is32Bit)
276 {
277 ShowMessages(" %08x (addr ", TargetAddress);
278 }
279 else
280 {
281 ShowMessages(" %016llx (addr ", TargetAddress);
282 }
283 }
284
285 //
286 // Show the name of the function if available
287 // Apply addressconversion of settings here
288 //
290 {
291 if (SymbolShowFunctionNameBasedOnAddress(TargetAddress, &UsedBaseAddress))
292 {
293 ShowMessages(" ");
294 }
295 }
296
297 if (Is32Bit)
298 {
299 ShowMessages("<%08x>)\n", TargetAddress);
300 }
301 else
302 {
303 ShowMessages("<%016llx>)\n", TargetAddress);
304 }
305 }
306 else
307 {
308 //
309 // Check if we wanna show the stack params
310 //
312 {
313 continue;
314 }
315
316 ShowMessages("[$+%03x] ", i * (Is32Bit ? sizeof(UINT32) : sizeof(UINT64)));
317
318 if (Is32Bit)
319 {
320 ShowMessages(" %08x\n", CallstackFrames[i].Value);
321 }
322 else
323 {
324 ShowMessages(" %016llx\n", CallstackFrames[i].Value);
325 }
326 }
327 }
328}
UCHAR BOOLEAN
Definition BasicTypes.h:39
unsigned __int64 UINT64
Definition BasicTypes.h:21
#define MAXIMUM_CALL_INSTR_SIZE
maximum size for call instruction in Intel
Definition Constants.h:473
@ DEBUGGER_CALLSTACK_DISPLAY_METHOD_WITHOUT_PARAMS
Definition RequestStructures.h:779
BOOLEAN g_AddressConversion
Whether converting addresses to object names or not.
Definition globals.h:584
BOOLEAN CallstackReturnAddressToCallingAddress(UCHAR *ReturnAddress, PUINT32 IndexOfCallFromReturnAddress)
Walkthrough the stack.
Definition callstack.cpp:30
RequestedActionOfThePacket Value(0x1) 00000000
UINT64 Value
Definition RequestStructures.h:765
BOOLEAN SymbolShowFunctionNameBasedOnAddress(UINT64 Address, PUINT64 UsedBaseAddress)
shows the functions' name for the disassembler
Definition symbol.cpp:162

◆ CommandBpRequest()

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

request breakpoint

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

◆ CommandEventsClearAllEventsAndResetTags()

VOID CommandEventsClearAllEventsAndResetTags ( )

Clears all the events and resets the tag.

Returns
VOID
471{
472 //
473 // Check if events are initialized
474 //
476 {
478
479 //
480 // Indicate that it's not initialized
481 //
483
484 //
485 // Reset tag numbering mechanism
486 //
488 }
489}
#define DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG
Apply event modifications to all tags.
Definition Constants.h:586
#define DebuggerEventTagStartSeed
The seeds that user-mode codes use as the starter of their events' tag.
Definition Constants.h:222
BOOLEAN CommandEventClearEvent(UINT64 Tag)
disable and remove a special event
Definition events.cpp:386
UINT64 g_EventTag
This variable holds the trace and generate numbers for new tags of events.
Definition globals.h:375
BOOLEAN g_EventTraceInitialized
it shows whether the debugger started using events or not or in other words, is g_EventTrace initiali...
Definition globals.h:390

◆ CommandEventsHandleModifiedEvent()

VOID CommandEventsHandleModifiedEvent ( UINT64 Tag,
PDEBUGGER_MODIFY_EVENTS ModifyEventRequest )

Handle events after modification.

Parameters
Tagthe tag of the target event
ModifyEventRequestResults
Returns
VOID
502{
503 if (ModifyEventRequest->KernelStatus == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
504 {
505 //
506 // Successful, nothing to show but we should also
507 // do the same (change) the user-mode structures
508 // that hold the event data
509 //
510 if (ModifyEventRequest->TypeOfAction == DEBUGGER_MODIFY_EVENTS_ENABLE)
511 {
513 {
514 ShowMessages("err, the event was successfully, "
515 "(enabled|disabled|cleared) but "
516 "can't apply it to the user-mode structures\n");
517 }
518 }
519 else if (ModifyEventRequest->TypeOfAction == DEBUGGER_MODIFY_EVENTS_DISABLE)
520 {
522 {
523 ShowMessages("err, the event was successfully, "
524 "(enabled|disabled|cleared) but "
525 "can't apply it to the user-mode structures\n");
526 }
527 else
528 {
529 //
530 // The action was applied successfully
531 //
533 {
534 //
535 // It is because we didn't query the target debuggee auto-flush
536 // variable
537 //
541 {
542 if (!g_AutoFlush)
543 {
545 "auto-flush mode is disabled, if there is still "
546 "messages or buffers in the kernel, you continue to see "
547 "the messages when you run 'g' until the kernel "
548 "buffers are empty. you can run 'settings autoflush "
549 "on' and after disabling and clearing events, "
550 "kernel buffers will be flushed automatically\n");
551 }
552 else
553 {
554 //
555 // We should flush buffers here
556 //
558 }
559 }
560 }
561 }
562 }
563 else if (ModifyEventRequest->TypeOfAction == DEBUGGER_MODIFY_EVENTS_CLEAR)
564 {
566 {
567 ShowMessages("err, the event was successfully, "
568 "(enabled|disabled|cleared) but "
569 "can't apply it to the user-mode structures\n");
570 }
571 else
572 {
573 //
574 // If HyperDbg is operating at the Debugger Mode, we'll indicate that
575 // the event will be cleared after continuing the debuggee
576 //
578 {
579 ShowMessages("%s successfully cleared, but please note in the Debugger Mode (current mode), HyperDbg "
580 "cannot clear events instantly. Instead, it first disables the events, and when "
581 "you continue the debuggee (e.g., by pressing the 'g' command), the event will be cleared. "
582 "Reapplying the same event without first continuing the debuggee may result in undefined behavior\n",
583 Tag == DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG ? "events are" : "the event is");
584 }
585
586 //
587 // The action was applied successfully
588 //
590 {
591 //
592 // It is because we didn't query the target debuggee auto-flush
593 // variable
594 //
596 {
597 if (!g_AutoFlush)
598 {
600 "auto-flush mode is disabled, if there is still "
601 "messages or buffers in the kernel, you continue to see "
602 "the messages when you run 'g' until the kernel "
603 "buffers are empty. you can run 'settings autoflush "
604 "on' and after disabling and clearing events, "
605 "kernel buffers will be flushed automatically\n");
606 }
607 else
608 {
609 //
610 // We should flush buffers here
611 //
613 }
614 }
615 }
616 }
617 }
618 else if (ModifyEventRequest->TypeOfAction ==
620 {
621 //
622 // Nothing to show
623 //
624 }
625 else
626 {
628 "err, the event was successfully, (enabled|disabled|cleared) but "
629 "can't apply it to the user-mode structures\n");
630 }
631 }
632 else
633 {
634 //
635 // Interpret error
636 //
637 ShowErrorMessage((UINT32)ModifyEventRequest->KernelStatus);
638 return;
639 }
640}
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
POOL_TYPE SIZE_T ULONG Tag
Definition Hooks.h:168
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:38
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host)
Definition globals.h:238
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
BOOLEAN CommandEventEnableEvent(UINT64 Tag)
enables a special event
Definition events.cpp:336
BOOLEAN CommandEventDisableEvent(UINT64 Tag)
Disable a special event.
Definition events.cpp:286
BOOLEAN g_AutoFlush
Whether auto-flush mode is enabled or not enabled.
Definition globals.h:591
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN g_BreakPrintingOutput
Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
Definition globals.h:499
VOID CommandFlushRequestFlush()
flush command handler
Definition flush.cpp:39
@ DEBUGGER_MODIFY_EVENTS_ENABLE
Definition Events.h:232
@ DEBUGGER_MODIFY_EVENTS_DISABLE
Definition Events.h:233
@ DEBUGGER_MODIFY_EVENTS_QUERY_STATE
Definition Events.h:231
@ DEBUGGER_MODIFY_EVENTS_CLEAR
Definition Events.h:234
DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction
Definition Events.h:246
UINT64 KernelStatus
Definition Events.h:244

◆ CommandEventsModifyAndQueryEvents()

BOOLEAN CommandEventsModifyAndQueryEvents ( UINT64 Tag,
DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction )

modify a special event (enable/disable/clear) and send the request directly to the kernel

if you pass DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG as the tag then it will be applied to all the active/disabled events in the kernel

Parameters
Tagthe tag of the target event
TypeOfActionwhether its a enable/disable/clear
Returns
BOOLEAN Shows whether the event is enabled or disabled
656{
657 BOOLEAN Status;
658 ULONG ReturnedLength;
659 DEBUGGER_MODIFY_EVENTS ModifyEventRequest = {0};
660
661 //
662 // Check if there is no event, then we shouldn't apply the
663 // enable, disable, or clear commands, this command also
664 // checks for DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG to
665 // see if at least one tag exists or not; however, it's not
666 // necessary as the kernel will check for the validity of
667 // tag too, but let's not send it to kernel as we can prevent
668 // invalid requests from user-mode too
669 //
670 if (!IsTagExist(Tag))
671 {
673 {
674 ShowMessages("there is no event\n");
675 }
676 else
677 {
678 ShowMessages("err, tag id is invalid\n");
679 }
680 return FALSE;
681 }
682
684 {
685 //
686 // Remote debuggee Debugger Mode
687 //
689 }
690 else
691 {
692 //
693 // Local debugging VMI-Mode
694 //
695
696 //
697 // Check if debugger is loaded or not
698 //
700
701 //
702 // Fill the structure to send it to the kernel
703 //
704 ModifyEventRequest.Tag = Tag;
705 ModifyEventRequest.TypeOfAction = TypeOfAction;
706
707 //
708 // Send the request to the kernel
709 //
710 Status =
711 DeviceIoControl(g_DeviceHandle, // Handle to device
712 IOCTL_DEBUGGER_MODIFY_EVENTS, // IO Control Code (IOCTL)
713 &ModifyEventRequest, // Input Buffer to driver.
714 SIZEOF_DEBUGGER_MODIFY_EVENTS, // Input buffer length
715 &ModifyEventRequest, // Output Buffer from driver.
716 SIZEOF_DEBUGGER_MODIFY_EVENTS, // Length of output
717 // buffer in bytes.
718 &ReturnedLength, // Bytes placed in buffer.
719 NULL // synchronous call
720 );
721
722 if (!Status)
723 {
724 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
725 return FALSE;
726 }
727
728 //
729 // Perform further actions
730 //
731 CommandEventsHandleModifiedEvent(Tag, &ModifyEventRequest);
732
733 if (TypeOfAction == DEBUGGER_MODIFY_EVENTS_QUERY_STATE)
734 {
735 return ModifyEventRequest.IsEnabled;
736 }
737 }
738
739 //
740 // in all the cases except query state it shows whether the operation was
741 // successful or not
742 //
743 return TRUE;
744}
unsigned long ULONG
Definition BasicTypes.h:37
#define IOCTL_DEBUGGER_MODIFY_EVENTS
ioctl, request to modify an event (enable/disable/clear)
Definition Ioctls.h:148
BOOLEAN IsTagExist(UINT64 Tag)
Check whether the tag exists or not, if the tag is DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG then if we...
Definition debugger.cpp:719
VOID CommandEventsHandleModifiedEvent(UINT64 Tag, PDEBUGGER_MODIFY_EVENTS ModifyEventRequest)
Handle events after modification.
Definition events.cpp:499
#define SIZEOF_DEBUGGER_MODIFY_EVENTS
Definition Events.h:197
BOOLEAN KdSendEventQueryAndModifyPacketToDebuggee(UINT64 Tag, DEBUGGER_MODIFY_EVENTS_TYPE TypeOfAction, BOOLEAN *IsEnabled)
Sends a query or request to enable/disable/clear for event.
Definition kd.cpp:265
#define AssertShowMessageReturnStmt(expr, message, rc)
Definition common.h:51
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:25
#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:471
request for modifying events (enable/disable/clear)
Definition Events.h:242
BOOLEAN IsEnabled
Definition Events.h:247
UINT64 Tag
Definition Events.h:243

◆ CommandEventsShowEvents()

VOID CommandEventsShowEvents ( )

print every active and disabled events

this function will not show cleared events

Returns
VOID
228{
229 //
230 // It's an events without any argument so we have to show
231 // all the currently active events
232 //
233 PLIST_ENTRY TempList = 0;
234 BOOLEAN IsThereAnyEvents = FALSE;
235
236 TempList = &g_EventTrace;
237 while (&g_EventTrace != TempList->Blink)
238 {
239 TempList = TempList->Blink;
240
241 PDEBUGGER_GENERAL_EVENT_DETAIL CommandDetail = CONTAINING_RECORD(TempList, DEBUGGER_GENERAL_EVENT_DETAIL, CommandsEventList);
242 string CommandMessage((char *)CommandDetail->CommandStringBuffer);
243
244 //
245 // Do not show the \n(s)
246 //
247 ReplaceAll(CommandMessage, "\n", " ");
248
249 //
250 // Only show portion of message
251 //
252 if (CommandMessage.length() > 70)
253 {
254 CommandMessage = CommandMessage.substr(0, 70);
255 CommandMessage += "...";
256 }
257
258 ShowMessages("%x\t(%s)\t %s\n",
259 CommandDetail->Tag - DebuggerEventTagStartSeed,
260 // CommandDetail->IsEnabled ? "enabled" : "disabled",
261 CommandEventQueryEventState(CommandDetail->Tag)
262 ? "enabled"
263 : "disabled", /* Query is live now */
264 CommandMessage.c_str());
265
266 if (!IsThereAnyEvents)
267 {
268 IsThereAnyEvents = TRUE;
269 }
270 }
271
272 if (!IsThereAnyEvents)
273 {
274 ShowMessages("no active/disabled events \n");
275 }
276}
VOID ReplaceAll(string &str, const string &from, const string &to)
general replace all function
Definition common.cpp:91
LIST_ENTRY g_EventTrace
Holds a list of events in kernel and the state of events and the commands to show the state of each c...
Definition globals.h:400
BOOLEAN CommandEventQueryEventState(UINT64 Tag)
Check the kernel whether the event is enabled or disabled.
Definition events.cpp:184
Each command is like the following struct, it also used for tracing works in user mode and sending it...
Definition Events.h:350
UINT64 Tag
Definition Events.h:388
PVOID CommandStringBuffer
Definition Events.h:393

◆ CommandFlushRequestFlush()

VOID CommandFlushRequestFlush ( )

flush command handler

Returns
VOID
40{
41 BOOL Status;
42 ULONG ReturnedLength;
43 DEBUGGER_FLUSH_LOGGING_BUFFERS FlushRequest = {0};
44
46 {
47 //
48 // It's a debug-mode
49 //
51 }
52 else
53 {
54 //
55 // It's a vmi-mode
56 //
58
59 //
60 // By the way, we don't need to send an input buffer
61 // to the kernel, but let's keep it like this, if we
62 // want to pass some other arguments to the kernel in
63 // the future
64 //
65 Status = DeviceIoControl(
66 g_DeviceHandle, // Handle to device
67 IOCTL_DEBUGGER_FLUSH_LOGGING_BUFFERS, // IO Control Code (IOCTL)
68 &FlushRequest, // Input Buffer to driver.
69 SIZEOF_DEBUGGER_FLUSH_LOGGING_BUFFERS, // Input buffer length
70 &FlushRequest, // Output Buffer from driver.
71 SIZEOF_DEBUGGER_FLUSH_LOGGING_BUFFERS, // Length of output buffer in
72 // bytes.
73 &ReturnedLength, // Bytes placed in buffer.
74 NULL // synchronous call
75 );
76
77 if (!Status)
78 {
79 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
80 return;
81 }
82
84 {
85 //
86 // The amount of message that are deleted are the amount of
87 // vmx-root messages and vmx non-root messages
88 //
90 "flushing buffers was successful, total %d messages were cleared.\n",
93 }
94 else
95 {
96 ShowMessages("flushing buffers was not successful :(\n");
97 }
98 }
99}
int BOOL
Definition BasicTypes.h:23
#define IOCTL_DEBUGGER_FLUSH_LOGGING_BUFFERS
ioctl, flush the kernel buffers
Definition Ioctls.h:155
#define SIZEOF_DEBUGGER_FLUSH_LOGGING_BUFFERS
Definition RequestStructures.h:286
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN KdSendFlushPacketToDebuggee()
Send a flush request to the debuggee.
Definition kd.cpp:314
#define AssertReturn
Definition common.h:19
request for flushing buffers
Definition RequestStructures.h:294
UINT32 CountOfMessagesThatSetAsReadFromVmxRoot
Definition RequestStructures.h:296
UINT32 CountOfMessagesThatSetAsReadFromVmxNonRoot
Definition RequestStructures.h:297
UINT32 KernelStatus
Definition RequestStructures.h:295

◆ CommandGRequest()

VOID CommandGRequest ( )

Request to unpause.

Returns
VOID
42{
43 //
44 // Check if the remote serial debuggee is paused or not
45 //
47 {
49 }
50 else
51 {
52 //
53 // Set the g_BreakPrintingOutput to FALSE
54 //
56
57 //
58 // If it's a remote debugger then we send the remote debuggee a 'g'
59 // and if we're connect to user debugger then we send the packet
60 // with current debugging thread token
61 //
63 {
64 RemoteConnectionSendCommand("g", (UINT32)strlen("g") + 1);
65 }
67 {
69 {
71
72 //
73 // Target process is running
74 //
76 }
77 else
78 {
79 ShowMessages("err, target process is already running\n");
80 }
81 }
82 }
83}
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
BOOLEAN g_BreakPrintingOutput
Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
Definition globals.h:499
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362
VOID KdBreakControlCheckAndContinueDebugger()
BOOLEAN IsPaused
Definition ud.h:53
VOID UdContinueDebuggee(UINT64 ProcessDetailToken)
Continue the target user debugger.
Definition ud.cpp:976

◆ CommandPauseRequest()

VOID CommandPauseRequest ( )

request to pause

Returns
VOID
41{
42 //
43 // Set the g_BreakPrintingOutput to TRUE
44 //
46 ShowMessages("pausing...\n");
47
48 //
49 // If it's a remote debugger then we send the remote debuggee a 'g'
50 //
52 {
53 RemoteConnectionSendCommand("pause", (UINT32)strlen("pause") + 1);
54 }
56 {
57 ShowMessages("please keep interacting with the process until all the "
58 "threads are intercepted and halted; whenever you execute "
59 "the first command, the thread interception will be stopped\n");
60 }
61}
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
BOOLEAN g_BreakPrintingOutput
Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
Definition globals.h:499
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362

◆ CommandTrackHandleReceivedCallInstructions()

VOID CommandTrackHandleReceivedCallInstructions ( const char * NameOfFunctionFromSymbols,
UINT64 ComputedAbsoluteAddress )

Handle received 'call'.

Parameters
NameOfFunctionFromSymbols
ComputedAbsoluteAddress
Returns
VOID

◆ CommandTrackHandleReceivedInstructions()

VOID CommandTrackHandleReceivedInstructions ( unsigned char * BufferToDisassemble,
UINT32 BuffLength,
BOOLEAN Isx86_64,
UINT64 RipAddress )

Handle received 'call' or 'ret'.

Parameters
BufferToDisassemble
BuffLength
Isx86_64
RipAddress
Returns
VOID
247{
248

◆ CommandTrackHandleReceivedRetInstructions()

VOID CommandTrackHandleReceivedRetInstructions ( UINT64 CurrentRip)

Handle received 'ret'.

Parameters
CurrentRip
Returns
VOID
317{
318

◆ DebuggerGetKernelBase()

UINT64 DebuggerGetKernelBase ( )

Get the base address of the kernel module.

Returns
UINT64
594{
595 UINT64 KernelBase = NULL;
596
598 {
599 KernelBase = g_KernelBaseAddress;
600 }
601 else
602 {
603 KernelBase = DebuggerGetNtoskrnlBase();
604 g_KernelBaseAddress = KernelBase;
605 }
606
607 return KernelBase;
608}
UINT64 g_KernelBaseAddress
Shows the kernel base address.
Definition globals.h:566
UINT64 DebuggerGetNtoskrnlBase()
Get ntoskrnl.exe base in the kernel.
Definition debugger.cpp:551
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest)
Definition globals.h:231
NULL()
Definition test-case-generator.py:530

◆ DebuggerGetNtoskrnlBase()

UINT64 DebuggerGetNtoskrnlBase ( )

Get ntoskrnl.exe base in the kernel.

Returns
UINT64 Base address of ntoskrnl.exe
552{
553 NTSTATUS Status = STATUS_UNSUCCESSFUL;
554 UINT64 NtoskrnlBase = NULL;
555 PRTL_PROCESS_MODULES Modules = NULL;
556 ULONG SysModuleInfoBufferSize = 0;
557
558 //
559 // Get required size of "RTL_PROCESS_MODULES" buffer
560 //
561 Status = NtQuerySystemInformation((SYSTEM_INFORMATION_CLASS)SystemModuleInformation, NULL, NULL, &SysModuleInfoBufferSize);
562
563 Modules = (PRTL_PROCESS_MODULES)malloc(SysModuleInfoBufferSize);
564
565 if (Modules == NULL)
566 {
567 return NULL64_ZERO;
568 }
569
570 NtQuerySystemInformation((SYSTEM_INFORMATION_CLASS)SystemModuleInformation, Modules, SysModuleInfoBufferSize, NULL);
571
572 for (UINT32 i = 0; i < Modules->NumberOfModules; i++)
573 {
574 if (!strcmp((const char *)Modules->Modules[i].FullPathName + Modules->Modules[i].OffsetToFileName,
575 "ntoskrnl.exe"))
576 {
577 NtoskrnlBase = (UINT64)Modules->Modules[i].ImageBase;
578 break;
579 }
580 }
581
582 free(Modules);
583
584 return NtoskrnlBase;
585}
#define NULL64_ZERO
Definition BasicTypes.h:52
@ SystemModuleInformation
Definition Hooks.h:116
enum _SYSTEM_INFORMATION_CLASS SYSTEM_INFORMATION_CLASS
System information class.
struct _RTL_PROCESS_MODULES * PRTL_PROCESS_MODULES
#define STATUS_UNSUCCESSFUL
Definition Windows.h:172
Definition Windows.h:33
ULONG NumberOfModules
Definition Windows.h:34

◆ DebuggerPauseDebuggee()

BOOLEAN DebuggerPauseDebuggee ( )

pauses the debuggee

Returns
BOOLEAN shows whether the pause was successful or not, if successful then when it returns true the debuggee is not paused anymore (continued)
618{
619 BOOLEAN StatusIoctl = 0;
620 ULONG ReturnedLength = 0;
621 DEBUGGER_PAUSE_PACKET_RECEIVED PauseRequest = {0};
622
623 //
624 // Send a pause IOCTL
625 //
626 StatusIoctl = DeviceIoControl(g_DeviceHandle, // Handle to device
627 IOCTL_PAUSE_PACKET_RECEIVED, // IO Control Code (IOCTL)
628 &PauseRequest, // Input Buffer to driver.
630 // length
631 &PauseRequest, // Output Buffer from driver.
632 SIZEOF_DEBUGGER_PAUSE_PACKET_RECEIVED, // Length of output
633 // buffer in bytes.
634 &ReturnedLength, // Bytes placed in buffer.
635 NULL // synchronous call
636 );
637
638 if (!StatusIoctl)
639 {
640 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
641 return FALSE;
642 }
643
644 if (PauseRequest.Result == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
645 {
646 //
647 // Nothing to show, the request was successfully processed
648 //
649 return TRUE;
650 }
651 else
652 {
653 ShowErrorMessage(PauseRequest.Result);
654 return FALSE;
655 }
656 return FALSE;
657}
#define SIZEOF_DEBUGGER_PAUSE_PACKET_RECEIVED
Definition DataTypes.h:170
#define IOCTL_PAUSE_PACKET_RECEIVED
ioctl, pause and halt the system
Definition Ioctls.h:184
request to pause and halt the system
Definition DataTypes.h:178
UINT32 Result
Definition DataTypes.h:179

◆ DetachFromProcess()

VOID DetachFromProcess ( )

perform detach from process

Returns
VOID
40{
42
43 //
44 // Check if debugger is loaded or not
45 //
47
48 //
49 // Check if we attached to a process or not
50 //
52 {
53 ShowMessages("you're not attached to any thread\n");
54 return;
55 }
56
57 //
58 // Perform the detaching of the target process
59 //
61}
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362
UINT32 ProcessId
Definition ud.h:51
request for attaching user-mode process
Definition RequestStructures.h:631
BOOLEAN UdDetachProcess(UINT32 TargetPid, UINT64 ProcessDetailToken)
Detach the target process.
Definition ud.cpp:764

◆ FreeEventsAndActionsMemory()

VOID FreeEventsAndActionsMemory ( PDEBUGGER_GENERAL_EVENT_DETAIL Event,
PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger,
PDEBUGGER_GENERAL_ACTION ActionCustomCode,
PDEBUGGER_GENERAL_ACTION ActionScript )

Deallocate buffers relating to events and actions.

Parameters

return VOID

2296{
2297 if (Event != NULL)
2298 {
2299 if (Event->CommandStringBuffer != NULL)
2300 {
2301 free(Event->CommandStringBuffer);
2302 }
2303
2304 free(Event);
2305 }
2306
2307 if (ActionBreakToDebugger != NULL)
2308 {
2309 free(ActionBreakToDebugger);
2310 }
2311 if (ActionCustomCode != NULL)
2312 {
2313 free(ActionCustomCode);
2314 }
2315 if (ActionScript != NULL)
2316 {
2317 free(ActionScript);
2318 }
2319}

◆ GetCommandAttributes()

UINT64 GetCommandAttributes ( const string & FirstCommand)

Get Command Attributes.

Parameters
FirstCommandjust the first word of command (without other parameters)
Returns
BOOLEAN Mask of the command's attributes
735{
736 CommandType::iterator Iterator;
737
738 //
739 // Some commands should not be passed to the remote system
740 // and instead should be handled in the current debugger
741 //
742
743 Iterator = g_CommandsList.find(FirstCommand);
744
745 if (Iterator == g_CommandsList.end())
746 {
747 //
748 // Command doesn't exist, if it's not exists then it's better to handle
749 // it locally, instead of sending it to the remote computer
750 //
752 }
753 else
754 {
755 return Iterator->second.CommandAttrib;
756 }
757
758 return NULL;
759}
#define DEBUGGER_COMMAND_ATTRIBUTE_ABSOLUTE_LOCAL
Absolute local commands.
Definition commands.h:202
CommandType g_CommandsList
List of command and attributes.
Definition globals.h:324

◆ GetNewDebuggerEventTag()

UINT64 GetNewDebuggerEventTag ( )

Get the New Debugger Event Tag object and increase the global variable for tag.

Returns
UINT64
2281{
2282 return g_EventTag++;
2283}
UINT64 g_EventTag
This variable holds the trace and generate numbers for new tags of events.
Definition globals.h:375

◆ HyperDbgDebugCurrentDeviceUsingComPort()

BOOLEAN HyperDbgDebugCurrentDeviceUsingComPort ( const CHAR * PortName,
DWORD Baudrate )

Connect to a remote serial device (Debuggee)

Parameters
PortName
Baudrate
Returns
BOOLEAN
171{
172 UINT32 Port;
173
174 //
175 // Check if baudrate is valid or not
176 //
177 if (!CommandDebugCheckBaudrate(Baudrate))
178 {
179 //
180 // Baud-rate is invalid
181 //
182 return FALSE;
183 }
184
185 //
186 // check if com port address is valid or not
187 //
188 if (!CommandDebugCheckComPort(PortName, &Port))
189 {
190 //
191 // com port is invalid
192 //
193 return FALSE;
194 }
195
196 //
197 // Everything is okay, connect to the remote machine to send (debuggee)
198 //
199 return KdPrepareAndConnectDebugPort(PortName, Baudrate, Port, TRUE, FALSE);
200}
BOOLEAN CommandDebugCheckComPort(const CHAR *ComPort, UINT32 *Port)
Check if COM port is valid or not.
Definition debug.cpp:60
BOOLEAN CommandDebugCheckBaudrate(DWORD Baudrate)
Check if baud rate is valid or not.
Definition debug.cpp:93
BOOLEAN KdPrepareAndConnectDebugPort(const char *PortName, DWORD Baudrate, UINT32 Port, BOOLEAN IsPreparing, BOOLEAN IsNamedPipe)

◆ HyperDbgDebugRemoteDeviceUsingComPort()

BOOLEAN HyperDbgDebugRemoteDeviceUsingComPort ( const CHAR * PortName,
DWORD Baudrate )

Connect to a remote serial device (Debugger)

Parameters
PortName
Baudrate
Returns
BOOLEAN
117{
118 UINT32 Port;
119
120 //
121 // Check if baudrate is valid or not
122 //
123 if (!CommandDebugCheckBaudrate(Baudrate))
124 {
125 //
126 // Baud-rate is invalid
127 //
128 return FALSE;
129 }
130
131 //
132 // check if com port address is valid or not
133 //
134 if (!CommandDebugCheckComPort(PortName, &Port))
135 {
136 //
137 // com port is invalid
138 //
139 return FALSE;
140 }
141
142 //
143 // Everything is okay, connect to the remote machine to send (debugger)
144 //
145 return KdPrepareAndConnectDebugPort(PortName, Baudrate, Port, FALSE, FALSE);
146}

◆ HyperDbgDebugRemoteDeviceUsingNamedPipe()

BOOLEAN HyperDbgDebugRemoteDeviceUsingNamedPipe ( const CHAR * NamedPipe)

Connect to a remote named pipe (Debugger)

Parameters
NamedPipe
Returns
BOOLEAN
157{
158 return KdPrepareAndConnectDebugPort(NamedPipe, NULL, NULL, FALSE, TRUE);
159}

◆ HyperDbgReadAllRegisters()

BOOLEAN HyperDbgReadAllRegisters ( GUEST_REGS * GuestRegisters,
GUEST_EXTRA_REGISTERS * ExtraRegisters )

Read all registers.

Parameters
GuestRegistersThe guest registers
ExtraRegistersThe extra registers
Returns
BOOLEAN Returns true if it was successful
175{
176 PGUEST_REGS Regs;
177 PGUEST_EXTRA_REGISTERS ExtraRegs;
179 UINT32 SizeOfRegState = 0;
180
181 //
182 // Calculate the size of the register state
183 //
184 SizeOfRegState = sizeof(DEBUGGEE_REGISTER_READ_DESCRIPTION) + sizeof(GUEST_REGS) + sizeof(GUEST_EXTRA_REGISTERS);
185
186 //
187 // Allocate memory for the register state
188 //
189 RegState = (DEBUGGEE_REGISTER_READ_DESCRIPTION *)malloc(SizeOfRegState);
190
191 //
192 // Check if the memory allocation was successful
193 //
194 if (RegState == NULL)
195 {
196 return FALSE;
197 }
198
199 //
200 // Set the register ID to show all registers
201 //
203
204 if (!KdSendReadRegisterPacketToDebuggee(RegState, SizeOfRegState))
205 {
206 free(RegState);
207 return FALSE;
208 }
209
211 {
212 //
213 // Copy the registers and extra registers to the output
214 //
215 Regs = (GUEST_REGS *)(((CHAR *)RegState) + sizeof(DEBUGGEE_REGISTER_READ_DESCRIPTION));
216 ExtraRegs = (GUEST_EXTRA_REGISTERS *)(((CHAR *)RegState) + sizeof(DEBUGGEE_REGISTER_READ_DESCRIPTION) + sizeof(GUEST_REGS));
217
218 if (GuestRegisters != NULL)
219 {
220 memcpy(GuestRegisters, Regs, sizeof(GUEST_REGS));
221 }
222
223 if (ExtraRegisters != NULL)
224 {
225 memcpy(ExtraRegisters, ExtraRegs, sizeof(GUEST_EXTRA_REGISTERS));
226 }
227 }
228 else
229 {
230 ShowErrorMessage(RegState->KernelStatus);
231 free(RegState);
232 return FALSE;
233 }
234
235 free(RegState);
236 return TRUE;
237}
struct GUEST_REGS GUEST_REGS
char CHAR
Definition BasicTypes.h:31
struct GUEST_EXTRA_REGISTERS GUEST_EXTRA_REGISTERS
struct for extra registers
#define DEBUGGEE_SHOW_ALL_REGISTERS
for reading all registers in r command.
Definition Constants.h:665
struct _DEBUGGEE_REGISTER_READ_DESCRIPTION DEBUGGEE_REGISTER_READ_DESCRIPTION
Register Descriptor Structure to use in r command.
BOOLEAN KdSendReadRegisterPacketToDebuggee(PDEBUGGEE_REGISTER_READ_DESCRIPTION RegDes, UINT32 RegBuffSize)
Send a read register packet to the debuggee.
Definition kd.cpp:527
Register Descriptor Structure to use in r command.
Definition RequestStructures.h:1156
UINT32 RegisterId
Definition RequestStructures.h:1157
UINT32 KernelStatus
Definition RequestStructures.h:1159
struct for extra registers
Definition BasicTypes.h:103
Definition BasicTypes.h:70

◆ HyperDbgReadTargetRegister()

BOOLEAN HyperDbgReadTargetRegister ( REGS_ENUM RegisterId,
UINT64 * TargetRegister )

Read target register.

Parameters
RegisterIdThe register ID
TargetRegisterThe value of the target register
Returns
BOOLEAN Returns true if it was successful
248{
250
251 //
252 // Set the register ID
253 //
254 RegState.RegisterId = (UINT32)RegisterId;
255
257 {
258 return FALSE;
259 }
260
262 {
263 if (TargetRegister != NULL)
264 {
265 *TargetRegister = RegState.Value;
266 }
267 }
268 else
269 {
271 return FALSE;
272 }
273
274 return TRUE;
275}
UINT64 Value
Definition RequestStructures.h:1158

◆ HyperDbgRegisterShowAll()

BOOLEAN HyperDbgRegisterShowAll ( )

handler of r show all registers

Returns
BOOLEAN
318{
319 GUEST_REGS Regs = {0};
320 GUEST_EXTRA_REGISTERS ExtraRegs = {0};
321 RFLAGS Rflags = {0};
322
323 if (!HyperDbgReadAllRegisters(&Regs, &ExtraRegs))
324 {
325 return FALSE;
326 }
327
328 //
329 // Show the result of reading registers like rax=0000000000018b01
330 //
331 Rflags.AsUInt = ExtraRegs.RFLAGS;
332
334 "RAX=%016llx RBX=%016llx RCX=%016llx\n"
335 "RDX=%016llx RSI=% 016llx RDI=%016llx\n"
336 "RIP=%016llx RSP=%016llx RBP=%016llx\n"
337 "R8 =%016llx R9 =%016llx R10=%016llx\n"
338 "R11=%016llx R12=%016llx R13=%016llx\n"
339 "R14=%016llx R15=%016llx IOPL=%02x\n"
340 "%s %s %s %s\n%s %s %s %s\n"
341 "CS %04x SS %04x DS %04x ES %04x FS %04x GS %04x\n"
342 "RFLAGS=%016llx\n",
343 Regs.rax,
344 Regs.rbx,
345 Regs.rcx,
346 Regs.rdx,
347 Regs.rsi,
348 Regs.rdi,
349 ExtraRegs.RIP,
350 Regs.rsp,
351 Regs.rbp,
352 Regs.r8,
353 Regs.r9,
354 Regs.r10,
355 Regs.r11,
356 Regs.r12,
357 Regs.r13,
358 Regs.r14,
359 Regs.r15,
360 Rflags.IoPrivilegeLevel,
361 Rflags.OverflowFlag ? "OF 1" : "OF 0",
362 Rflags.DirectionFlag ? "DF 1" : "DF 0",
363 Rflags.InterruptEnableFlag ? "IF 1" : "IF 0",
364 Rflags.SignFlag ? "SF 1" : "SF 0",
365 Rflags.ZeroFlag ? "ZF 1" : "ZF 0",
366 Rflags.ParityFlag ? "PF 1" : "PF 0",
367 Rflags.CarryFlag ? "CF 1" : "CF 0",
368 Rflags.AuxiliaryCarryFlag ? "AXF 1" : "AXF 0",
369 ExtraRegs.CS,
370 ExtraRegs.SS,
371 ExtraRegs.DS,
372 ExtraRegs.ES,
373 ExtraRegs.FS,
374 ExtraRegs.GS,
375 ExtraRegs.RFLAGS);
376
377 return TRUE;
378}
@ FS
Definition Common.h:28
@ ES
Definition Common.h:24
@ CS
Definition Common.h:25
@ GS
Definition Common.h:29
@ DS
Definition Common.h:27
@ SS
Definition Common.h:26
BOOLEAN HyperDbgReadAllRegisters(GUEST_REGS *GuestRegisters, GUEST_EXTRA_REGISTERS *ExtraRegisters)
Read all registers.
Definition r.cpp:174
UINT64 RFLAGS
Definition BasicTypes.h:110
UINT64 RIP
Definition BasicTypes.h:111
UINT64 rsp
Definition BasicTypes.h:79
UINT64 r14
Definition BasicTypes.h:89
UINT64 r15
Definition BasicTypes.h:90
UINT64 rdi
Definition BasicTypes.h:82
UINT64 rax
Definition BasicTypes.h:75
UINT64 r12
Definition BasicTypes.h:87
UINT64 r13
Definition BasicTypes.h:88
UINT64 r9
Definition BasicTypes.h:84
UINT64 r8
Definition BasicTypes.h:83
UINT64 rbp
Definition BasicTypes.h:80
UINT64 rbx
Definition BasicTypes.h:78
UINT64 r10
Definition BasicTypes.h:85
UINT64 rcx
Definition BasicTypes.h:76
UINT64 rsi
Definition BasicTypes.h:81
UINT64 r11
Definition BasicTypes.h:86
UINT64 rdx
Definition BasicTypes.h:77

◆ HyperDbgRegisterShowTargetRegister()

BOOLEAN HyperDbgRegisterShowTargetRegister ( REGS_ENUM RegisterId)

handler of r show the target register

Parameters
RegisterIdThe register ID
Returns
BOOLEAN Returns true if it was successful
388{
389 UINT64 TargetRegister = 0;
390
391 //
392 // Read target register
393 //
394 if (!HyperDbgReadTargetRegister(RegisterId, &TargetRegister))
395 {
396 return FALSE;
397 }
398
399 ShowMessages("%s=%016llx\n",
400 RegistersNames[RegisterId],
401 TargetRegister);
402
403 return TRUE;
404}
BOOLEAN HyperDbgReadTargetRegister(REGS_ENUM RegisterId, UINT64 *TargetRegister)
Read target register.
Definition r.cpp:247

◆ HyperDbgWriteMemory()

BOOLEAN HyperDbgWriteMemory ( PVOID DestinationAddress,
DEBUGGER_EDIT_MEMORY_TYPE MemoryType,
UINT32 ProcessId,
PVOID SourceAddress,
UINT32 NumberOfBytes )

API function for writing the memory content.

Parameters
AddressToEdit
MemoryType
ProcessId
SourceAddress
NumberOfBytes
Returns
BOOLEAN
198{
199 UINT32 RequiredBytes = 0;
201 UINT64 * TargetBuffer;
202 UINT32 FinalSize = 0;
203 BOOLEAN Result = FALSE;
204 BYTE * BufferToEdit = (BYTE *)SourceAddress;
205
206 //
207 // Set the byte size to byte granularity
208 //
209 ByteSize = EDIT_BYTE;
210
211 //
212 // Calculate the count of 64 chunks
213 //
214 RequiredBytes = NumberOfBytes * sizeof(UINT64);
215
216 //
217 // Allocate structure + buffer
218 //
219 TargetBuffer = (UINT64 *)malloc(RequiredBytes);
220
221 if (!TargetBuffer)
222 {
223 return FALSE;
224 }
225
226 //
227 // Zero the buffer
228 //
229 ZeroMemory(TargetBuffer, FinalSize);
230
231 //
232 // Copy requested memory in 64bit chunks
233 //
234 for (size_t i = 0; i < NumberOfBytes; i++)
235 {
236 TargetBuffer[i] = BufferToEdit[i];
237 }
238
239 //
240 // Perform the write operation
241 //
242 Result = WriteMemoryContent((UINT64)DestinationAddress,
243 MemoryType,
244 ByteSize,
245 ProcessId,
247 TargetBuffer);
248
249 //
250 // Free the malloc buffer
251 //
252 free(TargetBuffer);
253
254 return Result;
255}
unsigned char BYTE
Definition BasicTypes.h:24
POOL_TYPE SIZE_T NumberOfBytes
Definition Hooks.h:167
@ EDIT_BYTE
Definition RequestStructures.h:472
enum _DEBUGGER_EDIT_MEMORY_BYTE_SIZE DEBUGGER_EDIT_MEMORY_BYTE_SIZE
size of editing memory
BOOLEAN WriteMemoryContent(UINT64 AddressToEdit, DEBUGGER_EDIT_MEMORY_TYPE MemoryType, DEBUGGER_EDIT_MEMORY_BYTE_SIZE ByteSize, UINT32 Pid, UINT32 CountOf64Chunks, UINT64 *BufferToEdit)
Perform writing the memory content.
Definition e.cpp:64

◆ HyperDbgWriteTargetRegister()

BOOLEAN HyperDbgWriteTargetRegister ( REGS_ENUM RegisterId,
UINT64 Value )

Write target register.

Parameters
RegisterIdThe register ID
ValueThe value of the target register
Returns
BOOLEAN Returns true if it was successful
286{
288
289 //
290 // Set the register ID
291 //
292 RegState.RegisterId = (UINT32)RegisterId;
293 RegState.Value = Value;
294
296 {
297 return FALSE;
298 }
299
301 {
302 return TRUE;
303 }
304 else
305 {
307 return FALSE;
308 }
309}
BOOLEAN KdSendWriteRegisterPacketToDebuggee(PDEBUGGEE_REGISTER_WRITE_DESCRIPTION RegDes)
Send a write register packet to the debuggee.
Definition kd.cpp:562
Register Descriptor Structure to write on registers.
Definition RequestStructures.h:1171
UINT64 Value
Definition RequestStructures.h:1173
UINT32 RegisterId
Definition RequestStructures.h:1172
UINT32 KernelStatus
Definition RequestStructures.h:1174

◆ InterpretConditionsAndCodes()

BOOLEAN InterpretConditionsAndCodes ( vector< string > * SplitCommand,
vector< string > * SplitCommandCaseSensitive,
BOOLEAN IsConditionBuffer,
PUINT64 BufferAddress,
PUINT32 BufferLength )

Interpret conditions (if an event has condition) and custom code.

If this function returns true then it means that there is a condition or code buffer in this command split and the details are returned in the input structure

Parameters
SplitCommandthe initialized command that are split by space
SplitCommandCaseSensitivethe initialized command that are split by space case sensitive
IsConditionBufferis it a condition buffer or a custom code buffer
BufferAddressthe address that the allocated buffer will be saved on it
BufferLengththe length of the buffer
Returns
BOOLEAN shows whether the interpret was successful (true) or not successful (false)
1251{
1252 BOOLEAN IsAsm = FALSE;
1253 BOOLEAN IsTextVisited = FALSE;
1254 BOOLEAN IsInState = FALSE;
1255 BOOLEAN IsEnded = FALSE;
1256 string Temp;
1257 string TempStr;
1258 string AppendedFinalBuffer;
1259 vector<string> SaveBuffer;
1260 vector<CHAR> ParsedBytes;
1261 vector<int> IndexesToRemove;
1262 UCHAR * FinalBuffer;
1263 UINT32 AssembledByteCount;
1264 int NewIndexToRemove = 0;
1265 int Index = 0;
1266
1267 for (auto Section : *SplitCommand)
1268 {
1269 Index++;
1270
1271 if (IsInState)
1272 {
1273 //
1274 // Check if the buffer is ended or not
1275 //
1276 if (!Section.compare("}"))
1277 {
1278 //
1279 // Save to remove this string from the command
1280 //
1281 IndexesToRemove.push_back(Index);
1282 IsEnded = TRUE;
1283 break;
1284 }
1285
1286 //
1287 // Check if the condition is end or not
1288 //
1289 if (HasEnding(Section, "}"))
1290 {
1291 //
1292 // Save to remove this string from the command
1293 //
1294 IndexesToRemove.push_back(Index);
1295
1296 //
1297 // remove the last character and append it to the ConditionBuffer
1298 //
1299 SaveBuffer.emplace_back(Section.begin(), Section.begin() + Section.size() - 1);
1300
1301 IsEnded = TRUE;
1302 break;
1303 }
1304
1305 //
1306 // Save to remove this string from the command
1307 //
1308 IndexesToRemove.push_back(Index);
1309
1310 //
1311 // Add the codes into condition bi
1312 //
1313 SaveBuffer.push_back(Section);
1314
1315 //
1316 // We want to stay in this condition
1317 //
1318 continue;
1319 }
1320
1321 if (IsTextVisited && !Section.compare("{"))
1322 {
1323 //
1324 // Save to remove this string from the command
1325 //
1326 IndexesToRemove.push_back(Index);
1327
1328 IsInState = TRUE;
1329 continue;
1330 }
1331
1332 if (IsTextVisited && Section.rfind('{', 0) == 0)
1333 {
1334 //
1335 // Section starts with {
1336 //
1337
1338 //
1339 // Check if it ends with }
1340 //
1341 if (HasEnding(Section, "}"))
1342 {
1343 //
1344 // Save to remove this string from the command
1345 //
1346 IndexesToRemove.push_back(Index);
1347
1348 TempStr = Section.erase(0, 1);
1349 SaveBuffer.emplace_back(TempStr.begin(), TempStr.begin() + TempStr.size() - 1);
1350
1351 IsEnded = TRUE;
1352 break;
1353 }
1354
1355 //
1356 // Save to remove this string from the command
1357 //
1358 IndexesToRemove.push_back(Index);
1359
1360 SaveBuffer.push_back(Section.erase(0, 1));
1361
1362 IsInState = TRUE;
1363 continue;
1364 }
1365
1366 if (!Section.compare("asm"))
1367 {
1368 if (IsTextVisited)
1369 {
1370 ShowMessages("wrong use of \"asm\"\n"); // asm must not be after condition or code
1371 }
1372 else
1373 {
1374 IndexesToRemove.push_back(Index);
1375
1376 IsAsm = TRUE;
1377 continue;
1378 }
1379 }
1380
1381 if (IsConditionBuffer)
1382 {
1383 if (!Section.compare("condition"))
1384 {
1385 //
1386 // Save to remove this string from the command
1387 //
1388 IndexesToRemove.push_back(Index);
1389
1390 IsTextVisited = TRUE;
1391 continue;
1392 }
1393 }
1394 else
1395 {
1396 //
1397 // It's code
1398 //
1399 if (!Section.compare("code"))
1400 {
1401 //
1402 // Save to remove this string from the command
1403 //
1404 IndexesToRemove.push_back(Index);
1405
1406 IsTextVisited = TRUE;
1407 continue;
1408 }
1409 }
1410
1411 if (IsConditionBuffer)
1412 {
1413 if (!Section.compare("condition{"))
1414 {
1415 //
1416 // Save to remove this string from the command
1417 //
1418 IndexesToRemove.push_back(Index);
1419
1420 IsTextVisited = TRUE;
1421 IsInState = TRUE;
1422 continue;
1423 }
1424 }
1425 else
1426 {
1427 //
1428 // It's code
1429 //
1430 if (!Section.compare("code{"))
1431 {
1432 //
1433 // Save to remove this string from the command
1434 //
1435 IndexesToRemove.push_back(Index);
1436
1437 IsTextVisited = TRUE;
1438 IsInState = TRUE;
1439 continue;
1440 }
1441 }
1442
1443 if (IsConditionBuffer)
1444 {
1445 if (Section.rfind("condition{", 0) == 0)
1446 {
1447 //
1448 // Save to remove this string from the command
1449 //
1450 IndexesToRemove.push_back(Index);
1451
1452 IsTextVisited = TRUE;
1453 IsInState = TRUE;
1454
1455 if (!HasEnding(Section, "}"))
1456 {
1457 //
1458 // Section starts with condition{
1459 //
1460 SaveBuffer.push_back(Section.erase(0, 10));
1461 continue;
1462 }
1463 else
1464 {
1465 //
1466 // remove the last character and first character append it to the
1467 // ConditionBuffer
1468 //
1469 TempStr = Section.erase(0, 10);
1470 SaveBuffer.emplace_back(TempStr.begin(), TempStr.begin() + TempStr.size() - 1);
1471
1472 IsEnded = TRUE;
1473 break;
1474 }
1475 }
1476 }
1477 else
1478 {
1479 //
1480 // It's a code
1481 //
1482 if (Section.rfind("code{", 0) == 0)
1483 {
1484 //
1485 // Save to remove this string from the command
1486 //
1487 IndexesToRemove.push_back(Index);
1488
1489 IsTextVisited = TRUE;
1490 IsInState = TRUE;
1491
1492 if (!HasEnding(Section, "}"))
1493 {
1494 //
1495 // Section starts with code{
1496 //
1497 SaveBuffer.push_back(Section.erase(0, 5));
1498 continue;
1499 }
1500 else
1501 {
1502 //
1503 // remove the last character and first character append it to the
1504 // ConditionBuffer
1505 //
1506 TempStr = Section.erase(0, 5);
1507 SaveBuffer.emplace_back(TempStr.begin(), TempStr.begin() + TempStr.size() - 1);
1508
1509 IsEnded = TRUE;
1510 break;
1511 }
1512 }
1513 }
1514 }
1515
1516 //
1517 // Now we have everything in condition buffer
1518 // Check to see if it is empty or not
1519 //
1520 if (SaveBuffer.size() == 0)
1521 {
1522 //
1523 // Nothing in condition buffer, return zero
1524 //
1525 return FALSE;
1526 }
1527
1528 //
1529 // Check if we see '}' at the end
1530 //
1531 if (!IsEnded)
1532 {
1533 //
1534 // Nothing in condition buffer, return zero
1535 //
1536 return FALSE;
1537 }
1538
1539 //
1540 // Check if asm code was provided instead of hex
1541 //
1542 if (IsAsm)
1543 {
1544 //
1545 // Append " " between two std::strings
1546 //
1547 auto ApndSemCln = [](std::string a, std::string b) {
1548 return std::move(a) + ' ' + std::move(b);
1549 };
1550
1551 //
1552 // Concatenate each assembly line
1553 //
1554 std::string AsmCode = std::accumulate(std::next(SaveBuffer.begin()), SaveBuffer.end(), SaveBuffer[0], ApndSemCln);
1555
1557 AssembleData.AsmRaw = AsmCode; // by now, it should only have one element
1559
1560 //
1561 // Append a 'ret' at the end of asm code
1562 //
1563 AssembleData.AsmFixed += "; ret";
1564
1565 if (AssembleData.Assemble(0)) // we just want the hex bytes, so NULL instead of Start_Address
1566 {
1567 ShowMessages("err, assemble error code: '%u'\n\n", AssembleData.KsErr);
1568 return FALSE;
1569 }
1570 else
1571 {
1572 //
1573 // Get the BytesCount; for readability.
1574 //
1575 AssembledByteCount = (UINT32)AssembleData.BytesCount;
1576
1577 //
1578 // * FinalBuffer *
1579 //
1580 FinalBuffer = (unsigned char *)malloc(AssembledByteCount);
1581
1582 if (FinalBuffer == NULL)
1583 {
1584 return FALSE;
1585 }
1586
1587 memcpy(FinalBuffer, AssembleData.EncodedBytes, AssembledByteCount);
1588
1589 //
1590 // Set the buffer and length
1591 //
1592 *BufferAddress = (UINT64)FinalBuffer;
1593 *BufferLength = AssembledByteCount;
1594 }
1595 }
1596 else
1597 {
1598 //
1599 // Append a 'ret' at the end of the buffer
1600 //
1601 SaveBuffer.push_back("c3");
1602
1603 //
1604 // If we reach here then there is sth in condition buffer
1605 //
1606 for (auto Section : SaveBuffer)
1607 {
1608 //
1609 // Check if the section is started with '0x'
1610 //
1611 if (Section.rfind("0x", 0) == 0 || Section.rfind("0X", 0) == 0 || Section.rfind("\\x", 0) == 0 || Section.rfind("\\X", 0) == 0)
1612 {
1613 Temp = Section.erase(0, 2);
1614 }
1615 else if (Section.rfind('x', 0) == 0 || Section.rfind('X', 0) == 0)
1616 {
1617 Temp = Section.erase(0, 1);
1618 }
1619 else
1620 {
1621 Temp = std::move(Section);
1622 }
1623
1624 //
1625 // replace \x s
1626 //
1627 ReplaceAll(Temp, "\\x", "");
1628
1629 //
1630 // check if the buffer is aligned to 2
1631 //
1632 if (Temp.size() % 2 != 0)
1633 {
1634 //
1635 // Add a zero to the start of the buffer
1636 //
1637 Temp.insert(0, 1, '0');
1638 }
1639
1640 if (!IsHexNotation(Temp))
1641 {
1642 ShowMessages("please enter condition code in a hex notation\n");
1643 return FALSE;
1644 }
1645 AppendedFinalBuffer.append(Temp);
1646 }
1647
1648 //
1649 // Convert it to vectored bytes
1650 //
1651 ParsedBytes = HexToBytes(AppendedFinalBuffer);
1652
1653 //
1654 // Convert to a contigues buffer
1655 //
1656 FinalBuffer = (unsigned char *)malloc(ParsedBytes.size());
1657
1658 if (FinalBuffer == NULL)
1659 {
1660 return FALSE;
1661 }
1662
1663 std::copy(ParsedBytes.begin(), ParsedBytes.end(), FinalBuffer);
1664
1665 //
1666 // Set the buffer and length
1667 //
1668 *BufferAddress = (UINT64)FinalBuffer;
1669 *BufferLength = (UINT32)ParsedBytes.size();
1670 }
1671
1672 //
1673 // Removing the code or condition indexes from the command
1674 //
1675 NewIndexToRemove = 0;
1676 for (auto IndexToRemove : IndexesToRemove)
1677 {
1678 NewIndexToRemove++;
1679
1680 SplitCommand->erase(SplitCommand->begin() + (IndexToRemove - NewIndexToRemove));
1681 SplitCommandCaseSensitive->erase(SplitCommandCaseSensitive->begin() + (IndexToRemove - NewIndexToRemove));
1682 }
1683
1684 return TRUE;
1685}
unsigned char UCHAR
Definition BasicTypes.h:35
UINT64 BOOLEAN PVOID BufferAddress
Definition HyperDbgScriptImports.h:67
Definition assembler.h:16
VOID ParseAssemblyData()
tries to solve the symbol issue with Keystone, which apparently originates from LLVM-MC.
Definition assembler.cpp:20
std::string AsmFixed
Definition assembler.h:19
size_t BytesCount
Definition assembler.h:21
ks_err KsErr
Definition assembler.h:24
unsigned char * EncodedBytes
Definition assembler.h:22
INT Assemble(UINT64 StartAddr, ks_arch Arch=KS_ARCH_X86, INT Mode=KS_MODE_64, INT Syntax=KS_OPT_SYNTAX_INTEL)
Definition assembler.cpp:119
std::string AsmRaw
Definition assembler.h:18
BOOLEAN IsHexNotation(const string &s)
check whether the string is hex or not
Definition common.cpp:162
vector< char > HexToBytes(const string &hex)
converts hex to bytes
Definition common.cpp:216
BOOLEAN HasEnding(string const &fullString, string const &ending)
checks whether the string ends with a special string or not
Definition common.cpp:448

◆ InterpreterRemoveComments()

VOID InterpreterRemoveComments ( char * CommandText)

Remove batch comments.

Returns
VOID
510{
511 BOOLEAN IsComment = FALSE;
512 BOOLEAN IsOnString = FALSE;
513 UINT32 LengthOfCommand = (UINT32)strlen(CommandText);
514
515 for (size_t i = 0; i < LengthOfCommand; i++)
516 {
517 if (IsComment)
518 {
519 if (CommandText[i] == '\n')
520 {
521 IsComment = FALSE;
522 }
523 else
524 {
525 if (CommandText[i] != '\0')
526 {
527 memmove((void *)&CommandText[i], (const void *)&CommandText[i + 1], strlen(CommandText) - i);
528 i--;
529 }
530 }
531 }
532 else if (CommandText[i] == '#' && !IsOnString)
533 {
534 //
535 // Comment detected
536 //
537 IsComment = TRUE;
538 i--;
539 }
540 else if (CommandText[i] == '"')
541 {
542 if (i != 0 && CommandText[i - 1] == '\\')
543 {
544 //
545 // It's an escape character for : \"
546 //
547 }
548 else if (IsOnString)
549 {
550 IsOnString = FALSE;
551 }
552 else
553 {
554 IsOnString = TRUE;
555 }
556 }
557 }
558}

◆ InterpretGeneralEventAndActionsFields()

BOOLEAN InterpretGeneralEventAndActionsFields ( vector< string > * SplitCommand,
vector< string > * SplitCommandCaseSensitive,
VMM_EVENT_TYPE_ENUM EventType,
PDEBUGGER_GENERAL_EVENT_DETAIL * EventDetailsToFill,
PUINT32 EventBufferLength,
PDEBUGGER_GENERAL_ACTION * ActionDetailsToFillBreakToDebugger,
PUINT32 ActionBufferLengthBreakToDebugger,
PDEBUGGER_GENERAL_ACTION * ActionDetailsToFillCustomCode,
PUINT32 ActionBufferLengthCustomCode,
PDEBUGGER_GENERAL_ACTION * ActionDetailsToFillScript,
PUINT32 ActionBufferLengthScript,
PDEBUGGER_EVENT_PARSING_ERROR_CAUSE ReasonForErrorInParsing )

Interpret general event fields.

Parameters
SplitCommandthe commands that was split by space
SplitCommandCaseSensitivethe commands that was split by space case sensitive
EventTypetype of event
EventDetailsToFilla pointer address that will be filled by event detail buffer
EventBufferLengtha pointer the receives the buffer length of the event
ActionDetailsToFilla pointer address that will be filled by action detail buffer
ActionBufferLengtha pointer the receives the buffer length of the action
ReasonForErrorInParsingreason that interpretation failed, null if the returns true
Returns
BOOLEAN If this function returns true then it means that there was no error in parsing the general event details
2355{
2356 BOOLEAN Result = FALSE;
2358 PDEBUGGER_GENERAL_ACTION TempActionBreak = NULL;
2359 PDEBUGGER_GENERAL_ACTION TempActionScript = NULL;
2360 PDEBUGGER_GENERAL_ACTION TempActionCustomCode = NULL;
2362 UINT32 LengthOfCustomCodeActionBuffer = 0;
2363 UINT32 LengthOfScriptActionBuffer = 0;
2364 UINT32 LengthOfBreakActionBuffer = 0;
2365 UINT64 ConditionBufferAddress;
2366 UINT32 ConditionBufferLength = 0;
2367 vector<string> ListOfOutputSources;
2368 UINT64 CodeBufferAddress;
2369 UINT32 CodeBufferLength = 0;
2370 UINT64 ScriptBufferAddress;
2371 UINT64 ScriptCodeBuffer = 0;
2372 BOOLEAN HasScriptSyntaxError = 0;
2373 UINT32 ScriptBufferLength = 0;
2374 UINT32 ScriptBufferPointer = 0;
2375 UINT32 LengthOfEventBuffer = 0;
2376 string CommandString;
2377 BOOLEAN IsAShortCircuitingEventByDefault = FALSE;
2378 BOOLEAN HasConditionBuffer = FALSE;
2379 BOOLEAN HasOutputPath = FALSE;
2380 BOOLEAN HasCodeBuffer = FALSE;
2381 BOOLEAN HasScript = FALSE;
2382 BOOLEAN IsNextCommandPid = FALSE;
2383 BOOLEAN IsNextCommandCoreId = FALSE;
2384 BOOLEAN IsNextCommandBufferSize = FALSE;
2385 BOOLEAN IsNextCommandImmediateMessaging = FALSE;
2386 BOOLEAN IsNextCommandExecutionStage = FALSE;
2387 BOOLEAN IsNextCommandSc = FALSE;
2388 BOOLEAN ImmediateMessagePassing = UseImmediateMessagingByDefaultOnEvents;
2389 UINT32 CoreId;
2390 UINT32 ProcessId;
2391 UINT32 IndexOfValidSourceTags;
2392 UINT32 RequestBuffer = 0;
2393 PLIST_ENTRY TempList;
2394 BOOLEAN OutputSourceFound;
2395 vector<int> IndexesToRemove;
2396 vector<UINT64> ListOfValidSourceTags;
2397 int NewIndexToRemove = 0;
2398 int Index = 0;
2399
2400 //
2401 // Create a command string to show in the history
2402 //
2403 for (auto Section : *SplitCommandCaseSensitive)
2404 {
2405 CommandString.append(Section);
2406 CommandString.append(" ");
2407 }
2408
2409 //
2410 // Compute the size of buffer + 1 null for the end of buffer
2411 //
2412 UINT64 BufferOfCommandStringLength = CommandString.size() + 1;
2413
2414 //
2415 // Allocate Buffer and zero for command to the buffer
2416 //
2417 PVOID BufferOfCommandString = malloc(BufferOfCommandStringLength);
2418
2419 RtlZeroMemory(BufferOfCommandString, BufferOfCommandStringLength);
2420
2421 //
2422 // Copy the string to the buffer
2423 //
2424 memcpy(BufferOfCommandString, CommandString.c_str(), CommandString.size());
2425
2426 //
2427 // Check if there is a condition buffer in the command
2428 //
2429 if (!InterpretConditionsAndCodes(SplitCommand, SplitCommandCaseSensitive, TRUE, &ConditionBufferAddress, &ConditionBufferLength))
2430 {
2431 //
2432 // Indicate condition is not available
2433 //
2434 HasConditionBuffer = FALSE;
2435
2436 //
2437 // ShowMessages("\nNo condition!\n");
2438 //
2439 }
2440 else
2441 {
2442 //
2443 // Indicate condition is available
2444 //
2445 HasConditionBuffer = TRUE;
2446
2447 /*
2448 ShowMessages(
2449 "\n========================= Condition =========================\n");
2450
2451 ShowMessages(
2452 "\nUINT64 DebuggerCheckForCondition(PGUEST_REGS Regs_RCX, PVOID "
2453 "Context_RDX)\n{\n");
2454
2455 //
2456 // Disassemble the buffer
2457 //
2458 HyperDbgDisassembler64((unsigned char *)ConditionBufferAddress, 0x0,
2459 ConditionBufferLength);
2460
2461 ShowMessages("}\n\n");
2462
2463 ShowMessages(
2464 "=============================================================\n");
2465 */
2466 }
2467
2468 //
2469 // Check if there is a code buffer in the command
2470 //
2471 if (!InterpretConditionsAndCodes(SplitCommand, SplitCommandCaseSensitive, FALSE, &CodeBufferAddress, &CodeBufferLength))
2472 {
2473 //
2474 // Indicate code is not available
2475 //
2476 HasCodeBuffer = FALSE;
2477 //
2478 // ShowMessages("\nNo custom code!\n");
2479 //
2480 }
2481 else
2482 {
2483 //
2484 // Indicate code is available
2485 //
2486 HasCodeBuffer = TRUE;
2487
2488 /*
2489 ShowMessages(
2490 "\n========================= Code =========================\n");
2491 ShowMessages("\nPVOID DebuggerRunCustomCodeFunc(PVOID "
2492 "PreAllocatedBufferAddress_RCX, "
2493 "PGUEST_REGS Regs_RDX, PVOID Context_R8)\n{\n");
2494
2495 //
2496 // Disassemble the buffer
2497 //
2498 HyperDbgDisassembler64((unsigned char *)CodeBufferAddress, 0x0,
2499 CodeBufferLength);
2500
2501 ShowMessages("}\n\n");
2502
2503 ShowMessages(
2504 "=============================================================\n");
2505 */
2506 }
2507
2508 //
2509 // Check if there is a Script block in the command
2510 //
2511 if (!InterpretScript(SplitCommand,
2512 SplitCommandCaseSensitive,
2513 &HasScriptSyntaxError,
2514 &ScriptBufferAddress,
2515 &ScriptBufferLength,
2516 &ScriptBufferPointer,
2517 &ScriptCodeBuffer))
2518 {
2519 //
2520 // Indicate code is not available
2521 //
2522 HasScript = FALSE;
2523 //
2524 // ShowMessages("\nNo script!\n");
2525 //
2526 }
2527 else
2528 {
2529 //
2530 // Check if there is a syntax error
2531 //
2532 if (HasScriptSyntaxError)
2533 {
2534 free(BufferOfCommandString);
2535
2537 return FALSE;
2538 }
2539
2540 //
2541 // Indicate code is available
2542 //
2543 HasScript = TRUE;
2544 }
2545
2546 //
2547 // Check if there is a output path in the command
2548 //
2549 if (!InterpretOutput(SplitCommand, SplitCommandCaseSensitive, ListOfOutputSources))
2550 {
2551 //
2552 // Indicate output is not available
2553 //
2554 HasOutputPath = FALSE;
2555
2556 //
2557 // ShowMessages("\nNo condition!\n");
2558 //
2559 }
2560 else
2561 {
2562 //
2563 // Check for empty input
2564 //
2565 if (ListOfOutputSources.size() == 0)
2566 {
2567 //
2568 // No input !
2569 //
2570 free(BufferOfCommandString);
2571
2572 ShowMessages("err, no input found\n");
2573 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_NO_INPUT;
2574 return FALSE;
2575 }
2576
2577 //
2578 // Check whether the size exceed maximum size or not
2579 //
2580 if (ListOfOutputSources.size() > DebuggerOutputSourceMaximumRemoteSourceForSingleEvent)
2581 {
2582 free(BufferOfCommandString);
2583
2585 "err, based on this build of HyperDbg, the maximum input sources for "
2586 "a single event is 0x%x sources but you entered 0x%x sources\n",
2588 ListOfOutputSources.size());
2590 return FALSE;
2591 }
2592
2593 //
2594 // Check whether the output source initialized or not
2595 //
2597 {
2598 free(BufferOfCommandString);
2599
2600 ShowMessages("err, the name you entered, not found. Did you use "
2601 "'output' command to create it?\n");
2603 return FALSE;
2604 }
2605
2606 //
2607 // Convert output sources to the corresponding tags
2608 //
2609 for (auto item : ListOfOutputSources)
2610 {
2611 TempList = 0;
2612 OutputSourceFound = FALSE;
2613
2614 //
2615 // Now we should find the corresponding object in the list
2616 // of output sources and save its tags
2617 //
2618 TempList = &g_OutputSources;
2619
2620 while (&g_OutputSources != TempList->Flink)
2621 {
2622 TempList = TempList->Flink;
2623
2624 PDEBUGGER_EVENT_FORWARDING CurrentOutputSourceDetails = CONTAINING_RECORD(TempList, DEBUGGER_EVENT_FORWARDING, OutputSourcesList);
2625
2626 if (strcmp(CurrentOutputSourceDetails->Name,
2627 RemoveSpaces(item).c_str()) == 0)
2628 {
2629 //
2630 // Check to see the source state, whether it is closed or not
2631 //
2632 if (CurrentOutputSourceDetails->State == EVENT_FORWARDING_CLOSED)
2633 {
2634 free(BufferOfCommandString);
2635
2636 ShowMessages("err, output source already closed\n");
2638 return FALSE;
2639 }
2640
2641 //
2642 // Check to see the source state, whether it is opened or not
2643 //
2644 if (CurrentOutputSourceDetails->State == EVENT_FORWARDING_STATE_NOT_OPENED)
2645 {
2646 //
2647 // Just show a message
2648 //
2649 ShowMessages("some of the output(s) are not opened, it's not an error, but please ensure "
2650 "to open the output using the 'output' command to forward the results to the "
2651 "target resource\n");
2652 }
2653
2654 //
2655 // Indicate that we found this item
2656 //
2657 OutputSourceFound = TRUE;
2658
2659 //
2660 // Save the tag into a list which will be used later
2661 //
2662 ListOfValidSourceTags.push_back(
2663 CurrentOutputSourceDetails->OutputUniqueTag);
2664
2665 //
2666 // No need to search through the list anymore
2667 //
2668 break;
2669 }
2670 }
2671
2672 if (!OutputSourceFound)
2673 {
2674 free(BufferOfCommandString);
2675
2676 ShowMessages("err, the name you entered, not found. Did you use "
2677 "'output' command to create it?\n");
2679 return FALSE;
2680 }
2681 }
2682 //
2683 // Indicate output is available
2684 //
2685 HasOutputPath = TRUE;
2686 }
2687
2688 //
2689 // Create action and event based on previously parsed buffers
2690 // (DEBUGGER_GENERAL_ACTION)
2691 //
2692 // Allocate the buffer (with ConditionBufferLength and CodeBufferLength)
2693 //
2694
2695 /*
2696
2697 Layout of Buffer :
2698
2699 ________________________________
2700 | |
2701 | DEBUGGER_GENERAL_EVENT_DETAIL |
2702 | |
2703 |________________________________|
2704 | |
2705 | Condition Buffer |
2706 | |
2707 |________________________________|
2708
2709 */
2710
2711 /*
2712 ________________________________
2713 | |
2714 | DEBUGGER_GENERAL_ACTION |
2715 | |
2716 |________________________________|
2717 | |
2718 | Condition Custom Code |
2719 | or Script Buffer |
2720 |________________________________|
2721
2722 */
2723
2724 LengthOfEventBuffer = sizeof(DEBUGGER_GENERAL_EVENT_DETAIL) + ConditionBufferLength;
2725
2726 TempEvent = (PDEBUGGER_GENERAL_EVENT_DETAIL)malloc(LengthOfEventBuffer);
2727 RtlZeroMemory(TempEvent, LengthOfEventBuffer);
2728
2729 //
2730 // Check if buffer is available
2731 //
2732 if (TempEvent == NULL)
2733 {
2734 ShowMessages("err, allocation error\n");
2735 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_ALLOCATION_ERROR;
2736 goto ReturnWithError;
2737 }
2738
2739 //
2740 // Event is enabled by default when created
2741 //
2742 TempEvent->IsEnabled = TRUE;
2743
2744 //
2745 // Get a new tag for it
2746 //
2747 TempEvent->Tag = GetNewDebuggerEventTag();
2748
2749 //
2750 // Set the core Id and Process Id to all cores and all
2751 // processes, next time we check whether the user needs
2752 // a special core or a special process then we change it
2753 //
2755
2757 {
2758 ShowMessages("notice: as you're debugging a user-mode application, "
2759 "this event will only trigger on your current debugging process "
2760 "(pid:%x). If you want the event from the entire system, "
2761 "add 'pid all' to the event\n",
2763
2765 }
2766 else
2767 {
2769 }
2770
2771 //
2772 // Set the event type
2773 //
2774 TempEvent->EventType = EventType;
2775
2776 //
2777 // Get the current time
2778 //
2779 TempEvent->CreationTime = time(0);
2780
2781 //
2782 // Set buffer string command
2783 //
2784 TempEvent->CommandStringBuffer = BufferOfCommandString;
2785
2786 //
2787 // Fill the buffer of condition for event
2788 //
2789 if (HasConditionBuffer)
2790 {
2791 memcpy((PVOID)((UINT64)TempEvent + sizeof(DEBUGGER_GENERAL_EVENT_DETAIL)),
2792 (PVOID)ConditionBufferAddress,
2793 ConditionBufferLength);
2794
2795 //
2796 // Set the size of the buffer for event condition
2797 //
2798 TempEvent->ConditionBufferSize = ConditionBufferLength;
2799 }
2800
2801 //
2802 // Fill the buffer of custom code for action
2803 //
2804 if (HasCodeBuffer)
2805 {
2806 //
2807 // Allocate the Action (THIS ACTION BUFFER WILL BE FREED WHEN WE SENT IT TO
2808 // THE KERNEL AND RETURNED FROM THE KERNEL AS WE DON'T NEED IT ANYMORE)
2809 //
2810 LengthOfCustomCodeActionBuffer = sizeof(DEBUGGER_GENERAL_ACTION) + CodeBufferLength;
2811
2812 TempActionCustomCode = (PDEBUGGER_GENERAL_ACTION)malloc(LengthOfCustomCodeActionBuffer);
2813
2814 RtlZeroMemory(TempActionCustomCode, LengthOfCustomCodeActionBuffer);
2815
2816 memcpy(
2817 (PVOID)((UINT64)TempActionCustomCode + sizeof(DEBUGGER_GENERAL_ACTION)),
2818 (PVOID)CodeBufferAddress,
2819 CodeBufferLength);
2820 //
2821 // Set the action Tag
2822 //
2823 TempActionCustomCode->EventTag = TempEvent->Tag;
2824
2825 //
2826 // Set the action type
2827 //
2828 TempActionCustomCode->ActionType = RUN_CUSTOM_CODE;
2829
2830 //
2831 // Set the action buffer size
2832 //
2833 TempActionCustomCode->CustomCodeBufferSize = CodeBufferLength;
2834
2835 //
2836 // Increase the count of actions
2837 //
2838 TempEvent->CountOfActions = TempEvent->CountOfActions + 1;
2839 }
2840
2841 //
2842 // Fill the buffer of script for action
2843 //
2844 if (HasScript)
2845 {
2846 //
2847 // Allocate the Action (THIS ACTION BUFFER WILL BE FREED WHEN WE SENT IT TO
2848 // THE KERNEL AND RETURNED FROM THE KERNEL AS WE DON'T NEED IT ANYMORE)
2849 //
2850 LengthOfScriptActionBuffer = sizeof(DEBUGGER_GENERAL_ACTION) + ScriptBufferLength;
2851 TempActionScript = (PDEBUGGER_GENERAL_ACTION)malloc(LengthOfScriptActionBuffer);
2852
2853 RtlZeroMemory(TempActionScript, LengthOfScriptActionBuffer);
2854
2855 memcpy((PVOID)((UINT64)TempActionScript + sizeof(DEBUGGER_GENERAL_ACTION)),
2856 (PVOID)ScriptBufferAddress,
2857 ScriptBufferLength);
2858 //
2859 // Set the action Tag
2860 //
2861 TempActionScript->EventTag = TempEvent->Tag;
2862
2863 //
2864 // Set the action type
2865 //
2866 TempActionScript->ActionType = RUN_SCRIPT;
2867
2868 //
2869 // Set the action buffer size and pointer
2870 //
2871 TempActionScript->ScriptBufferSize = ScriptBufferLength;
2872 TempActionScript->ScriptBufferPointer = ScriptBufferPointer;
2873
2874 //
2875 // Increase the count of actions
2876 //
2877 TempEvent->CountOfActions = TempEvent->CountOfActions + 1;
2878
2879 //
2880 // Free the buffer of script related functions
2881 //
2882 ScriptEngineWrapperRemoveSymbolBuffer((PVOID)ScriptCodeBuffer);
2883 }
2884
2885 //
2886 // If this action didn't contain a buffer for custom code and
2887 // a buffer for script then it's a break to debugger
2888 //
2889 if (!HasCodeBuffer && !HasScript)
2890 {
2891 //
2892 // Allocate the Action (THIS ACTION BUFFER WILL BE FREED WHEN WE SENT IT TO
2893 // THE KERNEL AND RETURNED FROM THE KERNEL AS WE DON'T NEED IT ANYMORE)
2894 //
2895 LengthOfBreakActionBuffer = sizeof(DEBUGGER_GENERAL_ACTION);
2896
2897 TempActionBreak = (PDEBUGGER_GENERAL_ACTION)malloc(LengthOfBreakActionBuffer);
2898
2899 RtlZeroMemory(TempActionBreak, LengthOfBreakActionBuffer);
2900
2901 //
2902 // Set the action Tag
2903 //
2904 TempActionBreak->EventTag = TempEvent->Tag;
2905
2906 //
2907 // Set the action type
2908 //
2909 TempActionBreak->ActionType = BREAK_TO_DEBUGGER;
2910
2911 //
2912 // Increase the count of actions
2913 //
2914 TempEvent->CountOfActions = TempEvent->CountOfActions + 1;
2915 }
2916
2917 //
2918 // Interpret rest of the command
2919 //
2920 for (auto Section : *SplitCommand)
2921 {
2922 Index++;
2923 if (IsNextCommandBufferSize)
2924 {
2925 if (!ConvertStringToUInt32(Section, &RequestBuffer))
2926 {
2927 ShowMessages("err, buffer size is invalid\n");
2928 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
2929 goto ReturnWithError;
2930 }
2931 else
2932 {
2933 //
2934 // Set the specific requested buffer size
2935 //
2936 if (TempActionBreak != NULL)
2937 {
2938 TempActionBreak->PreAllocatedBuffer = RequestBuffer;
2939 }
2940 if (TempActionScript != NULL)
2941 {
2942 TempActionScript->PreAllocatedBuffer = RequestBuffer;
2943 }
2944 if (TempActionCustomCode != NULL)
2945 {
2946 TempActionCustomCode->PreAllocatedBuffer = RequestBuffer;
2947 }
2948 }
2949 IsNextCommandBufferSize = FALSE;
2950
2951 //
2952 // Add index to remove it from the command
2953 //
2954 IndexesToRemove.push_back(Index);
2955
2956 continue;
2957 }
2958
2959 if (IsNextCommandImmediateMessaging)
2960 {
2961 if (!Section.compare("yes"))
2962 {
2963 ImmediateMessagePassing = TRUE;
2964 }
2965 else if (!Section.compare("no"))
2966 {
2967 ImmediateMessagePassing = FALSE;
2968 }
2969 else
2970 {
2971 //
2972 // err, not token recognized error
2973 //
2974
2975 ShowMessages("err, immediate messaging token is invalid\n");
2976 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
2977 goto ReturnWithError;
2978 }
2979
2980 IsNextCommandImmediateMessaging = FALSE;
2981
2982 //
2983 // Add index to remove it from the command
2984 //
2985 IndexesToRemove.push_back(Index);
2986
2987 continue;
2988 }
2989
2990 if (IsNextCommandExecutionStage)
2991 {
2992 if (!Section.compare("pre"))
2993 {
2995 }
2996 else if (!Section.compare("post"))
2997 {
2999 }
3000 else if (!Section.compare("all"))
3001 {
3003 }
3004 else
3005 {
3006 //
3007 // err, not token recognized error
3008 //
3009
3010 ShowMessages("err, the specified execution mode is invalid; you can either choose 'pre' or 'post'\n");
3011 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3012 goto ReturnWithError;
3013 }
3014
3015 IsNextCommandExecutionStage = FALSE;
3016
3017 //
3018 // Add index to remove it from the command
3019 //
3020 IndexesToRemove.push_back(Index);
3021
3022 continue;
3023 }
3024
3025 if (IsNextCommandSc)
3026 {
3027 if (!Section.compare("on"))
3028 {
3029 IsAShortCircuitingEventByDefault = TRUE;
3030 }
3031 else if (!Section.compare("off"))
3032 {
3033 IsAShortCircuitingEventByDefault = FALSE;
3034 }
3035 else
3036 {
3037 //
3038 // err, not token recognized error
3039 //
3040
3041 ShowMessages("err, the specified short-circuiting state is invalid; you can either choose 'on' or 'off'\n");
3042 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3043 goto ReturnWithError;
3044 }
3045
3046 IsNextCommandSc = FALSE;
3047
3048 //
3049 // Add index to remove it from the command
3050 //
3051 IndexesToRemove.push_back(Index);
3052
3053 continue;
3054 }
3055
3056 if (IsNextCommandPid)
3057 {
3058 if (!Section.compare("all"))
3059 {
3061 }
3062 else if (!ConvertStringToUInt32(Section, &ProcessId))
3063 {
3064 ShowMessages("err, pid is invalid\n");
3065 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3066
3067 goto ReturnWithError;
3068 }
3069 else
3070 {
3071 //
3072 // Set the specific process id
3073 //
3074 TempEvent->ProcessId = ProcessId;
3075 }
3076
3077 IsNextCommandPid = FALSE;
3078
3079 //
3080 // Add index to remove it from the command
3081 //
3082 IndexesToRemove.push_back(Index);
3083
3084 continue;
3085 }
3086
3087 if (IsNextCommandCoreId)
3088 {
3089 if (!ConvertStringToUInt32(Section, &CoreId))
3090 {
3091 ShowMessages("err, core id is invalid\n");
3092 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3093 goto ReturnWithError;
3094 }
3095 else
3096 {
3097 //
3098 // Set the specific core id
3099 //
3100 TempEvent->CoreId = CoreId;
3101 }
3102 IsNextCommandCoreId = FALSE;
3103
3104 //
3105 // Add index to remove it from the command
3106 //
3107 IndexesToRemove.push_back(Index);
3108
3109 continue;
3110 }
3111
3112 if (!Section.compare("pid"))
3113 {
3114 IsNextCommandPid = TRUE;
3115
3116 //
3117 // Add index to remove it from the command
3118 //
3119 IndexesToRemove.push_back(Index);
3120
3121 continue;
3122 }
3123 if (!Section.compare("core"))
3124 {
3125 IsNextCommandCoreId = TRUE;
3126
3127 //
3128 // Add index to remove it from the command
3129 //
3130 IndexesToRemove.push_back(Index);
3131
3132 continue;
3133 }
3134
3135 if (!Section.compare("imm"))
3136 {
3137 //
3138 // the next command is immediate messaging indicator
3139 //
3140 IsNextCommandImmediateMessaging = TRUE;
3141
3142 //
3143 // Add index to remove it from the command
3144 //
3145 IndexesToRemove.push_back(Index);
3146
3147 continue;
3148 }
3149
3150 if (!Section.compare("stage"))
3151 {
3152 //
3153 // the next command is execution mode (pre- and post-events)
3154 //
3155 IsNextCommandExecutionStage = TRUE;
3156
3157 //
3158 // Add index to remove it from the command
3159 //
3160 IndexesToRemove.push_back(Index);
3161
3162 continue;
3163 }
3164
3165 if (!Section.compare("sc"))
3166 {
3167 //
3168 // the next command is the default short-circuiting state
3169 //
3170 IsNextCommandSc = TRUE;
3171
3172 //
3173 // Add index to remove it from the command
3174 //
3175 IndexesToRemove.push_back(Index);
3176
3177 continue;
3178 }
3179
3180 if (!Section.compare("buffer"))
3181 {
3182 IsNextCommandBufferSize = TRUE;
3183
3184 //
3185 // Add index to remove it from the command
3186 //
3187 IndexesToRemove.push_back(Index);
3188
3189 continue;
3190 }
3191 }
3192
3193 //
3194 // Additional validation
3195 //
3196 if (IsNextCommandCoreId)
3197 {
3198 ShowMessages("err, please specify a value for 'core'\n");
3199
3200 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3201
3202 goto ReturnWithError;
3203 }
3204
3205 if (IsNextCommandPid)
3206 {
3207 ShowMessages("err, please specify a value for 'pid'\n");
3208
3209 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3210
3211 goto ReturnWithError;
3212 }
3213
3214 if (IsNextCommandBufferSize)
3215 {
3216 ShowMessages("err, please specify a value for 'buffer'\n");
3217
3218 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3219
3220 goto ReturnWithError;
3221 }
3222
3223 if (IsNextCommandImmediateMessaging)
3224 {
3225 ShowMessages("err, please specify a value for 'imm'\n");
3226
3227 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3228
3229 goto ReturnWithError;
3230 }
3231
3232 if (IsNextCommandExecutionStage)
3233 {
3234 ShowMessages("err, please specify a value for 'stage'\n");
3235
3236 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3237
3238 goto ReturnWithError;
3239 }
3240
3241 if (IsNextCommandSc)
3242 {
3243 ShowMessages("err, please specify a value for 'sc'\n");
3244
3245 *ReasonForErrorInParsing = DEBUGGER_EVENT_PARSING_ERROR_CAUSE_FORMAT_ERROR;
3246
3247 goto ReturnWithError;
3248 }
3249
3250 //
3251 // Check to make sure that short-circuiting is not used in post-events
3252 //
3255 IsAShortCircuitingEventByDefault)
3256 {
3258 "err, using the short-circuiting mechanism with 'post' or 'all' stage events "
3259 "doesn't make sense; it's not supported!\n");
3260
3262
3263 goto ReturnWithError;
3264 }
3265
3266 //
3267 // It's not possible to break to debugger in VMI-mode
3268 //
3269 if (!g_IsSerialConnectedToRemoteDebuggee && TempActionBreak != NULL)
3270 {
3272 "err, the script or assembly code is either not found or invalid. "
3273 "As a result, the default action is to break. "
3274 "However, breaking to the debugger is not possible in the VMI Mode. "
3275 "To achieve full control of the system, you can switch to the Debugger Mode. "
3276 "In the VMI Mode, you can still use scripts and run custom code for local debugging."
3277 "For more information, please check: https://docs.hyperdbg.org/using-hyperdbg/prerequisites/operation-modes\n");
3278
3280
3281 goto ReturnWithError;
3282 }
3283
3284 //
3285 // We do not support non-immediate message passing if the user
3286 // specified a special output
3287 //
3288 if (!ImmediateMessagePassing && HasOutputPath)
3289 {
3290 ShowMessages("err, non-immediate message passing is not supported in "
3291 "'output-forwarding mode'\n");
3292
3294
3295 goto ReturnWithError;
3296 }
3297
3298 //
3299 // Set the specific requested immediate message passing
3300 //
3301 if (TempActionBreak != NULL)
3302 {
3303 TempActionBreak->ImmediateMessagePassing = ImmediateMessagePassing;
3304 }
3305 if (TempActionScript != NULL)
3306 {
3307 TempActionScript->ImmediateMessagePassing = ImmediateMessagePassing;
3308 }
3309 if (TempActionCustomCode != NULL)
3310 {
3311 TempActionCustomCode->ImmediateMessagePassing = ImmediateMessagePassing;
3312 }
3313
3314 //
3315 // Set the tags into the event list
3316 //
3317 IndexOfValidSourceTags = 0;
3318 for (auto item : ListOfValidSourceTags)
3319 {
3320 TempEvent->OutputSourceTags[IndexOfValidSourceTags] = item;
3321
3322 //
3323 // Increase index
3324 //
3325 IndexOfValidSourceTags++;
3326 }
3327
3328 //
3329 // If it has output then we should indicate it in event's object
3330 //
3331 if (HasOutputPath)
3332 {
3333 TempEvent->HasCustomOutput = TRUE;
3334 }
3335
3336 //
3337 // Set the specific requested short-circuiting state
3338 //
3339 if (IsAShortCircuitingEventByDefault)
3340 {
3341 TempEvent->EnableShortCircuiting = TRUE;
3342 }
3343
3344 //
3345 // Set the specific event mode (calling stage)
3346 //
3347 TempEvent->EventStage = CallingStage;
3348
3349 //
3350 // Fill the address and length of event before release
3351 //
3352 *EventDetailsToFill = TempEvent;
3353 *EventBufferLength = LengthOfEventBuffer;
3354
3355 //
3356 // Fill the address and length of action before release
3357 //
3358 if (TempActionBreak != NULL)
3359 {
3360 *ActionDetailsToFillBreakToDebugger = TempActionBreak;
3361 *ActionBufferLengthBreakToDebugger = LengthOfBreakActionBuffer;
3362 }
3363 if (TempActionScript != NULL)
3364 {
3365 *ActionDetailsToFillScript = TempActionScript;
3366 *ActionBufferLengthScript = LengthOfScriptActionBuffer;
3367 }
3368 if (TempActionCustomCode != NULL)
3369 {
3370 *ActionDetailsToFillCustomCode = TempActionCustomCode;
3371 *ActionBufferLengthCustomCode = LengthOfCustomCodeActionBuffer;
3372 }
3373
3374 //
3375 // Remove the command that we interpreted above from the command
3376 //
3377 for (auto IndexToRemove : IndexesToRemove)
3378 {
3379 NewIndexToRemove++;
3380 SplitCommand->erase(SplitCommand->begin() + (IndexToRemove - NewIndexToRemove));
3381 SplitCommandCaseSensitive->erase(SplitCommandCaseSensitive->begin() + (IndexToRemove - NewIndexToRemove));
3382 }
3383
3384 //
3385 // Check if list is initialized or not
3386 //
3388 {
3391 }
3392
3393 //
3394 // Add the event to the trace list
3395 // UPDATE : if we add it here, then if the event was not
3396 // successful then still the event shows this event, so
3397 // we have to add it lated
3398 //
3399 // InsertHeadList(&g_EventTrace, &(TempEvent->CommandsEventList));
3400
3401 //
3402 // Everything is ok, let's return TRUE
3403 //
3405 return TRUE;
3406
3407ReturnWithError:
3408
3409 if (BufferOfCommandString)
3410 {
3411 free(BufferOfCommandString);
3412 }
3413
3414 if (TempEvent)
3415 {
3416 free(TempEvent);
3417 }
3418
3419 if (TempActionBreak != NULL)
3420 {
3421 free(TempActionBreak);
3422 }
3423 if (TempActionScript != NULL)
3424 {
3425 free(TempActionScript);
3426 }
3427 if (TempActionCustomCode != NULL)
3428 {
3429 free(TempActionCustomCode);
3430 }
3431
3432 return FALSE;
3433}
#define UseImmediateMessagingByDefaultOnEvents
Use immediate messaging (means that it sends each message when they received and do not accumulate th...
Definition Configuration.h:57
#define DEBUGGER_EVENT_APPLY_TO_ALL_CORES
Apply the event to all the cores.
Definition Constants.h:611
#define DebuggerOutputSourceMaximumRemoteSourceForSingleEvent
Determines how many sources a debugger can have for a single event.
Definition Constants.h:243
#define DEBUGGER_EVENT_APPLY_TO_ALL_PROCESSES
Apply the event to all the processes.
Definition Constants.h:617
enum _VMM_CALLBACK_EVENT_CALLING_STAGE_TYPE VMM_CALLBACK_EVENT_CALLING_STAGE_TYPE
Type of calling the event.
@ VMM_CALLBACK_CALLING_STAGE_ALL_EVENT_EMULATION
Definition DataTypes.h:95
@ VMM_CALLBACK_CALLING_STAGE_PRE_EVENT_EMULATION
Definition DataTypes.h:93
@ VMM_CALLBACK_CALLING_STAGE_POST_EVENT_EMULATION
Definition DataTypes.h:94
FORCEINLINE VOID InitializeListHead(_Out_ PLIST_ENTRY ListHead)
Definition Windows.h:41
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
std::string RemoveSpaces(std::string str)
Remove all the spaces in a string.
Definition common.cpp:606
BOOLEAN InterpretOutput(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, vector< string > &InputSources)
Interpret output (if an event has special output)
Definition debugger.cpp:1703
BOOLEAN g_OutputSourcesInitialized
it shows whether the debugger started using output sources or not or in other words,...
Definition globals.h:408
LIST_ENTRY g_EventTrace
Holds a list of events in kernel and the state of events and the commands to show the state of each c...
Definition globals.h:400
BOOLEAN g_EventTraceInitialized
it shows whether the debugger started using events or not or in other words, is g_EventTrace initiali...
Definition globals.h:390
BOOLEAN InterpretConditionsAndCodes(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, BOOLEAN IsConditionBuffer, PUINT64 BufferAddress, PUINT32 BufferLength)
Interpret conditions (if an event has condition) and custom code.
Definition debugger.cpp:1246
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:362
BOOLEAN InterpretScript(vector< string > *SplitCommand, vector< string > *SplitCommandCaseSensitive, PBOOLEAN ScriptSyntaxErrors, PUINT64 BufferAddress, PUINT32 BufferLength, PUINT32 Pointer, PUINT64 ScriptCodeBuffer)
Interpret script (if an event has script)
Definition debugger.cpp:763
LIST_ENTRY g_OutputSources
Holds a list of output sources created by output command.
Definition globals.h:417
UINT64 GetNewDebuggerEventTag()
Get the New Debugger Event Tag object and increase the global variable for tag.
Definition debugger.cpp:2280
@ EVENT_FORWARDING_CLOSED
Definition forwarding.h:55
@ EVENT_FORWARDING_STATE_NOT_OPENED
Definition forwarding.h:53
struct _DEBUGGER_GENERAL_EVENT_DETAIL DEBUGGER_GENERAL_EVENT_DETAIL
Each command is like the following struct, it also used for tracing works in user mode and sending it...
struct _DEBUGGER_GENERAL_EVENT_DETAIL * PDEBUGGER_GENERAL_EVENT_DETAIL
@ RUN_CUSTOM_CODE
Definition Events.h:182
@ BREAK_TO_DEBUGGER
Definition Events.h:180
@ RUN_SCRIPT
Definition Events.h:181
struct _DEBUGGER_GENERAL_ACTION DEBUGGER_GENERAL_ACTION
Each event can have multiple actions.
struct _DEBUGGER_GENERAL_ACTION * PDEBUGGER_GENERAL_ACTION
VOID ScriptEngineWrapperRemoveSymbolBuffer(PVOID SymbolBuffer)
wrapper for removing symbol buffer
Definition script-engine-wrapper.cpp:860
structures hold the detail of event forwarding
Definition forwarding.h:80
DEBUGGER_EVENT_FORWARDING_STATE State
Definition forwarding.h:82
CHAR Name[MAXIMUM_CHARACTERS_FOR_EVENT_FORWARDING_NAME]
Definition forwarding.h:89
UINT64 OutputUniqueTag
Definition forwarding.h:86
Each event can have multiple actions.
Definition Events.h:406
UINT32 CustomCodeBufferSize
Definition Events.h:412
UINT32 ScriptBufferSize
Definition Events.h:413
DEBUGGER_EVENT_ACTION_TYPE_ENUM ActionType
Definition Events.h:408
UINT32 ScriptBufferPointer
Definition Events.h:414
UINT32 PreAllocatedBuffer
Definition Events.h:410
BOOLEAN ImmediateMessagePassing
Definition Events.h:409
UINT64 EventTag
Definition Events.h:407
BOOLEAN EnableShortCircuiting
Definition Events.h:366
BOOLEAN IsEnabled
Definition Events.h:364
VMM_EVENT_TYPE_ENUM EventType
Definition Events.h:389
UINT32 CountOfActions
Definition Events.h:386
UINT64 OutputSourceTags[DebuggerOutputSourceMaximumRemoteSourceForSingleEvent]
Definition Events.h:377
BOOLEAN HasCustomOutput
Definition Events.h:372
VMM_CALLBACK_EVENT_CALLING_STAGE_TYPE EventStage
Definition Events.h:369
UINT32 ConditionBufferSize
Definition Events.h:395
UINT32 ProcessId
Definition Events.h:360
UINT32 CoreId
Definition Events.h:357
time_t CreationTime
Definition Events.h:355

◆ IsConnectedToAnyInstanceOfDebuggerOrDebuggee()

BOOLEAN IsConnectedToAnyInstanceOfDebuggerOrDebuggee ( )

Shows whether the debugger is connected to a debugger or debuggee connected to a debugger.

we use this function to avoid connecting to a remote machine when debuggee or debugger is already connected to an instance

Returns
BOOLEAN
669{
670 if (g_DeviceHandle)
671 {
672 ShowMessages("err, the current system is already connected to the local "
673 "debugging, use '.disconnect' to disconnect\n");
674 return TRUE;
675 }
677 {
678 ShowMessages("err, the current system is already connected to remote "
679 "machine (debuggee), use '.disconnect' to disconnect from the "
680 "remote machine\n");
681 return TRUE;
682 }
684 {
685 ShowMessages("err, the current system is already connected to remote "
686 "machine (debugger), use '.disconnect' to disconnect from the "
687 "remote machine from debugger\n");
688 return TRUE;
689 }
691 {
693 "err, the current system is already connected to remote "
694 "machine (debuggee), use '.debug close' to disconnect from the "
695 "remote machine\n");
696 return TRUE;
697 }
699 {
701 "err, the current system is already connected to remote "
702 "machine (debugger), use '.debug close' to disconnect from the "
703 "remote machine from debugger\n");
704 return TRUE;
705 }
706
707 return FALSE;
708}
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host)
Definition globals.h:238
BOOLEAN g_IsConnectedToRemoteDebuggee
Shows whether the current debugger is the host and connected to a remote debuggee (guest)
Definition globals.h:74
BOOLEAN g_IsConnectedToRemoteDebugger
Shows whether the current system is a guest (debuggee) and a remote debugger is connected to this sys...
Definition globals.h:81

◆ IsTagExist()

BOOLEAN IsTagExist ( UINT64 Tag)

Check whether the tag exists or not, if the tag is DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG then if we find just one event, it also means that the tag is found.

Parameters
Tag
Returns
BOOLEAN
720{
721 PLIST_ENTRY TempList = 0;
722 PDEBUGGER_GENERAL_EVENT_DETAIL CommandDetail = {0};
723
725 {
726 return FALSE;
727 }
728
729 TempList = &g_EventTrace;
730 while (&g_EventTrace != TempList->Blink)
731 {
732 TempList = TempList->Blink;
733
734 CommandDetail = CONTAINING_RECORD(TempList, DEBUGGER_GENERAL_EVENT_DETAIL, CommandsEventList);
735
736 if (CommandDetail->Tag == Tag || Tag == DEBUGGER_MODIFY_EVENTS_APPLY_TO_ALL_TAG)
737 {
738 return TRUE;
739 }
740 }
741
742 //
743 // Not found
744 //
745 return FALSE;
746}

◆ ListeningSerialPauseDebuggeeThread()

DWORD WINAPI ListeningSerialPauseDebuggeeThread ( PVOID Param)

Check if the remote debugger needs to pause the system.

Parameters
SerialHandle
Returns
BOOLEAN
1245{
1246 //
1247 // Create a listening thead in debuggee
1248 //
1250
1251 return 0;
1252}
BOOLEAN ListeningSerialPortInDebuggee()
Check if the remote debugger needs to pause the system.
Definition kernel-listening.cpp:1054

◆ ListeningSerialPauseDebuggerThread()

DWORD WINAPI ListeningSerialPauseDebuggerThread ( PVOID Param)

Check if the remote debuggee needs to pause the system.

Parameters
Param
Returns
BOOLEAN
1228{
1229 //
1230 // Create a listening thead in debugger
1231 //
1233
1234 return 0;
1235}
BOOLEAN ListeningSerialPortInDebugger()
Check if the remote debuggee needs to pause the system and also process the debuggee's messages.
Definition kernel-listening.cpp:44

◆ LogopenSaveToFile()

VOID LogopenSaveToFile ( const char * Text)

Append text to the file object.

Parameters
Text
Returns
VOID
120{
121 g_LogOpenFile << Text;
122}
ofstream g_LogOpenFile
The object of log file ('.logopen' command)
Definition globals.h:484

◆ RegisterActionToEvent()

BOOLEAN RegisterActionToEvent ( PDEBUGGER_GENERAL_EVENT_DETAIL Event,
PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger,
UINT32 ActionBreakToDebuggerLength,
PDEBUGGER_GENERAL_ACTION ActionCustomCode,
UINT32 ActionCustomCodeLength,
PDEBUGGER_GENERAL_ACTION ActionScript,
UINT32 ActionScriptLength )

Register the action to the event.

Parameters
Eventthe event instance buffer
ActionBreakToDebuggerthe action of breaking into the debugger
ActionBreakToDebuggerLengththe action of breaking into the debugger (length)
ActionCustomCodethe action of custom code
ActionCustomCodeLengththe action of custom code (length)
ActionScriptthe action of script buffer
ActionScriptLengththe action of script buffer (length)
Returns
BOOLEAN BOOLEAN if the request was successful then true if the request was not successful then false
2093{
2094 BOOL Status;
2095 ULONG ReturnedLength;
2096 DEBUGGER_EVENT_AND_ACTION_RESULT ReturnedBuffer = {0};
2097 PDEBUGGER_EVENT_AND_ACTION_RESULT TempAddingResult;
2098
2100 {
2101 //
2102 // It's action(s) in debugger mode
2103 //
2104
2105 //
2106 // Send Break to debugger packet to debuggee
2107 //
2108 if (ActionBreakToDebugger != NULL)
2109 {
2110 //
2111 // Send the add action to event from here
2112 //
2113 TempAddingResult = KdSendAddActionToEventPacketToDebuggee(
2114 ActionBreakToDebugger,
2115 ActionBreakToDebuggerLength);
2116
2117 //
2118 // Move the buffer to local buffer
2119 //
2120 memcpy(&ReturnedBuffer, TempAddingResult, sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT));
2121 }
2122
2123 //
2124 // Send custom code packet to debuggee
2125 //
2126 if (ActionCustomCode != NULL)
2127 {
2128 //
2129 // Send the add action to event from here
2130 //
2131 TempAddingResult = KdSendAddActionToEventPacketToDebuggee(
2132 ActionCustomCode,
2133 ActionCustomCodeLength);
2134
2135 //
2136 // Move the buffer to local buffer
2137 //
2138 memcpy(&ReturnedBuffer, TempAddingResult, sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT));
2139 }
2140
2141 //
2142 // Send custom code packet to debuggee
2143 //
2144 if (ActionScript != NULL)
2145 {
2146 //
2147 // Send the add action to event from here
2148 //
2149 TempAddingResult = KdSendAddActionToEventPacketToDebuggee(
2150 ActionScript,
2151 ActionScriptLength);
2152
2153 //
2154 // Move the buffer to local buffer
2155 //
2156 memcpy(&ReturnedBuffer, TempAddingResult, sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT));
2157 }
2158 }
2159 else
2160 {
2161 //
2162 // It's either a local debugger to in vmi-mode remote conntection
2163 //
2164
2166
2167 //
2168 // Send IOCTLs
2169 //
2170
2171 //
2172 // Send Break to debugger ioctl
2173 //
2174 if (ActionBreakToDebugger != NULL)
2175 {
2176 Status = DeviceIoControl(
2177 g_DeviceHandle, // Handle to device
2178 IOCTL_DEBUGGER_ADD_ACTION_TO_EVENT, // IO Control Code (IOCTL)
2179 ActionBreakToDebugger, // Input Buffer to driver.
2180 ActionBreakToDebuggerLength, // Input buffer length
2181 &ReturnedBuffer, // Output Buffer from driver.
2182 sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT), // Length
2183 // of
2184 // output
2185 // buffer
2186 // in
2187 // bytes.
2188 &ReturnedLength, // Bytes placed in buffer.
2189 NULL // synchronous call
2190 );
2191
2192 if (!Status)
2193 {
2194 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
2195 return FALSE;
2196 }
2197 }
2198
2199 //
2200 // Send custom code ioctl
2201 //
2202 if (ActionCustomCode != NULL)
2203 {
2204 Status = DeviceIoControl(
2205 g_DeviceHandle, // Handle to device
2206 IOCTL_DEBUGGER_ADD_ACTION_TO_EVENT, // IO Control Code (IOCTL)
2207 ActionCustomCode, // Input Buffer to driver.
2208 ActionCustomCodeLength, // Input buffer length
2209 &ReturnedBuffer, // Output Buffer from driver.
2210 sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT), // Length
2211 // of
2212 // output
2213 // buffer
2214 // in
2215 // bytes.
2216 &ReturnedLength, // Bytes placed in buffer.
2217 NULL // synchronous call
2218 );
2219
2220 if (!Status)
2221 {
2222 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
2223 return FALSE;
2224 }
2225 }
2226
2227 //
2228 // Send custom code ioctl
2229 //
2230 if (ActionScript != NULL)
2231 {
2232 Status = DeviceIoControl(
2233 g_DeviceHandle, // Handle to device
2234 IOCTL_DEBUGGER_ADD_ACTION_TO_EVENT, // IO Control Code (IOCTL)
2235 ActionScript, // Input Buffer to driver.
2236 ActionScriptLength, // Input buffer length
2237 &ReturnedBuffer, // Output Buffer from driver.
2238 sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT), // Length
2239 // of
2240 // output
2241 // buffer
2242 // in
2243 // bytes.
2244 &ReturnedLength, // Bytes placed in buffer.
2245 NULL // synchronous call
2246 );
2247
2248 if (!Status)
2249 {
2250 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
2251 return FALSE;
2252 }
2253 }
2254 }
2255
2256 //
2257 // As we're not needing any of action buffer, we'll free all of the
2258 // here in the case of a successful registration of action, however
2259 // event detail is needed for the 'event' command's list
2260 //
2261 FreeEventsAndActionsMemory(NULL, ActionBreakToDebugger, ActionCustomCode, ActionScript);
2262
2263 //
2264 // Now, we'll register the command as returned buffer shows that
2265 // this event was successful and now we can add it to the list of
2266 // events
2267 //
2269
2270 return TRUE;
2271}
#define IOCTL_DEBUGGER_ADD_ACTION_TO_EVENT
ioctl, add action to event
Definition Ioctls.h:113
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ PLIST_ENTRY Entry)
Definition Windows.h:115
VOID FreeEventsAndActionsMemory(PDEBUGGER_GENERAL_EVENT_DETAIL Event, PDEBUGGER_GENERAL_ACTION ActionBreakToDebugger, PDEBUGGER_GENERAL_ACTION ActionCustomCode, PDEBUGGER_GENERAL_ACTION ActionScript)
Deallocate buffers relating to events and actions.
Definition debugger.cpp:2292
PDEBUGGER_EVENT_AND_ACTION_RESULT KdSendAddActionToEventPacketToDebuggee(PDEBUGGER_GENERAL_ACTION GeneralAction, UINT32 GeneralActionLength)
Send an add action to event request to the debuggee.
Definition kd.cpp:737
Status of register buffers.
Definition Events.h:423
LIST_ENTRY CommandsEventList
Definition Events.h:352

◆ SendEventToKernel()

BOOLEAN SendEventToKernel ( PDEBUGGER_GENERAL_EVENT_DETAIL Event,
UINT32 EventBufferLength )

Register the event to the kernel.

Parameters
Eventthe event structure to send
EventBufferLengththe buffer length of event
Returns
BOOLEAN if the request was successful then true if the request was not successful then false
1971{
1972 BOOL Status;
1973 ULONG ReturnedLength;
1974 DEBUGGER_EVENT_AND_ACTION_RESULT ReturnedBuffer = {0};
1976
1978 {
1979 //
1980 // It's a debugger, we should send the events buffer directly
1981 // from here
1982 //
1983
1984 //
1985 // Send the buffer from here
1986 //
1987 TempRegResult = KdSendRegisterEventPacketToDebuggee(Event, EventBufferLength);
1988
1989 //
1990 // Move the buffer to local buffer
1991 //
1992 memcpy(&ReturnedBuffer, TempRegResult, sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT));
1993 }
1994 else
1995 {
1996 //
1997 // It's either a debuggee or a local debugging instance
1998 //
1999
2001
2002 //
2003 // Send IOCTL
2004 //
2005
2006 Status = DeviceIoControl(g_DeviceHandle, // Handle to device
2007 IOCTL_DEBUGGER_REGISTER_EVENT, // IO Control Code (IOCTL)
2008 Event, // Input Buffer to driver.
2009 EventBufferLength, // Input buffer length
2010 &ReturnedBuffer, // Output Buffer from driver.
2011 sizeof(DEBUGGER_EVENT_AND_ACTION_RESULT), // Length
2012 // of
2013 // output
2014 // buffer
2015 // in
2016 // bytes.
2017 &ReturnedLength, // Bytes placed in buffer.
2018 NULL // synchronous call
2019 );
2020
2021 if (!Status)
2022 {
2023 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
2024 return FALSE;
2025 }
2026 }
2027
2028 if (ReturnedBuffer.IsSuccessful && ReturnedBuffer.Error == 0)
2029 {
2030 //
2031 // Check for auto-unpause mode
2032 //
2034 {
2035 //
2036 // Allow debugger to show its contents
2037 //
2038
2039 //
2040 // Set the g_BreakPrintingOutput to FALSE
2041 //
2043
2044 //
2045 // If it's a remote debugger then we send the remote debuggee a 'g'
2046 //
2048 {
2049 RemoteConnectionSendCommand("g", (UINT32)strlen("g") + 1);
2050 }
2051
2052 ShowMessages("\n");
2053 }
2054 }
2055 else
2056 {
2057 //
2058 // Show the error
2059 //
2060 if (ReturnedBuffer.Error != 0)
2061 {
2062 ShowErrorMessage(ReturnedBuffer.Error);
2063 }
2064
2065 return FALSE;
2066 }
2067
2068 return TRUE;
2069}
#define IOCTL_DEBUGGER_REGISTER_EVENT
ioctl, register an event
Definition Ioctls.h:106
BOOLEAN g_BreakPrintingOutput
Shows whether the pause command or CTRL+C or CTRL+Break is executed or not.
Definition globals.h:499
BOOLEAN g_AutoUnpause
Whether auto-unpause mode is enabled or not enabled.
Definition globals.h:577
PDEBUGGER_EVENT_AND_ACTION_RESULT KdSendRegisterEventPacketToDebuggee(PDEBUGGER_GENERAL_EVENT_DETAIL Event, UINT32 EventBufferLength)
Send a register event request to the debuggee.
Definition kd.cpp:670
UINT32 Error
Definition Events.h:425
BOOLEAN IsSuccessful
Definition Events.h:424

◆ ShowErrorMessage()

BOOLEAN ShowErrorMessage ( UINT32 Error)

shows the error message

Parameters
Error
Returns
BOOLEAN
39{
40 switch (Error)
41 {
43 ShowMessages("err, tag not found (%x)\n",
44 Error);
45 break;
46
48 ShowMessages("err, invalid action type (%x)\n",
49 Error);
50 break;
51
53 ShowMessages("err, action buffer size is zero (%x)\n",
54 Error);
55 break;
56
58 ShowMessages("err, the event type is invalid (%x)\n",
59 Error);
60 break;
61
63 ShowMessages("err, unable to create event (%x)\n",
64 Error);
65 break;
66
68
69 ShowMessages("err, invalid address (%x)\n"
70 "address may be paged-out or unavailable on the page table due to 'demand paging'\n"
71 "please refer to https://docs.hyperdbg.org/tips-and-tricks/considerations/accessing-invalid-address for further information\n",
72 Error);
73 break;
74
76 ShowMessages("err, invalid core id (%x)\n",
77 Error);
78 break;
79
81 ShowMessages("err, exception index exceed first 32 entries (%x)\n",
82 Error);
83 break;
84
86 ShowMessages("err, interrupt index is not valid (%x)\n",
87 Error);
88 break;
89
91 ShowMessages("err, unable to hide or unhide debugger (%x)\n",
92 Error);
93 break;
94
96 ShowMessages("err, debugger already unhide (%x)\n",
97 Error);
98 break;
99
101 ShowMessages("err, edit memory request has invalid parameters (%x)\n",
102 Error);
103 break;
104
106 ShowMessages("err, edit memory request has invalid address based on "
107 "current process layout, the address might be valid but not "
108 "present in the ram (%x)\n"
109 "address may be paged-out or unavailable on the page table due to 'demand paging'\n"
110 "please refer to https://docs.hyperdbg.org/tips-and-tricks/considerations/accessing-invalid-address for further information\n",
111 Error);
112 break;
113
115 ShowMessages("err, edit memory request has invalid address based on other "
116 "process layout (%x)\n",
117 Error);
118 break;
119
121 ShowMessages("err, modify event with invalid tag (%x)\n",
122 Error);
123 break;
124
126 ShowMessages("err, modify event with invalid type of action (%x)\n",
127 Error);
128 break;
129
131 ShowMessages("err, invalid parameter passed to stepping core. (%x)\n",
132 Error);
133 break;
134
137 "err, the target thread not found or the thread is disabled (%x)\n",
138 Error);
139 break;
140
142 ShowMessages("err, invalid baud rate (%x)\n",
143 Error);
144 break;
145
147 ShowMessages("err, invalid serial port (%x)\n",
148 Error);
149 break;
150
152 ShowMessages("err, invalid core selected in switching cores (%x)\n",
153 Error);
154 break;
155
157 ShowMessages("err, unable to switch to the new process (%x)\n",
158 Error);
159 break;
160
162 ShowMessages("err, unable to run the script on remote debuggee (%x)\n",
163 Error);
164 break;
165
167 ShowMessages("err, invalid register number (%x)\n",
168 Error);
169 break;
170
172 ShowMessages("err, maximum number of breakpoints are used, you need to "
173 "send an ioctl to re-allocate new pre-allocated buffers or "
174 "configure HyperDbg to pre-allocated more buffers by "
175 "configuring MAXIMUM_BREAKPOINTS_WITHOUT_CONTINUE (%x)\n",
176 Error);
177 break;
178
180 ShowMessages("err, breakpoint already exists on target address, you can "
181 "use 'bl' command to view a list of breakpoints (%x)\n",
182 Error);
183 break;
184
186 ShowMessages("err, breakpoint id is invalid (%x)\n",
187 Error);
188 break;
189
191 ShowMessages("err, breakpoint already disabled (%x)\n",
192 Error);
193 break;
194
196 ShowMessages("err, breakpoint already enabled (%x)\n",
197 Error);
198 break;
199
201 ShowMessages("err, the memory type is invalid (%x)\n",
202 Error);
203 break;
204
206 ShowMessages("err, the process id is invalid, make sure to enter the "
207 "process id in hex format, or if you want to use it in decimal "
208 "format, add '0n' prefix to the number (%x)\n",
209 Error);
210 break;
211
213 ShowMessages("err, the event is not applied (%x)\n",
214 Error);
215 break;
216
218 ShowMessages("err, either the process id or the _EPROCESS is invalid or "
219 "cannot get the details based on the provided parameters (%x)\n",
220 Error);
221 break;
222
224 ShowMessages("err, either the thread id, _ETHREAD, or _EPROCESS is invalid or "
225 "cannot get the details based on the provided parameters (%x)\n",
226 Error);
227 break;
228
230 ShowMessages("err, the maximum breakpoint for a single page is hit, "
231 "you cannot apply more breakpoints in this page (%x)\n",
232 Error);
233 break;
234
236 ShowMessages("err, the pre-allocated buffer is empty, usually this buffer will be "
237 "filled at the next IOCTL when the debugger is continued (%x)\n"
238 "please visit the documentation for the 'prealloc' command or use "
239 "'.help prealloc' to to reserve more pre-allocated pools\n",
240 Error);
241 break;
242
244 ShowMessages("err, could not convert 2MB large page to 4KB pages (%x)\n",
245 Error);
246 break;
247
249 ShowMessages("err, failed to get the PML1 entry of the target address (%x)\n",
250 Error);
251 break;
252
254 ShowMessages("err, the page modification is not applied, make sure that you don't "
255 "put multiple EPT Hooks or Monitors on a single page (%x)\n",
256 Error);
257 break;
258
260 ShowMessages("err, could not build the EPT hook (%x)\n",
261 Error);
262 break;
263
265 ShowMessages("err, could not find the allocation type (%x)\n",
266 Error);
267 break;
268
270 ShowMessages("err, invalid index specified for test query command (%x)\n",
271 Error);
272 break;
273
275 ShowMessages("err, unable to attach to the target process (%x)\n",
276 Error);
277 break;
278
280 ShowMessages("err, unable to remove hooks as the entrypoint of user-mode "
281 "process is not reached yet (%x)\n",
282 Error);
283 break;
284
286 ShowMessages("err, unable to remove hooks (%x)\n",
287 Error);
288 break;
289
291 ShowMessages("err, the routines for getting the PEB is not correctly "
292 "initialized (%x)\n",
293 Error);
294 break;
295
297 ShowMessages("err, unable to detect whether the process was 32-bit "
298 "or 64-bit (%x)\n",
299 Error);
300 break;
301
303 ShowMessages("err, unable to kill the process (%x)\n",
304 Error);
305 break;
306
308 ShowMessages("err, invalid thread debugging token (%x)\n",
309 Error);
310 break;
311
313 ShowMessages("err, unable to pause the threads of the process (%x)\n",
314 Error);
315 break;
316
318 ShowMessages("err, the user debugger is already attached to this "
319 "process, please use the '.switch' command to switch "
320 "to this process (%x)\n",
321 Error);
322 break;
323
325 ShowMessages("err, the user debugger is not already attached to "
326 "the process (%x)\n",
327 Error);
328 break;
329
331 ShowMessages("err, the user debugger is not able to detach from "
332 "this process as there are paused threads in the "
333 "target process, please make sure to remove all "
334 "the events and continue the target process, then "
335 "perform the detach again (%x)\n",
336 Error);
337 break;
338
340 ShowMessages("err, unable to switch to the process id or thread id "
341 "as the target process id or thread id is not found in "
342 "the attached threads list, please view the list of "
343 "processes and threads by using the '.switch list' command (%x)\n",
344 Error);
345 break;
346
348 ShowMessages("err, unable to switch to the process as the process doesn't "
349 "contain an active intercepted thread (%x)\n",
350 Error);
351 break;
352
354 ShowMessages("err, unable to get user-mode modules of the process (%x)\n",
355 Error);
356 break;
357
359 ShowMessages("err, unable to get the callstack (%x)\n",
360 Error);
361 break;
362
364 ShowMessages("err, unable to query count of processes or threads (%x)\n",
365 Error);
366 break;
367
369 ShowMessages("err, using short-circuiting event with post events is not possible (%x)\n",
370 Error);
371 break;
372
374 ShowMessages("err, unknown test query is received to the debugger (%x)\n",
375 Error);
376 break;
377
379 ShowMessages("err, invalid process or memory address (%x)\n",
380 Error);
381 break;
382
384 ShowMessages("err, unable to add the current thread/process to the list of trap flags. "
385 "Are you debugging multiple threads or stepping through different processes "
386 "simultaneously? (%x)\n",
387 Error);
388 break;
389
391 ShowMessages("err, process does not exists (already terminated?) (%x)\n",
392 Error);
393 break;
394
396 ShowMessages("err, the specified execution mode is invalid (%x)\n",
397 Error);
398 break;
399
401 ShowMessages("err, you cannot specify process id while the debugger is paused in the debugger mode. "
402 "You can use the '.process' or the '.thread' command to switch to the target process's "
403 "memory layout (%x)\n",
404 Error);
405 break;
406
408 ShowMessages("err, the requested buffer for storing event and conditions is larger than the pre-allocated "
409 "buffer size (%x)\nfor more information on how to resolve this issue, "
410 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
411 Error);
412 break;
413
415 ShowMessages("err, not enough pre-allocated buffer exists for storing the event. You can use the 'prealloc' "
416 "command to fix this issue by pre-allocating more buffers (%x)\nfor more information "
417 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
418 Error);
419 break;
420
422 ShowMessages("err, the requested event is considered as a \"big instant event\" and right now, there is no "
423 "pre-allocated buffer for storing it. You can use the 'prealloc' command to fix this issue by "
424 "pre-allocating big instant event buffers (%x)\nfor more information "
425 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
426 Error);
427 break;
428
430 ShowMessages("err, unable to allocate buffer for the target action (%x)\n",
431 Error);
432 break;
433
435 ShowMessages("err, not enough pre-allocated buffer exists for storing the event's action. You can use the 'prealloc' "
436 "command to fix this issue by pre-allocating more buffers (%x)\nfor more information "
437 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
438 Error);
439 break;
440
442 ShowMessages("err, the requested action is considered as a \"big instant event (action)\" and right now, there is no "
443 "pre-allocated buffer for storing it. You can use the 'prealloc' command to fix this issue by "
444 "pre-allocating big instant event's action buffers (%x)\nfor more information "
445 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
446 Error);
447 break;
448
450 ShowMessages("err, the requested buffer for storing action is larger than the pre-allocated "
451 "buffer size (%x)\nfor more information on how to resolve this issue, "
452 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
453 Error);
454 break;
455
457 ShowMessages("err, the requested optional buffer is bigger than the debuggers send/receive stack, "
458 "please select a smaller requested buffer for the target event (%x)\n",
459 Error);
460 break;
461
463 ShowMessages("err, by default HyperDbg won't allocate requested safe buffers for instant events in "
464 "the debugger mode. You can use the 'prealloc' command to allocate (regular) requested safe "
465 "buffers before running this command (%x)\nfor more information "
466 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
467 Error);
468 break;
469
471 ShowMessages("err, the requested safe buffer is bigger than regular buffers. You can use the 'prealloc' "
472 "command to allocate (big) requested safe buffers before running this command (%x)\n"
473 "for more information "
474 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
475 Error);
476 break;
477
479 ShowMessages("err, the requested buffer for storing safe buffers of the action is larger than the pre-allocated "
480 "buffer size (%x)\nfor more information on how to resolve this issue, "
481 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
482 Error);
483 break;
484
486 ShowMessages("err, unable to allocate buffer for the target requested safe buffer (%x)\n",
487 Error);
488 break;
489
491 ShowMessages("err, invalid type is specified for preactivation (%x)\n",
492 Error);
493 break;
494
496 ShowMessages("err, the '!mode' event command cannot be directly initialized in the Debugger Mode. "
497 "To avoid wasting system resources and performance issues we decided to use another "
498 "command to initialize it first then use it. You can use the 'preactivate mode' command "
499 "to preactivate this mechanism after that, you can use the '!mode' event (%x)\n",
500 Error);
501 break;
502
504 ShowMessages("err, the event(s) that you've requested are disabled, yet HyperDbg cannot remove (clear) them in "
505 "the subsequent run due to the user-mode priority buffers being at full capacity. "
506 "This typically occurs when you attempt to clear numerous events without resuming the debuggee. "
507 "Since these unserviced events remain in the queue, HyperDbg is unable to clear them. "
508 "To address this issue, you can resume the debuggee, allowing all queued events to be cleared (usually 2 to 10 seconds). "
509 "Afterward, you can pause the debuggee again and request the removal of new events (%x)\n"
510 "for more information on how to resolve this issue "
511 "please visit: https://docs.hyperdbg.org/tips-and-tricks/misc/instant-events\n",
512 Error);
513 break;
514
516 ShowMessages("err, the event cannot be applied since not all cores are locked! "
517 "If you are using the instant-event mechanism or switching between cores, this will likely halt the system. "
518 "This may be caused by a race condition, but continuing and halting the debugger might resolve it. "
519 "If the problem persists, please open an issue and provide steps to reproduce it (%x)\n",
520 Error);
521 break;
522
524 ShowMessages("err, target core is not locked! "
525 "This may be caused by a race condition, continuing and halting the debugger might resolve it. "
526 "If the problem persists, please open an issue and provide steps to reproduce it (%x)\n",
527 Error);
528 break;
529
531 ShowMessages("err, invalid physical address (%x)\n",
532 Error);
533 break;
534
535 default:
536 ShowMessages("err, error not found (%x)\n",
537 Error);
538 return FALSE;
539 break;
540 }
541
542 return TRUE;
543}
#define DEBUGGER_ERROR_ACTION_BUFFER_SIZE_IS_ZERO
error, the action buffer size is invalid
Definition ErrorCodes.h:45
#define DEBUGGER_ERROR_INSTANT_EVENT_REGULAR_PREALLOCATED_BUFFER_NOT_FOUND
error, the regular preallocated buffer not found
Definition ErrorCodes.h:441
#define DEBUGGER_ERROR_EPT_FAILED_TO_GET_PML1_ENTRY_OF_TARGET_ADDRESS
error, failed to get PML1 entry of the target address
Definition ErrorCodes.h:264
#define DEBUGGER_ERROR_UNABLE_TO_DETECT_32_BIT_OR_64_BIT_PROCESS
error, unable to get 32-bit or 64-bit of the target process
Definition ErrorCodes.h:320
#define DEBUGGER_ERROR_INSTANT_EVENT_BIG_REQUESTED_SAFE_BUFFER_NOT_FOUND
error, the requested safe buffer does not exists (big)
Definition ErrorCodes.h:489
#define DEBUGGER_ERROR_TAG_NOT_EXISTS
error, the tag not exist
Definition ErrorCodes.h:33
#define DEBUGGER_ERROR_INTERRUPT_INDEX_IS_NOT_VALID
error, the index for !interrupt command is not between 32 to 256
Definition ErrorCodes.h:81
#define DEBUGGER_ERROR_UNABLE_TO_REMOVE_HOOKS
error, could not remove the previous hook
Definition ErrorCodes.h:308
#define DEBUGGER_ERROR_INSTANT_EVENT_PREALLOCATED_BUFFER_IS_NOT_ENOUGH_FOR_EVENT_AND_CONDITIONALS
error, the preallocated buffer is not enough for storing event+conditional buffer
Definition ErrorCodes.h:435
#define DEBUGGER_ERROR_INSTANT_EVENT_REQUESTED_OPTIONAL_BUFFER_IS_BIGGER_THAN_DEBUGGERS_SEND_RECEIVE_STACK
error, the requested optional buffer is bigger than send/receive stack of the debugger
Definition ErrorCodes.h:477
#define DEBUGGER_ERROR_UNABLE_TO_ALLOCATE_REQUESTED_SAFE_BUFFER
error, enable to create requested safe buffer (cannot allocate buffer)
Definition ErrorCodes.h:501
#define DEBUGGER_ERROR_MAXIMUM_BREAKPOINT_WITHOUT_CONTINUE
error, maximum pools were used without continuing debuggee
Definition ErrorCodes.h:184
#define DEBUGGER_ERROR_INSTANT_EVENT_PREALLOCATED_BUFFER_IS_NOT_ENOUGH_FOR_REQUESTED_SAFE_BUFFER
error, the preallocated buffer is not enough for storing safe requested buffer
Definition ErrorCodes.h:495
#define DEBUGGER_ERROR_READING_MEMORY_INVALID_PARAMETER
error, for reading from memory in case of invalid parameters
Definition ErrorCodes.h:405
#define DEBUGGER_ERROR_INVALID_TEST_QUERY_INDEX
error, could not find the index of test query
Definition ErrorCodes.h:288
#define DEBUGGER_ERROR_PRE_ALLOCATED_BUFFER_IS_EMPTY
error, there is no pre-allocated buffer
Definition ErrorCodes.h:251
#define DEBUGGER_ERROR_COULD_NOT_FIND_ALLOCATION_TYPE
error, could not find the type of allocation
Definition ErrorCodes.h:282
#define DEBUGGER_ERROR_MODIFY_EVENTS_INVALID_TYPE_OF_ACTION
error, type of action (enable/disable/clear) is wrong
Definition ErrorCodes.h:127
#define DEBUGGER_ERROR_BREAKPOINT_ALREADY_EXISTS_ON_THE_ADDRESS
error, breakpoint already exists on the target address
Definition ErrorCodes.h:190
#define DEBUGGER_ERROR_EDIT_MEMORY_STATUS_INVALID_ADDRESS_BASED_ON_OTHER_PROCESS
error, an invalid address is specified based on anotehr process's cr3 in !e* or e* commands
Definition ErrorCodes.h:114
#define DEBUGGER_ERROR_INSTANT_EVENT_REGULAR_REQUESTED_SAFE_BUFFER_NOT_FOUND
error, the requested safe buffer does not exist (regular)
Definition ErrorCodes.h:483
#define DEBUGGER_ERROR_STEPPINGS_EITHER_THREAD_NOT_FOUND_OR_DISABLED
error, thread is invalid (not found) or disabled in stepping (step-in & step-out) requests
Definition ErrorCodes.h:140
#define DEBUGGER_ERROR_DETAILS_OR_SWITCH_THREAD_INVALID_PARAMETER
error, for thread switch or thread details, invalid parameter
Definition ErrorCodes.h:239
#define DEBUGGER_ERROR_UNABLE_TO_PAUSE_THE_PROCESS_THREADS
error, unable to pause the process's threads
Definition ErrorCodes.h:338
#define DEBUGGER_ERROR_INSTANT_EVENT_PREALLOCATED_BUFFER_IS_NOT_ENOUGH_FOR_ACTION_BUFFER
error, the preallocated buffer is not enough for storing action buffer
Definition ErrorCodes.h:471
#define DEBUGGER_ERROR_BREAKPOINT_ID_NOT_FOUND
error, breakpoint id not found
Definition ErrorCodes.h:196
#define DEBUGGER_ERROR_INVALID_CORE_ID
error, the core id is invalid
Definition ErrorCodes.h:69
#define DEBUGGER_ERROR_STEPPING_INVALID_PARAMETER
error, invalid parameters steppings actions
Definition ErrorCodes.h:133
#define DEBUGGER_ERROR_INVALID_REGISTER_NUMBER
error, invalid register number
Definition ErrorCodes.h:178
#define DEBUGGER_ERROR_UNABLE_TO_KILL_THE_PROCESS
error, unable to kill the target process
Definition ErrorCodes.h:326
#define DEBUGGER_ERROR_EDIT_MEMORY_STATUS_INVALID_ADDRESS_BASED_ON_CURRENT_PROCESS
error, an invalid address is specified based on current cr3 in !e* or e* commands
Definition ErrorCodes.h:106
#define DEBUGGER_ERROR_MODIFY_EVENTS_INVALID_TAG
error, invalid tag for 'events' command (tag id is unknown for kernel)
Definition ErrorCodes.h:121
#define DEBUGGER_ERROR_UNABLE_TO_GET_MODULES_OF_THE_PROCESS
error, unable to get modules
Definition ErrorCodes.h:374
#define DEBUGGER_ERROR_PREPARING_DEBUGGEE_INVALID_SERIAL_PORT
error, serial port address is invalid
Definition ErrorCodes.h:152
#define DEBUGGER_ERROR_THE_USER_DEBUGGER_NOT_ATTACHED_TO_THE_PROCESS
error, the user debugger is not attached to the target process
Definition ErrorCodes.h:350
#define DEBUGGER_ERROR_THE_TARGET_EVENT_IS_DISABLED_BUT_CANNOT_BE_CLEARED_PRIRITY_BUFFER_IS_FULL
error, the target event(s) is/are disabled but cannot clear them because the buffer of the user-mode ...
Definition ErrorCodes.h:520
#define DEBUGGER_ERROR_NOT_ALL_CORES_ARE_LOCKED_FOR_APPLYING_INSTANT_EVENT
error, not all cores are locked (probably due to a race condition in HyperDbg) in instant-event mecha...
Definition ErrorCodes.h:527
#define DEBUGGER_ERROR_DETAILS_OR_SWITCH_PROCESS_INVALID_PARAMETER
error, for process switch or process details, invalid parameter
Definition ErrorCodes.h:233
#define DEBUGGER_ERROR_UNABLE_TO_SWITCH_PROCESS_ID_OR_THREAD_ID_IS_INVALID
error, cannot switch to new thread as the process id or thread id is not found
Definition ErrorCodes.h:362
#define DEBUGGER_ERROR_THE_TRAP_FLAG_LIST_IS_FULL
error, the list of threads/process trap flag is full
Definition ErrorCodes.h:411
#define DEBUGGER_ERROR_UNABLE_TO_ATTACH_TO_AN_ALREADY_ATTACHED_PROCESS
error, user debugger already attached to this process
Definition ErrorCodes.h:344
#define DEBUGGER_ERROR_UNABLE_TO_KILL_THE_PROCESS_DOES_NOT_EXISTS
error, unable to kill the target process. process does not exists
Definition ErrorCodes.h:417
#define DEBUGGER_ERROR_UNABLE_TO_GET_CALLSTACK
error, unable to get the callstack
Definition ErrorCodes.h:380
#define DEBUGGER_ERROR_PREPARING_DEBUGGEE_INVALID_CORE_IN_REMOTE_DEBUGGE
error, invalid core selected in changing core in remote debuggee
Definition ErrorCodes.h:158
#define DEBUGGER_ERROR_INVALID_THREAD_DEBUGGING_TOKEN
error, invalid thread debugging token
Definition ErrorCodes.h:332
#define DEBUGGER_ERROR_UNABLE_TO_DETACH_AS_THERE_ARE_PAUSED_THREADS
error, cannot detach from the process as there are paused threads
Definition ErrorCodes.h:356
#define DEBUGGER_ERROR_EPT_MULTIPLE_HOOKS_IN_A_SINGLE_PAGE
error, multiple EPT Hooks or Monitors are applied on a single page
Definition ErrorCodes.h:270
#define DEBUGGER_ERROR_UNABLE_TO_CREATE_ACTION_CANNOT_ALLOCATE_BUFFER
error, enable to create action (cannot allocate buffer)
Definition ErrorCodes.h:453
#define DEBUGGER_ERROR_USING_SHORT_CIRCUITING_EVENT_WITH_POST_EVENT_MODE_IS_FORBIDDEDN
error, using short-circuiting event with post-event mode is not supported in HyperDbg
Definition ErrorCodes.h:393
#define DEBUGGER_ERROR_COULD_NOT_BUILD_THE_EPT_HOOK
error, could not build the EPT Hook
Definition ErrorCodes.h:276
#define DEBUGGER_ERROR_EVENT_IS_NOT_APPLIED
error, for event specific reasons the event is not applied
Definition ErrorCodes.h:227
#define DEBUGGER_ERROR_BREAKPOINT_ALREADY_DISABLED
error, breakpoint already disabled
Definition ErrorCodes.h:202
#define DEBUGGER_ERROR_THE_MODE_EXEC_TRAP_IS_NOT_INITIALIZED
error, the mode exec trap is not already initialized
Definition ErrorCodes.h:513
#define DEBUGGER_ERROR_UNABLE_TO_ATTACH_TO_TARGET_USER_MODE_PROCESS
error, failed to attach to the target user-mode process
Definition ErrorCodes.h:294
#define DEBUGGER_ERROR_MEMORY_TYPE_INVALID
error, memory type is invalid
Definition ErrorCodes.h:214
#define DEBUGGER_ERROR_FUNCTIONS_FOR_INITIALIZING_PEB_ADDRESSES_ARE_NOT_INITIALIZED
error, the needed routines for debugging is not initialized
Definition ErrorCodes.h:314
#define DEBUGGER_ERROR_MODE_EXECUTION_IS_INVALID
error, the execution mode is incorrect
Definition ErrorCodes.h:423
#define DEBUGGER_ERROR_INSTANT_EVENT_ACTION_BIG_PREALLOCATED_BUFFER_NOT_FOUND
error, the big preallocated buffer not found (for action)
Definition ErrorCodes.h:465
#define DEBUGGER_ERROR_COULD_NOT_FIND_PREACTIVATION_TYPE
error, could not find the type of preactivation
Definition ErrorCodes.h:507
#define DEBUGGER_ERROR_PROCESS_ID_CANNOT_BE_SPECIFIED_WHILE_APPLYING_EVENT_FROM_VMX_ROOT_MODE
error, the process id cannot be specified while the debugger is in VMX-root mode
Definition ErrorCodes.h:429
#define DEBUGGER_ERROR_EVENT_TYPE_IS_INVALID
error, the event type is unknown
Definition ErrorCodes.h:51
#define DEBUGGER_ERROR_UNKNOWN_TEST_QUERY_RECEIVED
error, unknown test query is received
Definition ErrorCodes.h:399
#define DEBUGGER_ERROR_INVALID_PHYSICAL_ADDRESS
error, invalid physical address
Definition ErrorCodes.h:540
#define DEBUGGER_ERROR_INSTANT_EVENT_BIG_PREALLOCATED_BUFFER_NOT_FOUND
error, the big preallocated buffer not found
Definition ErrorCodes.h:447
#define DEBUGGER_ERROR_MAXIMUM_BREAKPOINT_FOR_A_SINGLE_PAGE_IS_HIT
error, maximum breakpoint for a single page is hit
Definition ErrorCodes.h:245
#define DEBUGGER_ERROR_TARGET_SWITCHING_CORE_IS_NOT_LOCKED
error, switching to the target core is not possible because core is not locked (probably due to a rac...
Definition ErrorCodes.h:534
#define DEBUGGER_ERROR_EXCEPTION_INDEX_EXCEED_FIRST_32_ENTRIES
error, the index is greater than 32 in !exception command
Definition ErrorCodes.h:75
#define DEBUGGER_ERROR_INVALID_ADDRESS
error, invalid address specified for debugger
Definition ErrorCodes.h:63
#define DEBUGGER_ERROR_INSTANT_EVENT_ACTION_REGULAR_PREALLOCATED_BUFFER_NOT_FOUND
error, the regular preallocated buffer not found (for action)
Definition ErrorCodes.h:459
#define DEBUGGER_ERROR_UNABLE_TO_REMOVE_HOOKS_ENTRYPOINT_NOT_REACHED
error, failed to remove hooks as entrypoint is not reached yet
Definition ErrorCodes.h:302
#define DEBUGGER_ERROR_INVALID_ACTION_TYPE
error, invalid type of action
Definition ErrorCodes.h:39
#define DEBUGGER_ERROR_UNABLE_TO_HIDE_OR_UNHIDE_DEBUGGER
error, unable to hide the debugger and enter to transparent-mode
Definition ErrorCodes.h:87
#define DEBUGGER_ERROR_UNABLE_TO_CREATE_EVENT
error, enable to create event
Definition ErrorCodes.h:57
#define DEBUGGER_ERROR_INVALID_PROCESS_ID
error, the process id is invalid
Definition ErrorCodes.h:220
#define DEBUGGER_ERROR_PREPARING_DEBUGGEE_UNABLE_TO_SWITCH_TO_NEW_PROCESS
error, invalid process selected in changing process in remote debuggee
Definition ErrorCodes.h:165
#define DEBUGGER_ERROR_DEBUGGER_ALREADY_UHIDE
error, the debugger is already in transparent-mode
Definition ErrorCodes.h:93
#define DEBUGGER_ERROR_UNABLE_TO_SWITCH_THERE_IS_NO_THREAD_ON_THE_PROCESS
error, cannot switch to new thread the process doesn't contain an active thread
Definition ErrorCodes.h:368
#define DEBUGGER_ERROR_EDIT_MEMORY_STATUS_INVALID_PARAMETER
error, invalid parameters in !e* e* commands
Definition ErrorCodes.h:99
#define DEBUGGER_ERROR_BREAKPOINT_ALREADY_ENABLED
error, breakpoint already enabled
Definition ErrorCodes.h:208
#define DEBUGGER_ERROR_PREPARING_DEBUGGEE_INVALID_BAUDRATE
error, baud rate is invalid
Definition ErrorCodes.h:146
#define DEBUGGER_ERROR_UNABLE_TO_QUERY_COUNT_OF_PROCESSES_OR_THREADS
error, unable to query count of processes or threads
Definition ErrorCodes.h:386
#define DEBUGGER_ERROR_EPT_COULD_NOT_SPLIT_THE_LARGE_PAGE_TO_4KB_PAGES
error, in the EPT handler, it could not split the 2MB pages to 512 entries of 4 KB pages
Definition ErrorCodes.h:258
#define DEBUGGER_ERROR_PREPARING_DEBUGGEE_TO_RUN_SCRIPT
error, unable to run script in remote debuggee
Definition ErrorCodes.h:172