/[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/20 10:03:25	392
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/20 10:41:25	395
@@ -1,4 +1,4 @@
-#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 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
 #if !USE_AUTOMATIC_MEMORY_SEARCH_RANGE
 #define FORCE_USE_OF_MEMORYSIZECONSTANTS // when defined wil force the use of the constants defined in MemorySizeConstants for memory search range
 #endif
@@ -1030,8 +1030,8 @@
             provider.CloseProvider();
        
             if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
-            //MemoryStream ms = new MemoryStream(buffered_mem);
-            //BinaryReader r_ms = new BinaryReader(ms);
+            MemoryStream ms = new MemoryStream(buffered_mem);
+            BinaryReader r_ms = new BinaryReader(ms);
             logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
             int Last_Whole_Percent_Done = 0;
 
@@ -1040,24 +1040,24 @@
             {
                 st_first_search.Start();
                 SearchArgs.Results.Clear();
-                //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
+                r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
                 for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
                 {
                     ResultType<object> _tmp_result = new ResultType<object>();
                     switch (SearchArgs.DataType)
                     {
                         case SearchDataTypes._8bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, buffered_mem[i]); }
-                            else { _tmp_result = new ResultType<object>(i, buffered_mem[i]); } break;
+                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadByte()); }
+                            else { _tmp_result = new ResultType<object>(i, r_ms.ReadSByte()); } break;
                         case SearchDataTypes._16bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, BitConverter.ToUInt16(buffered_mem,(int)i)); }
-                            else { _tmp_result = new ResultType<object>(i,BitConverter.ToInt16(buffered_mem,(int)i)); } break;
+                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt16()); }
+                            else { _tmp_result = new ResultType<object>(i,r_ms.ReadInt16()); } break;
                         case SearchDataTypes._32bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, BitConverter.ToUInt32(buffered_mem,(int)i)); }
-                            else { _tmp_result = new ResultType<object>(i, BitConverter.ToInt32(buffered_mem,(int)i)); } break;
+                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt32()); }
+                            else { _tmp_result = new ResultType<object>(i, r_ms.ReadInt32()); } break;
                         case SearchDataTypes._64bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, BitConverter.ToUInt64(buffered_mem,(int)i)); }
-                            else { _tmp_result = new ResultType<object>(i, BitConverter.ToInt64(buffered_mem,(int)i)); } break;
+                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt64()); }
+                            else { _tmp_result = new ResultType<object>(i, r_ms.ReadInt64()); } break;
                     }
                     SearchArgs.Results.Add(_tmp_result);
                     double double_percent_done = 100.0 * (double)((double)i / (double)buffered_mem.Length);
@@ -1065,7 +1065,7 @@
                     if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
                     {
                         resultsprogress.Value = int_percent_done;
-                        //resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
+                        resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
                         Last_Whole_Percent_Done = int_percent_done;
                         //Application.DoEvents();
                     }
@@ -1086,7 +1086,7 @@
             #endregion
 
             #region Subsequent Searches
-            //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
+            r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
 
 
             // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
@@ -1108,10 +1108,10 @@
                     //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
                     ////second_tmp_Results.c
                     for (int i = 0; i < SearchArgs.Results.Count; i += 1)
-                    {
-                        //r_ms.BaseStream.Seek(SearchArgs.Results[i].Address, SeekOrigin.Begin);
+                    {                        
                         uint address = SearchArgs.Results[i].Address;
                         if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                        r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
                         switch (SearchArgs.DataType)
                         {
                             #region Comparer Support
@@ -1119,8 +1119,8 @@
                             case SearchDataTypes._8bits:
                                 if (SearchArgs.IsUnsignedDataType)
                                 {
-                                    byte lookup_value = buffered_mem[address];
-                                    _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    byte lookup_value = r_ms.ReadByte();
+                                    _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
                                     byte value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1145,8 +1145,8 @@
                                 }
                                 else
                                 {
-                                    sbyte lookup_value = (sbyte)buffered_mem[address];
-                                    _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    sbyte lookup_value = r_ms.ReadSByte();
+                                    _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
                                     sbyte value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1173,8 +1173,8 @@
                             case SearchDataTypes._16bits:
                                 if (SearchArgs.IsUnsignedDataType)
                                 {
-                                    ushort lookup_value = BitConverter.ToUInt16(buffered_mem,(int)address);
-                                    _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    ushort lookup_value = r_ms.ReadUInt16();
+                                    _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
                                     ushort value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1199,8 +1199,8 @@
                                 }
                                 else
                                 {
-                                    short lookup_value = BitConverter.ToInt16(buffered_mem,(int)address);
-                                    _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    short lookup_value = r_ms.ReadInt16();
+                                    _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
                                     short value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1227,8 +1227,8 @@
                             case SearchDataTypes._32bits:
                                 if (SearchArgs.IsUnsignedDataType)
                                 {
-                                    uint lookup_value = BitConverter.ToUInt32(buffered_mem,(int)address);
-                                    _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    uint lookup_value = r_ms.ReadUInt32();
+                                    _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
                                     uint value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1253,8 +1253,8 @@
                                 }
                                 else
                                 {
-                                    int lookup_value =BitConverter.ToInt32(buffered_mem,(int)address);
-                                    _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    int lookup_value = r_ms.ReadInt32();
+                                    _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
                                     int value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1281,8 +1281,8 @@
                             case SearchDataTypes._64bits:
                                 if (SearchArgs.IsUnsignedDataType)
                                 {
-                                    ulong lookup_value = BitConverter.ToUInt64(buffered_mem,(int)address);
-                                    _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    ulong lookup_value = r_ms.ReadUInt64();
+                                    _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
                                     ulong value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1307,8 +1307,8 @@
                                 }
                                 else
                                 {
-                                    long lookup_value = BitConverter.ToInt64(buffered_mem,(int)address);
-                                    _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, SearchArgs.Results[i].Address);
+                                    long lookup_value = r_ms.ReadInt64();
+                                    _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
                                     long value = 0;
                                     if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                     {
@@ -1339,7 +1339,7 @@
                         if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
                         {
                             resultsprogress.Value = int_percent_done;
-                            //resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
+                            resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
                             Last_Whole_Percent_Done = int_percent_done;
                             //Application.DoEvents();
                         }
@@ -1362,7 +1362,7 @@
                     {
                         uint address = SearchArgs.Results[i].Address;
                         if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                        //r_ms.BaseStream.Seek(SearchArgs.Results[i].Address, SeekOrigin.Begin);
+                        //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
                         if (SearchArgs.CompareType == SearchCompareTypes.Between)
                         {
                             InRangeComparer comparer = new InRangeComparer(address, 0);
@@ -1392,7 +1392,7 @@
                         if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
                         {
                             resultsprogress.Value = int_percent_done;
-                            //resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
+                            resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
                             Last_Whole_Percent_Done = int_percent_done;
                             //Application.DoEvents();
                         }
@@ -1414,7 +1414,7 @@
                 second_tmp_Results = null; // free memory
             }
 
-            //r_ms.Close();
+            r_ms.Close();
         }
 
         private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)

 

  ViewVC Help
Powered by ViewVC 1.1.22