コード例 #1
0
ファイル: RWStream.cs プロジェクト: CamxxCore/peek-poker
        /// <summary>
        /// Search Hex String
        /// </summary>
        /// <param name="pattern">The pattern you are searching for</param>
        /// <param name="startDumpOffset">The Offset you want to start dump from</param>
        /// <returns></returns>
        public BindingList<SearchResults> SearchHexString(byte[] pattern, uint startDumpOffset)
        {
            var buffer = new byte[_fStream.Length];
            _fStream.Read(buffer, 0, (int) _fStream.Length);
            int i = IndexOfInt(buffer, pattern[0], 0);
            var positions = new BindingList<SearchResults>();

            int x = 1;
            while (i >= 0 && i <= buffer.Length - pattern.Length)
            {
                if (_stopSearch) return positions;
                ReportProgress(0, buffer.Length, i, "Searching...");

                var segment = new byte[pattern.Length];
                Buffer.BlockCopy(buffer, i, segment, 0, pattern.Length);

                if (ByteArrayCompare(segment, pattern))
                {
                    var results = new SearchResults();
                    results.Offset = String.Format("{0:X}", startDumpOffset + (uint) i);

                    var hex = new StringBuilder(segment.Length*2);
                    foreach (byte b in segment)
                        hex.AppendFormat("{0:x2}", b);

                    results.Value = hex.ToString().ToUpper();
                    results.ID = x.ToString();
                    positions.Add(results);

                    //if (positions.Count == 1000) return positions;
                    if (_stopSearch) return positions;
                    i = IndexOfInt(buffer, pattern[0], i + pattern.Length);
                    x++;
                }
                else
                {
                    if (_stopSearch) return positions;
                    i = IndexOfInt(buffer, pattern[0], i + 1);
                }
                if (_stopSearch) return positions;
            }
            return positions;
        }
コード例 #2
0
ファイル: Search.cs プロジェクト: 360Haven/PeekPoker
        //Refresh results Thread
        private void RefreshResultList()
        {
            try
            {
                EnableControl(resultRefreshButton, false);
                var newSearchResults = new BindingList<SearchResults>();
                var limitSearchResults = new BindingList<SearchResults>();
                int value = 0;
                string retvalue = "";

                if (_searchResult.Count > 500)
                {
                    string results = _rtm.Peek(_tempOffset, _tempLength, _tempOffset, _tempLength);

                    _readWriter = new RwStream();
                    try
                    {
                        byte[] _buffer = Functions.HexToBytes(results);
                        _readWriter.WriteBytes(_buffer, 0, _buffer.Length);

                        _readWriter.Flush();
                        _readWriter.Position = 0;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }

                foreach (SearchResults item in _searchResult)
                {
                    UpdateProgressbar(0, _searchResult.Count, value, "Refreshing...");

                    string length = (item.Value.Length/2).ToString("X");
                    if (_searchResult.Count > 500)
                    {
                        //var retvalue = this._rtm.
                        uint pos = uint.Parse(item.Offset, NumberStyles.AllowHexSpecifier);
                        uint spos = uint.Parse(_tempOffset, NumberStyles.AllowHexSpecifier);
                        _readWriter.Position = (pos - spos);
                        byte[] _value = _readWriter.ReadBytes((item.Value.Length/2));
                        retvalue = Functions.ToHexString(_value);
                    }
                    else
                    {
                        retvalue = _rtm.Peek(item.Offset, length, item.Offset, length);
                    }

                    uint currentResults;
                    uint newResult;

                    if (!uint.TryParse(item.Value, out currentResults))
                        throw new Exception("Invalid Search Value this function only works for Unsigned Integers.");
                    uint.TryParse(retvalue, out newResult);

                    //===================================================
                    //Default
                    if (defaultRadioButton.Checked)
                    {
                        if (item.Value == retvalue) continue; //if value hasn't change continue for each loop
                        if (value < 1000)
                        {
                            GridRowColours(value);
                        }
                        item.Value = retvalue;
                    }
                    else if (ifEqualsRadioButton.Checked)
                    {
                        if (newResult == currentResults)
                        {
                            var searchResultItem = new SearchResults
                                                       {
                                                           ID = item.ID,
                                                           Offset = item.Offset,
                                                           Value = retvalue
                                                       };
                            newSearchResults.Add(searchResultItem);
                        }
                    }
                    else if (ifGreaterThanRadioButton.Checked)
                    {
                        if (newResult > currentResults)
                        {
                            var searchResultItem = new SearchResults
                                                       {
                                                           ID = item.ID,
                                                           Offset = item.Offset,
                                                           Value = retvalue
                                                       };
                            newSearchResults.Add(searchResultItem);
                        }
                    }
                    else if (ifLessThanRadioButton.Checked)
                    {
                        if (newResult < currentResults)
                        {
                            var searchResultItem = new SearchResults
                                                       {
                                                           ID = item.ID,
                                                           Offset = item.Offset,
                                                           Value = retvalue
                                                       };
                            newSearchResults.Add(searchResultItem);
                        }
                    }
                    else if (ifLessThanRadioButton.Checked)
                    {
                        if (newResult != currentResults)
                        {
                            var searchResultItem = new SearchResults
                                                       {
                                                           ID = item.ID,
                                                           Offset = item.Offset,
                                                           Value = retvalue
                                                       };
                            newSearchResults.Add(searchResultItem);
                        }
                    }
                    else if (ifChangeRadioButton.Checked)
                    {
                        if (item.Value != retvalue)
                        {
                            var searchResultItem = new SearchResults
                                                       {
                                                           ID = item.ID,
                                                           Offset = item.Offset,
                                                           Value = retvalue
                                                       };
                            newSearchResults.Add(searchResultItem);
                        }
                    }

                    value++;
                }
                if (defaultRadioButton.Checked)
                {
                    ResultGridUpdate();
                    ResultCountBoxUpdate();
                }
                else
                {
                    _searchResult = newSearchResults;
                    for (int i = 0; i < _searchResult.Count; i++)
                    {
                        if (i >= 1000)
                            break;

                        limitSearchResults.Add(_searchResult[i]);
                    }

                    _searchLimitedResult = limitSearchResults;
                    ResultGridUpdate();
                    ResultCountBoxUpdate();
                }
                UpdateProgressbar(0, 100, 0, "idle");
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message, string.Format("Peek Poker"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                EnableControl(resultRefreshButton, true);
                UpdateProgressbar(0, 100, 0, "idle");
                Thread.CurrentThread.Abort();
            }
        }