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

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

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

--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/20 11:18:56	397
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/20 12:16:34	398
@@ -432,51 +432,57 @@
                 
                 Address = Convert.ToInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16);
                 //r_ms.BaseStream.Seek(Address, SeekOrigin.Begin);                
-                GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
-                provider.OpenProvider();
-                int bytesReadSize;
-                byte[] data;    
-                uint bytesToRead = 0;
-                switch (_result.ValueType)
-                {
-                    case SearchDataTypes._8bits:
-                        bytesToRead = 1;
-                        break;
-                    case SearchDataTypes._16bits:
-                        bytesToRead = 2;
-                        break;
-                    case SearchDataTypes._32bits:
-                        bytesToRead = 4;
-                        break;
-                    case SearchDataTypes._64bits:
-                        bytesToRead = 8;
-                        break;
-                }
-                provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
-                MemoryStream ms = new MemoryStream(data);
-                BinaryReader r_ms = new BinaryReader(ms);
-                switch (_result.ValueType)
-                {
-                    case SearchDataTypes._8bits:
-                        if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
-                        else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
-                        break;
-                    case SearchDataTypes._16bits:
-                        if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
-                        else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
-                        break;
-                    case SearchDataTypes._32bits:
-                        if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
-                        else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
-                        break;
-                    case SearchDataTypes._64bits:
-                        if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
-                        else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
-                        break;
+                using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                {
+                    provider.OpenProvider();
+                    int bytesReadSize;
+                    byte[] data;
+                    uint bytesToRead = 0;
+                    switch (_result.ValueType)
+                    {
+                        case SearchDataTypes._8bits:
+                            bytesToRead = 1;
+                            break;
+                        case SearchDataTypes._16bits:
+                            bytesToRead = 2;
+                            break;
+                        case SearchDataTypes._32bits:
+                            bytesToRead = 4;
+                            break;
+                        case SearchDataTypes._64bits:
+                            bytesToRead = 8;
+                            break;
+                    }
+                    provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
+                    using (MemoryStream ms = new MemoryStream(data))
+                    {
+                        using (BinaryReader r_ms = new BinaryReader(ms))
+                        {
+                            switch (_result.ValueType)
+                            {
+                                case SearchDataTypes._8bits:
+                                    if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
+                                    else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
+                                    break;
+                                case SearchDataTypes._16bits:
+                                    if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
+                                    else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
+                                    break;
+                                case SearchDataTypes._32bits:
+                                    if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
+                                    else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
+                                    break;
+                                case SearchDataTypes._64bits:
+                                    if (_result.IsUnsigned) { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
+                                    else { ResultItems[i].SubItems[col_Found_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
+                                    break;
+                            }
+                            r_ms.Close();
+                        }
+                    }
+                    provider.CloseProvider();
                 }
-                r_ms.Close();
-                provider.CloseProvider();
-                Application.DoEvents();
+                //Application.DoEvents();
             }
             #endregion
 
@@ -508,51 +514,57 @@
                 int Address = 0;
                 ResultDataType _result = (ResultDataType)AddedItems[i].Tag;
                 Address = Convert.ToInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16);
-                GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
-                provider.OpenProvider();
-                int bytesReadSize;
-                byte[] data;
-                uint bytesToRead = 0;
-                switch (_result.ValueType)
-                {
-                    case SearchDataTypes._8bits:
-                        bytesToRead = 1;
-                        break;
-                    case SearchDataTypes._16bits:
-                        bytesToRead = 2;
-                        break;
-                    case SearchDataTypes._32bits:
-                        bytesToRead = 4;
-                        break;
-                    case SearchDataTypes._64bits:
-                        bytesToRead = 8;
-                        break;
-                }
-                provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
-                MemoryStream ms = new MemoryStream(data);
-                BinaryReader r_ms = new BinaryReader(ms);
-                switch (_result.ValueType)
-                {
-                    case SearchDataTypes._8bits:
-                        if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
-                        else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
-                        break;
-                    case SearchDataTypes._16bits:
-                        if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
-                        else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
-                        break;
-                    case SearchDataTypes._32bits:
-                        if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
-                        else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
-                        break;
-                    case SearchDataTypes._64bits:
-                        if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
-                        else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
-                        break;
+                using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+                {
+                    provider.OpenProvider();
+                    int bytesReadSize;
+                    byte[] data;
+                    uint bytesToRead = 0;
+                    switch (_result.ValueType)
+                    {
+                        case SearchDataTypes._8bits:
+                            bytesToRead = 1;
+                            break;
+                        case SearchDataTypes._16bits:
+                            bytesToRead = 2;
+                            break;
+                        case SearchDataTypes._32bits:
+                            bytesToRead = 4;
+                            break;
+                        case SearchDataTypes._64bits:
+                            bytesToRead = 8;
+                            break;
+                    }
+                    provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data);
+                    provider.CloseProvider();
+                    using (MemoryStream ms = new MemoryStream(data))
+                    {
+                        using (BinaryReader r_ms = new BinaryReader(ms))
+                        {
+                            switch (_result.ValueType)
+                            {
+                                case SearchDataTypes._8bits:
+                                    if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadByte()); }
+                                    else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x2}", r_ms.ReadSByte()); }
+                                    break;
+                                case SearchDataTypes._16bits:
+                                    if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadUInt16()); }
+                                    else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x4}", r_ms.ReadInt16()); }
+                                    break;
+                                case SearchDataTypes._32bits:
+                                    if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadUInt32()); }
+                                    else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x8}", r_ms.ReadInt32()); }
+                                    break;
+                                case SearchDataTypes._64bits:
+                                    if (_result.IsUnsigned) { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadUInt64()); }
+                                    else { AddedItems[i].SubItems[col_Added_Value].Text = string.Format("0x{0:x16}", r_ms.ReadInt64()); }
+                                    break;
+                            }
+                            r_ms.Close();
+                        }
+                    }
                 }
