Skip to content

Commit 2a698d5

Browse files
committed
Added struct packing.
Implemented DebugContinueStatus.
1 parent 0fd848b commit 2a698d5

File tree

2 files changed

+53
-38
lines changed

2 files changed

+53
-38
lines changed

NativeHelper/Debugger.cpp

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,59 @@ void __stdcall DebuggerDetachFromProcess(RC_Pointer id)
2020
DebugActiveProcessStop((DWORD)id);
2121
}
2222

23-
bool __stdcall DebuggerWaitForDebugEvent(DebugEvent* info)
23+
bool __stdcall DebuggerWaitForDebugEvent(DebugEvent* evt, int timeoutInMilliseconds)
2424
{
25-
DEBUG_EVENT evt = { };
26-
if (!WaitForDebugEvent(&evt, INFINITE))
25+
DEBUG_EVENT _evt = { };
26+
if (!WaitForDebugEvent(&_evt, timeoutInMilliseconds))
2727
{
2828
return false;
2929
}
3030

31-
info->ProcessId = (RC_Pointer)evt.dwProcessId;
32-
info->ThreadId = (RC_Pointer)evt.dwThreadId;
31+
evt->ProcessId = (RC_Pointer)_evt.dwProcessId;
32+
evt->ThreadId = (RC_Pointer)_evt.dwThreadId;
3333

34-
switch (evt.dwDebugEventCode)
34+
switch (_evt.dwDebugEventCode)
3535
{
3636
case CREATE_PROCESS_DEBUG_EVENT:
37-
info->Type = DebugEventType::CreateProcess;
38-
info->CreateProcessInfo.FileHandle = evt.u.CreateProcessInfo.hFile;
39-
info->CreateProcessInfo.ProcessHandle = evt.u.CreateProcessInfo.hProcess;
37+
evt->Type = DebugEventType::CreateProcess;
38+
evt->CreateProcessInfo.FileHandle = _evt.u.CreateProcessInfo.hFile;
39+
evt->CreateProcessInfo.ProcessHandle = _evt.u.CreateProcessInfo.hProcess;
4040
break;
4141
case EXIT_PROCESS_DEBUG_EVENT:
42-
info->Type = DebugEventType::ExitProcess;
43-
info->ExitProcessInfo.ExitCode = evt.u.ExitProcess.dwExitCode;
42+
evt->Type = DebugEventType::ExitProcess;
43+
evt->ExitProcessInfo.ExitCode = _evt.u.ExitProcess.dwExitCode;
4444
break;
4545
case CREATE_THREAD_DEBUG_EVENT:
46-
info->Type = DebugEventType::CreateThread;
47-
info->CreateThreadInfo.ThreadHandle = evt.u.CreateThread.hThread;
46+
evt->Type = DebugEventType::CreateThread;
47+
evt->CreateThreadInfo.ThreadHandle = _evt.u.CreateThread.hThread;
4848
break;
4949
case EXIT_THREAD_DEBUG_EVENT:
50-
info->Type = DebugEventType::ExitThread;
51-
info->ExitThreadInfo.ExitCode = evt.u.ExitProcess.dwExitCode;
50+
evt->Type = DebugEventType::ExitThread;
51+
evt->ExitThreadInfo.ExitCode = _evt.u.ExitProcess.dwExitCode;
5252
break;
5353
case LOAD_DLL_DEBUG_EVENT:
54-
info->Type = DebugEventType::LoadDll;
55-
info->LoadDllInfo.FileHandle = evt.u.LoadDll.hFile;
56-
info->LoadDllInfo.BaseOfDll = evt.u.LoadDll.lpBaseOfDll;
54+
evt->Type = DebugEventType::LoadDll;
55+
evt->LoadDllInfo.FileHandle = _evt.u.LoadDll.hFile;
56+
evt->LoadDllInfo.BaseOfDll = _evt.u.LoadDll.lpBaseOfDll;
5757
break;
5858
case UNLOAD_DLL_DEBUG_EVENT:
59-
info->Type = DebugEventType::UnloadDll;
60-
info->UnloadDllInfo.BaseOfDll = evt.u.UnloadDll.lpBaseOfDll;
59+
evt->Type = DebugEventType::UnloadDll;
60+
evt->UnloadDllInfo.BaseOfDll = _evt.u.UnloadDll.lpBaseOfDll;
6161
break;
6262
case OUTPUT_DEBUG_STRING_EVENT:
6363
break;
6464
case EXCEPTION_DEBUG_EVENT:
65-
info->Type = DebugEventType::Exception;
65+
evt->Type = DebugEventType::Exception;
6666

67-
auto& exception = evt.u.Exception;
67+
auto& exception = _evt.u.Exception;
6868

6969
// Copy basic informations.
70-
info->ExceptionInfo.IsFirstChance = exception.dwFirstChance != 0;
71-
info->ExceptionInfo.ExceptionAddress = exception.ExceptionRecord.ExceptionAddress;
72-
info->ExceptionInfo.ExceptionCode = exception.ExceptionRecord.ExceptionCode;
73-
info->ExceptionInfo.ExceptionFlags = exception.ExceptionRecord.ExceptionFlags;
70+
evt->ExceptionInfo.IsFirstChance = exception.dwFirstChance != 0;
71+
evt->ExceptionInfo.ExceptionAddress = exception.ExceptionRecord.ExceptionAddress;
72+
evt->ExceptionInfo.ExceptionCode = exception.ExceptionRecord.ExceptionCode;
73+
evt->ExceptionInfo.ExceptionFlags = exception.ExceptionRecord.ExceptionFlags;
7474

75-
auto handle = OpenThread(THREAD_GET_CONTEXT, FALSE, evt.dwThreadId);
75+
auto handle = OpenThread(THREAD_GET_CONTEXT, FALSE, _evt.dwThreadId);
7676

7777
CONTEXT ctx = { };
7878
ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_DEBUG_REGISTERS;
@@ -81,27 +81,27 @@ bool __stdcall DebuggerWaitForDebugEvent(DebugEvent* info)
8181
// Check if breakpoint was a hardware breakpoint.
8282
if (ctx.Dr6 & 0b0001)
8383
{
84-
info->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr0;
84+
evt->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr0;
8585
}
8686
else if (ctx.Dr6 & 0b0010)
8787
{
88-
info->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr1;
88+
evt->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr1;
8989
}
9090
else if (ctx.Dr6 & 0b0100)
9191
{
92-
info->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr2;
92+
evt->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr2;
9393
}
9494
else if (ctx.Dr6 & 0b1000)
9595
{
96-
info->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr3;
96+
evt->ExceptionInfo.CausedBy = HardwareBreakpointRegister::Dr3;
9797
}
9898
else
9999
{
100-
info->ExceptionInfo.CausedBy = HardwareBreakpointRegister::InvalidRegister;
100+
evt->ExceptionInfo.CausedBy = HardwareBreakpointRegister::InvalidRegister;
101101
}
102102

103103
// Copy registers.
104-
auto& reg = info->ExceptionInfo.Registers;
104+
auto& reg = evt->ExceptionInfo.Registers;
105105
#ifdef _WIN64
106106
reg.Rax = (RC_Pointer)ctx.Rax;
107107
reg.Rbx = (RC_Pointer)ctx.Rbx;
@@ -143,10 +143,21 @@ bool __stdcall DebuggerWaitForDebugEvent(DebugEvent* info)
143143

144144
void __stdcall DebuggerContinueEvent(DebugEvent* evt)
145145
{
146-
ContinueDebugEvent((DWORD)evt->ProcessId, (DWORD)evt->ThreadId, (DWORD)evt->ContinueStatus);
146+
DWORD continueStatus = 0;
147+
switch (evt->ContinueStatus)
148+
{
149+
case DebugContinueStatus::Handled:
150+
continueStatus = DBG_CONTINUE;
151+
break;
152+
case DebugContinueStatus::NotHandled:
153+
continueStatus = DBG_EXCEPTION_NOT_HANDLED;
154+
break;
155+
}
156+
157+
ContinueDebugEvent((DWORD)evt->ProcessId, (DWORD)evt->ThreadId, continueStatus);
147158
}
148159

149-
bool __stdcall DebuggerSetHardwareBreakpoint(RC_Pointer processId, RC_Pointer address, HardwareBreakpointRegister reg, HardwareBreakpointType type, HardwareBreakpointSize size, bool set)
160+
bool __stdcall DebuggerSetHardwareBreakpoint(RC_Pointer processId, RC_Pointer address, HardwareBreakpointRegister reg, HardwareBreakpointTrigger type, HardwareBreakpointSize size, bool set)
150161
{
151162
if (reg == HardwareBreakpointRegister::InvalidRegister)
152163
{
@@ -161,11 +172,11 @@ bool __stdcall DebuggerSetHardwareBreakpoint(RC_Pointer processId, RC_Pointer ad
161172
{
162173
addressValue = (decltype(CONTEXT::Dr0))address;
163174

164-
if (type == HardwareBreakpointType::Access)
175+
if (type == HardwareBreakpointTrigger::Execute)
165176
typeValue = 0;
166-
else if (type == HardwareBreakpointType::ReadWrite)
177+
else if (type == HardwareBreakpointTrigger::Access)
167178
typeValue = 3;
168-
else if (type == HardwareBreakpointType::Write)
179+
else if (type == HardwareBreakpointTrigger::Write)
169180
typeValue = 1;
170181

171182
if (size == HardwareBreakpointSize::Size1)

NativeHelper/ReClassNET_Plugin.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ enum class DebugEventType
127127

128128
// Structures
129129

130+
#pragma pack(push, 1)
131+
130132
struct EnumerateProcessData
131133
{
132134
RC_Size Id;
@@ -256,6 +258,8 @@ struct DebugEvent
256258
};
257259
};
258260

261+
#pragma pack(pop)
262+
259263
// Callbacks
260264

261265
typedef RC_Pointer(__stdcall *RequestFunctionPtrCallback)(RequestFunction request);

0 commit comments

Comments
 (0)