Skip to content

Commit fabac9b

Browse files
committed
Removed unneeded debug events.
1 parent cd80f17 commit fabac9b

File tree

7 files changed

+43
-318
lines changed

7 files changed

+43
-318
lines changed

Debugger/DataExchange.cs

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,16 @@
33

44
namespace ReClassNET.Debugger
55
{
6-
public enum DebugEventType
7-
{
8-
CreateProcess,
9-
ExitProcess,
10-
CreateThread,
11-
ExitThread,
12-
LoadDll,
13-
UnloadDll,
14-
Exception
15-
}
16-
17-
[StructLayout(LayoutKind.Sequential, Pack = 1)]
18-
public struct CreateProcessDebugInfo
19-
{
20-
public IntPtr FileHandle;
21-
22-
public IntPtr ProcessHandle;
23-
};
24-
25-
[StructLayout(LayoutKind.Sequential, Pack = 1)]
26-
public struct ExitProcessDebugInfo
27-
{
28-
public IntPtr ExitCode;
29-
};
30-
31-
[StructLayout(LayoutKind.Sequential, Pack = 1)]
32-
public struct CreateThreadDebugInfo
33-
{
34-
public IntPtr ThreadHandle;
35-
};
36-
37-
[StructLayout(LayoutKind.Sequential, Pack = 1)]
38-
public struct ExitThreadDebugInfo
39-
{
40-
public IntPtr ExitCode;
41-
};
42-
43-
[StructLayout(LayoutKind.Sequential, Pack = 1)]
44-
public struct LoadDllDebugInfo
45-
{
46-
public IntPtr FileHandle;
47-
48-
public IntPtr BaseOfDll;
49-
};
50-
51-
[StructLayout(LayoutKind.Sequential, Pack = 1)]
52-
public struct UnloadDllDebugInfo
53-
{
54-
public IntPtr BaseOfDll;
55-
};
56-
576
[StructLayout(LayoutKind.Sequential, Pack = 1)]
587
public struct ExceptionDebugInfo
598
{
609
public IntPtr ExceptionCode;
6110
public IntPtr ExceptionFlags;
6211
public IntPtr ExceptionAddress;
12+
6313
public HardwareBreakpointRegister CausedBy;
14+
15+
[MarshalAs(UnmanagedType.I1)]
6416
public bool IsFirstChance;
6517

6618
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -108,46 +60,13 @@ public enum DebugContinueStatus
10860
}
10961

11062
[StructLayout(LayoutKind.Sequential, Pack = 1)]
111-
public struct DebugEventHeader
63+
public struct DebugEvent
11264
{
11365
public DebugContinueStatus ContinueStatus;
11466

11567
public IntPtr ProcessId;
11668
public IntPtr ThreadId;
11769

118-
public DebugEventType Type;
119-
}
120-
121-
[StructLayout(LayoutKind.Explicit, Pack = 1)]
122-
public struct DebugEventUnion
123-
{
124-
[FieldOffset(0)]
125-
public CreateProcessDebugInfo CreateProcessInfo;
126-
[FieldOffset(0)]
127-
public ExitProcessDebugInfo ExitProcessInfo;
128-
[FieldOffset(0)]
129-
public CreateThreadDebugInfo CreateThreadInfo;
130-
[FieldOffset(0)]
131-
public ExitThreadDebugInfo ExitThreadInfo;
132-
[FieldOffset(0)]
133-
public LoadDllDebugInfo LoadDllInfo;
134-
[FieldOffset(0)]
135-
public UnloadDllDebugInfo UnloadDllInfo;
136-
[FieldOffset(0)]
13770
public ExceptionDebugInfo ExceptionInfo;
13871
}
139-
140-
[StructLayout(LayoutKind.Explicit, Pack = 1)]
141-
public struct DebugEvent
142-
{
143-
[FieldOffset(0)]
144-
public DebugEventHeader Header;
145-
146-
#if WIN64
147-
[FieldOffset(24)]
148-
#else
149-
[FieldOffset(16)]
150-
#endif
151-
public DebugEventUnion Data;
152-
}
15372
}