-                r_ms.Close();
-                provider.CloseProvider();
-                Application.DoEvents();
+                //Application.DoEvents();
             }
             #endregion
 
@@ -1020,403 +1032,414 @@
             //SearchArgs.Results.Clear();
             // log options
             SearchArgs.LogSearchOptions();
-            uint STEP_SIZE = (uint)SearchArgs.DataType / 8;            
-            GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
-            provider.OpenProvider();
-            int bytes_read = 0;
-
+            uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
             byte[] buffered_mem = new byte[(MemoryRangeSize - MemoryRangeStart)]; // throws OutOfMemoryException if size is over 2G
-            provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), out bytes_read, out buffered_mem);         
-            provider.CloseProvider();
-       
+            using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
+            {
+                provider.OpenProvider();
+                int bytes_read = 0;               
+                provider.ReadProcessMemoryAtOnce(MemoryRangeStart, (MemoryRangeSize - MemoryRangeStart), out bytes_read, out buffered_mem);
+                provider.CloseProvider();
+            }
             if (buffered_mem.Length == 0) { logger.Warn.WriteLine("Buffered Memory is Zero Length."); return; }
-            MemoryStream ms = new MemoryStream(buffered_mem);
-            BinaryReader r_ms = new BinaryReader(ms);
-            logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
-            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);
-                List<ResultType<object>> results_list = new List<ResultType<object>>();
-                for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
+            using (MemoryStream ms = new MemoryStream(buffered_mem))
+            {
+                using (BinaryReader r_ms = new BinaryReader(ms))
                 {
-                    ResultType<object> _tmp_result = new ResultType<object>();
-                    switch (SearchArgs.DataType)
+                    logger.Debug.WriteLine(string.Format("Buffered Memory Size -> 0x{0:x8}", buffered_mem.Length));
+                    int Last_Whole_Percent_Done = 0;
+
+                    #region First Search
+                    if (SearchArgs.IsFirstSearch)
                     {
-                        case SearchDataTypes._8bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadByte()); }
-                            else { _tmp_result = new ResultType<object>(i, r_ms.ReadSByte()); } break;
-                        case SearchDataTypes._16bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt16()); }
-                            else { _tmp_result = new ResultType<object>(i,r_ms.ReadInt16()); } break;
-                        case SearchDataTypes._32bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt32()); }
-                            else { _tmp_result = new ResultType<object>(i, r_ms.ReadInt32()); } break;
-                        case SearchDataTypes._64bits:
-                            if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType<object>(i, r_ms.ReadUInt64()); }
-                            else { _tmp_result = new ResultType<object>(i, r_ms.ReadInt64()); } break;
-                    }
-                    results_list.Add(_tmp_result);
-                    double double_percent_done = 100.0 * (double)((double)i / (double)buffered_mem.Length);
-                    int int_percent_done = (int)double_percent_done;
-                    if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
-                    {
-                        resultsprogress.Value = int_percent_done;
-                        resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
-                        Last_Whole_Percent_Done = int_percent_done;
+                        st_first_search.Start();
+                        SearchArgs.Results.Clear();
+                        r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
+                        //List<ResultType<object>> results_list = new List<ResultType<object>>();
+                        //for (uint i = 0; i < buffered_mem.Length; i += STEP_SIZE)
+                        //{
+                        while (r_ms.BaseStream.Position < r_ms.BaseStream.Length)
+                        {
+                            using (ResultType<object> _tmp_result = new ResultType<object>())
+                            {
+                                switch (SearchArgs.DataType)
+                                {
+                                    case SearchDataTypes._8bits:
+                                        if (SearchArgs.IsUnsignedDataType) { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadByte(); }
+                                        else { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadSByte(); } break;
+                                    case SearchDataTypes._16bits:
+                                        if (SearchArgs.IsUnsignedDataType) { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadUInt16(); }
+                                        else { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadInt16(); } break;
+                                    case SearchDataTypes._32bits:
+                                        if (SearchArgs.IsUnsignedDataType) { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadUInt32(); }
+                                        else { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadInt32(); } break;
+                                    case SearchDataTypes._64bits:
+                                        if (SearchArgs.IsUnsignedDataType) { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadUInt64(); }
+                                        else { _tmp_result.Address = (uint)r_ms.BaseStream.Position; _tmp_result.Value = r_ms.ReadInt64(); } break;
+                                }
+                                //results_list.Add(_tmp_result);
+                                SearchArgs.Results.Add(_tmp_result);
+                            }
+                            double double_percent_done = 100.0 * (double)((double)r_ms.BaseStream.Position / (double)buffered_mem.Length);
+                            int int_percent_done = (int)double_percent_done;
+                            if (int_percent_done != Last_Whole_Percent_Done && r_ms.BaseStream.Position % ElementsBeforeDisplay == 0)
+                            {
+                                resultsprogress.Value = int_percent_done;
+                                resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", r_ms.BaseStream.Position);
+                                Last_Whole_Percent_Done = int_percent_done;
+                                //Application.DoEvents();
+                            }
+
+                            if (SearchWorkerThread.CancellationPending == true)
+                            {
+                                e.Cancel = true;
+                                return;
+                            }
+                            //Application.DoEvents();
+                        }
+                        //}
+                        //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);
                     }
