/[RomCheater]/trunk/RomCheater/Docking/FloatingMemorySearcher.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/FloatingMemorySearcher.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/21 15:59:29	407
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/21 18:10:21	408
@@ -1023,7 +1023,60 @@
                 Debug.WriteLine(ex.ToString());
             }
         }
-
+        private void search_provider_OnBytesRead(OnBytesReadEventArgs e)
+        {
+            SearchDataTypes sdt = SearchArgs.DataType;
+            bool unsigned = SearchArgs.IsUnsignedDataType;
+            int Last_Whole_Percent_Done = 0;
+            uint CurrentIndex = e.CurrentIndex;
+            if (e.UserState != null)
+            {
+                SearchResultWriter writer = (e.UserState as SearchResultWriter);
+                if (writer == null)
+                    throw new InvalidOperationException("writer cannot be null");
+                using (MemoryStream ms = new MemoryStream(e.Data))
+                {
+                    using (BinaryReader br = new BinaryReader(ms))
+                    {
+                        while (br.BaseStream.Position < br.BaseStream.Length)
+                        {
+                            try
+                            {
+                                switch (sdt)
+                                {
+                                    case SearchDataTypes._8bits:
+                                        if (unsigned) { writer.WriteResult<Byte>((uint)br.BaseStream.Position, br.ReadByte()); }
+                                        else { writer.WriteResult<SByte>((uint)br.BaseStream.Position, br.ReadSByte()); } break;
+                                    case SearchDataTypes._16bits:
+                                        if (unsigned) { writer.WriteResult<UInt16>((uint)br.BaseStream.Position, br.ReadUInt16()); }
+                                        else { writer.WriteResult<Int16>((uint)br.BaseStream.Position, br.ReadInt16()); } break;
+                                    case SearchDataTypes._32bits:
+                                        if (unsigned) { writer.WriteResult<UInt32>((uint)br.BaseStream.Position, br.ReadUInt32()); }
+                                        else { writer.WriteResult<Int32>((uint)br.BaseStream.Position, br.ReadInt32()); } break;
+                                    case SearchDataTypes._64bits:
+                                        if (unsigned) { writer.WriteResult<UInt64>((uint)br.BaseStream.Position, br.ReadUInt64()); }
+                                        else { writer.WriteResult<Int64>((uint)br.BaseStream.Position, br.ReadInt64()); } break;
+                                }
+                            }
+                            catch (EndOfStreamException) { }
+                            double double_percent_done = 100.0 * (double)((double)CurrentIndex / (double)e.TotalCount);
+                            int int_percent_done = (int)double_percent_done;
+                            if (int_percent_done != Last_Whole_Percent_Done && (((double)Last_Whole_Percent_Done / 2.0) == (int)((double)Last_Whole_Percent_Done / 2.0)))
+                            {
+                                if (int_percent_done <= 100)
+                                {
+                                    resultsprogress.Value = int_percent_done;
+                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", (CurrentIndex + MemoryRangeStart));
+                                    Last_Whole_Percent_Done = int_percent_done;
+                                }
+                            }
+                            CurrentIndex++;
+                        }
+                     
+                    }
+                }
+            }
+        }
         private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e)
         {
             Stopwatch st = new Stopwatch();
@@ -1042,452 +1095,463 @@
 
             bool unsigned = SearchArgs.IsUnsignedDataType;
             SearchDataTypes sdt = SearchArgs.DataType;
-            byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
+            //byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
+            logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", MemoryRangeSize - MemoryRangeStart));
+            resultsprogress.Value = 0;
+            resultsprogress.Message = string.Format("Search is Warming Up...Please Wait...");
+
+            Stopwatch provider_st = new Stopwatch();
+            provider_st.Start();
             using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
             {
                 provider.OpenProvider();
-                int bytes_read = 0;               
-                provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), out bytes_read, out buffered_mem);
+                int count = (int)(MemoryRangeSize - MemoryRangeStart) / (int)STEP_SIZE;
+                SearchResultWriter writer = new SearchResultWriter(count);
+                provider.OnBytesRead += new BaseEventHandler<OnBytesReadEventArgs>(search_provider_OnBytesRead);
+                provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), writer);
                 provider.CloseProvider();
+                writer.Dispose();
             }
