3
3
using System . Diagnostics . Contracts ;
4
4
using System . Drawing ;
5
5
using System . IO . MemoryMappedFiles ;
6
- using System . Runtime . InteropServices ;
7
6
using System . Windows . Forms ;
7
+ using ReClassNET . Core ;
8
+ using ReClassNET . Debugger ;
8
9
using ReClassNET . Memory ;
9
10
using ReClassNET . Plugins ;
10
- using RGiesecke . DllExport ;
11
- using static ReClassNET . Memory . NativeHelper ;
12
11
13
12
namespace LoadBinaryPlugin
14
13
{
15
- public class LoadBinaryPluginExt : Plugin
14
+ public class LoadBinaryPluginExt : Plugin , ICoreProcessFunctions
16
15
{
17
- private static object sync = new object ( ) ;
16
+ private object sync = new object ( ) ;
18
17
19
- private static IPluginHost host ;
18
+ private IPluginHost host ;
20
19
21
- private static string currentFile ;
20
+ private string currentFile ;
22
21
23
- private static Dictionary < IntPtr , MemoryMappedFile > openFiles ;
22
+ private Dictionary < IntPtr , MemoryMappedFile > openFiles ;
24
23
25
24
public override Image Icon => Properties . Resources . icon ;
26
25
@@ -35,7 +34,9 @@ public override bool Initialize(IPluginHost host)
35
34
throw new ArgumentNullException ( nameof ( host ) ) ;
36
35
}
37
36
38
- LoadBinaryPluginExt . host = host ;
37
+ this . host = host ;
38
+
39
+ host . Process . CoreFunctions . RegisterFunctions ( "Load Binary" , this ) ;
39
40
40
41
openFiles = new Dictionary < IntPtr , MemoryMappedFile > ( ) ;
41
42
@@ -56,7 +57,7 @@ public override void Terminate()
56
57
/// <summary>Gets a <see cref="MemoryMappedFile"/> by its plugin internal identifier.</summary>
57
58
/// <param name="id">The identifier.</param>
58
59
/// <returns>The file or null if the identifier doesn't exist.</returns>
59
- private static MemoryMappedFile GetMappedFileById ( IntPtr id )
60
+ private MemoryMappedFile GetMappedFileById ( IntPtr id )
60
61
{
61
62
MemoryMappedFile file ;
62
63
openFiles . TryGetValue ( id , out file ) ;
@@ -66,7 +67,7 @@ private static MemoryMappedFile GetMappedFileById(IntPtr id)
66
67
/// <summary>Logs the exception and removes the file.</summary>
67
68
/// <param name="id">The identifier.</param>
68
69
/// <param name="ex">The exception.</param>
69
- private static void LogErrorAndRemoveFile ( IntPtr id , Exception ex )
70
+ private void LogErrorAndRemoveFile ( IntPtr id , Exception ex )
70
71
{
71
72
Contract . Requires ( ex != null ) ;
72
73
@@ -84,8 +85,7 @@ private static void LogErrorAndRemoveFile(IntPtr id, Exception ex)
84
85
/// <summary>Queries if the file is valid.</summary>
85
86
/// <param name="process">The file to check.</param>
86
87
/// <returns>True if the file is valid, false if not.</returns>
87
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
88
- public static bool IsProcessValid ( IntPtr process )
88
+ public bool IsProcessValid ( IntPtr process )
89
89
{
90
90
lock ( sync )
91
91
{
@@ -97,8 +97,7 @@ public static bool IsProcessValid(IntPtr process)
97
97
/// <param name="pid">The file id.</param>
98
98
/// <param name="desiredAccess">The desired access. (ignored)</param>
99
99
/// <returns>A plugin internal handle to the file.</returns>
100
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
101
- private static IntPtr OpenRemoteProcess ( IntPtr id , ProcessAccess desiredAccess )
100
+ public IntPtr OpenRemoteProcess ( IntPtr id , ProcessAccess desiredAccess )
102
101
{
103
102
lock ( sync )
104
103
{
@@ -126,8 +125,7 @@ private static IntPtr OpenRemoteProcess(IntPtr id, ProcessAccess desiredAccess)
126
125
127
126
/// <summary>Closes the file.</summary>
128
127
/// <param name="process">The file to close.</param>
129
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
130
- private static void CloseRemoteProcess ( IntPtr process )
128
+ public void CloseRemoteProcess ( IntPtr process )
131
129
{
132
130
lock ( sync )
133
131
{
@@ -144,11 +142,11 @@ private static void CloseRemoteProcess(IntPtr process)
144
142
/// <summary>Reads memory of the file.</summary>
145
143
/// <param name="process">The process to read from.</param>
146
144
/// <param name="address">The address to read from.</param>
147
- /// <param name="buffer">The buffer to read into.</param>
145
+ /// <param name="buffer">[out] The buffer to read into.</param>
146
+ /// <param name="offset">The offset into the buffer.</param>
148
147
/// <param name="size">The size of the memory to read.</param>
149
148
/// <returns>True if it succeeds, false if it fails.</returns>
150
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
151
- private static bool ReadRemoteMemory ( IntPtr process , IntPtr address , IntPtr buffer , int size )
149
+ public bool ReadRemoteMemory ( IntPtr process , IntPtr address , ref byte [ ] buffer , int offset , int size )
152
150
{
153
151
lock ( sync )
154
152
{
@@ -159,10 +157,7 @@ private static bool ReadRemoteMemory(IntPtr process, IntPtr address, IntPtr buff
159
157
{
160
158
using ( var stream = file . CreateViewStream ( address . ToInt64 ( ) , size ) )
161
159
{
162
- var tempBuffer = new byte [ size ] ;
163
- stream . Read ( tempBuffer , 0 , size ) ;
164
-
165
- Marshal . Copy ( tempBuffer , 0 , buffer , size ) ;
160
+ stream . Read ( buffer , 0 , size ) ;
166
161
167
162
return true ;
168
163
}
@@ -184,21 +179,20 @@ private static bool ReadRemoteMemory(IntPtr process, IntPtr address, IntPtr buff
184
179
/// <summary>Not supported.</summary>
185
180
/// <param name="process">The file to write to.</param>
186
181
/// <param name="address">The address to write to.</param>
187
- /// <param name="buffer">The memory to write.</param>
182
+ /// <param name="buffer">[in] The memory to write.</param>
183
+ /// <param name="offset">The offset into the buffer.</param>
188
184
/// <param name="size">The size of the memory to write.</param>
189
185
/// <returns>True if it succeeds, false if it fails.</returns>
190
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
191
- private static bool WriteRemoteMemory ( IntPtr process , IntPtr address , IntPtr buffer , int size )
186
+ public bool WriteRemoteMemory ( IntPtr process , IntPtr address , ref byte [ ] buffer , int offset , int size )
192
187
{
193
- // No write support .
188
+ // Not supported .
194
189
195
190
return false ;
196
191
}
197
192
198
193
/// <summary>Opens a file browser dialog and reports the selected file.</summary>
199
194
/// <param name="callbackProcess">The callback which gets called for the selected file.</param>
200
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
201
- private static void EnumerateProcesses ( EnumerateProcessCallback callbackProcess )
195
+ public void EnumerateProcesses ( Action < Tuple < IntPtr , string > > callbackProcess )
202
196
{
203
197
if ( callbackProcess == null )
204
198
{
@@ -213,13 +207,7 @@ private static void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
213
207
{
214
208
currentFile = ofd . FileName ;
215
209
216
- var data = new EnumerateProcessData
217
- {
218
- Id = ( IntPtr ) currentFile . GetHashCode ( ) ,
219
- Path = currentFile
220
- } ;
221
-
222
- callbackProcess ( ref data ) ;
210
+ callbackProcess ( Tuple . Create ( ( IntPtr ) currentFile . GetHashCode ( ) , currentFile ) ) ;
223
211
}
224
212
}
225
213
}
@@ -228,10 +216,45 @@ private static void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
228
216
/// <param name="process">The process.</param>
229
217
/// <param name="callbackSection">The callback which gets called for every section.</param>
230
218
/// <param name="callbackModule">The callback which gets called for every module.</param>
231
- [ DllExport ( CallingConvention = CallingConvention . StdCall ) ]
232
- private static void EnumerateRemoteSectionsAndModules ( IntPtr process , EnumerateRemoteSectionCallback callbackSection , EnumerateRemoteModuleCallback callbackModule )
219
+ public void EnumerateRemoteSectionsAndModules ( IntPtr process , Action < Section > callbackSection , Action < Module > callbackModule )
220
+ {
221
+ // Not supported.
222
+ }
223
+
224
+ public void ControlRemoteProcess ( IntPtr process , ControlRemoteProcessAction action )
225
+ {
226
+ // Not supported.
227
+ }
228
+
229
+ public bool AttachDebuggerToProcess ( IntPtr id )
230
+ {
231
+ // Not supported.
232
+
233
+ return false ;
234
+ }
235
+
236
+ public void DetachDebuggerFromProcess ( IntPtr id )
237
+ {
238
+ // Not supported.
239
+ }
240
+
241
+ public bool AwaitDebugEvent ( ref DebugEvent evt , int timeoutInMilliseconds )
242
+ {
243
+ // Not supported.
244
+
245
+ return false ;
246
+ }
247
+
248
+ public void HandleDebugEvent ( ref DebugEvent evt )
233
249
{
234
- // No modules and sections here.
250
+ // Not supported.
251
+ }
252
+
253
+ public bool SetHardwareBreakpoint ( IntPtr id , IntPtr address , HardwareBreakpointRegister register , HardwareBreakpointTrigger trigger , HardwareBreakpointSize size , bool set )
254
+ {
255
+ // Not supported.
256
+
257
+ return false ;
235
258
}
236
259
}
237
260
}
0 commit comments