+                    #endregion
 
-                    if (SearchWorkerThread.CancellationPending == true)
-                    {
-                        e.Cancel = true;
-                        return;
-                    }
-                    //Application.DoEvents();
-                }
-                SearchArgs.Results.AddRange(results_list);
-                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);
-            }
-            #endregion
+                    #region Subsequent Searches
+                    r_ms.BaseStream.Seek(0, SeekOrigin.Begin);
 
-            #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
+                    }
 
-            // 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
-                    for (int i = 0; i < SearchArgs.Results.Count; i += 1)
-                    {                        
-                        uint address = SearchArgs.Results[i].Address;
-                        if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                        r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
-                        switch (SearchArgs.DataType)
+                    if (NeedToCompare)
+                    {
+                        if (SearchArgs.CompareType != SearchCompareTypes.Between && SearchArgs.CompareType != SearchCompareTypes.NotBetween)
                         {
-                            #region Comparer Support
-                            #region case SearchDataTypes._8bits:
-                            case SearchDataTypes._8bits:
-                                if (SearchArgs.IsUnsignedDataType)
+                            #region Non-Range Searches
+                            st_nonrange_search.Start();
+                            //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
+                            ////second_tmp_Results.c
+                            for (int i = 0; i < SearchArgs.Results.Count; i += 1)
+                            {
+                                uint address = SearchArgs.Results[i].Address;
+                                if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                                r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
+                                switch (SearchArgs.DataType)
                                 {
-                                    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 = Convert.ToByte(SearchArgs.Results[i].Value);
-                                        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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
-                                    }
-                                    comparer = null; // free memory
+                                    #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 = Convert.ToByte(SearchArgs.Results[i].Value);
+                                                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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToSByte(SearchArgs.Results[i].Value);
+                                            }
+                                            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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToUInt16(SearchArgs.Results[i].Value);
+                                                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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToInt16(SearchArgs.Results[i].Value);
+                                            }
+                                            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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToUInt32(SearchArgs.Results[i].Value);
+                                                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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToInt32(SearchArgs.Results[i].Value);
+                                            }
+                                            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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToUInt64(SearchArgs.Results[i].Value);
+                                                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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            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 = Convert.ToInt64(SearchArgs.Results[i].Value);
+                                            }
+                                            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);
+                                                //_tmp_result = null; // free memory
+                                                //SearchArgs.Results.RemoveAt(i);
+                                                SearchArgs.Results[i].Value = comparer.Value;
+                                                second_tmp_Results.Add(SearchArgs.Results[i]);
+                                            }
+                                            comparer = null; // free memory
+                                        }
+                                        break;
+                                    #endregion
+                                    #endregion
                                 }
