/[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	2013/06/03 09:21:03	473
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/03 16:48:28	474
@@ -1056,6 +1056,359 @@
                 Debug.WriteLine(ex.ToString());
             }
         }
+        private void search_provider_OnBytesRead_compare_only(OnBytesReadEventArgs e)
+        {
+            if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
+            SearchDataTypes sdt = SearchArgs.DataType;
+            bool unsigned = SearchArgs.IsUnsignedDataType;
+            //int Last_Whole_Percent_Done = 0;
+            uint CurrentIndex = e.CurrentIndex;
+            if (e.UserState != null)
+            {
+                SearchResultWriter writer = (e.UserState as SearchResultWriter);
+                if (writer == null)
+                    throw new InvalidOperationException("writer cannot be null");
+                using (MemoryStream ms = new MemoryStream(e.Data))
+                {
+                    using (BinaryReader br = new BinaryReader(ms))
+                    {
+                        while (br.BaseStream.Position < br.BaseStream.Length)
+                        {
+                            try
+                            {
+                                switch (sdt)
+                                {
+                                    case SearchDataTypes._8bits:
+                                        if (unsigned)
+                                        {
+                                            #region 8bits - unsigned
+                                            var Value = br.ReadByte();
+                                            using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                byte value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToByte(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToByte(Value), value))
+                                                {
+                                                    writer.WriteResult<byte>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        }
+                                        else
+                                        {
+                                            #region 8bits - signed
+                                            var Value = br.ReadSByte();
+                                            using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                sbyte value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToSByte(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToSByte(Value), value))
+                                                {
+                                                    writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        } break;
+                                    case SearchDataTypes._16bits:
+                                        if (unsigned)
+                                        {
+                                            #region 16bits - unsigned
+                                            var Value = br.ReadUInt16();
+                                            using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                ushort value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToUInt16(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToUInt16(Value), value))
+                                                {
+                                                    writer.WriteResult<ushort>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        }
+                                        else
+                                        {
+                                            #region 16bits - signed
+                                            var Value = br.ReadInt16();
+                                            using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                short value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToInt16(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToSByte(Value), value))
+                                                {
+                                                    writer.WriteResult<short>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        } break;
+                                    case SearchDataTypes._32bits:
+                                        if (unsigned)
+                                        {
+                                            #region 32bits - unsigned
+                                            var Value = br.ReadUInt32();
+                                            using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                uint value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToUInt32(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToUInt32(Value), value))
+                                                {
+                                                    writer.WriteResult<uint>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        }
+                                        else
+                                        {
+                                            #region 32bits - signed
+                                            var Value = br.ReadInt32();
+                                            using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                int value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToInt32(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToInt32(Value), value))
+                                                {
+                                                    writer.WriteResult<int>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        } break;
+                                    case SearchDataTypes._64bits:
+                                        if (unsigned)
+                                        {
+                                            #region 64bits - unsigned
+                                            var Value = br.ReadUInt64();
+                                            using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                ulong value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToUInt64(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToUInt64(Value), value))
+                                                {
+                                                    writer.WriteResult<ulong>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        }
+                                        else
+                                        {
+                                            #region 64bits - signed
+                                            var Value = br.ReadInt64();
+                                            using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, CurrentIndex))
+                                            {
+                                                long value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(CurrentIndex, out value);
+                                                            gmp.CloseProvider();
+                                                        }
+                                                        catch (Exception ex)
+                                                        {
+                                                            logger.VerboseError.WriteLine(ex.ToString());
+                                                        }
+                                                    }
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToInt64(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(Convert.ToInt64(Value), value))
+                                                {
+                                                    writer.WriteResult<long>(comparer.Address, comparer.Value);
+                                                }
+                                            }
+                                            #endregion
+                                        } break;
+                                }
+                                if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
+                            }
+                            catch (EndOfStreamException) { }
+                            if (e.ReportProgress)
+                            {
+                                double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
+                                int int_percent_done = (int)double_percent_done;
+                                if (CurrentIndex % 10 == 0)
+                                {
+                                    if (int_percent_done <= 100)
+                                    {
+                                        new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Reading Index: 0x{0:x8} of 0x{1:x8}", CurrentIndex, e.TotalCount));
+                                    }
+                                    if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
+                                }
+                            }
+                            //switch (sdt)
+                            //{
+                            //    case SearchDataTypes._8bits:
+                            //        CurrentIndex += sizeof(byte);
+                            //        break;
+                            //    case SearchDataTypes._16bits:
+                            //        CurrentIndex += sizeof(ushort);
+                            //        break;
+                            //    case SearchDataTypes._32bits:
+                            //        CurrentIndex += sizeof(uint);
+                            //        break;
+                            //    case SearchDataTypes._64bits:
+                            //        CurrentIndex += sizeof(ulong);
+                            //        break;
+                            //}
+                        }
+
+                    }
+                }
+            }
+            if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
+        }
         private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
         {
             if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
@@ -1187,7 +1540,6 @@
                                                 }
                                             }
                                             #endregion