Debugger/RemoteDebugger.Handler.cs

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using ReClassNET.Native;
7-
8-
namespace ReClassNET.Debugger
1+
namespace ReClassNET.Debugger
92
{
103
public partial class RemoteDebugger
114
{
12-
private bool HandleEvent(ref DebugEvent evt)
13-
{
14-
switch (evt.Header.Type)
15-
{
16-
case DebugEventType.CreateProcess:
17-
return HandleCreateProcessEvent(ref evt);
18-
case DebugEventType.ExitProcess:
19-
return HandleExitProcessEvent(ref evt);
20-
case DebugEventType.CreateThread:
21-
return HandleCreateThreadEvent(ref evt);
22-
case DebugEventType.ExitThread:
23-
return HandleExitThreadEvent(ref evt);
24-
case DebugEventType.LoadDll:
25-
return HandleLoadDllEvent(ref evt);
26-
case DebugEventType.UnloadDll:
27-
return HandleUnloadDllEvent(ref evt);
28-
case DebugEventType.Exception:
29-
return HandleExceptionEvent(ref evt);
30-
}
31-
32-
return true;
33-
}
34-
35-
private bool HandleCreateProcessEvent(ref DebugEvent evt)
36-
{
37-
return true;
38-
}
39-
40-
private bool HandleExitProcessEvent(ref DebugEvent evt)
41-
{
42-
return false;
43-
}
44-
45-
private bool HandleCreateThreadEvent(ref DebugEvent evt)
46-
{
47-
return true;
48-
}
49-
50-
private bool HandleExitThreadEvent(ref DebugEvent evt)
51-
{
52-
return true;
53-
}
54-
55-
private bool HandleLoadDllEvent(ref DebugEvent evt)
56-
{
57-
return true;
58-
}
59-
60-
private bool HandleUnloadDllEvent(ref DebugEvent evt)
61-
{
62-
return true;
63-
}
64-
65-
private bool HandleExceptionEvent(ref DebugEvent evt)
5+
private void HandleExceptionEvent(ref DebugEvent evt)
666
{
677
IBreakpoint current = null;
688
lock (syncBreakpoint)
699
{
70-
var causedBy = evt.Data.ExceptionInfo.CausedBy;
10+
var causedBy = evt.ExceptionInfo.CausedBy;
7111

7212
foreach (var bp in breakpoints)
7313
{
@@ -76,19 +16,13 @@ private bool HandleExceptionEvent(ref DebugEvent evt)
7616
{
7717
if (causedBy == hwbp.Register)
7818
{
79-
current = bp;
19+
current.Handler(ref evt);
20+
8021
break;
8122
}
8223
}
8324
}
8425
}
85-
86-
if (current != null)
87-
{
88-
current.Handler(ref evt);
89-
}
90-
91-
return true;
9226
}
9327
}
9428
}

Debugger/RemoteDebugger.Thread.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,24 @@ private void Run()
5656
isAttached = true;
5757

5858
var evt = new DebugEvent();
59+
5960
running = true;
6061
while (running)
6162
{
6263
if (process.CoreFunctions.AwaitDebugEvent(ref evt, 100))
6364
{
64-
evt.Header.ContinueStatus = DebugContinueStatus.Handled;
65+
evt.ContinueStatus = DebugContinueStatus.Handled;
6566

66-
if (HandleEvent(ref evt))
67-
{
68-
process.CoreFunctions.HandleDebugEvent(ref evt);
69-
}
70-
else
71-
{
72-
Terminate(false);
73-
}
67+
HandleExceptionEvent(ref evt);
68+
69+
process.CoreFunctions.HandleDebugEvent(ref evt);
7470
}
7571
else
7672
{
77-
73+
if (!process.IsValid)
74+
{
75+
Terminate(false);
76+
}
7877
}
7978
}
8079

Debugger/RemoteDebugger.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using ReClassNET.Forms;
66
using ReClassNET.Memory;
7-
using ReClassNET.Native;
87
using ReClassNET.Util;
98

