HyperDbg Debugger
Loading...
Searching...
No Matches
user-listening.cpp File Reference

Listening for user debugger thread events. More...

#include "pch.h"

Functions

VOID UdHandleUserDebuggerPausing (PDEBUGGEE_UD_PAUSED_PACKET PausePacket)
 Handle pause packets from user debugger.

Variables

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
 State of active debugging thread.
DEBUGGER_SYNCRONIZATION_EVENTS_STATE g_UserSyncronizationObjectsHandleTable [DEBUGGER_MAXIMUM_SYNCRONIZATION_USER_DEBUGGER_OBJECTS]
 In debugger (not debuggee), we save the handle of the user-mode listening thread for pauses here for user debugger.

Detailed Description

Listening for user debugger thread events.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2022-01-28

Function Documentation

◆ UdHandleUserDebuggerPausing()

VOID UdHandleUserDebuggerPausing ( PDEBUGGEE_UD_PAUSED_PACKET PausePacket)

Handle pause packets from user debugger.

Parameters
PausePacket
Returns
VOID
30{
31 //
32 // Perform extra tasks for pausing reasons
33 //
34 switch (PausePacket->PausingReason)
35 {
37
38 ShowMessages("the target module is loaded and a breakpoint is set to the entrypoint\n"
39 "press 'g' to reach to the entrypoint of the main module...\n");
40
41 break;
43
44 // ShowMessages("\nthread: %x from process: %x intercepted\n",
45 // PausePacket->ThreadId,
46 // PausePacket->ProcessId);
47
48 break;
49
50 default:
51 break;
52 }
53
54 //
55 // Check if the instruction is received completely or not
56 //
57 if (PausePacket->ReadInstructionLen != MAXIMUM_INSTR_SIZE)
58 {
59 //
60 // We check if the disassembled buffer has greater size
61 // than what is retrieved
62 //
65 PausePacket->Is32Bit ? FALSE : TRUE) > PausePacket->ReadInstructionLen)
66 {
67 ShowMessages("oOh, no! there might be a misinterpretation in disassembling the current instruction\n");
68 }
69 }
70
71 //
72 // For the first thread that is paused, show the disassembly
73 //
74 if (g_ActiveProcessDebuggingState.IsPaused == FALSE || PausePacket->ThreadId == g_ActiveProcessDebuggingState.ThreadId)
75 {
76 //
77 // Set the current active debugging process (thread)
78 //
80 PausePacket->Rip,
81 PausePacket->ProcessId,
82 PausePacket->ThreadId,
83 PausePacket->Is32Bit,
84 TRUE,
85 &PausePacket->InstructionBytesOnRip[0]);
86
87 if (!PausePacket->Is32Bit)
88 {
89 //
90 // Show diassembles
91 //
92 ShowMessages("\n");
94 PausePacket->Rip,
96 1,
97 TRUE,
98 (PRFLAGS)&PausePacket->Rflags);
99 }
100 else
101 {
102 //
103 // Show diassembles
104 //
105 ShowMessages("\n");
107 PausePacket->Rip,
109 1,
110 TRUE,
111 (PRFLAGS)&PausePacket->Rflags);
112 }
113 }
114
115 //
116 // Unpause the user debugger to get commands
117 //
120 .IsOnWaitingState == TRUE)
121 {
123 }
124}
ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
State of active debugging thread.
Definition globals.h:372
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
@ DEBUGGEE_PAUSING_REASON_DEBUGGEE_GENERAL_THREAD_INTERCEPTED
Definition Connection.h:42
@ DEBUGGEE_PAUSING_REASON_DEBUGGEE_STARTING_MODULE_LOADED
Definition Connection.h:36
#define MAXIMUM_INSTR_SIZE
maximum instruction size in Intel
Definition Constants.h:470
UINT32 HyperDbgLengthDisassemblerEngine(UCHAR *BufferToDisassemble, UINT64 BuffLength, BOOLEAN Isx86_64)
Length Disassembler engine based on Zydis.
Definition disassembler.cpp:856
INT HyperDbgDisassembler64(UCHAR *BufferToDisassemble, UINT64 BaseAddress, UINT64 Size, UINT32 MaximumInstrDecoded, BOOLEAN ShowBranchIsTakenOrNot, PRFLAGS Rflags)
Disassemble x64 assemblies.
Definition disassembler.cpp:333
INT HyperDbgDisassembler32(UCHAR *BufferToDisassemble, UINT64 BaseAddress, UINT64 Size, UINT32 MaximumInstrDecoded, BOOLEAN ShowBranchIsTakenOrNot, PRFLAGS Rflags)
Disassemble 32 bit assemblies.
Definition disassembler.cpp:373
RFLAGS * PRFLAGS
Definition pch.h:34
#define DbgReceivedUserResponse(UserSyncObjectId)
Definition common.h:178
#define DEBUGGER_SYNCRONIZATION_OBJECT_USER_DEBUGGER_IS_DEBUGGER_RUNNING
An event to show whether the debugger is running or not in user-debugger.
Definition debugger.h:107
DEBUGGEE_PAUSING_REASON PausingReason
Definition DataTypes.h:266
UINT16 ReadInstructionLen
Definition DataTypes.h:273
UINT64 Rip
Definition DataTypes.h:263
BOOLEAN Is32Bit
Definition DataTypes.h:265
UINT64 ProcessDebuggingToken
Definition DataTypes.h:264
BYTE InstructionBytesOnRip[MAXIMUM_INSTR_SIZE]
Definition DataTypes.h:272
UINT64 Rflags
Definition DataTypes.h:269
UINT32 ThreadId
Definition DataTypes.h:268
UINT32 ProcessId
Definition DataTypes.h:267
VOID UdSetActiveDebuggingProcess(UINT64 DebuggingId, UINT64 Rip, UINT32 ProcessId, UINT32 ThreadId, BOOLEAN Is32Bit, BOOLEAN IsPaused, BYTE InstructionBytesOnRip[])
set the current active debugging process (thread)
Definition ud.cpp:112
DEBUGGER_SYNCRONIZATION_EVENTS_STATE g_UserSyncronizationObjectsHandleTable[DEBUGGER_MAXIMUM_SYNCRONIZATION_USER_DEBUGGER_OBJECTS]
In debugger (not debuggee), we save the handle of the user-mode listening thread for pauses here for ...
Definition globals.h:198

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

372{0};

◆ g_UserSyncronizationObjectsHandleTable

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

198{0};