--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs 2012/06/04 16:55:33 279 +++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs 2012/06/05 00:13:29 280 @@ -1,4 +1,9 @@ -//#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze +#define USE_FORCED_LOGGING_CONTROL // when defined, will override and force an internal logging control +//#define DONOT_HAVE_RANGED_SEARCH_SUPPORT // when defined, indicates that ranged searches have not been implemented + +#define INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY // when defined will set MIN RESULTS to 0x2701 otherwise 0x03e8 + +//#define DO_NOT_SUSPEND_RESUME_THREAD_ON_FREEZE // when defined will not freeze/resume thread on freeze using System; using System.Collections.Generic; using System.ComponentModel; @@ -27,6 +32,12 @@ ISearchInProgress, IAcceptsBrowseMemoryRegion { +#if INCREASE_NUMBER_OF_RESULTS_BEFORE_DISPLAY + const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x2701; // 10,000 results +#else + const int MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY = 0x03e8; // 1,000 results +#endif + private bool DefaultUnsignedState = true; // set unsigned to true public FloatingMemorySearcher() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; SearchInProgess = false; Reload(); } public FloatingMemorySearcher(IConfigPlugin config) : this() { this.AcceptedPlugin = config; } @@ -70,6 +81,7 @@ PATCH_RESULTS_LIST = 0x3001, UKNOWN_RESULTS_LIST = 0x3001 } + bool IsFirstSearch = true; SearchType SearchArgs; static int col_Found_Address = 1; static int col_Found_Value = 2; @@ -905,19 +917,485 @@ private void SearchWorkerThread_DoWork(object sender, DoWorkEventArgs e) { + //List> tmp_Results = new List>(); + List> second_tmp_Results = new List>(); + const double _UPDATE_DELAY = 1024.0; + int UPDATE_DELAY = (int)(_UPDATE_DELAY / 1000); + //tmp_Results = SearchArgs.Results.GetRange(0,SearchArgs.Results.Count); + //SearchArgs.Results = null; + //SearchArgs.Results.Clear(); + // log options + SearchArgs.LogSearchOptions(); + int STEP_SIZE = (int)SearchArgs.DataType / 8; + + GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); + provider.OpenProvider(); + int bytes_read = 0; + byte[] buffered_mem = new byte[int.MaxValue]; + provider.ReadProcessMemory(0, int.MaxValue, 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}", r_ms.BaseStream.Length)); + int Last_Whole_Percent_Done = 0; + + #region First Search + if (SearchArgs.IsFirstSearch) + { + SearchArgs.Results.Clear(); + r_ms.BaseStream.Seek(0, SeekOrigin.Begin); + for (int i = 0; i < r_ms.BaseStream.Length; i += STEP_SIZE) + { + ResultType _tmp_result = new ResultType(); + + + switch (SearchArgs.DataType) + { + case SearchDataTypes._8bits: + if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType((int)i, r_ms.ReadByte()); } + else { _tmp_result = new ResultType((int)i, r_ms.ReadSByte()); } break; + case SearchDataTypes._16bits: + if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType((int)i, r_ms.ReadUInt16()); } + else { _tmp_result = new ResultType((int)i, r_ms.ReadInt16()); } break; + case SearchDataTypes._32bits: + if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType((int)i, r_ms.ReadUInt32()); } + else { _tmp_result = new ResultType((int)i, r_ms.ReadInt32()); } break; + case SearchDataTypes._64bits: + if (SearchArgs.IsUnsignedDataType) { _tmp_result = new ResultType((int)i, r_ms.ReadUInt64()); } + else { _tmp_result = new ResultType((int)i, r_ms.ReadInt64()); } break; + } + SearchArgs.Results.Add(_tmp_result); + double double_percent_done = 100.0 * (double)((double)i / (double)r_ms.BaseStream.Length); + int int_percent_done = (int)double_percent_done; + if ((i / UPDATE_DELAY) == (int)(i / UPDATE_DELAY) && int_percent_done != Last_Whole_Percent_Done) + { + resultsprogress.Value = int_percent_done; + resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i); + Last_Whole_Percent_Done = int_percent_done; + Application.DoEvents(); + } + + if (SearchWorkerThread.CancellationPending == true) + { + e.Cancel = true; + return; + } + + } + resultsprogress.Value = 100; + resultsprogress.Message = ""; + Application.DoEvents(); + + } + #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 + //second_tmp_Results = new List>(SearchArgs.Results.Count * 1024); + ////second_tmp_Results.c + for (int i = 0; i < SearchArgs.Results.Count; i += 1) + { + r_ms.BaseStream.Seek(SearchArgs.Results[i].Address, SeekOrigin.Begin); + + switch (SearchArgs.DataType) + { + #region Comparer Support + case SearchDataTypes._8bits: + if (SearchArgs.IsUnsignedDataType) + { + byte lookup_value = r_ms.ReadByte(); + _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].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 _tmp_result = new ResultType(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, SearchArgs.Results[i].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 _tmp_result = new ResultType(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; + case SearchDataTypes._16bits: + if (SearchArgs.IsUnsignedDataType) + { + ushort lookup_value = r_ms.ReadUInt16(); + _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].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 _tmp_result = new ResultType(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, SearchArgs.Results[i].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 _tmp_result = new ResultType(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; + case SearchDataTypes._32bits: + if (SearchArgs.IsUnsignedDataType) + { + uint lookup_value = r_ms.ReadUInt32(); + _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].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 _tmp_result = new ResultType(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, SearchArgs.Results[i].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 _tmp_result = new ResultType(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; + case SearchDataTypes._64bits: + if (SearchArgs.IsUnsignedDataType) + { + ulong lookup_value = r_ms.ReadUInt64(); + _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, SearchArgs.Results[i].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 _tmp_result = new ResultType(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, SearchArgs.Results[i].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 _tmp_result = new ResultType(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 + } + + double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count); + int int_percent_done = (int)double_percent_done; + if ((i / UPDATE_DELAY) == (int)(i / UPDATE_DELAY) && int_percent_done != Last_Whole_Percent_Done) + { + resultsprogress.Value = int_percent_done; + resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i); + Last_Whole_Percent_Done = int_percent_done; + Application.DoEvents(); + } + } + #endregion + } + #region Ranged Searches +#if !DONOT_HAVE_RANGED_SEARCH_SUPPORT + if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween) + { + object start, end; + + start = SearchArgs.CompareStartValue; + end = SearchArgs.CompareEndValue; + for (int i = 0; i < SearchArgs.Results.Count; i += 1) + { + //r_ms.BaseStream.Seek(SearchArgs.Results[i].Address, SeekOrigin.Begin); + if (SearchArgs.CompareType == SearchCompareTypes.Between) + { + InRangeComparer comparer = new InRangeComparer(SearchArgs.Results[i].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(SearchArgs.Results[i].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 ((i / UPDATE_DELAY) == (int)(i / UPDATE_DELAY) && int_percent_done != Last_Whole_Percent_Done) + { + resultsprogress.Value = int_percent_done; + resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i); + Last_Whole_Percent_Done = int_percent_done; + Application.DoEvents(); + } + } + } +#endif + #endregion + + } + #endregion + // leave SearchArgs.Results alone, if false + if (NeedToCompare) + { + SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count); + second_tmp_Results = null; // free memory + } + + r_ms.Close(); } private void SearchWorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e) { - + //if (SearchArgs.ProgressLogger != null) + //{ + // resultsprogress.Value = e.ProgressPercentage; + // //Application.DoEvents(); + //} } private void SearchWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { + resultsprogress.Value = 100; + logger.Debug.WriteLine(string.Format("\nResults Count -> 0x{0:x8}", SearchArgs.Results.Count)); + + if (SearchArgs.Results.Count == 1) // debug message for 1 result using 32bit unsigned + logger.Debug.WriteLine(string.Format("\nDebug: Found 1 result -> Address: 0x{0:x8} Value: 0x{1:x8}", SearchArgs.Results[0].Address, SearchArgs.Results[0].Value)); + + logger.Info.WriteLine(string.Format("\nFound 0x{0:x8} results", SearchArgs.Results.Count)); + + if (SearchArgs.Results.Count <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY) + { + lstResults.Items.Clear(); + List items = new List(); + for (int i = 0; i < SearchArgs.Results.Count; i++) + { + ResultItem item = new ResultItem(0, false); + //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address); + //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address)); + switch (SearchArgs.DataType) + { + + case SearchDataTypes._8bits: + if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToByte(SearchArgs.Results[i].Value)); } + else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToSByte(SearchArgs.Results[i].Value)); } + break; + case SearchDataTypes._16bits: + if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt16(SearchArgs.Results[i].Value)); } + else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt16(SearchArgs.Results[i].Value)); } + break; + case SearchDataTypes._32bits: + if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt32(SearchArgs.Results[i].Value)); } + else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt32(SearchArgs.Results[i].Value)); } + break; + case SearchDataTypes._64bits: + if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt64(SearchArgs.Results[i].Value)); } + else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt64(SearchArgs.Results[i].Value)); } + break; + } + if (!items.Contains(item)) + items.Add(item); + } + lstResults.Items.AddRange(items.ToArray()); + } + + this.DoSearchDoneSpecific(); + //System.Threading.Thread.Sleep(100); + //if (_SEARCH_MODE != SearchMode.SEARCH_MODE_NORMAL_WITH_JOKER) + this.ThawResultsUpdate(); + Application.DoEvents(); } + private void DoSearchDoneSpecific() + { + SearchWorkerThread.CancelAsync(); + if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; } + else { timer_update_results.Enabled = false; } + + search_progress_updater.Enabled = false; + btnCancel.Enabled = false; + btnReset.Enabled = true; + btnSearch.Enabled = true; + grpCompareType.Enabled = true; + grpCompareValue.Enabled = true; + resultsprogress.Value = 0; + resultsprogress.Message = ""; + grpDataType.Enabled = false; + // resume process on reset, incase it was suspended + ThreadControl.ResumeProcess(this.AcceptedProcess.Id); + //Application.DoEvents(); + this.Refresh(); + } + + private void DoCancelSpecific() + { + this.DoSearchDoneSpecific(); + } + private void DoResetSpecific() + { + this.DoCancelSpecific(); + IsFirstSearch = true; + grpDataType.Enabled = true; + } private void search_progress_updater_Tick(object sender, EventArgs e) { if ((this.AcceptedProcess ==null) || Process.GetProcessById(this.AcceptedProcess.Id) == null) @@ -928,28 +1406,159 @@ } } + #region Search Button private void btnSearch_Click(object sender, EventArgs e) { this.SearchInProgess = true; - btnCancel.Enabled = true; - btnReset.Enabled = false; - btnSearch.Enabled = false; + //btnCancel.Enabled = true; + //btnReset.Enabled = false; + //btnSearch.Enabled = false; this.FreezeResultsUpdate(); + this.handle_btnSearch_Click(); } + private void handle_btnSearch_Click() + { + //this.FreezeResultsUpdate(); + lstResults.Items.Clear(); + if (lstResults.Items.Count > 0) { timer_update_results.Enabled = true; } + else { timer_update_results.Enabled = false; } + + + resultsprogress.Value = 0; + bool _is_unsigned = chkUnsigned.Checked; + SearchType search_type = new SearchType(); + SearchDataTypes _data_type = new SearchDataTypes(); + SearchCompareTypes _compare_type = new SearchCompareTypes(); + CompareValueTypes _compare_value_type = new CompareValueTypes(); + object start_value = 0; + object end_value = 0; + // get datatype + if (radio_8bits.Checked) { _data_type = SearchDataTypes._8bits; } + else if (radio_16bits.Checked) { _data_type = SearchDataTypes._16bits; } + else if (radio_32bits.Checked) { _data_type = SearchDataTypes._32bits; } + else if (radio_64bits.Checked) { _data_type = SearchDataTypes._64bits; } + else { logger.Error.WriteLine("Could not determine search data type bit size. (was not 8/16/32/or 64bits)"); } + // get compare type + if (radiocompare_equal.Checked) { _compare_type = SearchCompareTypes.Equal; } + else if (radiocompare_greaterthan.Checked) { _compare_type = SearchCompareTypes.GreaterThan; } + else if (radiocompare_lessthan.Checked) { _compare_type = SearchCompareTypes.LessThan; } + else if (radiocompare_greaterthan_orequal.Checked) { _compare_type = SearchCompareTypes.GreaterThanOrEqual; } + else if (radiocompare_lessthan_orequal.Checked) { _compare_type = SearchCompareTypes.LessThanOrEqual; } + else if (radiocompare_notequal.Checked) { _compare_type = SearchCompareTypes.NotEqual; } + else if (radiocompare_between.Checked) { _compare_type = SearchCompareTypes.Between; } + else if (radiocompare_notbetween.Checked) { _compare_type = SearchCompareTypes.NotBetween; } + else { logger.Error.WriteLine("Could not determine search comparison type. (was not == > < >= <= != <> or !<>)"); } + // get compare valure type + if (radio_oldvalue.Checked) { _compare_value_type = CompareValueTypes.OldValue; } + else if (radio_specificvalue.Checked) { _compare_value_type = CompareValueTypes.SpecificValue; } + else { logger.Error.WriteLine("Could not determine search comparison type. (was not old or specific value"); } + + if (_compare_value_type == CompareValueTypes.SpecificValue || (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween)) + { + + switch (_data_type) + { + case SearchDataTypes._8bits: + if (_is_unsigned) { start_value = txtStartAddr.ToByte(); } + else { start_value = txtStartAddr.ToSByte(); } + break; + case SearchDataTypes._16bits: + if (_is_unsigned) { start_value = txtStartAddr.ToUInt16(); } + else { start_value = txtStartAddr.ToInt16(); } + break; + case SearchDataTypes._32bits: + if (_is_unsigned) { start_value = txtStartAddr.ToUInt32(); } + else { start_value = txtStartAddr.ToInt32(); } + break; + case SearchDataTypes._64bits: + if (_is_unsigned) { start_value = txtStartAddr.ToUInt64(); } + else { start_value = txtStartAddr.ToInt64(); } + break; + default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type."); + } + } + if (_compare_type == SearchCompareTypes.Between || _compare_type == SearchCompareTypes.NotBetween) + { + switch (_data_type) + { + case SearchDataTypes._8bits: + if (_is_unsigned) { end_value = txtEndAddr.ToByte(); } + else { end_value = txtEndAddr.ToSByte(); } + break; + case SearchDataTypes._16bits: + if (_is_unsigned) { end_value = txtEndAddr.ToUInt16(); } + else { end_value = txtEndAddr.ToInt16(); } + break; + case SearchDataTypes._32bits: + if (_is_unsigned) { end_value = txtEndAddr.ToUInt32(); } + else { end_value = txtEndAddr.ToInt32(); } + break; + case SearchDataTypes._64bits: + if (_is_unsigned) { end_value = txtEndAddr.ToUInt64(); } + else { end_value = txtEndAddr.ToInt64(); } + break; + default: throw new InvalidOperationException("In SearchType(): Encounterd an Unkown Search Data Type."); + } + } + + search_type = new SearchType(_data_type, _is_unsigned, _compare_type, _compare_value_type, start_value, end_value, resultsprogress); + + //search_type.LogSearchOptions(); + + search_type.IsFirstSearch = IsFirstSearch; + + + + DoSearch(search_type); + IsFirstSearch = false; + } + private void DoSearch(SearchType args) + { + if (!args.IsFirstSearch && SearchArgs != null) + { + //args.Results.AddRange(SearchArgs.Results.ToArray()); + args.Results = SearchArgs.Results; + } + SearchArgs = args; +#if DONOT_HAVE_RANGED_SEARCH_SUPPORT + if (SearchArgs.CompareType == SearchCompareTypes.Between || SearchArgs.CompareType == SearchCompareTypes.NotBetween) + { + throw new NotImplementedException("Between and Not Between Range searches have not been implemented."); + } +#endif + search_progress_updater.Enabled = true; + //padPluginSelector.Enabled = false; + //gsPluginSelector.Enabled = false; + btnReset.Enabled = false; + btnSearch.Enabled = false; + btnCancel.Enabled = true; + grpDataType.Enabled = false; + grpCompareType.Enabled = false; + grpCompareValue.Enabled = false; + this.Refresh(); + Application.DoEvents(); + SearchWorkerThread.RunWorkerAsync(); + } + #endregion private void btnReset_Click(object sender, EventArgs e) { this.SearchInProgess = false; - btnSearch.Enabled = true; - btnCancel.Enabled = false; + //btnSearch.Enabled = true; + //btnCancel.Enabled = false; + this.DoResetSpecific(); + lstResults.Items.Clear(); + try { SearchArgs.Results = new List>(); } + catch { } } private void btnCancel_Click(object sender, EventArgs e) { this.SearchInProgess = false; - btnCancel.Enabled = false; - btnSearch.Enabled = true; - btnReset.Enabled = true; + //btnCancel.Enabled = false; + //btnSearch.Enabled = true; + //btnReset.Enabled = true; + this.DoCancelSpecific(); } private void mnuItemPatchListViewMemoryRegion_Click(object sender, EventArgs e)