-                                            writer.WriteResult<ushort>(CurrentIndex, br.ReadUInt16());
                                         }
                                         else
                                         {
@@ -1469,51 +1821,70 @@
                             byte[] guid = SearchGuid.ToByteArray();
                             guid[guid.Length - 1]++; // increment the search guid by 1
                             Guid new_SearchGuid = new Guid(guid);
-                            //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
-                            //int count = 0;
-                            //int Last_Whole_Percent_Done = 0;
-                            //var results = reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
-
-                            //reader.WriteUpdatedEntries(new_SearchGuid, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
-
-                            const int item_count = 0x1;
+                            const int item_count = 0x100;
                             using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
                             {
-                                //int Last_Whole_Percent_Done = 0;
+                                ////int Last_Whole_Percent_Done = 0;
+                                //for (int i = 0; i < reader.ResultCount; i += item_count)
+                                //{                                   
+                                //    var items = reader.GetResultRangeAtIndex(i,item_count, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
+                                //    for (int j = 0; j < items.Count(); j++)
+                                //    {
+                                //        int index = i + j;
+                                //        var item = items[j];
+                                //        provider.OpenProvider();
+                                //        int bytesRead = 0;
+                                //        byte[] data = new byte[STEP_SIZE];
+                                //        provider.ReadProcessMemory(item.Address, STEP_SIZE, out bytesRead, out data);
+                                //        BaseEventHandler<OnBytesReadEventArgs> t = new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
+                                //        OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, (uint)index, (uint)reader.ResultCount, false);
+                                //        t.Invoke(t_args);
+                                //        t = null;
+                                //        t_args = null;
+                                //        data = null;
+                                //        provider.CloseProvider();                                        
+                                //        //double double_percent_done = 100.0 * (double)((double)index / (double)reader.ResultCount);
+                                //        //int int_percent_done = (int)double_percent_done;
+                                //        //if (i % item_count == 0)
+                                //        //{
+                                //        //    if (int_percent_done <= 100)
+                                //        //    {
+                                //        //        new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Loading value for Address: 0x{0:x8}", item.Address));
+                                //        //        //Last_Whole_Percent_Done = int_percent_done;
+                                //        //    }
+                                //        //}
+                                //    }                                    
+                                //}
                                 for (int i = 0; i < reader.ResultCount; i += item_count)
-                                {                                   
-                                    var item = reader.GetResultAtIndex(i, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
+                                {
+                                    var items = reader.GetResultRangeAtIndex(i, item_count, SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress));
+
+                                    provider.OpenProvider();
+                                    int count = 0;
+                                    foreach (var item in items)
+                                    {
+                                        uint bytesToRead = STEP_SIZE;
+                                        int bytesRead = 0;
+                                        byte[] data = new byte[bytesToRead];
+                                        provider.ReadProcessMemory(item.Address, bytesToRead, out bytesRead, out data);
+                                        BaseEventHandler<OnBytesReadEventArgs> t = new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead_compare_only);
+                                        OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, (uint)count, (uint)item_count, true);
+                                        t.Invoke(t_args);
+                                        t = null;
+                                        t_args = null;
+                                        count++;
+                                    }
                                     double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
                                     int int_percent_done = (int)double_percent_done;
-                                    if (i % 10 == 0)
+                                    if (i % item_count == 0)
                                     {
                                         if (int_percent_done <= 100)
                                         {
-                                            new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Loading value for Address: 0x{0:x8}", item.Address));
+                                            new Action<int, string>(UpdateProgress).Invoke(int_percent_done, string.Format(" -> Loaded {0} value(s) from index: 0x{1:x8}", item_count, i));
                                             //Last_Whole_Percent_Done = int_percent_done;
                                         }
                                     }
-                                    //for (int j = 0; j < items.Count(); j++)
-                                    //{
-                                        //var item = items[j];
-                                        provider.OpenProvider();
-                                        int bytesRead = 0;
-                                        byte[] data = new byte[STEP_SIZE];
-                                        provider.ReadProcessMemory(item.Address, STEP_SIZE, out bytesRead, out data);
-                                        BaseEventHandler<OnBytesReadEventArgs> t = new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
-                                        OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, item.Address, (uint)reader.ResultCount, false);
-                                        t.Invoke(t_args);
-                                        t = null;
-                                        t_args = null;
-                                        data = null;
-                                        provider.CloseProvider();
-                                        //double percent_done = 100.0 * ((double)i+(double)j / (double)reader.ResultCount);
-
-                                        
-
-                                        //double percent_done = 100.0 * ((double)i / (double)reader.ResultCount);
-                                        //new Action<int, string>(UpdateProgress).Invoke((int)percent_done, string.Format(" -> Reading Address: 0x{0:x8}", item.Address));
-                                    //}                                 
+                                    provider.CloseProvider();
                                 }
                             }
                             SearchGuid = new_SearchGuid;

 

  ViewVC Help
Powered by ViewVC 1.1.22