2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics . Contracts ;
4
4
using System . Drawing ;
5
+ using System . IO ;
5
6
using System . IO . MemoryMappedFiles ;
6
7
using System . Windows . Forms ;
7
8
using ReClassNET . Core ;
8
9
using ReClassNET . Debugger ;
10
+ using ReClassNET . Memory ;
9
11
using ReClassNET . Plugins ;
10
12
11
13
namespace LoadBinaryPlugin
@@ -18,7 +20,7 @@ public class LoadBinaryPluginExt : Plugin, ICoreProcessFunctions
18
20
19
21
private string currentFile ;
20
22
21
- private Dictionary < IntPtr , MemoryMappedFile > openFiles ;
23
+ private Dictionary < IntPtr , MemoryMappedFileInfo > openFiles ;
22
24
23
25
public override Image Icon => Properties . Resources . icon ;
24
26
@@ -29,7 +31,7 @@ public override bool Initialize(IPluginHost host)
29
31
30
32
host . Process . CoreFunctions . RegisterFunctions ( "Load Binary" , this ) ;
31
33
32
- openFiles = new Dictionary < IntPtr , MemoryMappedFile > ( ) ;
34
+ openFiles = new Dictionary < IntPtr , MemoryMappedFileInfo > ( ) ;
33
35
34
36
return true ;
35
37
}
@@ -38,17 +40,17 @@ public override void Terminate()
38
40
{
39
41
foreach ( var kv in openFiles )
40
42
{
41
- kv . Value . Dispose ( ) ;
43
+ kv . Value . File . Dispose ( ) ;
42
44
}
43
45
openFiles . Clear ( ) ;
44
46
45
47
host = null ;
46
48
}
47
49
48
- /// <summary>Gets a <see cref="MemoryMappedFile "/> by its plugin internal identifier.</summary>
50
+ /// <summary>Gets a <see cref="MemoryMappedFileInfo "/> by its plugin internal identifier.</summary>
49
51
/// <param name="id">The identifier.</param>
50
52
/// <returns>The file or null if the identifier doesn't exist.</returns>
51
- private MemoryMappedFile GetMappedFileById ( IntPtr id )
53
+ private MemoryMappedFileInfo GetMappedFileById ( IntPtr id )
52
54
{
53
55
openFiles . TryGetValue ( id , out var file ) ;
54
56
return file ;
@@ -61,9 +63,9 @@ private void LogErrorAndRemoveFile(IntPtr id, Exception ex)
61
63
{
62
64
Contract . Requires ( ex != null ) ;
63
65
64
- if ( openFiles . TryGetValue ( id , out var file ) )
66
+ if ( openFiles . TryGetValue ( id , out var info ) )
65
67
{
66
- file . Dispose ( ) ;
68
+ info . File . Dispose ( ) ;
67
69
}
68
70
69
71
openFiles . Remove ( id ) ;
@@ -94,11 +96,18 @@ public IntPtr OpenRemoteProcess(IntPtr id, ProcessAccess desiredAccess)
94
96
{
95
97
try
96
98
{
97
- var file = MemoryMappedFile . CreateFromFile ( currentFile ) ;
99
+ var mappedFile = MemoryMappedFile . CreateFromFile ( currentFile ) ;
98
100
99
- var handle = file . SafeMemoryMappedFileHandle . DangerousGetHandle ( ) ;
101
+ var handle = mappedFile . SafeMemoryMappedFileHandle . DangerousGetHandle ( ) ;
100
102
101
- openFiles . Add ( handle , file ) ;
103
+ openFiles . Add (
104
+ handle ,
105
+ new MemoryMappedFileInfo (
106
+ currentFile ,
107
+ ( int ) new FileInfo ( currentFile ) . Length ,
108
+ mappedFile
109
+ )
110
+ ) ;
102
111
103
112
return handle ;
104
113
}
@@ -118,11 +127,11 @@ public void CloseRemoteProcess(IntPtr process)
118
127
{
119
128
lock ( sync )
120
129
{
121
- if ( openFiles . TryGetValue ( process , out var file ) )
130
+ if ( openFiles . TryGetValue ( process , out var info ) )
122
131
{
123
132
openFiles . Remove ( process ) ;
124
133
125
- file . Dispose ( ) ;
134
+ info . File . Dispose ( ) ;
126
135
}
127
136
}
128
137
}
@@ -138,12 +147,12 @@ public bool ReadRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer,
138
147
{
139
148
lock ( sync )
140
149
{
141
- var file = GetMappedFileById ( process ) ;
142
- if ( file != null )
150
+ var info = GetMappedFileById ( process ) ;
151
+ if ( info != null )
143
152
{
144
153
try
145
154
{
146
- using ( var stream = file . CreateViewStream ( address . ToInt64 ( ) , size ) )
155
+ using ( var stream = info . File . CreateViewStream ( address . ToInt64 ( ) , size ) )
147
156
{
148
157
stream . Read ( buffer , 0 , size ) ;
149
158
@@ -198,6 +207,7 @@ public void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
198
207
var data = new EnumerateProcessData
199
208
{
200
209
Id = ( IntPtr ) currentFile . GetHashCode ( ) ,
210
+ Name = Path . GetFileName ( currentFile ) ,
201
211
Path = currentFile
202
212
} ;
203
213
@@ -206,13 +216,38 @@ public void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
206
216
}
207
217
}
208
218
209
- /// <summary>Not supported .</summary>
219
+ /// <summary>Reports a single module and section for the loaded file .</summary>
210
220
/// <param name="process">The process.</param>
211
221
/// <param name="callbackSection">The callback which gets called for every section.</param>
212
222
/// <param name="callbackModule">The callback which gets called for every module.</param>
213
223
public void EnumerateRemoteSectionsAndModules ( IntPtr process , EnumerateRemoteSectionCallback callbackSection , EnumerateRemoteModuleCallback callbackModule )
214
224
{
215
- // Not supported.
225
+ lock ( sync )
226
+ {
227
+ var info = GetMappedFileById ( process ) ;
228
+ if ( info != null )
229
+ {
230
+ var module = new EnumerateRemoteModuleData
231
+ {
232
+ BaseAddress = IntPtr . Zero ,
233
+ Path = info . Path ,
234
+ Size = ( IntPtr ) info . Size
235
+ } ;
236
+ callbackModule ( ref module ) ;
237
+
238
+ var section = new EnumerateRemoteSectionData
239
+ {
240
+ BaseAddress = IntPtr . Zero ,
241
+ Size = ( IntPtr ) info . Size ,
242
+ Type = SectionType . Image ,
243
+ Category = SectionCategory . Unknown ,
244
+ ModulePath = info . Path ,
245
+ Name = string . Empty ,
246
+ Protection = SectionProtection . Read
247
+ } ;
248
+ callbackSection ( ref section ) ;
249
+ }
250
+ }
216
251
}
217
252
218
253
public void ControlRemoteProcess ( IntPtr process , ControlRemoteProcessAction action )
0 commit comments