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

Annotation of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 201 - (hide annotations) (download)
Thu May 31 08:10:25 2012 UTC (9 years, 3 months ago) by william
File size: 10723 byte(s)
+ get memoryview working

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 144 //private bool log_window_expanded = false;
36     //private double log_window_splitter_default_position = 1.4045;
37 william 86 PluginLoader loader = null;
38 william 87 IConfigPlugin ConfigPlugin = null;
39     IInputPlugin InputPlugin = null;
40     IWindowPlugin WindowPlugin = null;
41 william 146 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
42 william 20 private const string t = "RomCheater";
43 william 17 #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 william 196 private void OnProcessChanged(ProcessChangedEventArgs e)
54 william 151 {
55 william 153 SelectedProcess = Process.GetProcessById(e.ProcessID);
56     m_RamDump.AcceptedProcess = SelectedProcess;
57 william 196 m_RamDump.AcceptedPlugin = this.ConfigPlugin;
58    
59     m_memoryview.AcceptedProcess = SelectedProcess;
60     m_memoryview.AcceptedPlugin = this.ConfigPlugin;
61 william 151 }
62    
63 william 144 #region Dock Support
64     private IDockContent GetContentFromPersistString(string persistString)
65     {
66     if (persistString == typeof(FloatingLogWindow).ToString())
67     {
68     return m_LogWindow;
69     }
70 william 152 //if (persistString == typeof(FloatingAboutBox).ToString())
71     //{
72     // return m_AboutBox;
73     //}
74 william 148 if (persistString == typeof(FloatingRamDumperDialog).ToString())
75     {
76     return m_RamDump;
77     }
78 william 152 if (persistString == typeof(PIDSelector).ToString())
79     {
80     return m_PIDSelector;
81     }
82 william 196 if (persistString == typeof(FloatingMemoryView).ToString())
83     {
84     return m_memoryview;
85     }
86 william 144 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 william 147 m_AboutBox = new FloatingAboutBox();
96 william 148 m_RamDump = new FloatingRamDumperDialog();
97     m_PIDSelector = new PIDSelector();
98 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
99     m_memoryview = new FloatingMemoryView();
100 william 144 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
101     }
102     public void ShowDocks()
103     {
104     ShowLogWindow();
105 william 152 //ShowAboutBox();
106 william 148 ShowRamDump();
107 william 196 ShowMemoryView();
108 william 148 ShowPidSelector();
109 william 144 }
110     public void ShowLogWindow()
111 william 147 {
112 william 152 m_LogWindow.Show(dockPanel, DockState.DockBottom);
113 william 144 }
114 william 147 public void ShowAboutBox()
115     {
116 william 148 m_AboutBox.ShowDialog();
117 william 147 }
118 william 148 public void ShowRamDump()
119     {
120 william 153 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
121 william 201 m_RamDump.AcceptedProcess = SelectedProcess;
122 william 196 m_RamDump.Show(dockPanel);
123 william 148 }
124 william 196 public void ShowMemoryView()
125     {
126     m_memoryview = new FloatingMemoryView(ConfigPlugin);
127 william 201 m_memoryview.AcceptedProcess = SelectedProcess;
128 william 196 m_memoryview.Show(dockPanel);
129     }
130 william 148 public void ShowPidSelector()
131     {
132     //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
133     m_PIDSelector = new PIDSelector(ConfigPlugin);
134 william 196 m_PIDSelector.OnSelectedProcessChanged += new BaseEventHandler<ProcessChangedEventArgs>(OnProcessChanged);
135 william 148 m_PIDSelector.Show(dockPanel);
136     }
137 william 144 #endregion
138    
139    
140 william 117 public Main() : this(false) { }
141     public Main(bool no_console_redirect)
142 william 5 {
143     InitializeComponent();
144 william 158 #if SHOW_DEBUG_MENU
145     mnuDebug.Visible = true;
146     #else
147     mnuDebug.Visible = false;
148     #endif
149 william 83 load_loggerflags();
150 william 144 SetupDocks();
151     LoggerInstance = m_LogWindow.Logwriter;
152 william 23 LoggerInstance.CreateNewLog(false);
153 william 112 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
154 william 87 load_plugins();
155 william 117 if (no_console_redirect)
156     LoggerInstance.RedirectConsoleOutput = false;
157 william 158
158    
159 william 144
160 william 5 }
161 william 83 private void load_loggerflags()
162     {
163 william 111 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
164 william 99 #if FORCE_ALL_LOGGING_FLAGS
165     logger.SetLoggingFlags(loggerflags.ALL);
166     #endif
167 william 83 }
168 william 87 private void load_plugins()
169     {
170     loader = new PluginLoader();
171     loader.LoadPlugins();
172 william 83
173 william 87 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 william 153 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
184     m_RamDump.AcceptedPlugin = ConfigPlugin;
185     if (this.SelectedProcess != null)
186     m_RamDump.AcceptedProcess = SelectedProcess;
187 william 152
188 william 87 }
189    
190 william 14 private void mnuItemExit_Click(object sender, EventArgs e)
191     {
192     this.Close();
193     }
194 william 16
195     private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
196     {
197    
198     }
199 william 17
200     private void Main_Load(object sender, EventArgs e)
201 william 144 {
202 william 152
203 william 17 }
204 william 63
205     private void mnuItemConfig_Click(object sender, EventArgs e)
206     {
207 william 86 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
208 william 63 dlg.ShowDialog();
209 william 92 // reload plugins
210     load_plugins();
211 william 63 }
212 william 69
213     private void mnuItemOpenProcess_Click(object sender, EventArgs e)
214     {
215 william 148 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
216     //PIDSelector selector = new PIDSelector(ConfigPlugin);
217     //selector.ShowDialog();
218 william 69 }
219 william 104
220 william 144 private void Main_Shown(object sender, EventArgs e)
221 william 104 {
222 william 152 //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 william 177 catch (Exception)
232 william 152 {
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 william 104 }
248 william 144
249     private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
250     {
251     ShowLogWindow();
252     }
253 william 147
254     private void mnuItemHelpAbout_Click(object sender, EventArgs e)
255     {
256     ShowAboutBox();
257     }
258 william 148
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 william 201 private void mnuItemShowMemoryView_Click(object sender, EventArgs e)
269     {
270     ShowMemoryView();
271     }
272 william 152 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 william 158
281     private void mnuTestExeParse_Click(object sender, EventArgs e)
282     {
283 william 159 PEReader reader = new PEReader(@"C:\Windows\System32\notepad.exe");
284 william 158 }
285 william 201
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 william 5 }
299     }

  ViewVC Help
Powered by ViewVC 1.1.22