/[RomCheater]/trunk/RomCheater/Docking/FloatingMemorySectionViewer.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Docking/FloatingMemorySectionViewer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 602 - (hide annotations) (download)
Fri Jun 7 12:11:46 2013 UTC (8 years, 5 months ago) by william
File size: 6333 byte(s)

1 william 596 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Linq;
7     using System.Text;
8     using System.Windows.Forms;
9     using WeifenLuo.WinFormsUI.Docking;
10     using RomCheater.PluginFramework.Interfaces;
11     using System.Diagnostics;
12     using RomCheater.PluginFramework.Events;
13     using Sojaner.MemoryScanner;
14 william 599 using Sojaner.MemoryScanner.MemoryProviers;
15 william 600 using ManagedWinapi;
16 william 596
17     namespace RomCheater.Docking
18     {
19     public partial class FloatingMemorySectionViewer : DockContent,
20     IAcceptsPlugin<IConfigPlugin>,
21     IAcceptsProcess<Process>,
22     IAcceptsProcessAndConfig,
23     IAcceptPEData
24     {
25     public FloatingMemorySectionViewer()
26     {
27     InitializeComponent();
28     }
29    
30     public FloatingMemorySectionViewer(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
31     public FloatingMemorySectionViewer(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
32    
33     #region IAcceptsPlugin<IConfigPlugin> Members
34     private IConfigPlugin _AcceptedPlugin;
35     public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedPlugin(value); } }
36     private void UpdateAcceptedPlugin(IConfigPlugin config)
37     {
38 william 597 if (config == null) { return; }
39 william 596 // perform processing when config plugin is updated
40     }
41     #endregion
42     #region IAcceptsProcess<Process> Members
43     private Process _AcceptedProcess;
44     public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcess(value); } }
45     private void UpdateAcceptedProcess(Process process)
46     {
47     if (process == null) { return; }
48     // perform processing when process is updated
49 william 600 List<MEMORY_REGION_INFORMATION> regions = new List<MEMORY_REGION_INFORMATION>();
50 william 599 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
51     {
52     provider.OpenProvider();
53 william 600 if (this.PEData != null)
54     {
55     if (this.PEData.Is32bitAssembly())
56     {
57     regions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86);
58     }
59     else
60     {
61     regions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x64);
62     }
63     }
64     else
65     {
66     regions = provider.QueryMemoryRegions(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddressSize_x86);
67     }
68    
69 william 599 provider.CloseProvider();
70     }
71 william 601 PopulateMemoryRegions(regions);
72 william 596 }
73     #endregion
74    
75     #region IAcceptPEData Members
76     private IPEDData _PEData;
77     private IPEDData PEData { get { return _PEData; } set { _PEData = value; } }
78     public void SetPEViewerData(Sojaner.MemoryScanner.IPEDData peData)
79     {
80     this.PEData = peData;
81     }
82     #endregion
83 william 600
84    
85 william 601
86     private void PopulateMemoryRegions(List<MEMORY_REGION_INFORMATION> regions)
87     {
88     lstMemoryRegions.Items.Clear();
89     if (regions.Count == 0) { return; }
90    
91     List<ListViewItem> items = new List<ListViewItem>();
92    
93     foreach (var region in regions)
94     {
95 william 602 ListViewItem li = new ListViewItem();
96    
97     li.Text =string.Format("0x{0}", region.StartAddress.ToString("X"));
98     li.SubItems.Add(string.Format("0x{0}", region.EndAddress.ToString("X")));
99     li.SubItems.Add(string.Format("0x{0}", region.Size.ToString("X")));
100     li.SubItems.Add(string.Format("{0}", region.RegionInfo.Protect.ToString()));
101     li.SubItems.Add(string.Format("{0}", region.RegionInfo.State.ToString()));
102     li.SubItems.Add(string.Format("{0}", region.RegionInfo.Type.ToString()));
103    
104    
105     if(region.RegionInfo.Protect == AllocationProtect.PAGE_NOACCESS ||
106     region.RegionInfo.Protect.HasFlag(AllocationProtect.PAGE_NOACCESS))
107     {
108     li.ForeColor = Color.Red;
109     }
110    
111     else if (region.RegionInfo.Protect == AllocationProtect.PAGE_READONLY ||
112     region.RegionInfo.Protect.HasFlag(AllocationProtect.PAGE_READONLY) ||
113     region.RegionInfo.Protect == AllocationProtect.PAGE_EXECUTE_READ ||
114     region.RegionInfo.Protect.HasFlag(AllocationProtect.PAGE_EXECUTE_READ))
115     {
116     li.ForeColor = Color.RoyalBlue;
117     }
118     else if (region.RegionInfo.Protect == AllocationProtect.PAGE_READWRITE ||
119     region.RegionInfo.Protect.HasFlag(AllocationProtect.PAGE_READWRITE) ||
120     region.RegionInfo.Protect == AllocationProtect.PAGE_EXECUTE_READWRITE ||
121     region.RegionInfo.Protect.HasFlag(AllocationProtect.PAGE_EXECUTE_READWRITE))
122     {
123     li.ForeColor = Color.Green;
124     }
125     else if (region.RegionInfo.Protect == AllocationProtect.NONE)
126     {
127     li.ForeColor = Color.Orange;
128     }
129     else
130     {
131     li.ForeColor = Color.Black;
132     }
133    
134     items.Add(li);
135 william 601 }
136    
137     if (items.Count == 0) { return; }
138    
139     lstMemoryRegions.BeginUpdate();
140     lstMemoryRegions.Items.AddRange(items.ToArray());
141     lstMemoryRegions.EndUpdate();
142    
143 william 602
144     foreach (var col in Enumerable.Range(0, lstMemoryRegions.Columns.Count))
145     {
146     lstMemoryRegions.AutoResizeColumn(col, ColumnHeaderAutoResizeStyle.ColumnContent);
147     }
148    
149 william 601 }
150    
151 william 596 }
152     }

  ViewVC Help
Powered by ViewVC 1.1.22