ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Main.cs
Revision: 206
Committed: Thu May 31 09:31:57 2012 UTC (11 years, 6 months ago) by william
File size: 10721 byte(s)
Log Message:
+ add support for memory view to accept a memory address externally

File Contents

# Content
1 #define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL
2 #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden
3 using System;
4 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 using RomCheater.Logging;
12 using RomCheater.Properties;
13 using RomCheater.UserSettingsSupport;
14 using RomCheater.PluginFramework.Core;
15 using System.Diagnostics;
16 using RomCheater.PluginFramework.Interfaces;
17 using WeifenLuo.WinFormsUI.Docking;
18 using RomCheater.Docking;
19 using System.IO;
20 using Sojaner.MemoryScanner;
21 using RomCheater.PluginFramework.Events;
22
23 namespace RomCheater
24 {
25 public partial class Main : Form
26 {
27 private bool m_bSaveLayout = true;
28 private Process SelectedProcess = null;
29 private DeserializeDockContent m_deserializeDockContent;
30 private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
31 private FloatingAboutBox m_AboutBox = new FloatingAboutBox();
32 private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog();
33 private PIDSelector m_PIDSelector = new PIDSelector();
34 private FloatingMemoryView m_memoryview = new FloatingMemoryView();
35 //private bool log_window_expanded = false;
36 //private double log_window_splitter_default_position = 1.4045;
37 PluginLoader loader = null;
38 IConfigPlugin ConfigPlugin = null;
39 IInputPlugin InputPlugin = null;
40 IWindowPlugin WindowPlugin = null;
41 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
42 private const string t = "RomCheater";
43 #region LogWriterSupport
44 static LogWriter _LoggerInstance;
45 static LogWriter LoggerInstance
46 {
47 get { return _LoggerInstance; }
48 set { _LoggerInstance = value; }
49 }
50 #endregion
51
52
53 private void OnProcessChanged(ProcessChangedEventArgs e)
54 {
55 SelectedProcess = Process.GetProcessById(e.ProcessID);
56 m_RamDump.AcceptedProcess = SelectedProcess;
57 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
58
59 m_memoryview.AcceptedProcess = SelectedProcess;
60 m_memoryview.AcceptedPlugin = this.ConfigPlugin;
61 }
62
63 #region Dock Support
64 private IDockContent GetContentFromPersistString(string persistString)
65 {
66 if (persistString == typeof(FloatingLogWindow).ToString())
67 {
68 return m_LogWindow;
69 }
70 //if (persistString == typeof(FloatingAboutBox).ToString())
71 //{
72 // return m_AboutBox;
73 //}
74 if (persistString == typeof(FloatingRamDumperDialog).ToString())
75 {
76 return m_RamDump;
77 }
78 if (persistString == typeof(PIDSelector).ToString())
79 {
80 return m_PIDSelector;
81 }
82 if (persistString == typeof(FloatingMemoryView).ToString())
83 {
84 return m_memoryview;
85 }
86 else
87 {
88 // not sure if this is appropriate
89 return null;
90 }
91 }
92 public void SetupDocks()
93 {
94 m_LogWindow = new FloatingLogWindow();
95 m_AboutBox = new FloatingAboutBox();
96 m_RamDump = new FloatingRamDumperDialog();
97 m_PIDSelector = new PIDSelector();
98 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
99 m_memoryview = new FloatingMemoryView();
100 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
101 }
102 public void ShowDocks()
103 {
104 ShowLogWindow();
105 //ShowAboutBox();
106 ShowRamDump();
107 ShowMemoryView();
108 ShowPidSelector();
109 }
110 public void ShowLogWindow()
111 {
112 m_LogWindow.Show(dockPanel, DockState.DockBottom);
113 }
114 public void ShowAboutBox()
115 {
116 m_AboutBox.ShowDialog();
117 }
118 public void ShowRamDump()
119 {
120 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
121 m_RamDump.AcceptedProcess = SelectedProcess;
122 m_RamDump.Show(dockPanel);
123 }
124 public void ShowMemoryView()
125 {
126 m_memoryview = new FloatingMemoryView(ConfigPlugin);
127 m_memoryview.AcceptedProcess = SelectedProcess;
128 m_memoryview.Show(dockPanel);
129 }
130 public void ShowPidSelector()
131 {
132 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
133 m_PIDSelector = new PIDSelector(ConfigPlugin);
134 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
135 m_PIDSelector.Show(dockPanel);
136 }
137 #endregion
138
139
140 public Main() : this(false) { }
141 public Main(bool no_console_redirect)
142 {
143 InitializeComponent();
144 #if SHOW_DEBUG_MENU
145 mnuDebug.Visible = true;
146 #else
147 mnuDebug.Visible = false;
148 #endif
149 load_loggerflags();
150 SetupDocks();
151 LoggerInstance = m_LogWindow.Logwriter;
152 LoggerInstance.CreateNewLog(false);
153 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
154 load_plugins();
155 if (no_console_redirect)
156 LoggerInstance.RedirectConsoleOutput = false;
157
158
159
160 }
161 private void load_loggerflags()
162 {
163 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
164 #if FORCE_ALL_LOGGING_FLAGS
165 logger.SetLoggingFlags(loggerflags.ALL);
166 #endif
167 }
168 private void load_plugins()
169 {
170 loader = new PluginLoader();
171 loader.LoadPlugins();
172
173 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
174 if (ConfigPlugin != null)
175 logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
176 InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
177 if (InputPlugin != null)
178 logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
179 WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
180 if (WindowPlugin != null)
181 logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
182
183 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
184 m_RamDump.AcceptedPlugin = ConfigPlugin;
185 if (this.SelectedProcess != null)
186 m_RamDump.AcceptedProcess = SelectedProcess;
187
188 }
189
190 private void mnuItemExit_Click(object sender, EventArgs e)
191 {
192 this.Close();
193 }
194
195 private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
196 {
197
198 }
199
200 private void Main_Load(object sender, EventArgs e)
201 {
202
203 }
204
205 private void mnuItemConfig_Click(object sender, EventArgs e)
206 {
207 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
208 dlg.ShowDialog();
209 // reload plugins
210 load_plugins();
211 }
212
213 private void mnuItemOpenProcess_Click(object sender, EventArgs e)
214 {
215 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
216 //PIDSelector selector = new PIDSelector(ConfigPlugin);
217 //selector.ShowDialog();
218 }
219
220 private void Main_Shown(object sender, EventArgs e)
221 {
222 //dockPanel.SuspendLayout(true);
223 //ShowDocks();
224 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
225 if (File.Exists(configFile))
226 {
227 try
228 {
229 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
230 }
231 catch (Exception)
232 {
233 this.Controls.Remove(dockPanel);
234 dockPanel = new DockPanel();
235 dockPanel.Dock = DockStyle.Fill;
236 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
237 this.Controls.Add(dockPanel);
238 ShowDocks();
239 }
240 }
241 else
242 {
243 ShowDocks();
244 }
245
246 //dockPanel.ResumeLayout(true, true);
247 }
248
249 private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
250 {
251 ShowLogWindow();
252 }
253
254 private void mnuItemHelpAbout_Click(object sender, EventArgs e)
255 {
256 ShowAboutBox();
257 }
258
259 private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
260 {
261 ShowRamDump();
262 }
263
264 private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
265 {
266 ShowPidSelector();
267 }
268 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
269 {
270 ShowMemoryView();
271 }
272 private void Main_FormClosing(object sender, FormClosingEventArgs e)
273 {
274 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
275 if (m_bSaveLayout)
276 dockPanel.SaveAsXml(configFile);
277 else if (File.Exists(configFile))
278 File.Delete(configFile);
279 }
280
281 private void mnuTestExeParse_Click(object sender, EventArgs e)
282 {
283 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
284 }
285
286 private void mnuItemFindMaxNonNegativeHexValue_Click(object sender, EventArgs e)
287 {
288
289 //uint start = 0xf0000000;
290 uint end = uint.MaxValue;
291 //for (uint i = start; i < end; i++)
292 //{
293 ulong value = Convert.ToUInt64(end.ToString(), 16);
294 //}
295 }
296
297 }
298 }