/[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 07:37:37	525
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/05 08:03:28	526
@@ -1802,13 +1802,7 @@
                     {
                         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);
-
-
-                        Stopwatch st_profiler = new Stopwatch();
-                        st_profiler.Start();
+                        SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);                                             
                         int Last_Whole_Percent_Done = 0;
                         uint size = STEP_SIZE * 4096;
                         for (uint i = MemoryRangeStart; i < MemoryRangeSize; i+=size)
@@ -1816,25 +1810,17 @@
                            
                             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 ( (int_percent_done != Last_Whole_Percent_Done) && (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;
                             }
 
-
+                            uint address_index = i;
                             #region comparison and serialization
                             switch (sdt)
                             {
@@ -1846,7 +1832,7 @@
                                         foreach (var Value in t_data)
                                         {
                                             if (SearchWorkerThread.CancellationPending) { break; }
-                                            using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, i))
+                                            using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
                                             {
                                                 byte value = 0;
                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -1856,7 +1842,7 @@
                                                         try
                                                         {
                                                             gmp.OpenProvider();
-                                                            gmp.ReadMemory(i, out value);
+                                                            gmp.ReadMemory(address_index, out value);
                                                             gmp.CloseProvider();
                                                         }
                                                         catch (Exception ex)
@@ -1876,6 +1862,7 @@
                                                     writer.WriteResult<byte>(comparer.Address, comparer.Value);
                                                 }
                                             }
+                                            address_index += STEP_SIZE;
                                         }
                                         #endregion
                                     }
@@ -1886,7 +1873,7 @@
                                         foreach (var Value in t_data)
                                         {
                                             if (SearchWorkerThread.CancellationPending) { break; }
-                                            using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, i))
+                                            using (_8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address_index))
                                             {
                                                 sbyte value = 0;
                                                 if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -1896,7 +1883,7 @@
                                                         try
                                                         {
                                                             gmp.OpenProvider();
-                                                            gmp.ReadMemory(i, out value);
+                                                            gmp.ReadMemory(address_index, out value);
                                                             gmp.CloseProvider();
                                                         }
                                                         catch (Exception ex)
@@ -1916,6 +1903,7 @@
                                                     writer.WriteResult<sbyte>(comparer.Address, comparer.Value);
                                                 }
                                             }
+                                            address_index += STEP_SIZE;
                                         }
                                         #endregion
                                     } break;
@@ -1927,7 +1915,7 @@
                                           foreach (var Value in t_data)
                                           {
                                               if (SearchWorkerThread.CancellationPending) { break; }
-                                              using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, i))
+                                              using (_16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address_index))
                                               {
                                                   ushort value = 0;
                                                   if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -1937,7 +1925,7 @@
                                                           try
                                                           {
                                                               gmp.OpenProvider();
-                                                              gmp.ReadMemory(i, out value);
+                                                              gmp.ReadMemory(address_index, out value);
                                                               gmp.CloseProvider();
                                                           }
                                                           catch (Exception ex)
@@ -1957,6 +1945,7 @@
                                                       writer.WriteResult<ushort>(comparer.Address, comparer.Value);
                                                   }
                                               }
+                                              address_index += STEP_SIZE;
                                           }
                                         #endregion
                                     }
@@ -1967,7 +1956,7 @@
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
-                                             using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, i))
+                                             using (_16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address_index))
                                              {
                                                  short value = 0;
                                                  if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -1977,7 +1966,7 @@
                                                          try
                                                          {
                                                              gmp.OpenProvider();
-                                                             gmp.ReadMemory(i, out value);
+                                                             gmp.ReadMemory(address_index, out value);
                                                              gmp.CloseProvider();
                                                          }
                                                          catch (Exception ex)
@@ -1997,6 +1986,7 @@
                                                      writer.WriteResult<short>(comparer.Address, comparer.Value);
                                                  }
                                              }
+                                             address_index += STEP_SIZE;
                                          }
                                         #endregion
                                     } break;
