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

Diff of /trunk/RomCheater/Docking/FloatingMemorySearcher.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 286 by william, Tue Jun 5 02:19:13 2012 UTC revision 287 by william, Tue Jun 5 08:52:07 2012 UTC
# Line 1  Line 1 
1  #define USE_FORCED_LOGGING_CONTROL // when defined, will override and force an internal logging control  #define USE_AUTOMATIC_MEMORY_SEARCH_RANGE // when defined will automatically choose the best starting address and size for memory search otherwise it will use the constants defined in MemorySizeConstants
2    #define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
3  //#define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented  //#define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented
   
4  #define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8  #define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8
   
5  //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze  //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
6  using System;  using System;
7  using System.Collections.Generic;  using System.Collections.Generic;
# Line 22  using RomCheater.Logging; Line 21  using RomCheater.Logging;
21  using System.IO;  using System.IO;
22  using Sojaner.MemoryScanner.MemoryProviers;  using Sojaner.MemoryScanner.MemoryProviers;
23  using RomCheater.PluginFramework.Events;  using RomCheater.PluginFramework.Events;
24    using System.Reflection;
25    
26  namespace RomCheater.Docking  namespace RomCheater.Docking
27  {  {
# Line 30  namespace RomCheater.Docking Line 30  namespace RomCheater.Docking
30          IAcceptsProcess<Process>,          IAcceptsProcess<Process>,
31          IAcceptsProcessAndConfig,          IAcceptsProcessAndConfig,
32          ISearchInProgress,          ISearchInProgress,
33          IAcceptsBrowseMemoryRegion          IAcceptsBrowseMemoryRegion,
34            IAcceptsMemoryRange
35      {      {
36  #if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY  #if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY
37          const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results          const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results
# Line 39  namespace RomCheater.Docking Line 40  namespace RomCheater.Docking
40  #endif  #endif
41    
42          private bool DefaultUnsignedState = true; // set unsigned to true          private bool DefaultUnsignedState = true; // set unsigned to true
43          public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }          public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; OnBrowseMemoryRegion = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); }
44          public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }          public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
45          public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }          public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
46    
# Line 52  namespace RomCheater.Docking Line 53  namespace RomCheater.Docking
53          public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedProcessAndConfig(value, AcceptedProcess); } }          public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedProcessAndConfig(value, AcceptedProcess); } }
54          #endregion          #endregion
55          #region IAcceptsBrowseMemoryRegion members          #region IAcceptsBrowseMemoryRegion members
56          public BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion { get; set; }          public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
57          #endregion          #endregion
58    
59          private void UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process)          private void UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process)
# Line 61  namespace RomCheater.Docking Line 62  namespace RomCheater.Docking
62              this.lstResults.AcceptedProcess = process;              this.lstResults.AcceptedProcess = process;
63              this.lstPatchList.AcceptedPlugin = config;              this.lstPatchList.AcceptedPlugin = config;
64              this.lstPatchList.AcceptedProcess = process;              this.lstPatchList.AcceptedProcess = process;
65    
66    #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
67    //#error Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined
68                logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
69                logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
70                logger.Warn.WriteLine("FORCE_USE_OF_MEMORYSIZECONSTANTS will take precedence and will ignore the values supplied in the memeory search range");
71    #endif
72    #if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
73                // code to automatically choose the best starting memory address and size
74    #endif
75    
76          }          }
77          #region ISearchInProgress members          #region ISearchInProgress members
78          public bool SearchInProgess { get; private set; }          public bool SearchInProgess { get; private set; }
79          #endregion          #endregion
80    
81            #region IAcceptsMemoryRange
82    #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
83            private int _MemoryRangeStart;
84            private uint _MemoryRangeSize;
85    #endif
86            public int MemoryRangeStart
87            {
88                get
89                {
90    #if FORCE_USE_OF_MEMORYSIZECONSTANTS
91                    return MemorySizeConstants.MinimumAddress;
92    #else
93                    return _MemoryRangeStart;
94    #endif
95                }
96                set
97                {
98    #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
99                    _MemoryRangeStart = value;
100    #endif
101                }
102            }        
103            public uint MemoryRangeSize
104            {
105                get
106                {
107    #if FORCE_USE_OF_MEMORYSIZECONSTANTS
108                    return (MemorySizeConstants.MinimumAddress > 0) ? (uint)(MemorySizeConstants.MaximumAddress - MemorySizeConstants.MinimumAddress) : MemorySizeConstants.MaximumAddress;
109    #else
110                    return _MemoryRangeSize;
111    #endif
112                }
113                set
114                {
115    #if !FORCE_USE_OF_MEMORYSIZECONSTANTS
116                    _MemoryRangeSize = value;
117    #endif
118                }
119            }
120            #endregion
121    
122          public void Reload()          public void Reload()
123          {          {
# Line 935  namespace RomCheater.Docking Line 987  namespace RomCheater.Docking
987              provider.OpenProvider();              provider.OpenProvider();
988              int bytes_read = 0;              int bytes_read = 0;
989    
990              byte[] buffered_mem = new byte[MemorySizeConstants.MaximumAddress]; // throws OutOfMemoryException if size is over 2G              byte[] buffered_mem = new byte[txtMemorySize.Value]; // throws OutOfMemoryException if size is over 2G
991              provider.ReadProcessMemory(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddress, out bytes_read, out buffered_mem);              provider.ReadProcessMemory((int)txtMemoryStart.Value, (uint)txtMemorySize.Value, out bytes_read, out buffered_mem);
992              provider.CloseProvider();              provider.CloseProvider();
993                
994              if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }              if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
# Line 1603  namespace RomCheater.Docking Line 1655  namespace RomCheater.Docking
1655          private void ViewMemoryRegion(ResultDataType rdt)          private void ViewMemoryRegion(ResultDataType rdt)
1656          {          {
1657              if (OnBrowseMemoryRegion != null)              if (OnBrowseMemoryRegion != null)
             {  
1658                  OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(rdt.Address));                  OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(rdt.Address));
             }  
1659          }          }
1660    
1661          private void mnuAddedResults_Opening(object sender, CancelEventArgs e)          private void mnuAddedResults_Opening(object sender, CancelEventArgs e)
# Line 1635  namespace RomCheater.Docking Line 1685  namespace RomCheater.Docking
1685              if (SearchArgs == null) e.Cancel = true;              if (SearchArgs == null) e.Cancel = true;
1686              if (e.Cancel) return;              if (e.Cancel) return;
1687          }          }
1688    
1689            private void chkMemoryRangeExpertMode_CheckedChanged(object sender, EventArgs e)
1690            {
1691                txtMemoryStart.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1692                txtMemorySize.ReadOnly = !chkMemoryRangeExpertMode.Checked;
1693            }
1694    
1695            private void txtMemoryStart_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeStart = Convert.ToInt32(e.NewValue); }
1696            private void txtMemorySize_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeSize = Convert.ToUInt32(e.NewValue); }
1697                  
1698      }      }
1699  }  }

Legend:
Removed from v.286  
changed lines
  Added in v.287

  ViewVC Help
Powered by ViewVC 1.1.22