1 |
william |
414 |
#region Logging Defines |
2 |
|
|
// include this any class or method that required logging, and comment-out what is not needed |
3 |
william |
415 |
|
4 |
william |
414 |
#region Enabled logging levels |
5 |
|
|
#define LOGGING_ENABLE_INFO |
6 |
|
|
#define LOGGING_ENABLE_WARN |
7 |
|
|
#define LOGGING_ENABLE_DEBUG |
8 |
|
|
//#define LOGGING_ENABLE_VERBOSEDEBUG |
9 |
|
|
#define LOGGING_ENABLE_ERROR |
10 |
|
|
//#define LOGGING_ENABLE_VERBOSEERROR |
11 |
|
|
#define LOGGING_ENABLE_PROFILER |
12 |
|
|
#endregion |
13 |
|
|
#endregion |
14 |
|
|
//#define DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST // when defined will disable verbose logging for performance speed-up |
15 |
|
|
//#define DISALLOW_VERBOSE_LOGGING // when defined will disallow verbose logging for performance reasons |
16 |
william |
174 |
#define ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED // when defined system processes will be included in process list |
17 |
william |
150 |
using System; |
18 |
william |
79 |
using System.Collections.Generic; |
19 |
|
|
using System.Linq; |
20 |
|
|
using System.Text; |
21 |
william |
83 |
using System.Diagnostics; |
22 |
william |
88 |
using libWin32.Win32.Threading; |
23 |
william |
98 |
using RomCheater.Logging; |
24 |
william |
101 |
using System.IO; |
25 |
william |
889 |
using RomCheater.Interfaces; |
26 |
william |
812 |
using Enterprise.Logging; |
27 |
william |
829 |
using System.ComponentModel; |
28 |
william |
79 |
|
29 |
|
|
namespace RomCheater.PluginFramework.Core |
30 |
|
|
{ |
31 |
|
|
/// <summary> |
32 |
|
|
/// Base class for all configuration plugins |
33 |
|
|
/// </summary> |
34 |
william |
389 |
public abstract class ConfigPlugin : PluginBase, IConfigPlugin, IAcceptsReadOnlyMemoryRange |
35 |
william |
79 |
{ |
36 |
william |
92 |
public ConfigPlugin() : this(false) { } |
37 |
william |
389 |
public ConfigPlugin(bool doinit) : base() { SetupConfig(); if (doinit) init(); } |
38 |
william |
88 |
|
39 |
william |
696 |
private IWebBrowserProvider _WebBrowserProvider; |
40 |
|
|
public IWebBrowserProvider WebBrowserProvider |
41 |
|
|
{ |
42 |
|
|
get |
43 |
|
|
{ |
44 |
|
|
return _WebBrowserProvider; |
45 |
|
|
} |
46 |
|
|
set |
47 |
|
|
{ |
48 |
|
|
_WebBrowserProvider = value; |
49 |
|
|
} |
50 |
|
|
} |
51 |
william |
682 |
public override bool IsGenericPlugin { get { return false; } } |
52 |
|
|
public override bool IsNullPlugin { get { return false; } } |
53 |
|
|
|
54 |
william |
389 |
private void SetupConfig() |
55 |
|
|
{ |
56 |
|
|
this.ValidProcessesForPlugin = new List<ProcContainer>(); |
57 |
|
|
MemoryRangeStart = 0; |
58 |
|
|
MemoryRangeSize = int.MaxValue; |
59 |
|
|
} |
60 |
|
|
|
61 |
william |
329 |
public override void Reload(bool silent) |
62 |
william |
92 |
{ |
63 |
william |
329 |
if (!silent) |
64 |
william |
812 |
gLog.Debug.WriteLine(" Loading config for {0}...", this.ToString()); |
65 |
william |
330 |
init(silent); |
66 |
william |
329 |
if (!silent) |
67 |
william |
812 |
gLog.Debug.WriteLine(" Loaded config for {0}.", this.ToString()); |
68 |
william |
92 |
} |
69 |
william |
330 |
private void init() { init(false); } |
70 |
|
|
private void init(bool silent) |
71 |
william |
88 |
{ |
72 |
william |
329 |
// loggerflags flags = logger.GetLoggingFlags(); |
73 |
william |
150 |
|
74 |
william |
329 |
//#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST |
75 |
|
|
// ushort performance_flags = flags.Value; |
76 |
|
|
// if (flags.HasFlag(loggerflags.VERBOSE_DEBUG)) |
77 |
|
|
// { |
78 |
|
|
// performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value); |
79 |
|
|
// } |
80 |
|
|
// if (flags.HasFlag(loggerflags.VERBOSE_ERROR)) |
81 |
|
|
// { |
82 |
|
|
// performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value); |
83 |
|
|
// } |
84 |
|
|
//#endif |
85 |
|
|
// logger.SetLoggingFlags(performance_flags); |
86 |
william |
150 |
|
87 |
william |
88 |
List<ProcContainer> proc_list = new List<ProcContainer>(); |
88 |
|
|
foreach (Process proc in Process.GetProcesses()) |
89 |
|
|
{ |
90 |
william |
101 |
string proc_name = proc.ProcessName.ToLower(); |
91 |
william |
88 |
try |
92 |
|
|
{ |
93 |
|
|
bool isSystem = false; |
94 |
william |
686 |
string proc_user = libWin32.Win32.Threading.ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower(); |
95 |
william |
174 |
#if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED |
96 |
william |
88 |
if (isSystem) |
97 |
|
|
{ |
98 |
william |
151 |
#if !DISALLOW_VERBOSE_LOGGING |
99 |
william |
330 |
if(!silent) |
100 |
william |
99 |
logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name); |
101 |
william |
151 |
#endif |
102 |
william |
88 |
continue; |
103 |
|
|
} |
104 |
william |
174 |
#endif |
105 |
william |
88 |
ProcContainer container = null; |
106 |
|
|
try |
107 |
william |
101 |
{ |
108 |
william |
88 |
container = new ProcContainer(proc); |
109 |
william |
329 |
#if !DISALLOW_VERBOSE_LOGGING |
110 |
william |
330 |
if(!silent) |
111 |
william |
812 |
gLog.Verbose.Debug.WriteLine(" adding process {0} ", proc_name); |
112 |
william |
151 |
#endif |
113 |
william |
101 |
proc_list.Add(container); |
114 |
william |
88 |
} |
115 |
william |
101 |
catch (FileNotFoundException) { } |
116 |
william |
329 |
#if !DISALLOW_VERBOSE_LOGGING |
117 |
william |
300 |
catch (Exception ex) |
118 |
william |
88 |
{ |
119 |
william |
98 |
//throw; |
120 |
william |
330 |
if(!silent) |
121 |
william |
812 |
gLog.Verbose.Error.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
122 |
william |
101 |
//continue; |
123 |
william |
88 |
} |
124 |
william |
329 |
#else |
125 |
|
|
catch (Exception) { } |
126 |
|
|
#endif |
127 |
william |
88 |
} |
128 |
william |
101 |
catch (System.ComponentModel.Win32Exception ex) |
129 |
william |
88 |
{ |
130 |
william |
101 |
if (!((uint)ex.ErrorCode == 0x80004005)) |
131 |
|
|
{ |
132 |
william |
329 |
#if !DISALLOW_VERBOSE_LOGGING |
133 |
william |
330 |
if(!silent) |
134 |
william |
812 |
gLog.Verbose.Error.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
135 |
william |
151 |
#endif |
136 |
william |
329 |
} |
137 |
william |
101 |
//continue; |
138 |
william |
88 |
} |
139 |
william |
329 |
#if !DISALLOW_VERBOSE_LOGGING |
140 |
william |
300 |
catch (Exception ex) |
141 |
william |
88 |
{ |
142 |
william |
330 |
if(!silent) |
143 |
william |
812 |
gLog.Verbose.Error.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
144 |
william |
101 |
//continue; |
145 |
william |
88 |
} |
146 |
william |
329 |
#else |
147 |
|
|
catch (Exception) { } |
148 |
|
|
#endif |
149 |
william |
88 |
} |
150 |
|
|
proc_list = proc_list.OrderBy(p => p.Name).ToList(); |
151 |
william |
829 |
Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(InternalIsNotValidProcess); |
152 |
william |
88 |
proc_list.RemoveAll(predicate); |
153 |
|
|
ValidProcessesForPlugin = proc_list; |
154 |
william |
151 |
//logger.SetLoggingFlags(flags); // reset flags |
155 |
william |
88 |
} |
156 |
|
|
|
157 |
william |
829 |
private bool InternalIsNotValidProcess(ProcContainer p) |
158 |
|
|
{ |
159 |
|
|
bool internal_valid = true; |
160 |
|
|
// determinie if process is valid (for 32/64 bit) |
161 |
|
|
try |
162 |
|
|
{ |
163 |
|
|
var proc_module = p.ProcessInfo.MainModule; |
164 |
|
|
} |
165 |
|
|
catch (Win32Exception ex) |
166 |
|
|
{ |
167 |
|
|
if (ex.Message.ToLower() == "A 32 bit processes cannot access modules of a 64 bit process.".ToLower()) |
168 |
|
|
{ |
169 |
|
|
if (IntPtr.Size != 8) |
170 |
|
|
{ |
171 |
|
|
// our process is 32-bit |
172 |
|
|
gLog.Warn.WriteLine("Cannout open 64-bit process: '{0}' -- use the 64-bit version RomCheater", p.ProcessInfo.ProcessName); |
173 |
|
|
internal_valid = false; |
174 |
|
|
} |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
|
if (internal_valid) { return IsNotValidProcess(p); } |
178 |
|
|
return true; // we are saying that the process IS NOT valid |
179 |
|
|
} |
180 |
william |
88 |
protected abstract bool IsNotValidProcess(ProcContainer p); |
181 |
|
|
|
182 |
william |
83 |
#region IConfigPlugin Members |
183 |
william |
88 |
public List<ProcContainer> ValidProcessesForPlugin { get; protected set; } |
184 |
william |
94 |
public override Guid ID |
185 |
william |
86 |
{ |
186 |
|
|
get { return new Guid(); } |
187 |
|
|
} |
188 |
|
|
public override string Name |
189 |
|
|
{ |
190 |
|
|
get |
191 |
|
|
{ |
192 |
|
|
return "Unknown Config Plugin"; |
193 |
|
|
} |
194 |
|
|
} |
195 |
|
|
public override string Description |
196 |
|
|
{ |
197 |
|
|
get |
198 |
|
|
{ |
199 |
|
|
return ""; |
200 |
|
|
} |
201 |
william |
682 |
} |
202 |
william |
83 |
#endregion |
203 |
william |
389 |
#region IAcceptsReadOnlyMemoryRange members |
204 |
william |
590 |
public virtual ulong MemoryRangeStart { get; protected set; } |
205 |
|
|
public virtual ulong MemoryRangeSize { get; protected set; } |
206 |
william |
389 |
#endregion |
207 |
william |
399 |
|
208 |
|
|
#region ISearchInProgress members |
209 |
|
|
private ISearchInProgress sip = null; |
210 |
|
|
public bool SearchInProgess { get { return (sip == null) ? false : sip.SearchInProgess; } } |
211 |
william |
444 |
public Guid SearchGuid { get { return (sip == null) ? Guid.Empty : sip.SearchGuid; } } |
212 |
william |
399 |
#endregion |
213 |
|
|
|
214 |
|
|
#region IAcceptsMemorySearch Members |
215 |
|
|
public void SetMemorySearchReference(ISearchInProgress sip) |
216 |
|
|
{ |
217 |
|
|
this.sip = sip; |
218 |
|
|
} |
219 |
|
|
#endregion |
220 |
william |
79 |
} |
221 |
|
|
} |