@@ -2008,7 +1998,7 @@
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
-                                             using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, i))
+                                             using (_32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address_index))
                                              {
                                                  uint value = 0;
                                                  if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -2018,7 +2008,7 @@
                                                          try
                                                          {
                                                              gmp.OpenProvider();
-                                                             gmp.ReadMemory(i, out value);
+                                                             gmp.ReadMemory(address_index, out value);
                                                              gmp.CloseProvider();
                                                          }
                                                          catch (Exception ex)
@@ -2038,6 +2028,7 @@
                                                      writer.WriteResult<uint>(comparer.Address, comparer.Value);
                                                  }
                                              }
+                                             address_index += STEP_SIZE;
                                          }
                                         #endregion
                                     }
@@ -2048,7 +2039,7 @@
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
-                                             using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, i))
+                                             using (_32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address_index))
                                              {
                                                  int value = 0;
                                                  if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -2058,7 +2049,7 @@
                                                          try
                                                          {
                                                              gmp.OpenProvider();
-                                                             gmp.ReadMemory(i, out value);
+                                                             gmp.ReadMemory(address_index, out value);
                                                              gmp.CloseProvider();
                                                          }
                                                          catch (Exception ex)
@@ -2078,6 +2069,7 @@
                                                      writer.WriteResult<int>(comparer.Address, comparer.Value);
                                                  }
                                              }
+                                             address_index += STEP_SIZE;
                                          }
                                         #endregion
                                     } break;
@@ -2089,7 +2081,7 @@
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
-                                             using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, i))
+                                             using (_64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address_index))
                                              {
                                                  ulong value = 0;
                                                  if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -2099,7 +2091,7 @@
                                                          try
                                                          {
                                                              gmp.OpenProvider();
-                                                             gmp.ReadMemory(i, out value);
+                                                             gmp.ReadMemory(address_index, out value);
                                                              gmp.CloseProvider();
                                                          }
                                                          catch (Exception ex)
@@ -2119,6 +2111,7 @@
                                                      writer.WriteResult<ulong>(comparer.Address, comparer.Value);
                                                  }
                                              }
+                                             address_index += STEP_SIZE;
                                          }
                                         #endregion
                                     }
@@ -2129,7 +2122,7 @@
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
-                                             using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, i))
+                                             using (_64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address_index))
                                              {
                                                  long value = 0;
                                                  if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
@@ -2139,7 +2132,7 @@
                                                          try
                                                          {
                                                              gmp.OpenProvider();
-                                                             gmp.ReadMemory(i, out value);
+                                                             gmp.ReadMemory(address_index, out value);
                                                              gmp.CloseProvider();
                                                          }
                                                          catch (Exception ex)
@@ -2159,30 +2152,17 @@
                                                      writer.WriteResult<long>(comparer.Address, comparer.Value);
                                                  }
                                              }
+                                             address_index += STEP_SIZE;
                                          }
                                         #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();
@@ -2190,15 +2170,10 @@
                                 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();
