/[RomCheater]/trunk/RomCheater.PluginFramework/Core/PluginBase.cs
ViewVC logotype

Contents of /trunk/RomCheater.PluginFramework/Core/PluginBase.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 733 - (show annotations) (download)
Wed Jun 19 15:32:53 2013 UTC (7 years, 3 months ago) by william
File size: 7290 byte(s)
+ if no web browser provider is defined, return an EmptyProvider which uses the default system browser

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Diagnostics;
6 using RomCheater.Core;
7 using Sojaner.MemoryScanner.MemoryProviers;
8 using ManagedWinapi;
9
10 namespace RomCheater.PluginFramework.Core
11 {
12 /// <summary>
13 /// The base class for all plugins
14 /// </summary>
15 public abstract class PluginBase : IPluginBase
16 {
17 public PluginBase() { }
18
19 public virtual bool IsNullPlugin { get { return false; } }
20 public virtual bool IsGenericPlugin { get { return false; } }
21 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 return WebBrowserProvider.DefaultProvider;
33 }
34 }
35
36
37 public void ReadProcessMemory(ulong MemoryAddress, ulong bytesToRead, out ulong bytesRead, out byte[] data)
38 {
39 try
40 {
41 bytesRead = 0x00;
42 data = new byte[bytesToRead];
43 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 }
53 catch (Exception ex)
54 {
55 throw ex;
56 }
57 }
58 public void WriteProcessMemory(long MemoryAddress, byte[] bytesToWrite, out ulong bytesWritten)
59 {
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 public List<MEMORY_REGION_INFORMATION> QueryMemoryRegions()
79 {
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 #region IPluginBase Members
107 public abstract Guid ID { get; }
108 public abstract string Name { get; }
109 public abstract string Description { get; }
110 public virtual void Reload() { Reload(false); }
111 public abstract void Reload(bool silent);
112 #endregion
113 public override string ToString()
114 {
115 return string.Format("{0} [{1}]", Name, ID.ToString());
116 }
117
118 private IPEDData _peData;
119 protected IPEDData peData { get { return _peData; } }
120 public void SetPEViewerData(IPEDData peData)
121 {
122 _peData = peData;
123 if (OnPEDataUpdated != null)
124 {
125 OnPEDataUpdated.Invoke(new PEViewerDataUpdatedEventArgs(this, peData));
126 }
127 }
128
129 private Process _AcceptedProcess;
130 protected Process AcceptedProcess { get { return _AcceptedProcess; } }
131 public void SetAcceptedProcess(Process proc)
132 {
133 _AcceptedProcess = proc;
134 if (OnSelectedProcessChanged != null)
135 {
136 OnSelectedProcessChanged.Invoke(new ProcessChangedEventArgs(this, proc.Id));
137 }
138 }
139
140 private IConfigPlugin _AcceptedConfig;
141 protected IConfigPlugin AcceptedConfig { get { return _AcceptedConfig; } }
142 public void SetAcceptedConfig(IConfigPlugin config)
143 {
144 _AcceptedConfig = config;
145 if (OnSelectedConfigChanged != null)
146 {
147 OnSelectedConfigChanged.Invoke(new ConfigChangedEventArgs(this, config));
148 }
149 }
150
151
152 public void SetAcceptedProcessAndConfig(IAcceptsProcessAndConfig iapc)
153 {
154 SetAcceptedConfig(iapc.AcceptedPlugin);
155 SetAcceptedProcess(iapc.AcceptedProcess);
156 }
157
158 public event BaseEventHandler<PEViewerDataUpdatedEventArgs> OnPEDataUpdated;
159 public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged;
160 public event BaseEventHandler<ConfigChangedEventArgs> OnSelectedConfigChanged;
161
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 }
187 }

  ViewVC Help
Powered by ViewVC 1.1.22