/[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/05 04:50:44	520
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/05 07:06:53	521
@@ -1443,27 +1443,22 @@
                         {
                             try
                             {
-                                if (e.ReportProgress)
-                                {
-                                    double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
-                                    int int_percent_done = (int)double_percent_done;
-                                    
-                                    double align_base = 100000;
-                                    double align_power = 1;
-                                    double align = align_base * align_power;
-                                    if ((int_percent_done != Last_Whole_Percent_Done) && (CurrentIndex % align) == 0)
-                                    //if ((CurrentIndex % align) == 0)
-                                    {
-                                        if (int_percent_done <= 100)
-                                        {
-                                            string message = string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart));
-                                            UpdateProgress(int_percent_done, message);
-                                            //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, message);
-                                            Last_Whole_Percent_Done = int_percent_done;
-                                        }
-                                        if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
-                                    }
-                                }
+                                //if (e.ReportProgress)
+                                //{
+                                //    double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
+                                //    int int_percent_done = (int)double_percent_done;
+                                //    int align_base = 100;
+                                //    int align_power = 1;
+                                //    int align = align_base * align_power;
+                                //    if (int_percent_done != Last_Whole_Percent_Done && (CurrentIndex % align) == 0)
+                                //    {
+                                //        string message = string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart));
+                                //        UpdateProgress((int)double_percent_done, message);
+                                //        //new Action<int, string>(UpdateProgress).Invoke(int_percent_done, message);
+                                //        Last_Whole_Percent_Done = int_percent_done;
+                                //        if (SearchWorkerThread.CancellationPending) { e.Canceled = true; return; }
+                                //    }
+                                //}
 
                                 switch (sdt)
                                 {
@@ -1807,8 +1802,422 @@
                         provider.OpenProvider();
                         int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
                         SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
-                        provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
-                        provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), writer);
+                        //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
+                        //provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), writer);
+
+
+                        Stopwatch st_profiler = new Stopwatch();
+                        st_profiler.Start();
+                        //int Last_Whole_Percent_Done = 0;
+                        uint size = STEP_SIZE * 4096;
+                        for (uint i = MemoryRangeStart; i < MemoryRangeSize; i+=size)
+                        {
+                           
+                            int bytesRead=0;
+                            byte[] data = new byte[size];
+                            //provider.ReadProcessMemory(i, size, out bytesRead, out data);
+
+                            provider.ReadProcessMemoryAtOnce(i, size, out bytesRead, out data);
+
+                            //OnBytesReadEventArgs t_args = new OnBytesReadEventArgs(this, writer, data, i, MemoryRangeSize, true);
+                            //search_provider_OnBytesRead(t_args);
+                            //t_args = null;
+
+                            string message = string.Format(" -> Reading Address: 0x{0:x8}", (i + MemoryRangeStart));
+                            double double_percent_done = 100.0 * (double)((double)i / (double)MemoryRangeSize);
+                            //int int_percent_done = (int)double_percent_done;
+                            if ((i % 10000) == 0)
+                            {
+                                UpdateProgress((int)double_percent_done, message);
+                                logger.Profiler.WriteLine("Memory Search Operation Profiler: search operation has taken {0} seconds", st_profiler.Elapsed.TotalSeconds.ToString());
+                                //Last_Whole_Percent_Done = int_percent_done;
+                            }
+
+                            //int len = data.Length / BitTools.SizeOf<int>(sdt);
+                            //switch (sdt)
+                            //{
+                            //    case SearchDataTypes._8bits: 
+                            //        // use the data array as is
+                            //        break;
+                            //    case SearchDataTypes._16bits: 
+                            //        // create a short or ushort arrray from data
+                            //        break;
+                            //    case SearchDataTypes._32bits:
+                            //        // create a int or uing arrray from data
+                            //        break;
+                            //    case SearchDataTypes._64bits:
+                            //        // create a long or ulong arrray from data
+                            //        break;
+                            //}
+
+                            // testing byte array conversion
+                            
+
+
+                            #region comparison and serialization
+                            switch (sdt)
+                            {
+                                case SearchDataTypes._8bits:
+                                    if (unsigned)
+                                    {
+                                        #region 8bits - unsigned
+                                        var t_data = BitTools.ConvertByteArray<byte>(data);
+                                        foreach (var Value in t_data)
+                                        {
+                                            if (SearchWorkerThread.CancellationPending) { break; }
+                                            using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, i))
+                                            {
+                                                byte value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<sbyte>(data);
+                                        foreach (var Value in t_data)
+                                        {
+                                            if (SearchWorkerThread.CancellationPending) { break; }
+                                            using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, i))
+                                            {
+                                                sbyte value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                    {
+                                                        try
+                                                        {
+                                                            gmp.OpenProvider();
+                                                            gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<ushort>(data);
+                                          foreach (var Value in t_data)
+                                          {
+                                              if (SearchWorkerThread.CancellationPending) { break; }
+                                              using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, i))
+                                              {
+                                                  ushort value = 0;
+                                                  if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                  {
+                                                      using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                      {
+                                                          try
+                                                          {
+                                                              gmp.OpenProvider();
+                                                              gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<short>(data);
+                                         foreach (var Value in t_data)
+                                         {
+                                             if (SearchWorkerThread.CancellationPending) { break; }
+                                             using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, i))
+                                             {
+                                                 short value = 0;
+                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                 {
+                                                     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                     {
+                                                         try
+                                                         {
+                                                             gmp.OpenProvider();
+                                                             gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<uint>(data);
+                                         foreach (var Value in t_data)
+                                         {
+                                             if (SearchWorkerThread.CancellationPending) { break; }
+                                             using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, i))
+                                             {
+                                                 uint value = 0;
+                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                 {
+                                                     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                     {
+                                                         try
+                                                         {
+                                                             gmp.OpenProvider();
+                                                             gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<int>(data);
+                                         foreach (var Value in t_data)
+                                         {
+                                             if (SearchWorkerThread.CancellationPending) { break; }
+                                             using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, i))
+                                             {
+                                                 int value = 0;
+                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                 {
+                                                     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                     {
+                                                         try
+                                                         {
+                                                             gmp.OpenProvider();
+                                                             gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<ulong>(data);
+                                         foreach (var Value in t_data)
+                                         {
+                                             if (SearchWorkerThread.CancellationPending) { break; }
+                                             using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, i))
+                                             {
+                                                 ulong value = 0;
+                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                 {
+                                                     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                     {
+                                                         try
+                                                         {
+                                                             gmp.OpenProvider();
+                                                             gmp.ReadMemory(i, 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 t_data = BitTools.ConvertByteArray<long>(data);
+                                         foreach (var Value in t_data)
+                                         {
+                                             if (SearchWorkerThread.CancellationPending) { break; }
+                                             using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, i))
+                                             {
+                                                 long value = 0;
+                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                 {
+                                                     using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                     {
+                                                         try
+                                                         {
+                                                             gmp.OpenProvider();
+                                                             gmp.ReadMemory(i, 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;
+                            }
+                            
+                            //using (MemoryStream ms = new MemoryStream(data))
+                            //{
+                            //    using (BinaryReader br = new BinaryReader(ms))
+                            //    {
+                            //        while (br.BaseStream.Position < br.BaseStream.Length)
+                            //        {
+                            //            if (SearchWorkerThread.CancellationPending)
+                            //            {
+                            //                break;
+                            //            }                                       
+                            //        }
+                            //    }
+                            //}
+                            #endregion
+
+
+                            if (SearchWorkerThread.CancellationPending)
+                            {
+                                st_profiler.Stop();
+                                provider_st.Stop();
+                                st.Stop();
+                                writer.CancelRequest();
+                                writer.Dispose();
+                                writer = null;
+                                e.Result = true;
+                                provider.CloseProvider();
+                                logger.Profiler.WriteLine("Memory Search Operation Profiler: search operation took {0} seconds", st_profiler.Elapsed.TotalSeconds.ToString());
+                                return;
+                            }
+                        }
+
+                        st_profiler.Stop();
+
+                        logger.Profiler.WriteLine("Memory Search Operation Profiler: search operation took {0} seconds", st_profiler.Elapsed.TotalSeconds.ToString());
+
                         if (SearchWorkerThread.CancellationPending)
                         {
                             provider_st.Stop();

 

  ViewVC Help
Powered by ViewVC 1.1.22