/[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 688 - (show annotations) (download)
Mon Jun 17 09:46:51 2013 UTC (6 years, 4 months ago) by william
File size: 5894 byte(s)

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
22
23 public void ReadProcessMemory(ulong MemoryAddress, ulong bytesToRead, out ulong bytesRead, out byte[] data)
24 {
25 try
26 {
27 bytesRead = 0x00;
28 data = new byte[bytesToRead];
29 if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return; }
30 IConfigPlugin config = this.AcceptedConfig;
31 Process proc = this.AcceptedProcess;
32 using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc))
33 {
34 provider.OpenProvider();
35 provider.ReadProcessMemory(MemoryAddress, bytesToRead, out bytesRead, out data);
36 provider.CloseProvider();
37 }
38 }
39 catch (Exception ex)
40 {
41 throw ex;
42 }
43 }
44 public void WriteProcessMemory(long MemoryAddress, byte[] bytesToWrite, out ulong bytesWritten)
45 {
46 try
47 {
48 bytesWritten = 0;
49 if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return; }
50 IConfigPlugin config = this.AcceptedConfig;
51 Process proc = this.AcceptedProcess;
52 using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc))
53 {
54 provider.OpenProvider();
55 provider.WriteProcessMemory(MemoryAddress, bytesToWrite, out bytesWritten);
56 provider.CloseProvider();
57 }
58 }
59 catch (Exception ex)
60 {
61 throw ex;
62 }
63 }
64 public List<MEMORY_REGION_INFORMATION> QueryMemoryRegions()
65 {
66 if (this.AcceptedConfig == null || this.AcceptedProcess == null) { return new List<MEMORY_REGION_INFORMATION>(); }
67 IConfigPlugin config = this.AcceptedConfig;
68 Process proc = this.AcceptedProcess;
69 List<MEMORY_REGION_INFORMATION> MemoryRegions = new List<MEMORY_REGION_INFORMATION>();
70 using (GenericMemoryProvider provider = new GenericMemoryProvider(config, proc))
71 {
72 provider.OpenProvider();
73 if (this.peData != null)
74 {
75 if (this.peData.Is32bitAssembly())
76 {
77 MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86);
78 }
79 else
80 {
81 MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x64);
82 }
83 }
84 else
85 {
86 MemoryRegions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86);
87 }
88 provider.CloseProvider();
89 }
90 return MemoryRegions;
91 }
92 #region IPluginBase Members
93 public abstract Guid ID { get; }
94 public abstract string Name { get; }
95 public abstract string Description { get; }
96 public virtual void Reload() { Reload(false); }
97 public abstract void Reload(bool silent);
98 #endregion
99 public override string ToString()
100 {
101 return string.Format("{0} [{1}]", Name, ID.ToString());
102 }
103
104 private IPEDData _peData;
105 protected IPEDData peData { get { return _peData; } }
106 public void SetPEViewerData(IPEDData peData)
107 {
108 _peData = peData;
109 if (OnPEDataUpdated != null)
110 {
111 OnPEDataUpdated.Invoke(new PEViewerDataUpdatedEventArgs(this, peData));
112 }
113 }
114
115 private Process _AcceptedProcess;
116 protected Process AcceptedProcess { get { return _AcceptedProcess; } }
117 public void SetAcceptedProcess(Process proc)
118 {
119 _AcceptedProcess = proc;
120 if (OnSelectedProcessChanged != null)
121 {
122 OnSelectedProcessChanged.Invoke(new ProcessChangedEventArgs(this, proc.Id));
123 }
124 }
125
126 private IConfigPlugin _AcceptedConfig;
127 protected IConfigPlugin AcceptedConfig { get { return _AcceptedConfig; } }
128 public void SetAcceptedConfig(IConfigPlugin config)
129 {
130 _AcceptedConfig = config;
131 if (OnSelectedConfigChanged != null)
132 {
133 OnSelectedConfigChanged.Invoke(new ConfigChangedEventArgs(this, config));
134 }
135 }
136
137
138 public void SetAcceptedProcessAndConfig(IAcceptsProcessAndConfig iapc)
139 {
140 SetAcceptedConfig(iapc.AcceptedPlugin);
141 SetAcceptedProcess(iapc.AcceptedProcess);
142 }
143
144 public event BaseEventHandler<PEViewerDataUpdatedEventArgs> OnPEDataUpdated;
145 public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged;
146 public event BaseEventHandler<ConfigChangedEventArgs> OnSelectedConfigChanged;
147 }
148 }

  ViewVC Help
Powered by ViewVC 1.1.22