@@ -2216,186 +2191,459 @@
                     }
                     else
                     {
-
-                        #region action_onbytesread :: custom in-line delegate for processing read bytes
-                        // custom in-line delegate for processing read bytes
-                        Action<OnBytesReadEventArgs> action_onbytesread = delegate(OnBytesReadEventArgs obre)
+                        // need to get the address list
+                        using (SearchResultReader reader = new SearchResultReader(SearchGuid, false)) // delete the file on dispose
                         {
-                            SearchDataTypes obre_sdt = SearchArgs.DataType;
-                            bool obre_unsigned = SearchArgs.IsUnsignedDataType;
-                            uint obre_CurrentIndex = obre.CurrentIndex; // this should represent the address
-                            SearchResultReader reader = null;
-                            if (obre.UserState != null)
-                            {
-                                reader = (obre.UserState as SearchResultReader);
-                                if (reader == null)
-                                    throw new InvalidOperationException("writer cannot be null");
-                            }
-                            else
-                            {
-                                throw new ArgumentNullException("UserState", "UserState cannot be null, it must be an instance of a SearchResultReader");
-                            }
-                            using (MemoryStream ms = new MemoryStream(obre.Data))
-                            {
-                                using (BinaryReader br = new BinaryReader(ms))
+                            #region old-code
+                            //provider.OpenProvider();
+                            ////int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
+                            ////SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
+                            //provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(action_onbytesread);
+                            //provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), reader);
+                            //if (SearchWorkerThread.CancellationPending)
+                            //{
+                            //    provider_st.Stop();
+                            //    st.Stop();           
+                            //    e.Result = true;
+                            //    provider.CloseProvider();
+                            //    return;
+                            //}
+                            //provider.CloseProvider();
+
+                            //byte[] guid = SearchGuid.ToByteArray();
+                            //guid[guid.Length - 1]++; // increment the search guid by 1
+                            //Guid new_SearchGuid = new Guid(guid);
+                            ////const int item_count = 0x100;
+                            //using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
+                            //{
+                            //    var items = reader.GetSearchAddressValueMatches((IAcceptsProcessAndConfig)this, SearchArgs, new Action<int, string>(UpdateProgress));
+                            //    reader.Dispose(); // delete the result file, if allowed
+                            //    foreach (var item in items)
+                            //    {
+                            //        switch (SearchArgs.DataType)
+                            //        {
+                            //            case SearchDataTypes._8bits:
+                            //                if (SearchArgs.IsUnsignedDataType)
+                            //                {
+                            //                    writer.WriteResult<byte>(item.Address, Convert.ToByte(item.Value));
+                            //                }
+                            //                else
+                            //                {
+                            //                    writer.WriteResult<sbyte>(item.Address, Convert.ToSByte(item.Value));
+                            //                }
+                            //                break;
+                            //            case SearchDataTypes._16bits:
+                            //                if (SearchArgs.IsUnsignedDataType)
+                            //                {
+                            //                    writer.WriteResult<ushort>(item.Address, Convert.ToUInt16(item.Value));
+                            //                }
+                            //                else
+                            //                {
+                            //                    writer.WriteResult<short>(item.Address, Convert.ToInt16(item.Value));
+                            //                }
+                            //                break;
+                            //            case SearchDataTypes._32bits:
+                            //                if (SearchArgs.IsUnsignedDataType)
+                            //                {
+                            //                    writer.WriteResult<uint>(item.Address, Convert.ToUInt32(item.Value));
+                            //                }
+                            //                else
+                            //                {
+                            //                    writer.WriteResult<int>(item.Address, Convert.ToInt32(item.Value));
+                            //                }
+                            //                break;
+                            //            case SearchDataTypes._64bits:
+                            //                if (SearchArgs.IsUnsignedDataType)
+                            //                {
+                            //                    writer.WriteResult<ulong>(item.Address, Convert.ToUInt64(item.Value));
+                            //                }
+                            //                else
+                            //                {
+                            //                    writer.WriteResult<long>(item.Address, Convert.ToInt64(item.Value));
+                            //                }
+                            //                break;
+                            //        }
+                            //    }
+                            //}
+                            //SearchGuid = new_SearchGuid;
+                            #endregion
+
+                            byte[] guid = SearchGuid.ToByteArray();
+                            guid[guid.Length - 1]++; // increment the search guid by 1
+                            Guid new_SearchGuid = new Guid(guid);
+
+                            foreach(var k in reader.GetResults(SearchArgs.IsUnsignedDataType,SearchArgs.DataType,new Action<int,string>(UpdateProgress)))
+                            {                                
+                                provider.OpenProvider();
+                                int bytesRead=0;
+                                byte[] data = new byte[STEP_SIZE];
+                                provider.ReadProcessMemory(k.Address, STEP_SIZE, out bytesRead, out data);
+                                provider.CloseProvider();
+
+                                uint address_index = k.Address;
+                                #region comparison and serialization
+                                switch (sdt)
                                 {
-                                    while (br.BaseStream.Position < br.BaseStream.Length)
-                                    {
-                                        ISerializedResult sr = (reader as ISerializedResult);
-                                        if (sr == null)
+                                    case SearchDataTypes._8bits:
+                                        if (unsigned)
                                         {
-                                            throw new ArgumentNullException("sr", string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name, typeof(ISerializedResult).Name));
-                                        }
-                                        int sr_index = 0;
-                                        try
-                                        {
-                                            if (sr.ContainsAddress(obre_CurrentIndex, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out sr_index))
+                                            #region 8bits - unsigned
+                                            var t_data = BitTools.ConvertByteArray<byte>(data);
+                                            foreach (var Value in t_data)
                                             {
-                                                StructResultType<ulong> result = StructResultType<ulong>.Empty;
-                                                sr.GetResultAtIndex(sr_index, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out result);
-                                                if (Debugger.IsAttached)
+                                                if (SearchWorkerThread.CancellationPending) { break; }
+                                                using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address_index))
                                                 {
-                                                    Debugger.Break();
+                                                    byte value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-
+                                                address_index += STEP_SIZE;
                                             }
+                                            #endregion
                                         }
-                                        catch (Exception ex)
+                                        else
                                         {
-                                            throw ex;
-                                        }
-                                        switch (obre_sdt)
-                                        {
-                                            case SearchDataTypes._8bits:
-                                                if (obre_unsigned)
+                                            #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, address_index))
                                                 {
-                                                    #region 8bit - unsigned
-                                                    var new_value = br.ReadByte(); // this should contain the updated value from memory
-                                                    using (_8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, obre_CurrentIndex))
+                                                    sbyte value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                                     {
-                                                        byte value = 0; // this is the vaule we want to compare against
-                                                        value = Convert.ToByte(SearchArgs.CompareStartValue);
-                                                        comparer.Value = value;
-                                                        if (comparer.Compare(new_value, value))
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
                                                         {
-                                                            //writer.WriteResult<byte>(comparer.Address, comparer.Value);
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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
-                                                }
-                                                else
-                                                {
                                                 }
-                                                break;
-                                            case SearchDataTypes._16bits:
-                                                if (obre_unsigned)
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #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, address_index))
                                                 {
+                                                    ushort value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-                                                else
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #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, address_index))
                                                 {
+                                                    short value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-                                                break;
-                                            case SearchDataTypes._32bits:
-                                                if (obre_unsigned)
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #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, address_index))
                                                 {
+                                                    uint value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-                                                else
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #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, address_index))
                                                 {
+                                                    int value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-                                                break;
-                                            case SearchDataTypes._64bits:
-                                                if (obre_unsigned)
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #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, address_index))
                                                 {
+                                                    ulong value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-                                                else
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #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, address_index))
                                                 {
+                                                    long value = 0;
+                                                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                    {
+                                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                                                        {
+                                                            try
+                                                            {
+                                                                gmp.OpenProvider();
+                                                                gmp.ReadMemory(address_index, 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);
+                                                    }
                                                 }
-                                                break;
-                                        }
-                                        uint size = 0;
-                                        BitTools.SizeOf(obre_sdt, out size);
-                                        obre_CurrentIndex += size;
-                                    }
+                                                address_index += STEP_SIZE;
+                                            }
+                                            #endregion
+                                        } break;
+
                                 }
-                            }
-                        };
-                        #endregion
-                        // need to get the address list
-                        using (SearchResultReader reader = new SearchResultReader(SearchGuid, false)) // delete the file on dispose
-                        {
-                           
+                                #endregion
 
-                            provider.OpenProvider();
-                            //int count = (int)((MemoryRangeSize - MemoryRangeStart) / STEP_SIZE);
-                            //SearchResultWriter writer = new SearchResultWriter((int)(count), SearchGuid);
-                            provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(action_onbytesread);
-                            provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), reader);
-                            if (SearchWorkerThread.CancellationPending)
-                            {
-                                provider_st.Stop();
-                                st.Stop();           
-                                e.Result = true;
-                                provider.CloseProvider();
-                                return;
                             }
-                            provider.CloseProvider();
 
-                        //byte[] guid = SearchGuid.ToByteArray();
-                        //guid[guid.Length - 1]++; // increment the search guid by 1
-                        //Guid new_SearchGuid = new Guid(guid);
-                        ////const int item_count = 0x100;
-                        //using (SearchResultWriter writer = new SearchResultWriter((int)(reader.ResultCount), new_SearchGuid))
-                        //{
-                        //    var items = reader.GetSearchAddressValueMatches((IAcceptsProcessAndConfig)this, SearchArgs, new Action<int, string>(UpdateProgress));
-                        //    reader.Dispose(); // delete the result file, if allowed
-                        //    foreach (var item in items)
-                        //    {
-                        //        switch (SearchArgs.DataType)
-                        //        {
-                        //            case SearchDataTypes._8bits:
-                        //                if (SearchArgs.IsUnsignedDataType)
-                        //                {
-                        //                    writer.WriteResult<byte>(item.Address, Convert.ToByte(item.Value));
-                        //                }
-                        //                else
-                        //                {
-                        //                    writer.WriteResult<sbyte>(item.Address, Convert.ToSByte(item.Value));
-                        //                }
-                        //                break;
-                        //            case SearchDataTypes._16bits:
-                        //                if (SearchArgs.IsUnsignedDataType)
-                        //                {
-                        //                    writer.WriteResult<ushort>(item.Address, Convert.ToUInt16(item.Value));
-                        //                }
-                        //                else
-                        //                {
-                        //                    writer.WriteResult<short>(item.Address, Convert.ToInt16(item.Value));
-                        //                }
-                        //                break;
-                        //            case SearchDataTypes._32bits:
-                        //                if (SearchArgs.IsUnsignedDataType)
-                        //                {
-                        //                    writer.WriteResult<uint>(item.Address, Convert.ToUInt32(item.Value));
-                        //                }
-                        //                else
-                        //                {
-                        //                    writer.WriteResult<int>(item.Address, Convert.ToInt32(item.Value));
-                        //                }
-                        //                break;
-                        //            case SearchDataTypes._64bits:
-                        //                if (SearchArgs.IsUnsignedDataType)
-                        //                {
-                        //                    writer.WriteResult<ulong>(item.Address, Convert.ToUInt64(item.Value));
-                        //                }
-                        //                else
-                        //                {
-                        //                    writer.WriteResult<long>(item.Address, Convert.ToInt64(item.Value));
-                        //                }
-                        //                break;
-                        //        }
-                        //    }
-                        //}
-                        //SearchGuid = new_SearchGuid;
+
+                            //ISerializedResult sr = (reader as ISerializedResult);
+                            //if (sr == null)
+                            //{
+                            //    throw new ArgumentNullException("sr", string.Format("Unable to cast: '{0}' to '{1}'", reader.GetType().Name, typeof(ISerializedResult).Name));
+                            //}
+                            //int sr_index = 0;
+                            //try
+                            //{
+                            //    if (sr.ContainsAddress(obre_CurrentIndex, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out sr_index))
+                            //    {
+                            //        StructResultType<ulong> result = StructResultType<ulong>.Empty;
+                            //        sr.GetResultAtIndex(sr_index, obre_unsigned, obre_sdt, new Action<int, string>(this.UpdateProgress), out result);
+                            //        if (Debugger.IsAttached)
+                            //        {
+                            //            Debugger.Break();
+                            //        }
+                            //    }
+                            //}
+
+
+
                         }
                     }
                 }

 

  ViewVC Help
Powered by ViewVC 1.1.22