ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.CorePlugins/Config/PCSX2Config.cs
(Generate patch)

Comparing trunk/RomCheater.CorePlugins/Config/PCSX2Config.cs (file contents):
Revision 146 by william, Thu May 10 11:31:05 2012 UTC vs.
Revision 147 by william, Sun May 27 23:05:18 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines