/[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

--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/05 02:19:13	286
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/05 08:52:07	287
@@ -1,8 +1,7 @@
-#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
+#define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
 //#define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented
-
 #define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8
-
 //#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze
 using System;
 using System.Collections.Generic;
@@ -22,6 +21,7 @@
 using System.IO;
 using Sojaner.MemoryScanner.MemoryProviers;
 using RomCheater.PluginFramework.Events;
+using System.Reflection;
 
 namespace RomCheater.Docking
 {
@@ -30,7 +30,8 @@
         IAcceptsProcess<Process>,
         IAcceptsProcessAndConfig,
         ISearchInProgress,
-        IAcceptsBrowseMemoryRegion
+        IAcceptsBrowseMemoryRegion,
+        IAcceptsMemoryRange
     {
 #if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY
         const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results
@@ -39,7 +40,7 @@
 #endif
 
         private bool DefaultUnsignedState = true; // set unsigned to true
-        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(); }
         public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; }
         public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; }
 
@@ -52,7 +53,7 @@
         public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedProcessAndConfig(value, AcceptedProcess); } }
         #endregion
         #region IAcceptsBrowseMemoryRegion members
-        public BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion { get; set; }
+        public event BaseEventHandler<BrowseMemoryRegionEvent> OnBrowseMemoryRegion;
         #endregion
 
         private void UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process)
@@ -61,11 +62,62 @@
             this.lstResults.AcceptedProcess = process;
             this.lstPatchList.AcceptedPlugin = config;
             this.lstPatchList.AcceptedProcess = process;
+
+#if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && FORCE_USE_OF_MEMORYSIZECONSTANTS
+//#error Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined
+            logger.Warn.WriteLine("FloatingMemorySearcher.UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process):");
+            logger.Warn.WriteLine("Both USE_AUTOMATIC_MEMORY_SEARCH_RANGE and FORCE_USE_OF_MEMORYSIZECONSTANTS are defined");
+            logger.Warn.WriteLine("FORCE_USE_OF_MEMORYSIZECONSTANTS will take precedence and will ignore the values supplied in the memeory search range");
+#endif
+#if USE_AUTOMATIC_MEMORY_SEARCH_RANGE && !FORCE_USE_OF_MEMORYSIZECONSTANTS
+            // code to automatically choose the best starting memory address and size
+#endif
+
         }
         #region ISearchInProgress members
-        public bool SearchInProgess { get; private set; } 
+        public bool SearchInProgess { get; private set; }
         #endregion
 
+        #region IAcceptsMemoryRange
+#if !FORCE_USE_OF_MEMORYSIZECONSTANTS
+        private int _MemoryRangeStart;
+        private uint _MemoryRangeSize;
+#endif
+        public int MemoryRangeStart
+        {
+            get
+            {
+#if FORCE_USE_OF_MEMORYSIZECONSTANTS
+                return MemorySizeConstants.MinimumAddress;
+#else
+                return _MemoryRangeStart;
+#endif
+            }
+            set
+            {
+#if !FORCE_USE_OF_MEMORYSIZECONSTANTS
+                _MemoryRangeStart = value;
+#endif
+            }
+        }         
+        public uint MemoryRangeSize
+        {
+            get
+            {
+#if FORCE_USE_OF_MEMORYSIZECONSTANTS
+                return (MemorySizeConstants.MinimumAddress > 0) ? (uint)(MemorySizeConstants.MaximumAddress - MemorySizeConstants.MinimumAddress) : MemorySizeConstants.MaximumAddress;
+#else
+                return _MemoryRangeSize;
+#endif
+            }
+            set
+            {
+#if !FORCE_USE_OF_MEMORYSIZECONSTANTS
+                _MemoryRangeSize = value;
+#endif
+            }
+        }
+        #endregion
 
         public void Reload()
         {
@@ -935,8 +987,8 @@
             provider.OpenProvider();
             int bytes_read = 0;
 
-            byte[] buffered_mem = new byte[MemorySizeConstants.MaximumAddress]; // throws OutOfMemoryException if size is over 2G
-            provider.ReadProcessMemory(MemorySizeConstants.MinimumAddress, MemorySizeConstants.MaximumAddress, out bytes_read, out buffered_mem);
+            byte[] buffered_mem = new byte[txtMemorySize.Value]; // throws OutOfMemoryException if size is over 2G
+            provider.ReadProcessMemory((int)txtMemoryStart.Value, (uint)txtMemorySize.Value, out bytes_read, out buffered_mem);
             provider.CloseProvider();
        
             if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
@@ -1603,9 +1655,7 @@
         private void ViewMemoryRegion(ResultDataType rdt)
         {
             if (OnBrowseMemoryRegion != null)
-            {
                 OnBrowseMemoryRegion(new BrowseMemoryRegionEvent(rdt.Address));
-            }
         }
 
         private void mnuAddedResults_Opening(object sender, CancelEventArgs e)
@@ -1635,5 +1685,15 @@
             if (SearchArgs == null) e.Cancel = true;
             if (e.Cancel) return;
         }
+
+        private void chkMemoryRangeExpertMode_CheckedChanged(object sender, EventArgs e)
+        {
+            txtMemoryStart.ReadOnly = !chkMemoryRangeExpertMode.Checked;
+            txtMemorySize.ReadOnly = !chkMemoryRangeExpertMode.Checked;
+        }
+
+        private void txtMemoryStart_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeStart = Convert.ToInt32(e.NewValue); }
+        private void txtMemorySize_ValueChanged(object sender, ValueChangedEventArgs e) { this.MemoryRangeSize = Convert.ToUInt32(e.NewValue); }
+               
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22