1 |
william |
79 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
william |
680 |
using System.Diagnostics; |
6 |
william |
889 |
using RomCheater.Interfaces; |
7 |
william |
687 |
using Sojaner.MemoryScanner.MemoryProviers; |
8 |
|
|
using ManagedWinapi; |
9 |
william |
79 |
|
10 |
|
|
namespace RomCheater.PluginFramework.Core |
11 |
|
|
{ |
12 |
|
|
/// <summary> |
13 |
|
|
/// The base class for all plugins |
14 |
|
|
/// </summary> |
15 |
william |
83 |
public abstract class PluginBase : IPluginBase |
16 |
william |
79 |
{ |
17 |
william |
86 |
public PluginBase() { } |
18 |
william |
682 |
|
19 |
|
|
public virtual bool IsNullPlugin { get { return false; } } |
20 |
|
|
public virtual bool IsGenericPlugin { get { return false; } } |
21 |
william |
696 |
public IWebBrowserInterface WebBrowserInterface |
22 |
|
|
{ |
23 |
|
|
get |
24 |
|
|
{ |
25 |
|
|
if (this.AcceptedConfig != null) |
26 |
|
|
{ |
27 |
|
|
if (this.AcceptedConfig.WebBrowserProvider != null) |
28 |
|
|
{ |
29 |
|
|
return this.AcceptedConfig.WebBrowserProvider.GetProvider(); |
30 |
|
|
} |
31 |
|
|
} |
32 |
william |
738 |
return WebBrowserProvider.Empty.GetProvider(); |
33 |
william |
696 |
} |
34 |
|
|
} |
35 |
|
|
|
36 |
william |
682 |
|
37 |
william |
688 |
public void ReadProcessMemory(ulong MemoryAddress, ulong bytesToRead, out ulong bytesRead, out byte[] data) |
38 |
william |
686 |
{ |
39 |
|
|
try |
40 |
|
|
{ |
41 |
|
|
bytesRead = 0x00; |
42 |
|
|
data = new byte[bytesToRead]; |
43 |
william |
687 |
if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return; } |
44 |
|
|
IConfigPlugin config = this.AcceptedConfig; |
45 |
|
|
Process proc = this.AcceptedProcess; |
46 |
|
|
using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc)) |
47 |
|
|
{ |
48 |
|
|
provider.OpenProvider(); |
49 |
|
|
provider.ReadProcessMemory(MemoryAddress, bytesToRead, out bytesRead, out data); |
50 |
|
|
provider.CloseProvider(); |
51 |
|
|
} |
52 |
william |
686 |
} |
53 |
|
|
catch (Exception ex) |
54 |
|
|
{ |
55 |
|
|
throw ex; |
56 |
|
|
} |
57 |
|
|
} |
58 |
william |
688 |
public void WriteProcessMemory(long MemoryAddress, byte[] bytesToWrite, out ulong bytesWritten) |
59 |
william |
687 |
{ |
60 |
|
|
try |
61 |
|
|
{ |
62 |
|
|
bytesWritten = 0; |
63 |
|
|
if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return; } |
64 |
|
|
IConfigPlugin config = this.AcceptedConfig; |
65 |
|
|
Process proc = this.AcceptedProcess; |
66 |
|
|
using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc)) |
67 |
|
|
{ |
68 |
|
|
provider.OpenProvider(); |
69 |
|
|
provider.WriteProcessMemory(MemoryAddress, bytesToWrite, out bytesWritten); |
70 |
|
|
provider.CloseProvider(); |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
catch (Exception ex) |
74 |
|
|
{ |
75 |
|
|
throw ex; |
76 |
|
|
} |
77 |
|
|
} |
78 |
william |
688 |
public List<MEMORY_REGION_INFORMATION> QueryMemoryRegions() |
79 |
william |
687 |
{ |
80 |
|
|
if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return new List<MEMORY_REGION_INFORMATION>(); } |
81 |
|
|
IConfigPlugin config = this.AcceptedConfig; |
82 |
|
|
Process proc = this.AcceptedProcess; |
83 |
|
|
List<MEMORY_REGION_INFORMATION> MemoryRegions = new List<MEMORY_REGION_INFORMATION>(); |
84 |
|
|
using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc)) |
85 |
|
|
{ |
86 |
|
|
provider.OpenProvider(); |
87 |
|
|
if (this.peData != null) |
88 |
|
|
{ |
89 |
|
|
if (this.peData.Is32bitAssembly()) |
90 |
|
|
{ |
91 |
|
|
MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86); |
92 |
|
|
} |
93 |
|
|
else |
94 |
|
|
{ |
95 |
|
|
MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x64); |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
else |
99 |
|
|
{ |
100 |
|
|
MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86); |
101 |
|
|
} |
102 |
|
|
provider.CloseProvider(); |
103 |
|
|
} |
104 |
|
|
return MemoryRegions; |
105 |
|
|
} |
106 |
william |
83 |
#region IPluginBase Members |
107 |
william |
94 |
public abstract Guid ID { get; } |
108 |
william |
83 |
public abstract string Name { get; } |
109 |
|
|
public abstract string Description { get; } |
110 |
william |
329 |
public virtual void Reload() { Reload(false); } |
111 |
|
|
public abstract void Reload(bool silent); |
112 |
william |
83 |
#endregion |
113 |
william |
86 |
public override string ToString() |
114 |
|
|
{ |
115 |
william |
94 |
return string.Format("{0} [{1}]", Name, ID.ToString()); |
116 |
william |
86 |
} |
117 |
william |
680 |
|
118 |
|
|
private IPEDData _peData; |
119 |
|
|
protected IPEDData peData { get { return _peData; } } |
120 |
|
|
public void SetPEViewerData(IPEDData peData) |
121 |
|
|
{ |
122 |
|
|
_peData = peData; |
123 |
william |
684 |
if (OnPEDataUpdated != null) |
124 |
|
|
{ |
125 |
|
|
OnPEDataUpdated.Invoke(new PEViewerDataUpdatedEventArgs(this, peData)); |
126 |
|
|
} |
127 |
william |
680 |
} |
128 |
|
|
|
129 |
|
|
private Process _AcceptedProcess; |
130 |
|
|
protected Process AcceptedProcess { get { return _AcceptedProcess; } } |
131 |
|
|
public void SetAcceptedProcess(Process proc) |
132 |
|
|
{ |
133 |
|
|
_AcceptedProcess = proc; |
134 |
william |
684 |
if (OnSelectedProcessChanged != null) |
135 |
|
|
{ |
136 |
|
|
OnSelectedProcessChanged.Invoke(new ProcessChangedEventArgs(this, proc.Id)); |
137 |
|
|
} |
138 |
william |
680 |
} |
139 |
|
|
|
140 |
|
|
private IConfigPlugin _AcceptedConfig; |
141 |
|
|
protected IConfigPlugin AcceptedConfig { get { return _AcceptedConfig; } } |
142 |
|
|
public void SetAcceptedConfig(IConfigPlugin config) |
143 |
|
|
{ |
144 |
|
|
_AcceptedConfig = config; |
145 |
william |
684 |
if (OnSelectedConfigChanged != null) |
146 |
|
|
{ |
147 |
|
|
OnSelectedConfigChanged.Invoke(new ConfigChangedEventArgs(this, config)); |
148 |
|
|
} |
149 |
william |
680 |
} |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
public void SetAcceptedProcessAndConfig(IAcceptsProcessAndConfig iapc) |
153 |
|
|
{ |
154 |
|
|
SetAcceptedConfig(iapc.AcceptedPlugin); |
155 |
|
|
SetAcceptedProcess(iapc.AcceptedProcess); |
156 |
|
|
} |
157 |
william |
684 |
|
158 |
|
|
public event BaseEventHandler<PEViewerDataUpdatedEventArgs> OnPEDataUpdated; |
159 |
|
|
public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged; |
160 |
|
|
public event BaseEventHandler<ConfigChangedEventArgs> OnSelectedConfigChanged; |
161 |
william |
689 |
|
162 |
|
|
public void RaisePluginFrameworkEvents() |
163 |
|
|
{ |
164 |
|
|
if (this.OnPEDataUpdated != null) |
165 |
|
|
{ |
166 |
|
|
if (this.peData != null) |
167 |
|
|
{ |
168 |
|
|
this.OnPEDataUpdated.Invoke(new PEViewerDataUpdatedEventArgs(this, this.peData)); |
169 |
|
|
} |
170 |
|
|
} |
171 |
|
|
if (this.OnSelectedProcessChanged != null) |
172 |
|
|
{ |
173 |
|
|
if (this.AcceptedProcess != null) |
174 |
|
|
{ |
175 |
|
|
this.OnSelectedProcessChanged.Invoke(new ProcessChangedEventArgs(this, this.AcceptedProcess.Id)); |
176 |
|
|
} |
177 |
|
|
} |
178 |
|
|
if (this.OnSelectedConfigChanged != null) |
179 |
|
|
{ |
180 |
|
|
if (this.AcceptedConfig != null) |
181 |
|
|
{ |
182 |
|
|
this.OnSelectedConfigChanged.Invoke(new ConfigChangedEventArgs(this, this.AcceptedConfig)); |
183 |
|
|
} |
184 |
|
|
} |
185 |
|
|
} |
186 |
william |
79 |
} |
187 |
|
|
} |