Skip to content

Commit f081ba4

Browse files
committed
Moved Module and Section class to seperate files.
1 parent 2641259 commit f081ba4

File tree

8 files changed

+100
-80
lines changed

8 files changed

+100
-80
lines changed

Memory/Module.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace ReClassNET.Memory
4+
{
5+
public class Module
6+
{
7+
public IntPtr Start;
8+
public IntPtr End;
9+
public IntPtr Size;
10+
public string Name;
11+
public string Path;
12+
}
13+
}

Memory/NativeHelper.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,54 @@ public void EnumerateRemoteSectionsAndModules(IntPtr process, EnumerateRemoteSec
343343
enumerateRemoteSectionsAndModulesDelegate(process, callbackSection, callbackModule);
344344
}
345345

346+
public void EnumerateRemoteSectionsAndModules(IntPtr process, Action<Section> callbackSection, Action<Module> callbackModule)
347+
{
348+
var c1 = callbackSection == null ? (EnumerateRemoteSectionCallback)null : delegate (IntPtr baseAddress, IntPtr regionSize, string name, NativeMethods.StateEnum state, NativeMethods.AllocationProtectEnum protection, NativeMethods.TypeEnum type, string modulePath)
349+
{
350+
var section = new Section
351+
{
352+
Start = baseAddress,
353+
End = baseAddress.Add(regionSize),
354+
Size = regionSize,
355+
Name = name,
356+
State = state,
357+
Protection = protection,
358+
Type = type,
359+
ModulePath = modulePath,
360+
ModuleName = Path.GetFileName(modulePath),
361+
Category = type == NativeMethods.TypeEnum.MEM_PRIVATE ? SectionCategory.HEAP : SectionCategory.Unknown
362+
};
363+
switch (section.Name)
364+
{
365+
case ".text":
366+
case "code":
367+
section.Category = SectionCategory.CODE;
368+
break;
369+
case ".data":
370+
case "data":
371+
case ".rdata":
372+
case ".idata":
373+
section.Category = SectionCategory.DATA;
374+
break;
375+
}
376+
callbackSection(section);
377+
};
378+
379+
var c2 = callbackModule == null ? (EnumerateRemoteModuleCallback)null : delegate (IntPtr baseAddress, IntPtr size, string modulePath)
380+
{
381+
callbackModule(new Module
382+
{
383+
Start = baseAddress,
384+
End = baseAddress.Add(size),
385+
Size = size,
386+
Path = modulePath,
387+
Name = Path.GetFileName(modulePath)
388+
});
389+
};
390+
391+
EnumerateRemoteSectionsAndModules(process, c1, c2);
392+
}
393+
346394
public void DisassembleRemoteCode(IntPtr process, IntPtr address, int length, DisassembleRemoteCodeCallback remoteCodeCallback)
347395
{
348396
disassembleRemoteCodeDelegate(process, address, length, remoteCodeCallback);

Memory/NodeDissector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,18 @@ private static Type GuessPointerType(IntPtr address, MemoryBuffer memory)
116116
var section = memory.Process.GetSectionToPointer(address);
117117
if (section != null) // If the address points to a section it's valid memory.
118118
{
119-
if (section.Category == RemoteProcess.SectionCategory.CODE) // If the section contains code, it should be a function pointer.
119+
if (section.Category == SectionCategory.CODE) // If the section contains code, it should be a function pointer.
120120
{
121121
return typeof(FunctionPtrNode);
122122
}
123-
else if (section.Category == RemoteProcess.SectionCategory.DATA || section.Category == RemoteProcess.SectionCategory.HEAP) // If the section contains data, it is at least a pointer to a class or something.
123+
else if (section.Category == SectionCategory.DATA || section.Category == SectionCategory.HEAP) // If the section contains data, it is at least a pointer to a class or something.
124124
{
125125
// Check if it is a vtable. Check if the first 3 values are pointers to a code section.
126126
bool valid = true;
127127
for (var i = 0; i < 3; ++i)
128128
{
129129
var pointee = memory.Process.ReadRemoteObject<IntPtr>(address);
130-
if (memory.Process.GetSectionToPointer(pointee)?.Category != RemoteProcess.SectionCategory.CODE)
130+
if (memory.Process.GetSectionToPointer(pointee)?.Category != SectionCategory.CODE)
131131
{
132132
valid = false;
133133
break;

Memory/RemoteProcess.cs

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,6 @@ public ProcessInfo Process
3030

3131
private readonly Dictionary<IntPtr, string> rttiCache = new Dictionary<IntPtr, string>();
3232

33-
public class Module
34-
{
35-
public IntPtr Start;
36-
public IntPtr End;
37-
public string Name;
38-
public string Path;
39-
}
40-
41-
public enum SectionCategory
42-
{
43-
Unknown,
44-
CODE,
45-
DATA,
46-
HEAP
47-
}
48-
49-
public class Section
50-
{
51-
public IntPtr Start;
52-
public IntPtr End;
53-
public string Name;
54-
public SectionCategory Category;
55-
public NativeMethods.StateEnum State;
56-
public NativeMethods.AllocationProtectEnum Protection;
57-
public NativeMethods.TypeEnum Type;
58-
public string ModuleName;
59-
public string ModulePath;
60-
}
61-
6233
private readonly List<Module> modules = new List<Module>();
6334

6435
private readonly List<Section> sections = new List<Section>();
@@ -455,48 +426,7 @@ public Task UpdateProcessInformationsAsync()
455426
var newModules = new List<Module>();
456427
var newSections = new List<Section>();
457428

458-
nativeHelper.EnumerateRemoteSectionsAndModules(
459-
process.Handle,
460-
delegate (IntPtr baseAddress, IntPtr regionSize, string name, NativeMethods.StateEnum state, NativeMethods.AllocationProtectEnum protection, NativeMethods.TypeEnum type, string modulePath)
461-
{
462-
var section = new Section
463-
{
464-
Start = baseAddress,
465-
End = baseAddress.Add(regionSize),
466-
Name = name,
467-
State = state,
468-
Protection = protection,
469-
Type = type,
470-
ModulePath = modulePath,
471-
ModuleName = Path.GetFileName(modulePath),
472-
Category = type == NativeMethods.TypeEnum.MEM_PRIVATE ? SectionCategory.HEAP : SectionCategory.Unknown
473-
};
474-
switch (section.Name)
475-
{
476-
case ".text":
477-
case "code":
478-
section.Category = SectionCategory.CODE;
479-
break;
480-
case ".data":
481-
case "data":
482-
case ".rdata":
483-
case ".idata":
484-
section.Category = SectionCategory.DATA;
485-
break;
486-
}
487-
newSections.Add(section);
488-
},
489-
delegate (IntPtr baseAddress, IntPtr regionSize, string modulePath)
490-
{
491-
newModules.Add(new Module
492-
{
493-
Start = baseAddress,
494-
End = baseAddress.Add(regionSize),
495-
Path = modulePath,
496-
Name = Path.GetFileName(modulePath)
497-
});
498-
}
499-
);
429+
nativeHelper.EnumerateRemoteSectionsAndModules(process.Handle, newSections.Add, newModules.Add);
500430

501431
newModules.Sort((m1, m2) => m1.Start.CompareTo(m2.Start));
502432
newSections.Sort((s1, s2) => s1.Start.CompareTo(s2.Start));

Memory/Section.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using ReClassNET.Util;
3+
4+
namespace ReClassNET.Memory
5+
{
6+
public enum SectionCategory
7+
{
8+
Unknown,
9+
CODE,
10+
DATA,
11+
HEAP
12+
}
13+
14+
public class Section
15+
{
16+
public IntPtr Start;
17+
public IntPtr End;
18+
public IntPtr Size;
19+
public string Name;
20+
public SectionCategory Category;
21+
public NativeMethods.StateEnum State;
22+
public NativeMethods.AllocationProtectEnum Protection;
23+
public NativeMethods.TypeEnum Type;
24+
public string ModuleName;
25+
public string ModulePath;
26+
}
27+
}

ReClass.NET.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@
152152
<Compile Include="Forms\InputBytesForm.Designer.cs">
153153
<DependentUpon>InputBytesForm.cs</DependentUpon>
154154
</Compile>
155+
<Compile Include="Memory\Module.cs" />
155156
<Compile Include="Memory\NodeDissector.cs" />
157+
<Compile Include="Memory\Section.cs" />
156158
<Compile Include="Memory\UnionDataType.cs" />
157159
<Compile Include="Nodes\BoolNode.cs" />
158160
<Compile Include="Nodes\ClassUtil.cs" />

Symbols/SymbolReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Dispose()
4747
GC.SuppressFinalize(this);
4848
}
4949

50-
public static void TryResolveSymbolsForModule(RemoteProcess.Module module, string searchPath)
50+
public static void TryResolveSymbolsForModule(Module module, string searchPath)
5151
{
5252
Contract.Requires(module != null);
5353

@@ -57,7 +57,7 @@ public static void TryResolveSymbolsForModule(RemoteProcess.Module module, strin
5757
}
5858
}
5959

60-
public static SymbolReader FromModule(RemoteProcess.Module module, string searchPath)
60+
public static SymbolReader FromModule(Module module, string searchPath)
6161
{
6262
Contract.Requires(module != null);
6363

@@ -85,7 +85,7 @@ private void CreateSession()
8585
diaSession = new ComDisposableWrapper<IDiaSession>(session);
8686
}
8787

88-
public string GetSymbolString(IntPtr address, RemoteProcess.Module module)
88+
public string GetSymbolString(IntPtr address, Module module)
8989
{
9090
Contract.Requires(module != null);
9191

Symbols/SymbolStore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void ResolveSearchPath()
107107
}
108108
}
109109

110-
public void TryResolveSymbolsForModule(RemoteProcess.Module module)
110+
public void TryResolveSymbolsForModule(Module module)
111111
{
112112
Contract.Requires(module != null);
113113

@@ -140,7 +140,7 @@ public void TryResolveSymbolsForModule(RemoteProcess.Module module)
140140
}
141141
}
142142

143-
public void LoadSymbolsForModule(RemoteProcess.Module module)
143+
public void LoadSymbolsForModule(Module module)
144144
{
145145
Contract.Requires(module != null);
146146

@@ -186,7 +186,7 @@ public void LoadSymbolsFromPDB(string path)
186186
}
187187
}
188188

189-
public SymbolReader GetSymbolsForModule(RemoteProcess.Module module)
189+
public SymbolReader GetSymbolsForModule(Module module)
190190
{
191191
Contract.Requires(module != null);
192192

0 commit comments

Comments
 (0)