-            if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
-            using (MemoryStream ms = new MemoryStream(buffered_mem))
+            provider_st.Stop();
+            logger.Profiler.WriteLine("It took a total of {0} seconds for the memory provider to complete it's operation(s).", provider_st.Elapsed.TotalSeconds);
+            //if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }            
+            int Last_Whole_Percent_Done = 0;
+
+            #region First Search
+            //if (SearchArgs.IsFirstSearch)
+            //{
+            //    st_first_search.Start();
+            //    //SearchArgs.Results.Clear();
+            //    r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
+            //    int count = (int)buffered_mem.Length / (int)STEP_SIZE;
+            //    #region using (SearchResultWriter writer = new SearchResultWriter(count))
+            //    using (SearchResultWriter writer = new SearchResultWriter(count))
+            //    {
+            //        //List<ResultType<object>> results_list = new List<ResultType<object>>();
+            //        //for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
+            //        //{
+            //        #region while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
+            //        while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
+            //        {
+            //            //using (ResultType<object> _tmp_result = new ResultType<object>())
+            //            //{
+            //            try
+            //            {
+            //                switch (sdt)
+            //                {
+            //                    case SearchDataTypes._8bits:
+            //                        if (unsigned) { writer.WriteResult<Byte>((uint)r_ms.BaseStream.Position, r_ms.ReadByte()); }
+            //                        else { writer.WriteResult<SByte>((uint)r_ms.BaseStream.Position, r_ms.ReadSByte()); } break;
+            //                    case SearchDataTypes._16bits:
+            //                        if (unsigned) { writer.WriteResult<UInt16>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt16()); }
+            //                        else { writer.WriteResult<Int16>((uint)r_ms.BaseStream.Position, r_ms.ReadInt16()); } break;
+            //                    case SearchDataTypes._32bits:
+            //                        if (unsigned) { writer.WriteResult<UInt32>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt32()); }
+            //                        else { writer.WriteResult<Int32>((uint)r_ms.BaseStream.Position, r_ms.ReadInt32()); } break;
+            //                    case SearchDataTypes._64bits:
+            //                        if (unsigned) { writer.WriteResult<UInt64>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt64()); }
+            //                        else { writer.WriteResult<Int64>((uint)r_ms.BaseStream.Position, r_ms.ReadInt64()); } break;
+            //                }
+            //            }
+            //            catch (EndOfStreamException)
+            //            {
+            //                //logger.VerboseError.WriteLine(ex.ToString());
+            //                break;
+            //            }
+            //            //results_list.Add(_tmp_result);
+            //            //SearchArgs.Results.Add(_tmp_result);
+            //            double double_percent_done = 100.0 * (double)((double)r_ms.BaseStream.Position / (double)r_ms.BaseStream.Length);
+            //            int int_percent_done = (int)double_percent_done;
+            //            if (int_percent_done != Last_Whole_Percent_Done)
+            //            {
+            //                if (int_percent_done <= 100)
+            //                {
+            //                    resultsprogress.Value = int_percent_done;
+            //                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", (r_ms.BaseStream.Position + MemoryRangeStart));
+            //                    Last_Whole_Percent_Done = int_percent_done;
+            //                }
+            //            }
+            //        }
+            //        if (SearchWorkerThread.CancellationPending == true)
+            //        {
+            //            e.Cancel = true;
+            //            return;
+            //        }
+            //        #endregion
+            //    }
+            //    #endregion
+            //    //}
+            //    //SearchArgs.Results.AddRange(results_list);
+            //    //results_list = null;
+            //    resultsprogress.Value = 100;
+            //    resultsprogress.Message = "";
+            //    //Application.DoEvents();
+            //    st_first_search.Stop();
+            //    logger.Profiler.WriteLine("First search took a total of {0} seconds to complete.", st_first_search.Elapsed.TotalSeconds);
+            //    Last_Whole_Percent_Done = 0;
+            //}
+            #endregion
+
+            #region Subsequent Searches
+            //r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
+
+
+            // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
+            bool NeedToCompare = true;
+            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
+                SearchArgs.CompareType == SearchCompareTypes.Equal &&
+                SearchArgs.IsFirstSearch)
             {
-                using (BinaryReader r_ms = new BinaryReader(ms))
+                NeedToCompare = false;
+                //second_tmp_Results = null; // Free Memory
+            }
+
+            if (NeedToCompare)
+            {
+                if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
                 {
-                    logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
-                    int Last_Whole_Percent_Done = 0;
+                    #region Non-Range Searches
+                    st_nonrange_search.Start();
+                    //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
+                    ////second_tmp_Results.c
 
-                    #region First Search
-                    if (SearchArgs.IsFirstSearch)
+                    using (SearchResultReader reader = new SearchResultReader())
                     {
-                        st_first_search.Start();
-                        //SearchArgs.Results.Clear();
-                        r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
-                        int count = (int)buffered_mem.Length / (int)STEP_SIZE;
-                        #region using (SearchResultWriter writer = new SearchResultWriter(count))
-                        using (SearchResultWriter writer = new SearchResultWriter(count))
+                        for (int i = 0; i < reader.ResultCount; i += 1)
                         {
-                            //List<ResultType<object>> results_list = new List<ResultType<object>>();
-                            //for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
-                            //{
-                            #region while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
-                            while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
-                            {
-                                //using (ResultType<object> _tmp_result = new ResultType<object>())
-                                //{
-                                try
-                                {
-                                    switch (sdt)
-                                    {
-                                        case SearchDataTypes._8bits:
-                                            if (unsigned) { writer.WriteResult<Byte>((uint)r_ms.BaseStream.Position, r_ms.ReadByte()); }
-                                            else { writer.WriteResult<SByte>((uint)r_ms.BaseStream.Position, r_ms.ReadSByte()); } break;
-                                        case SearchDataTypes._16bits:
-                                            if (unsigned) { writer.WriteResult<UInt16>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt16()); }
-                                            else { writer.WriteResult<Int16>((uint)r_ms.BaseStream.Position, r_ms.ReadInt16()); } break;
-                                        case SearchDataTypes._32bits:
-                                            if (unsigned) { writer.WriteResult<UInt32>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt32()); }
-                                            else { writer.WriteResult<Int32>((uint)r_ms.BaseStream.Position, r_ms.ReadInt32()); } break;
-                                        case SearchDataTypes._64bits:
-                                            if (unsigned) { writer.WriteResult<UInt64>((uint)r_ms.BaseStream.Position, r_ms.ReadUInt64()); }
-                                            else { writer.WriteResult<Int64>((uint)r_ms.BaseStream.Position, r_ms.ReadInt64()); } break;
-                                    }
-                                }
-                                catch (EndOfStreamException)
-                                {
-                                    //logger.VerboseError.WriteLine(ex.ToString());
-                                    break;
-                                }
-                                //results_list.Add(_tmp_result);
-                                //SearchArgs.Results.Add(_tmp_result);
-                                double double_percent_done = 100.0 * (double)((double)r_ms.BaseStream.Position / (double)r_ms.BaseStream.Length);
-                                int int_percent_done = (int)double_percent_done;
-                                if (int_percent_done != Last_Whole_Percent_Done)
+                            if (reader.ReadCurrentAddess)
+                            {
+                                if (!reader.ReadCurrentValue)
                                 {
-                                    if (int_percent_done <= 100)
+                                    switch (SearchArgs.DataType)
                                     {
-                                        resultsprogress.Value = int_percent_done;
-                                        resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", (r_ms.BaseStream.Position + MemoryRangeStart));
-                                        Last_Whole_Percent_Done = int_percent_done;
+                                        case SearchDataTypes._8bits: if (unsigned) { reader.CurrentResult<byte>(); } else { reader.CurrentResult<sbyte>(); } break;
+                                        case SearchDataTypes._16bits: if (unsigned) { reader.CurrentResult<ushort>(); } else { reader.CurrentResult<short>(); } break;
+                                        case SearchDataTypes._32bits: if (unsigned) { reader.CurrentResult<uint>(); } else { reader.CurrentResult<int>(); } break;
+                                        case SearchDataTypes._64bits: if (unsigned) { reader.CurrentResult<ulong>(); } else { reader.CurrentResult<long>(); } break;
                                     }
                                 }
                             }
-                            if (SearchWorkerThread.CancellationPending == true)
+                            uint address = reader.CurrentAddress();
+                            if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                            try
                             {
-                                e.Cancel = true;
-                                return;
+                                //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
                             }
-                            #endregion
-                        }
-                        #endregion
-                        
-                        //}
-                        //SearchArgs.Results.AddRange(results_list);
-                        //results_list = null;
-                        resultsprogress.Value = 100;
-                        resultsprogress.Message = "";
-                        //Application.DoEvents();
-                        st_first_search.Stop();
-                        logger.Profiler.WriteLine("First search took a total of {0} seconds to complete.", st_first_search.Elapsed.TotalSeconds);
-                        Last_Whole_Percent_Done = 0;
-                    }
-                    #endregion
-
-                    #region Subsequent Searches
-                    r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
-
-
-                    // hack to help with OutOfMemory Exceptions (OldValue and Equal compare will always add all found search results)
-                    bool NeedToCompare = true;
-                    if (SearchArgs.CompareValueType == CompareValueTypes.OldValue &&
-                        SearchArgs.CompareType == SearchCompareTypes.Equal &&
-                        SearchArgs.IsFirstSearch)
-                    {
-                        NeedToCompare = false;
-                        //second_tmp_Results = null; // Free Memory
-                    }
-
-                    if (NeedToCompare)
-                    {
-                        if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
-                        {
-                            #region Non-Range Searches
-                            st_nonrange_search.Start();
-                            //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
-                            ////second_tmp_Results.c
-
-                            using (SearchResultReader reader = new SearchResultReader())
+                            catch (Exception)
                             {
-                                for (int i = 0; i < reader.ResultCount; i += 1)
-                                {
-                                    if (reader.ReadCurrentAddess)
-                                    {
-                                        if (!reader.ReadCurrentValue)
+                                throw;
+                            }
+                            switch (SearchArgs.DataType)
+                            {
+                                #region Comparer Support
+                                #region case SearchDataTypes._8bits:
+                                case SearchDataTypes._8bits:
+                                    if (SearchArgs.IsUnsignedDataType)
+                                    {
+                                        byte lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
+                                        byte value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<byte>();
+                                            comparer.Value = value;
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToByte(SearchArgs.CompareStartValue);
+                                            comparer.Value = value;
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
                                         {
-                                            switch (SearchArgs.DataType)
-                                            {
-                                                case SearchDataTypes._8bits: if (unsigned) { reader.CurrentResult<byte>(); } else { reader.CurrentResult<sbyte>(); } break;
-                                                case SearchDataTypes._16bits: if (unsigned) { reader.CurrentResult<ushort>(); } else { reader.CurrentResult<short>(); } break;
-                                                case SearchDataTypes._32bits: if (unsigned) { reader.CurrentResult<uint>(); } else { reader.CurrentResult<int>(); } break;
-                                                case SearchDataTypes._64bits: if (unsigned) { reader.CurrentResult<ulong>(); } else { reader.CurrentResult<long>(); } break;
-                                            }
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
                                         }
+                                        comparer = null; // free memory
                                     }
-                                    uint address = reader.CurrentAddress();
-                                    if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                                    try
+                                    else
                                     {
-                                        r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
+                                        sbyte lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
+                                        sbyte value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<sbyte>();
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToSByte(SearchArgs.CompareStartValue);
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
+                                        {
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
+                                        }
+                                        comparer = null; // free memory
                                     }
-                                    catch(Exception)
-                                    {
-                                        throw;
+                                    break;
+                                #endregion
+                                #region case SearchDataTypes._16bits:
+                                case SearchDataTypes._16bits:
+                                    if (SearchArgs.IsUnsignedDataType)
+                                    {
+                                        ushort lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
+                                        ushort value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<ushort>();
+                                            comparer.Value = value;
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToUInt16(SearchArgs.CompareStartValue);
+                                            comparer.Value = value;
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
+                                        {
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
+                                        }
+                                        comparer = null; // free memory
                                     }
-                                    switch (SearchArgs.DataType)
+                                    else
                                     {
-                                        #region Comparer Support
-                                        #region case SearchDataTypes._8bits:
-                                        case SearchDataTypes._8bits:
-                                            if (SearchArgs.IsUnsignedDataType)
-                                            {
-                                                byte lookup_value = r_ms.ReadByte();
-                                                _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
-                                                byte value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<byte>();
-                                                    comparer.Value = value;
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToByte(SearchArgs.CompareStartValue);
-                                                    comparer.Value = value;
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            else
-                                            {
-                                                sbyte lookup_value = r_ms.ReadSByte();
-                                                _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
-                                                sbyte value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<sbyte>();
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToSByte(SearchArgs.CompareStartValue);
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            break;
-                                        #endregion
-                                        #region case SearchDataTypes._16bits:
-                                        case SearchDataTypes._16bits:
-                                            if (SearchArgs.IsUnsignedDataType)
-                                            {
-                                                ushort lookup_value = r_ms.ReadUInt16();
-                                                _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
-                                                ushort value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<ushort>();
-                                                    comparer.Value = value;
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToUInt16(SearchArgs.CompareStartValue);
-                                                    comparer.Value = value;
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            else
-                                            {
-                                                short lookup_value = r_ms.ReadInt16();
-                                                _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
-                                                short value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<short>();
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToInt16(SearchArgs.CompareStartValue);
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            break;
-                                        #endregion
-                                        #region case SearchDataTypes._32bits:
-                                        case SearchDataTypes._32bits:
-                                            if (SearchArgs.IsUnsignedDataType)
-                                            {
-                                                uint lookup_value = r_ms.ReadUInt32();
-                                                _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
-                                                uint value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<uint>();
-                                                    comparer.Value = value;
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToUInt32(SearchArgs.CompareStartValue);
-                                                    comparer.Value = value;
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            else
-                                            {
-                                                int lookup_value = r_ms.ReadInt32();
-                                                _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
-                                                int value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<int>();
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToInt32(SearchArgs.CompareStartValue);
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            break;
-                                        #endregion
-                                        #region case SearchDataTypes._64bits:
-                                        case SearchDataTypes._64bits:
-                                            if (SearchArgs.IsUnsignedDataType)
-                                            {
-                                                ulong lookup_value = r_ms.ReadUInt64();
-                                                _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
-                                                ulong value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<ulong>();
-                                                    comparer.Value = value;
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToUInt64(SearchArgs.CompareStartValue);
-                                                    comparer.Value = value;
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            else
-                                            {
-                                                long lookup_value = r_ms.ReadInt64();
-                                                _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
-                                                long value = 0;
-                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                                {
-                                                    value = reader.CurrentResult<long>();
-                                                }
-                                                else
-                                                {
-                                                    value = Convert.ToInt64(SearchArgs.CompareStartValue);
-                                                }
-                                                if (comparer.Compare(lookup_value, value))
-                                                {
-                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
-                                                    second_tmp_Results.Add(_tmp_result);
-                                                }
-                                                comparer = null; // free memory
-                                            }
-                                            break;
-                                        #endregion
-                                        #endregion
+                                        short lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
+                                        short value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<short>();
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToInt16(SearchArgs.CompareStartValue);
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
+                                        {
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
+                                        }
+                                        comparer = null; // free memory
                                     }
-
-                                    double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
-                                    int int_percent_done = (int)double_percent_done;
-                                    if (int_percent_done != Last_Whole_Percent_Done)
-                                    {
-                                        if (int_percent_done <= 100)
+                                    break;
+                                #endregion
+                                #region case SearchDataTypes._32bits:
+                                case SearchDataTypes._32bits:
+                                    if (SearchArgs.IsUnsignedDataType)
+                                    {
+                                        uint lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
+                                        uint value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
                                         {
-                                            resultsprogress.Value = int_percent_done;
-                                            resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
-                                            Last_Whole_Percent_Done = int_percent_done;
+                                            value = reader.CurrentResult<uint>();
+                                            comparer.Value = value;
                                         }
+                                        else
+                                        {
+                                            value = Convert.ToUInt32(SearchArgs.CompareStartValue);
+                                            comparer.Value = value;
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
+                                        {
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
+                                        }
+                                        comparer = null; // free memory
                                     }
-
-                                }
-                            }
-                            st_nonrange_search.Stop();
-                            logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
-                            Last_Whole_Percent_Done = 0;
-                            #endregion
-                        }
-                        #region Ranged Searches
-#if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
-                        if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
-                        {
-                            st_ranged_search.Start();
-                            object start, end;
-
-                            start = SearchArgs.CompareStartValue;
-                            end = SearchArgs.CompareEndValue;
-                            using (SearchResultReader reader = new SearchResultReader())
-                            {
-                                for (int i = 0; i < reader.ResultCount; i += 1)
-                                {
-                                    uint address = reader.CurrentAddress();
-                                    if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                                    r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
-                                    if (SearchArgs.CompareType == SearchCompareTypes.Between)
+                                    else
                                     {
-                                        InRangeComparer comparer = new InRangeComparer(address, 0);
-                                        if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
+                                        int lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
+                                        int value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<int>();
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToInt32(SearchArgs.CompareStartValue);
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
                                         {
                                             ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
                                             second_tmp_Results.Add(_tmp_result);
                                         }
-                                        comparer = null;
+                                        comparer = null; // free memory
                                     }
-                                    else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
-                                    {
-                                        NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
-                                        if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
+                                    break;
+                                #endregion
+                                #region case SearchDataTypes._64bits:
+                                case SearchDataTypes._64bits:
+                                    if (SearchArgs.IsUnsignedDataType)
+                                    {
+                                        ulong lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
+                                        ulong value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<ulong>();
+                                            comparer.Value = value;
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToUInt64(SearchArgs.CompareStartValue);
+                                            comparer.Value = value;
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
                                         {
                                             ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
                                             second_tmp_Results.Add(_tmp_result);
                                         }
-                                        comparer = null;
+                                        comparer = null; // free memory
                                     }
                                     else
                                     {
-                                        throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
-                                    }
-                                    double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
-                                    int int_percent_done = (int)double_percent_done;
-                                    if (int_percent_done != Last_Whole_Percent_Done)
-                                    {
-                                        if (int_percent_done <= 100)
+                                        long lookup_value = 0;
+                                        using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) { gmp.OpenProvider(); gmp.ReadMemory(address, out lookup_value); gmp.CloseProvider(); }
+                                        _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
+                                        long value = 0;
+                                        if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                        {
+                                            value = reader.CurrentResult<long>();
+                                        }
+                                        else
+                                        {
+                                            value = Convert.ToInt64(SearchArgs.CompareStartValue);
+                                        }
+                                        if (comparer.Compare(lookup_value, value))
                                         {
-                                            resultsprogress.Value = int_percent_done;
-                                            resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
-                                            Last_Whole_Percent_Done = int_percent_done;
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
                                         }
+                                        comparer = null; // free memory
                                     }
+                                    break;
+                                #endregion
+                                #endregion
+                            }
+
+                            double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
+                            int int_percent_done = (int)double_percent_done;
+                            if (int_percent_done != Last_Whole_Percent_Done && i % 100000 == 0)
+                            {
+                                if (int_percent_done <= 100)
+                                {
+                                    resultsprogress.Value = int_percent_done;
+                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
+                                    Last_Whole_Percent_Done = int_percent_done;
                                 }
                             }
-                            st_ranged_search.Stop();
-                            logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
-                        }
-#endif
-                        #endregion
 
+                        }
                     }
+                    st_nonrange_search.Stop();
+                    logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
+                    Last_Whole_Percent_Done = 0;
                     #endregion
-                    // leave SearchArgs.Results alone, if false
-                    if (NeedToCompare)
+                }
+                #region Ranged Searches
+#if !DONOT_HAVE_RANGED_SEARCH_SUPPORT
+                if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween)
+                {
+                    st_ranged_search.Start();
+                    object start, end;
+
+                    start = SearchArgs.CompareStartValue;
+                    end = SearchArgs.CompareEndValue;
+                    using (SearchResultReader reader = new SearchResultReader())
                     {
-                        // fix addresses when memory start is not zero
-                        if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < second_tmp_Results.Count; i++) { second_tmp_Results[i].Address = second_tmp_Results[i].Address + MemoryRangeStart; } }
-                        using (SearchResultWriter writer = new SearchResultWriter(second_tmp_Results.Count))
+                        for (int i = 0; i < reader.ResultCount; i += 1)
                         {
-                            for (int i = 0; i < second_tmp_Results.Count; i++)
+                            uint address = reader.CurrentAddress();
+                            if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                            //r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
+                            if (SearchArgs.CompareType == SearchCompareTypes.Between)
                             {
-                                switch (sdt)
+                                InRangeComparer comparer = new InRangeComparer(address, 0);
+                                if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
                                 {
-                                    case SearchDataTypes._8bits:
-                                        if (unsigned) { writer.WriteResult<Byte>(second_tmp_Results[i].Address, Convert.ToByte(second_tmp_Results[i].Value)); }
-                                        else { writer.WriteResult<SByte>(second_tmp_Results[i].Address, Convert.ToSByte(second_tmp_Results[i].Value)); } break;
-                                    case SearchDataTypes._16bits:
-                                        if (unsigned) { writer.WriteResult<UInt16>(second_tmp_Results[i].Address, Convert.ToUInt16(second_tmp_Results[i].Value)); }
-                                        else { writer.WriteResult<Int16>(second_tmp_Results[i].Address, Convert.ToInt16(second_tmp_Results[i].Value)); } break;
-                                    case SearchDataTypes._32bits:
-                                        if (unsigned) { writer.WriteResult<UInt32>(second_tmp_Results[i].Address, Convert.ToUInt32(second_tmp_Results[i].Value)); }
-                                        else { writer.WriteResult<Int32>(second_tmp_Results[i].Address, Convert.ToInt32(second_tmp_Results[i].Value)); } break;
-                                    case SearchDataTypes._64bits:
-                                        if (unsigned) { writer.WriteResult<UInt64>(second_tmp_Results[i].Address, Convert.ToUInt64(second_tmp_Results[i].Value)); }
-                                        else { writer.WriteResult<Int64>(second_tmp_Results[i].Address, Convert.ToInt64(second_tmp_Results[i].Value)); } break;
+                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                    second_tmp_Results.Add(_tmp_result);
                                 }
+                                comparer = null;
                             }
-                        }                      
-                        second_tmp_Results = null; // free memory                       
+                            else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
+                            {
+                                NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
+                                if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, (IAcceptsProcessAndConfig)this))
+                                {
+                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                    second_tmp_Results.Add(_tmp_result);
+                                }
+                                comparer = null;
+                            }
+                            else
+                            {
+                                throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
+                            }
+                            double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
+                            int int_percent_done = (int)double_percent_done;
+                            if (int_percent_done != Last_Whole_Percent_Done)
+                            {
+                                if (int_percent_done <= 100)
+                                {
+                                    resultsprogress.Value = int_percent_done;
+                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
+                                    Last_Whole_Percent_Done = int_percent_done;
+                                }
+                            }
+                        }
                     }
+                    st_ranged_search.Stop();
+                    logger.Profiler.WriteLine("Ranged search took a total of {0} seconds to complete.", st_ranged_search.Elapsed.TotalSeconds);
+                }
+#endif
+                #endregion
 
-                    r_ms.Close();
+            }
+            #endregion
+            // leave SearchArgs.Results alone, if false
+            if (NeedToCompare)
+            {
+                // fix addresses when memory start is not zero
+                if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < second_tmp_Results.Count; i++) { second_tmp_Results[i].Address = second_tmp_Results[i].Address + MemoryRangeStart; } }
+                using (SearchResultWriter writer = new SearchResultWriter(second_tmp_Results.Count))
+                {
+                    for (int i = 0; i < second_tmp_Results.Count; i++)
+                    {
+                        switch (sdt)
+                        {
+                            case SearchDataTypes._8bits:
+                                if (unsigned) { writer.WriteResult<Byte>(second_tmp_Results[i].Address, Convert.ToByte(second_tmp_Results[i].Value)); }
+                                else { writer.WriteResult<SByte>(second_tmp_Results[i].Address, Convert.ToSByte(second_tmp_Results[i].Value)); } break;
+                            case SearchDataTypes._16bits:
+                                if (unsigned) { writer.WriteResult<UInt16>(second_tmp_Results[i].Address, Convert.ToUInt16(second_tmp_Results[i].Value)); }
+                                else { writer.WriteResult<Int16>(second_tmp_Results[i].Address, Convert.ToInt16(second_tmp_Results[i].Value)); } break;
+                            case SearchDataTypes._32bits:
+                                if (unsigned) { writer.WriteResult<UInt32>(second_tmp_Results[i].Address, Convert.ToUInt32(second_tmp_Results[i].Value)); }
+                                else { writer.WriteResult<Int32>(second_tmp_Results[i].Address, Convert.ToInt32(second_tmp_Results[i].Value)); } break;
+                            case SearchDataTypes._64bits:
+                                if (unsigned) { writer.WriteResult<UInt64>(second_tmp_Results[i].Address, Convert.ToUInt64(second_tmp_Results[i].Value)); }
+                                else { writer.WriteResult<Int64>(second_tmp_Results[i].Address, Convert.ToInt64(second_tmp_Results[i].Value)); } break;
+                        }
+                    }
                 }
+                second_tmp_Results = null; // free memory                       
             }
         }
 
+      
+
         private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
         {
             //if (SearchArgs.ProgressLogger != null)

 

  ViewVC Help
Powered by ViewVC 1.1.22