-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathCoreFunctionsManager.cs
More file actions
207 lines (164 loc) · 5.63 KB
/
CoreFunctionsManager.cs
File metadata and controls
207 lines (164 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ReClassNET.Debugger;
using ReClassNET.Extensions;
using ReClassNET.Memory;
namespace ReClassNET.Core
{
public class CoreFunctionsManager : IDisposable
{
private readonly Dictionary<string, ICoreProcessFunctions> functionsRegistry = new Dictionary<string, ICoreProcessFunctions>();
private readonly InternalCoreFunctions internalCoreFunctions;
private ICoreProcessFunctions currentFunctions;
public IEnumerable<string> FunctionProviders => functionsRegistry.Keys;
public ICoreProcessFunctions CurrentFunctions => currentFunctions;
public string CurrentFunctionsProvider => functionsRegistry
.Where(kv => kv.Value == currentFunctions)
.Select(kv => kv.Key)
.FirstOrDefault();
public CoreFunctionsManager()
{
internalCoreFunctions = InternalCoreFunctions.Create();
RegisterFunctions("Default", internalCoreFunctions);
currentFunctions = internalCoreFunctions;
}
#region IDisposable Support
public void Dispose()
{
internalCoreFunctions.Dispose();
}
#endregion
public void RegisterFunctions(string provider, ICoreProcessFunctions functions)
{
Contract.Requires(provider != null);
Contract.Requires(functions != null);
functionsRegistry.Add(provider, functions);
}
public void SetActiveFunctionsProvider(string provider)
{
if (!functionsRegistry.TryGetValue(provider, out var functions))
{
throw new ArgumentException();
}
currentFunctions = functions;
}
#region Plugin Functions
public void EnumerateProcesses(Action<ProcessInfo> callbackProcess)
{
var c = callbackProcess == null ? null : (EnumerateProcessCallback)delegate (ref EnumerateProcessData data)
{
callbackProcess(new ProcessInfo(data.Id, data.Name, data.Path));
};
currentFunctions.EnumerateProcesses(c);
}
public IList<ProcessInfo> EnumerateProcesses()
{
var processes = new List<ProcessInfo>();
EnumerateProcesses(processes.Add);
return processes;
}
public void EnumerateRemoteSectionsAndModules(IntPtr process, Action<Section> callbackSection, Action<Module> callbackModule)
{
var c1 = callbackSection == null ? null : (EnumerateRemoteSectionCallback)delegate (ref EnumerateRemoteSectionData data)
{
callbackSection(new Section
{
Start = data.BaseAddress,
End = data.BaseAddress.Add(data.Size),
Size = data.Size,
Name = data.Name,
Protection = data.Protection,
Type = data.Type,
ModulePath = data.ModulePath,
ModuleName = Path.GetFileName(data.ModulePath),
Category = data.Category
});
};
var c2 = callbackModule == null ? null : (EnumerateRemoteModuleCallback)delegate (ref EnumerateRemoteModuleData data)
{
callbackModule(new Module
{
Start = data.BaseAddress,
End = data.BaseAddress.Add(data.Size),
Size = data.Size,
Path = data.Path,
Name = Path.GetFileName(data.Path)
});
};
currentFunctions.EnumerateRemoteSectionsAndModules(process, c1, c2);
}
public void EnumerateRemoteSectionsAndModules(IntPtr process, out List<Section> sections, out List<Module> modules)
{
sections = new List<Section>();
modules = new List<Module>();
EnumerateRemoteSectionsAndModules(process, sections.Add, modules.Add);
}
public IntPtr OpenRemoteProcess(IntPtr pid, ProcessAccess desiredAccess)
{
return currentFunctions.OpenRemoteProcess(pid, desiredAccess);
}
public bool IsProcessValid(IntPtr process)
{
return currentFunctions.IsProcessValid(process);
}
public void CloseRemoteProcess(IntPtr process)
{
currentFunctions.CloseRemoteProcess(process);
}
public bool ReadRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer, int offset, int size)
{
return currentFunctions.ReadRemoteMemory(process, address, ref buffer, offset, size);
}
public bool WriteRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer, int offset, int size)
{
return currentFunctions.WriteRemoteMemory(process, address, ref buffer, offset, size);
}
public void ControlRemoteProcess(IntPtr process, ControlRemoteProcessAction action)
{
currentFunctions.ControlRemoteProcess(process, action);
}
public bool AttachDebuggerToProcess(IntPtr id)
{
return currentFunctions.AttachDebuggerToProcess(id);
}
public void DetachDebuggerFromProcess(IntPtr id)
{
currentFunctions.DetachDebuggerFromProcess(id);
}
public void HandleDebugEvent(ref DebugEvent evt)
{
currentFunctions.HandleDebugEvent(ref evt);
}
public bool AwaitDebugEvent(ref DebugEvent evt, int timeoutInMilliseconds)
{
return currentFunctions.AwaitDebugEvent(ref evt, timeoutInMilliseconds);
}
public bool SetHardwareBreakpoint(IntPtr id, IntPtr address, HardwareBreakpointRegister register, HardwareBreakpointTrigger trigger, HardwareBreakpointSize size, bool set)
{
return currentFunctions.SetHardwareBreakpoint(id, address, register, trigger, size, set);
}
#endregion
#region Internal Core Functions
public bool DisassembleCode(IntPtr address, int length, IntPtr virtualAddress, bool determineStaticInstructionBytes, EnumerateInstructionCallback callback)
{
return internalCoreFunctions.DisassembleCode(address, length, virtualAddress, determineStaticInstructionBytes, callback);
}
public IntPtr InitializeInput()
{
return internalCoreFunctions.InitializeInput();
}
public Keys[] GetPressedKeys(IntPtr handle)
{
return internalCoreFunctions.GetPressedKeys(handle);
}
public void ReleaseInput(IntPtr handle)
{
internalCoreFunctions.ReleaseInput(handle);
}
#endregion
}
}