-                                else
+
+                                double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
+                                int int_percent_done = (int)double_percent_done;
+                                if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
                                 {
-                                    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 = Convert.ToSByte(SearchArgs.Results[i].Value);
-                                    }
-                                    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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
-                                    }
-                                    comparer = null; // free memory
+                                    resultsprogress.Value = int_percent_done;
+                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
+                                    Last_Whole_Percent_Done = int_percent_done;
+                                    //Application.DoEvents();
                                 }
-                                break;
+
+                            }
+                            st_nonrange_search.Stop();
+                            logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
                             #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 = Convert.ToUInt16(SearchArgs.Results[i].Value);
-                                        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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
-                                    }
-                                    comparer = null; // free memory
-                                }
-                                else
+                        }
+                        #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;
+                            for (int i = 0; i < SearchArgs.Results.Count; i += 1)
+                            {
+                                uint address = SearchArgs.Results[i].Address;
+                                if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                                r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
+                                if (SearchArgs.CompareType == SearchCompareTypes.Between)
                                 {
-                                    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 = Convert.ToInt16(SearchArgs.Results[i].Value);
-                                    }
-                                    else
+                                    InRangeComparer comparer = new InRangeComparer(address, 0);
+                                    if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
                                     {
-                                        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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
                                         SearchArgs.Results[i].Value = comparer.Value;
                                         second_tmp_Results.Add(SearchArgs.Results[i]);
                                     }
-                                    comparer = null; // free memory
+                                    comparer = null;
                                 }
