1 |
//#define DISALLOW_VERBOSE_LOGGING // when defined will disallow verbose logging for performance reasons |
2 |
//using System; |
3 |
//using System.Collections.Generic; |
4 |
//using System.Linq; |
5 |
//using System.Text; |
6 |
//using RomCheater.PluginFramework.Core; |
7 |
//using System.IO; |
8 |
//using System.Diagnostics; |
9 |
//using RomCheater.Logging; |
10 |
//using Sojaner.MemoryScanner.MemoryProviers; |
11 |
//using RomCheater.PluginFramework.Interfaces; |
12 |
|
13 |
//namespace RomCheater.CorePlugins.Config |
14 |
//{ |
15 |
// public sealed class PCSX2Config : ConfigPlugin |
16 |
// { |
17 |
// #region Configuration Memvers |
18 |
// const string PCXS2_PROCESS_MAGIC = "pcsx2"; |
19 |
// const string PCXS2_LOOKUP_MAGIC_001 = "pcsx2"; |
20 |
// const string PCXS2_LOOKUP_MAGIC_002 = "compiled on"; |
21 |
// const uint VTLB_VADDR_OFFSET_DEBUG = 0x20000000; |
22 |
// const uint VTLB_VADDR_SIZE = 0x02000000; |
23 |
// #endregion |
24 |
// public PCSX2Config() : base(false) { } |
25 |
// public PCSX2Config(bool doinit) : base(doinit) { } |
26 |
// protected override bool IsNotValidProcess(ProcContainer proc) |
27 |
// { |
28 |
// bool isDebug = false; |
29 |
// uint VTLB_RELEASE_OFFSET = 0; |
30 |
// bool notvalid = !IsValidPSX2Process(proc.ProcessInfo.Id, out isDebug, out VTLB_RELEASE_OFFSET, proc); |
31 |
|
32 |
// this.MemoryRangeStart = VTLB_RELEASE_OFFSET; |
33 |
// if (isDebug) |
34 |
// this.MemoryRangeStart = VTLB_VADDR_OFFSET_DEBUG; |
35 |
|
36 |
// this.MemoryRangeSize = VTLB_VADDR_SIZE; |
37 |
|
38 |
// if (notvalid) |
39 |
// { |
40 |
//#if !DISALLOW_VERBOSE_LOGGING |
41 |
// logger.VerboseDebug.WriteLine(" Not Allowing process {0} to be added because it was filterd out", proc.Name); |
42 |
//#endif |
43 |
// } |
44 |
// else |
45 |
// { |
46 |
//#if !DISALLOW_VERBOSE_LOGGING |
47 |
// logger.VerboseDebug.WriteLine(" Allowing process {0} to be added", proc.Name); |
48 |
//#endif |
49 |
// } |
50 |
// return notvalid; |
51 |
// } |
52 |
// #region IPluginBase Members |
53 |
// public override Guid ID |
54 |
// { |
55 |
// get |
56 |
// { |
57 |
// return new GuidGenerator(typeof(PCSX2Config).FullName).Guid; |
58 |
// } |
59 |
// } |
60 |
// public override string Name |
61 |
// { |
62 |
// get { return "PCSX2 Configuration Plugin"; } |
63 |
// } |
64 |
// public override string Description |
65 |
// { |
66 |
// get { return "This plugin provides a configuration suitable for use with PCSX2"; } |
67 |
// } |
68 |
// #endregion |
69 |
// private bool IsValidPSX2Process(int pid, out bool isDebug, out uint VTLB_RELEASE_OFFSET, ProcContainer proc) |
70 |
// { |
71 |
// bool isValid = false; |
72 |
// isDebug = false; |
73 |
// VTLB_RELEASE_OFFSET = 0; |
74 |
// try |
75 |
// { |
76 |
// Process p = null; |
77 |
|
78 |
// try |
79 |
// { |
80 |
// p = Process.GetProcessById(pid); |
81 |
// } |
82 |
// catch { return false; } |
83 |
|
84 |
// string filename = p.MainModule.FileName; |
85 |
// FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); |
86 |
//// BinaryReader r = new BinaryReader(fs); |
87 |
//// byte[] exe_check = new byte[] { |
88 |
//// 0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, |
89 |
//// 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
90 |
//// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
91 |
//// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
92 |
//// 0x0E, 0x1F, 0xBA, 0x0E, 0x00, 0xB4, 0x09, 0xCD, 0x21, 0xB8, 0x01, 0x4C, 0xCD, 0x21, 0x54, 0x68, |
93 |
//// 0x69, 0x73, 0x20, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x20, 0x63, 0x61, 0x6E, 0x6E, 0x6F, |
94 |
//// 0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6E, 0x20, 0x69, 0x6E, 0x20, 0x44, 0x4F, 0x53, 0x20, |
95 |
//// 0x6D, 0x6F, 0x64, 0x65, 0x2E |
96 |
//// }; |
97 |
//// r.BaseStream.Seek(0, SeekOrigin.Begin); |
98 |
//// byte[] data = r.ReadBytes(exe_check.Length); |
99 |
//// bool isExe = false; |
100 |
//// for (int i = 0; i < exe_check.Length; i++) { if (exe_check[i] == data[i]) { isExe = true; } else { isExe = false; } } |
101 |
//// r.Close(); |
102 |
//// if (!isExe) |
103 |
//// { |
104 |
////#if !DISALLOW_VERBOSE_LOGGING |
105 |
//// logger.VerboseDebug.WriteLine(" Process: {0} is not a valid executable file", filename); |
106 |
////#endif |
107 |
//// isValid = false; |
108 |
//// } |
109 |
//// else |
110 |
//// { |
111 |
// // check for valid pcsx2 exe |
112 |
// fs = new FileStream(filename, FileMode.Open, FileAccess.Read); |
113 |
// StreamReader sr = new StreamReader(fs); |
114 |
// string found_string = sr.ReadToEnd(); |
115 |
// if (found_string.ToLower().Contains(PCXS2_LOOKUP_MAGIC_001.ToLower()) && found_string.ToLower().Contains(PCXS2_LOOKUP_MAGIC_002.ToLower())) |
116 |
// { |
117 |
// isValid = true; |
118 |
//#if !DISALLOW_VERBOSE_LOGGING |
119 |
// logger.VerboseDebug.WriteLine(" Process: {0} found MAGIC LOOKUP {1} and {2}", filename, PCXS2_LOOKUP_MAGIC_001.ToLower(), PCXS2_LOOKUP_MAGIC_002.ToLower()); |
120 |
//#endif |
121 |
// } |
122 |
// sr.Close(); |
123 |
// // check for debug |
124 |
// fs = new FileStream(filename, FileMode.Open, FileAccess.Read); |
125 |
// sr = new StreamReader(fs); |
126 |
// found_string = sr.ReadToEnd(); |
127 |
// // DebugBreak should only be present in debug build version(s) of pcsx2 |
128 |
// if (found_string.ToLower().Contains("DebugBreak".ToLower())) |
129 |
// { |
130 |
// isDebug = true; |
131 |
//#if !DISALLOW_VERBOSE_LOGGING |
132 |
// logger.VerboseDebug.WriteLine(" Process: {0} found DebugBreak", filename); |
133 |
//#endif |
134 |
// } |
135 |
// sr.Close(); |
136 |
//// } |
137 |
// //this.IsDebugBuild = isDebug; |
138 |
// // run check to see if we have a later version with offset fixed at: 0x20000000 |
139 |
// byte[] entrypoint_data = new byte[]{ |
140 |
// 0x01, 0x80, 0x1A, 0x3C, 0x78, 0x53, 0x59, 0xFF, 0x00, 0x68, 0x19, 0x40, |
141 |
// 0x01, 0x80, 0x1A, 0x3C, 0x7C, 0x00, 0x39, 0x33, 0x21, 0xD0, 0x59, 0x03, |
142 |
// 0x40, 0x53, 0x5A, 0x8F, 0x01, 0x80, 0x19, 0x3C, 0x08, 0x00, 0x40, 0x03, |
143 |
// 0x78, 0x53, 0x39, 0xDF |
144 |
// }; |
145 |
// //uint address = ramdumper.VTLB_VADDR_OFFSET_DEBUG; |
146 |
// IAcceptsProcessAndConfig pconfig = new AcceptedProcessAndConfig(this, proc.ProcessInfo); |
147 |
// GenericMemoryProvider provider = new GenericMemoryProvider(pconfig); |
148 |
// provider.OpenProvider(); |
149 |
// int bytesReadSize; |
150 |
// byte[] check_data = new byte[entrypoint_data.Length]; |
151 |
// provider.ReadProcessMemory(VTLB_VADDR_OFFSET_DEBUG, (uint)entrypoint_data.Length, out bytesReadSize, out check_data); |
152 |
// isDebug = check_data.SequenceEqual(entrypoint_data); |
153 |
//#if !DISALLOW_VERBOSE_LOGGING |
154 |
// logger.VerboseDebug.WriteLine(" Process: {0} isDebug: {1}", filename, isDebug.ToString()); |
155 |
//#endif |
156 |
// //List<uint> addresses = new List<uint>(); |
157 |
// if (!isDebug) |
158 |
// { |
159 |
// for (int i = 0x1000; i < 0x2000; i++) |
160 |
// { |
161 |
// try |
162 |
// { |
163 |
// uint t = ((uint)i << 16) | 0x5000; |
164 |
// provider.ReadProcessMemory(t, (uint)entrypoint_data.Length, out bytesReadSize, out check_data); |
165 |
// isValid = check_data.SequenceEqual(entrypoint_data); |
166 |
// if (isValid) |
167 |
// { |
168 |
// //addresses.Add(t); |
169 |
// VTLB_RELEASE_OFFSET = t; |
170 |
//#if !DISALLOW_VERBOSE_LOGGING |
171 |
// logger.VerboseDebug.WriteLine(" Process: {0} found release build entrypoint at 0x{1:x8}", filename, t); |
172 |
//#endif |
173 |
// break; //use only the first valid value |
174 |
// } |
175 |
// } |
176 |
// catch { } |
177 |
// } |
178 |
// } |
179 |
// provider.CloseProvider(); |
180 |
// return isValid; |
181 |
// } |
182 |
// catch (System.ComponentModel.Win32Exception) { } |
183 |
// catch (Exception) { } |
184 |
// return isValid; |
185 |
// } |
186 |
// } |
187 |
//} |