109
namespace ReClassNET.Debugger
@@ -90,7 +89,7 @@ public void FindCodeByBreakpoint(IntPtr address, int size, HardwareBreakpointTri
9089

9190
BreakpointHandler handler = delegate (IBreakpoint bp, ref DebugEvent evt)
9291
{
93-
fcf.AddRecord(evt.Data.ExceptionInfo);
92+
fcf.AddRecord(evt.ExceptionInfo);
9493
};
9594

9695
var breakpoint = new HardwareBreakpoint(breakpointList[0].Address, register, trigger, (HardwareBreakpointSize)breakpointList[0].Size, handler);

NativeCore/Unix/ReClassNET_Plugin.hpp

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <algorithm>
55
#include <cstdint>
66
#include <codecvt>
7-
#include <locale>
8-
#include <cstring>
97

108
// Types
119

@@ -49,7 +47,7 @@ inline SectionProtection& operator|=(SectionProtection& lhs, SectionProtection r
4947
using T = std::underlying_type_t<SectionProtection>;
5048

5149
lhs = static_cast<SectionProtection>(static_cast<T>(lhs) | static_cast<T>(rhs));
52-
50+
5351
return lhs;
5452
}
5553

@@ -108,17 +106,6 @@ enum class HardwareBreakpointSize
108106
Size8 = 8
109107
};
110108

111-
enum class DebugEventType
112-
{
113-
CreateProcess,
114-
ExitProcess,
115-
CreateThread,
116-
ExitThread,
117-
LoadDll,
118-
UnloadDll,
119-
Exception
120-
};
121-
122109
// Structures
123110

124111
#pragma pack(push, 1)
@@ -154,38 +141,6 @@ struct EnumerateRemoteModuleData
154141
RC_UnicodeChar Path[PATH_MAXIMUM_LENGTH];
155142
};
156143

157-
struct CreateProcessDebugInfo
158-
{
159-
RC_Pointer FileHandle;
160-
RC_Pointer ProcessHandle;
161-
};
162-
163-
struct ExitProcessDebugInfo
164-
{
165-
RC_Size ExitCode;
166-
};
167-
168-
struct CreateThreadDebugInfo
169-
{
170-
RC_Pointer ThreadHandle;
171-
};
172-
173-
struct ExitThreadDebugInfo
174-
{
175-
RC_Size ExitCode;
176-
};
177-
178-
struct LoadDllDebugInfo
179-
{
180-
RC_Pointer FileHandle;
181-
RC_Pointer BaseOfDll;
182-
};
183-
184-
struct UnloadDllDebugInfo
185-
{
186-
RC_Pointer BaseOfDll;
187-
};
188-
189144
struct ExceptionDebugInfo
190145
{
191146
RC_Size ExceptionCode;
@@ -239,36 +194,25 @@ struct DebugEvent
239194
RC_Pointer ProcessId;
240195
RC_Pointer ThreadId;
241196

242-
DebugEventType Type;
243-
244-
union
245-
{
246-
CreateProcessDebugInfo CreateProcessInfo;
247-
ExitProcessDebugInfo ExitProcessInfo;
248-
CreateThreadDebugInfo CreateThreadInfo;
249-
ExitThreadDebugInfo ExitThreadInfo;
250-
LoadDllDebugInfo LoadDllInfo;
251-
UnloadDllDebugInfo UnloadDllInfo;
252-
ExceptionDebugInfo ExceptionInfo;
253-
};
197+
ExceptionDebugInfo ExceptionInfo;
254198
};
255199

256200
#pragma pack(pop)
257201

258202
// Callbacks
259203

260-
typedef void(EnumerateProcessCallback)(EnumerateProcessData* data);
204+
typedef void(__stdcall *EnumerateProcessCallback)(EnumerateProcessData* data);
261205

262-
typedef void(EnumerateRemoteSectionsCallback)(EnumerateRemoteSectionData* data);
263-
typedef void(EnumerateRemoteModulesCallback)(EnumerateRemoteModuleData* data);
206+
typedef void(__stdcall EnumerateRemoteSectionsCallback)(EnumerateRemoteSectionData* data);
207+
typedef void(__stdcall EnumerateRemoteModulesCallback)(EnumerateRemoteModuleData* data);
264208

265209
// Helpers
266210

267211
inline void MultiByteToUnicode(const char* src, RC_UnicodeChar* dst, int size)
268212
{
269213
#if _MSC_VER == 1900
270214
// VS Bug: https://connect.microsoft.com/VisualStudio/feedback/details/1348277/link-error-when-using-std-codecvt-utf8-utf16-char16-t
271-
215+
272216
auto temp = std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t>{}.from_bytes(src);
273217
#else
274218
auto temp = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(src);

0 commit comments

Comments
 (0)