-                                break;
-                            #endregion
-                            #region case SearchDataTypes._32bits:
-                            case SearchDataTypes._32bits:
-                                if (SearchArgs.IsUnsignedDataType)
+                                else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
                                 {
-                                    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 = Convert.ToUInt32(SearchArgs.Results[i].Value);
-                                        comparer.Value = value;
-                                    }
-                                    else
-                                    {
-                                        value = Convert.ToUInt32(SearchArgs.CompareStartValue);
-                                        comparer.Value = value;
-                                    }
-                                    if (comparer.Compare(lookup_value, value))
+                                    NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
+                                    if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
                                     {
-                                        //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                        //second_tmp_Results.Add(_tmp_result);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
                                         SearchArgs.Results[i].Value = comparer.Value;
                                         second_tmp_Results.Add(SearchArgs.Results[i]);
                                     }
-                                    comparer = null; // free memory
+                                    comparer = null;
                                 }
                                 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 = Convert.ToInt32(SearchArgs.Results[i].Value);
-                                    }
-                                    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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
-                                    }
-                                    comparer = null; // free memory
+                                    throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
                                 }
-                                break;
-                            #endregion
-                            #region case SearchDataTypes._64bits:
-                            case SearchDataTypes._64bits:
-                                if (SearchArgs.IsUnsignedDataType)
+                                double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
+                                int int_percent_done = (int)double_percent_done;
+                                if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
                                 {
-                                    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 = Convert.ToUInt64(SearchArgs.Results[i].Value);
-                                        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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
-                                    }
-                                    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 = Convert.ToInt64(SearchArgs.Results[i].Value);
-                                    }
-                                    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);
-                                        //_tmp_result = null; // free memory
-                                        //SearchArgs.Results.RemoveAt(i);
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
-                                    }
-                                    comparer = null; // free memory
+                                    resultsprogress.Value = int_percent_done;
+                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
+                                    Last_Whole_Percent_Done = int_percent_done;
+                                    //Application.DoEvents();
                                 }
-                                break;
-                            #endregion
-                            #endregion
-                        }
-
-                        double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
-                        int int_percent_done = (int)double_percent_done;
-                        if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
-                        {
-                            resultsprogress.Value = int_percent_done;
-                            resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
-                            Last_Whole_Percent_Done = int_percent_done;
-                            //Application.DoEvents();
+                            }
+                            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);
                     #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;
-                    for (int i = 0; i < SearchArgs.Results.Count; i += 1)
-                    {
-                        uint address = SearchArgs.Results[i].Address;
-                        if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                        r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
-                        if (SearchArgs.CompareType == SearchCompareTypes.Between)
-                        {
-                            InRangeComparer comparer = new InRangeComparer(address, 0);
-                            if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
-                            {
-                                SearchArgs.Results[i].Value = comparer.Value;
-                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                            }
-                            comparer = null;
-                        }
-                        else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
-                        {
-                            NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
-                            if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
-                            {
-                                SearchArgs.Results[i].Value = comparer.Value;
-                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                            }
-                            comparer = null;
-                        }
-                        else
-                        {
-                            throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
-                        }
-                        double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
-                        int int_percent_done = (int)double_percent_done;
-                        if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
-                        {
-                            resultsprogress.Value = int_percent_done;
-                            resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
-                            Last_Whole_Percent_Done = int_percent_done;
-                            //Application.DoEvents();
-                        }
+                    // leave SearchArgs.Results alone, if false
+                    if (NeedToCompare)
+                    {
+                        SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count);
+                        // fix addresses when memory start is not zero
+                        if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < SearchArgs.Results.Count; i++) { SearchArgs.Results[i].Address = SearchArgs.Results[i].Address + MemoryRangeStart; } }
+                        second_tmp_Results = null; // free memory
                     }
-                    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)
-            {
-                SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count);
-                // fix addresses when memory start is not zero
-                if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < SearchArgs.Results.Count; i++) { SearchArgs.Results[i].Address = SearchArgs.Results[i].Address + MemoryRangeStart; } }
-                second_tmp_Results = null; // free memory
-            }
-
-            r_ms.Close();
         }
 
         private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)

 

  ViewVC Help
Powered by ViewVC 1.1.22