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 // Set the current active debugging process (thread)
33 //
35 PausePacket->ProcessId,
36 PausePacket->ThreadId,
37 PausePacket->Is32Bit,
38 TRUE);
39
40 //
41 // Perform extra tasks for pausing reasons
42 //
43 switch (PausePacket->PausingReason)
44 {
46
47 ShowMessages("the target module is loaded and a breakpoint is set to the entrypoint\n"
48 "press 'g' to reach to the entrypoint of the main module...\n");
49
50 break;
52
53 ShowMessages("\nthread: %x from process: %x intercepted\n",
54 PausePacket->ThreadId,
55 PausePacket->ProcessId);
56
57 break;
58
59 default:
60 break;
61 }
62
63 //
64 // Check if the instruction is received completely or not
65 //
66 if (PausePacket->ReadInstructionLen != MAXIMUM_INSTR_SIZE)
67 {
68 //
69 // We check if the disassembled buffer has greater size
70 // than what is retrieved
71 //
74 PausePacket->Is32Bit ? FALSE : TRUE) > PausePacket->ReadInstructionLen)
75 {
76 ShowMessages("oOh, no! there might be a misinterpretation in disassembling the current instruction\n");
77 }
78 }
79
80 if (!PausePacket->Is32Bit)
81 {
82 //
83 // Show diassembles
84 //
86 PausePacket->Rip,
88 1,
89 TRUE,
90 (PRFLAGS)&PausePacket->Rflags);
91 }
92 else
93 {
94 //
95 // Show diassembles
96 //
98 PausePacket->Rip,
100 1,
101 TRUE,
102 (PRFLAGS)&PausePacket->Rflags);
103 }
104
105 //
106 // Unpause the user debugger to get commands
107 //
110 .IsOnWaitingState == TRUE)
111 {
113 }
114}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
@ 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:468
int HyperDbgDisassembler32(unsigned char *BufferToDisassemble, UINT64 BaseAddress, UINT64 Size, UINT32 MaximumInstrDecoded, BOOLEAN ShowBranchIsTakenOrNot, PRFLAGS Rflags)
Disassemble 32 bit assemblies.
Definition disassembler.cpp:373
int HyperDbgDisassembler64(unsigned char *BufferToDisassemble, UINT64 BaseAddress, UINT64 Size, UINT32 MaximumInstrDecoded, BOOLEAN ShowBranchIsTakenOrNot, PRFLAGS Rflags)
Disassemble x64 assemblies.
Definition disassembler.cpp:333
UINT32 HyperDbgLengthDisassemblerEngine(unsigned char *BufferToDisassemble, UINT64 BuffLength, BOOLEAN Isx86_64)
Length Disassembler engine based on Zydis.
Definition disassembler.cpp:856
#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:99
#define DbgReceivedUserResponse(UserSyncObjectId)
Definition ud.h:28
RFLAGS * PRFLAGS
Definition pch.h:34
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
DEBUGGEE_PAUSING_REASON PausingReason
Definition DataTypes.h:233
UINT16 ReadInstructionLen
Definition DataTypes.h:240
UINT64 Rip
Definition DataTypes.h:230
BOOLEAN Is32Bit
Definition DataTypes.h:232
UINT64 ProcessDebuggingToken
Definition DataTypes.h:231
UINT64 Rflags
Definition DataTypes.h:236
UINT32 ThreadId
Definition DataTypes.h:235
UINT32 ProcessId
Definition DataTypes.h:234
BYTE InstructionBytesOnRip[MAXIMUM_INSTR_SIZE]
Definition DataTypes.h:239
VOID UdSetActiveDebuggingProcess(UINT64 DebuggingId, UINT32 ProcessId, UINT32 ThreadId, BOOLEAN Is32Bit, BOOLEAN IsPaused)
set the current active debugging process (thread)
Definition ud.cpp:100
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:176

Variable Documentation

◆ g_ActiveProcessDebuggingState

ACTIVE_DEBUGGING_PROCESS g_ActiveProcessDebuggingState
extern

State of active debugging thread.

362{0};

◆ g_UserSyncronizationObjectsHandleTable

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

176{0};