/[RomCheater]/trunk/RomCheater/Main.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 270 - (hide annotations) (download)
Sun Jun 3 20:57:44 2012 UTC (9 years, 4 months ago) by william
File size: 14108 byte(s)

1 william 99 #define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL
2 william 158 #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden
3 william 99 using System;
4 william 5 using System.Collections.Generic;
5     using System.ComponentModel;
6     using System.Data;
7     using System.Drawing;
8     using System.Linq;
9     using System.Text;
10     using System.Windows.Forms;
11 william 17 using RomCheater.Logging;
12 william 34 using RomCheater.Properties;
13     using RomCheater.UserSettingsSupport;
14 william 83 using RomCheater.PluginFramework.Core;
15 william 86 using System.Diagnostics;
16 william 87 using RomCheater.PluginFramework.Interfaces;
17 william 144 using WeifenLuo.WinFormsUI.Docking;
18 william 146 using RomCheater.Docking;
19 william 152 using System.IO;
20 william 159 using Sojaner.MemoryScanner;
21 william 196 using RomCheater.PluginFramework.Events;
22 william 5
23     namespace RomCheater
24     {
25 william 13 public partial class Main : Form
26 william 5 {
27 william 152 private bool m_bSaveLayout = true;
28 william 196 private Process SelectedProcess = null;
29 william 144 private DeserializeDockContent m_deserializeDockContent;
30     private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
31 william 147 private FloatingAboutBox m_AboutBox = new FloatingAboutBox();
32 william 148 private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog();
33     private PIDSelector m_PIDSelector = new PIDSelector();
34 william 196 private FloatingMemoryView m_memoryview = new FloatingMemoryView();
35 william 218 private FloatingDataTypeConverter m_typeconverter = new FloatingDataTypeConverter();
36 william 227 private FloatingMemorySearcher m_memsearcher = new FloatingMemorySearcher();
37 william 144 //private bool log_window_expanded = false;
38     //private double log_window_splitter_default_position = 1.4045;
39 william 86 PluginLoader loader = null;
40 william 87 IConfigPlugin ConfigPlugin = null;
41     IInputPlugin InputPlugin = null;
42     IWindowPlugin WindowPlugin = null;
43 william 146 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
44 william 20 private const string t = "RomCheater";
45 william 17 #region LogWriterSupport
46     static LogWriter _LoggerInstance;
47     static LogWriter LoggerInstance
48     {
49     get { return _LoggerInstance; }
50     set { _LoggerInstance = value; }
51     }
52     #endregion
53    
54    
55 william 196 private void OnProcessChanged(ProcessChangedEventArgs e)
56 william 151 {
57 william 228 if (m_memsearcher.SearchInProgess)
58     {
59     DialogResult result = MessageBox.Show("Do you want to start a new search with the selected process?", "A memory search is currently in progress", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
60     if (result != DialogResult.Yes || result != DialogResult.OK) { return; }
61     m_memsearcher = null; //free memory used by the memory searcher
62     m_memsearcher = new FloatingMemorySearcher();
63     }
64 william 153 SelectedProcess = Process.GetProcessById(e.ProcessID);
65 william 196 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
66 william 245 m_RamDump.AcceptedProcess = SelectedProcess;
67 william 196
68 william 244 m_memoryview.AcceptedPlugin = this.ConfigPlugin;
69 william 196 m_memoryview.AcceptedProcess = SelectedProcess;
70 william 227
71 william 244 m_memsearcher.AcceptedPlugin = this.ConfigPlugin;
72 william 227 m_memsearcher.AcceptedProcess = SelectedProcess;
73 william 151 }
74    
75 william 144 #region Dock Support
76     private IDockContent GetContentFromPersistString(string persistString)
77     {
78 william 228 if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
79     if (persistString == typeof(FloatingRamDumperDialog).ToString()) { return m_RamDump; }
80     if (persistString == typeof(PIDSelector).ToString()) { return m_PIDSelector; }
81     if (persistString == typeof(FloatingMemoryView).ToString()) { return m_memoryview; }
82     if (persistString == typeof(FloatingDataTypeConverter).ToString()) { return m_typeconverter; }
83     if (persistString == typeof(FloatingMemorySearcher).ToString()) { return m_memsearcher; }
84     else { return null; }
85 william 144 }
86     public void SetupDocks()
87     {
88     m_LogWindow = new FloatingLogWindow();
89 william 147 m_AboutBox = new FloatingAboutBox();
90 william 148 m_RamDump = new FloatingRamDumperDialog();
91     m_PIDSelector = new PIDSelector();
92 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
93     m_memoryview = new FloatingMemoryView();
94 william 218 m_typeconverter = new FloatingDataTypeConverter();
95 william 227 m_memsearcher = new FloatingMemorySearcher();
96 william 144 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
97     }
98     public void ShowDocks()
99     {
100     ShowLogWindow();
101 william 152 //ShowAboutBox();
102 william 148 ShowRamDump();
103 william 196 ShowMemoryView();
104 william 148 ShowPidSelector();
105 william 218 ShowDataTypeConverter();
106 william 227 ShowMemorySearch();
107 william 144 }
108     public void ShowLogWindow()
109 william 218 {
110     if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
111 william 263 LoggerInstance = m_LogWindow.Logwriter;
112 william 264 LoggerInstance.CreateNewLog(false);
113 william 152 m_LogWindow.Show(dockPanel, DockState.DockBottom);
114 william 263
115 william 144 }
116 william 147 public void ShowAboutBox()
117     {
118 william 218 if (m_AboutBox == null || m_AboutBox.IsDisposed) { m_AboutBox = new FloatingAboutBox(); }
119 william 148 m_AboutBox.ShowDialog();
120 william 147 }
121 william 148 public void ShowRamDump()
122     {
123 william 218 load_plugins();
124 william 153 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
125 william 201 m_RamDump.AcceptedProcess = SelectedProcess;
126 william 196 m_RamDump.Show(dockPanel);
127 william 148 }
128 william 196 public void ShowMemoryView()
129     {
130 william 218 load_plugins();
131 william 196 m_memoryview = new FloatingMemoryView(ConfigPlugin);
132 william 201 m_memoryview.AcceptedProcess = SelectedProcess;
133 william 196 m_memoryview.Show(dockPanel);
134     }
135 william 148 public void ShowPidSelector()
136     {
137 william 218 load_plugins();
138 william 148 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
139     m_PIDSelector = new PIDSelector(ConfigPlugin);
140 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
141 william 148 m_PIDSelector.Show(dockPanel);
142     }
143 william 218 public void ShowDataTypeConverter()
144     {
145     if (m_typeconverter == null || m_typeconverter.IsDisposed) { m_typeconverter = new FloatingDataTypeConverter(); }
146     m_typeconverter.Show(dockPanel, DockState.DockRightAutoHide);
147     }
148 william 227 public void ShowMemorySearch()
149     {
150     load_plugins();
151     m_memsearcher = new FloatingMemorySearcher(ConfigPlugin);
152     m_memsearcher.AcceptedProcess = SelectedProcess;
153     m_memsearcher.Show(dockPanel);
154     }
155 william 144 #endregion
156    
157    
158 william 117 public Main() : this(false) { }
159     public Main(bool no_console_redirect)
160 william 5 {
161     InitializeComponent();
162 william 158 #if SHOW_DEBUG_MENU
163     mnuDebug.Visible = true;
164     #else
165     mnuDebug.Visible = false;
166     #endif
167 william 83 load_loggerflags();
168 william 144 SetupDocks();
169     LoggerInstance = m_LogWindow.Logwriter;
170 william 23 LoggerInstance.CreateNewLog(false);
171 william 112 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
172 william 87 load_plugins();
173 william 117 if (no_console_redirect)
174     LoggerInstance.RedirectConsoleOutput = false;
175 william 158
176    
177 william 144
178 william 5 }
179 william 83 private void load_loggerflags()
180     {
181 william 111 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
182 william 99 #if FORCE_ALL_LOGGING_FLAGS
183     logger.SetLoggingFlags(loggerflags.ALL);
184     #endif
185 william 83 }
186 william 87 private void load_plugins()
187     {
188     loader = new PluginLoader();
189     loader.LoadPlugins();
190 william 83
191 william 87 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
192     if (ConfigPlugin != null)
193     logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
194     InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
195     if (InputPlugin != null)
196     logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
197     WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
198     if (WindowPlugin != null)
199     logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
200    
201 william 153 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
202     m_RamDump.AcceptedPlugin = ConfigPlugin;
203 william 267 m_memoryview.AcceptedPlugin = ConfigPlugin;
204     m_memsearcher.AcceptedPlugin = ConfigPlugin;
205    
206 william 153 if (this.SelectedProcess != null)
207 william 267 {
208 william 153 m_RamDump.AcceptedProcess = SelectedProcess;
209 william 267 m_memoryview.AcceptedProcess = SelectedProcess;
210     m_memsearcher.AcceptedProcess = SelectedProcess;
211     }
212 william 152
213 william 87 }
214    
215 william 14 private void mnuItemExit_Click(object sender, EventArgs e)
216     {
217     this.Close();
218     }
219 william 16
220 william 17
221     private void Main_Load(object sender, EventArgs e)
222 william 144 {
223 william 152
224 william 17 }
225 william 63
226     private void mnuItemConfig_Click(object sender, EventArgs e)
227     {
228 william 86 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
229 william 63 dlg.ShowDialog();
230 william 270 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
231 william 92 // reload plugins
232     load_plugins();
233 william 270
234 william 63 }
235 william 69
236     private void mnuItemOpenProcess_Click(object sender, EventArgs e)
237     {
238 william 148 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
239     //PIDSelector selector = new PIDSelector(ConfigPlugin);
240     //selector.ShowDialog();
241 william 69 }
242 william 104
243 william 144 private void Main_Shown(object sender, EventArgs e)
244 william 104 {
245 william 152 //dockPanel.SuspendLayout(true);
246     //ShowDocks();
247     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
248     if (File.Exists(configFile))
249     {
250     try
251     {
252     dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
253     }
254 william 177 catch (Exception)
255 william 152 {
256     this.Controls.Remove(dockPanel);
257     dockPanel = new DockPanel();
258     dockPanel.Dock = DockStyle.Fill;
259     dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
260     this.Controls.Add(dockPanel);
261     ShowDocks();
262     }
263     }
264     else
265     {
266     ShowDocks();
267     }
268    
269     //dockPanel.ResumeLayout(true, true);
270 william 104 }
271 william 144
272     private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
273     {
274     ShowLogWindow();
275     }
276 william 147
277     private void mnuItemHelpAbout_Click(object sender, EventArgs e)
278     {
279     ShowAboutBox();
280     }
281 william 148
282     private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
283     {
284     ShowRamDump();
285     }
286    
287     private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
288     {
289     ShowPidSelector();
290     }
291 william 201 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
292     {
293     ShowMemoryView();
294     }
295 william 152 private void Main_FormClosing(object sender, FormClosingEventArgs e)
296     {
297     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
298     if (m_bSaveLayout)
299     dockPanel.SaveAsXml(configFile);
300     else if (File.Exists(configFile))
301     File.Delete(configFile);
302     }
303 william 158
304     private void mnuTestExeParse_Click(object sender, EventArgs e)
305     {
306 william 159 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
307 william 158 }
308 william 201
309     private void mnuItemFindMaxNonNegativeHexValue_Click(object sender, EventArgs e)
310     {
311    
312     //uint start = 0xf0000000;
313     uint end = uint.MaxValue;
314     //for (uint i = start; i < end; i++)
315     //{
316     ulong value = Convert.ToUInt64(end.ToString(), 16);
317     //}
318     }
319 william 218
320     private void mnuItemShowDataTypeConverter_Click(object sender, EventArgs e)
321     {
322     ShowDataTypeConverter();
323     }
324 william 227
325     private void mnuItemShowMemorySearch_Click(object sender, EventArgs e)
326     {
327     ShowMemorySearch();
328     }
329 william 260
330     private void mnuItemDateShift_Click(object sender, EventArgs e)
331     {
332     DateTime t = DateTime.Now;
333     int year = Convert.ToInt32(t.ToString("yy"));
334     int y = year << 9;
335     int m = t.Month << 5;
336     int d = t.Day;
337    
338     ushort v1 = (ushort)(y | m | d);
339    
340     t = t.AddDays(1);
341     year = Convert.ToInt32(t.ToString("yy"));
342     y = year << 9;
343     m = t.Month << 5;
344     d = t.Day;
345     ushort v2 = (ushort)(y | m | d);
346    
347     t = t.AddDays(1);
348     year = Convert.ToInt32(t.ToString("yy"));
349     y = year << 9;
350     m = t.Month << 5;
351     d = t.Day;
352     ushort v3 = (ushort)(y | m | d);
353    
354     t = new DateTime(9999,12,31);
355     year = Convert.ToInt32(t.ToString("yy"));
356     y = year << 9;
357     m = t.Month << 5;
358     d = t.Day;
359     ushort v4 = (ushort)(y | m | d);
360     }
361 william 201
362 william 5 }
363     }

  ViewVC Help
Powered by ViewVC 1.1.22