示例#1
0
        public void Find(FindByteDataOption findByteDataOption)
        {
            _startIndex = findByteDataOption.SearchStartIndex;
            _matchCase  = findByteDataOption.MatchCase;

            FindByteDataEventArgs args = new FindByteDataEventArgs();

            if (findByteDataOption.SearchBytes == null)
            {
                args.FoundPosition = -1;
                OnFindPositionFound(args);
                return;
            }

            if (findByteDataOption.SearchDirection == SearchDirection.Direction_Up)
            {
                args.FoundPosition = FindUp(findByteDataOption);
            }
            else
            {
                args.FoundPosition = FindDown(findByteDataOption);
            }

            OnFindPositionFound(args);
        }
示例#2
0
        public long FindDown(FindByteDataOption findByteDataOption)
        {
            while (_startIndex < _byteData.Length)
            {
                long bufferSize = FillBuffer(_buffer, _startIndex);

                int i = FindBuffer(_buffer, findByteDataOption.SearchBytes);

                if (i >= 0)
                {
                    return(_startIndex + i);
                }
                else
                {
                    _startIndex += _buffer.Length - findByteDataOption.SearchBytes.Length + 1;
                }
            }

            return(-1);
        }
示例#3
0
        public long FindUp(FindByteDataOption findByteDataOption)
        {
            while (_startIndex > 0)
            {
                long bufferSize = FillBufferUp(_buffer, _startIndex);

                int i = FindBuffer(_buffer, findByteDataOption.SearchBytes);

                if (i >= 0)
                {
                    //return _startIndex - (_buffer.Length - i) + 1;
                    return(_startIndex - (bufferSize - i) + 1);
                }
                else
                {
                    _startIndex -= _buffer.Length - findByteDataOption.SearchBytes.Length + 1;
                }
            }

            return(-1);
        }