Exemplo n.º 1
0
        public void FindLargestMatch0()
        {
            var A = new byte[] { 0, 2, 3, 4, 5, 6, 7 };
            var B = new byte[] { 1, 2, 3, 4, 5, 6, 7 };

            fixed(byte *_A = A)
            fixed(byte *_B = B)
            {
                Assert.Equal(0, PointerUtils.FindLargestMatch(_A, _B, 5));
            }
        }
Exemplo n.º 2
0
        public void FindLargestMatch5()
        {
            var A = new byte[] { 1, 2, 3, 4, 5, 0, 7 };
            var B = new byte[] { 1, 2, 3, 4, 5, 6, 7 };

            fixed(byte *_A = A)
            fixed(byte *_B = B)
            {
                Assert.Equal(5, PointerUtils.FindLargestMatch(_A, _B, A.Length));
            }
        }
Exemplo n.º 3
0
        public FindSequenceResult FindMaxSequence()
        {
            var FindSequenceResult = new FindSequenceResult()
            {
                Offset = 0,
                Size   = 0,
            };

            if ((Data.Length - _Offset) >= MinSize)
            {
                fixed(byte *DataPtr = this.Data)
                {
                    var Hash = GetOffsetHash(_Offset);

                    if (Waypoints.ContainsKey(Hash))
                    {
                        //var Node = Waypoints[Hash].Last;
                        foreach (var CompareOffset in Waypoints[Hash])
                        {
                            int LocalMaxSize = Math.Min((Data.Length - _Offset), MaxSize);

                            //if (!AllowOverlapping && (CompareOffset + LocalMaxSize > _Offset)) continue;

                            int MatchedLength = PointerUtils.FindLargestMatch(
                                &DataPtr[CompareOffset],
                                &DataPtr[_Offset],
                                LocalMaxSize
                                );

                            /*
                             * var Hash1 = PointerUtils.FastHash(&DataPtr[CompareOffset], MinSize);
                             * var Hash2 = PointerUtils.FastHash(&DataPtr[_Offset], MinSize);
                             * for (int n = 0; n < MinSize; n++)
                             * {
                             *      Console.WriteLine("{0:X2}, {1:X2}", DataPtr[CompareOffset + n], DataPtr[_Offset + n]);
                             * }
                             * Console.WriteLine();
                             * Console.WriteLine("{0}, {1}, {2}, {3}: {4:X8}, {5:X8}, {6:X8}", MatchedLength, MinSize, MaxSize, LocalMaxSize, Hash, Hash1, Hash2);
                             */

                            //Console.WriteLine("{0}, {1}, {2}", CompareOffset - _Offset, MatchedLength, CompareOffset - _Offset + MatchedLength);

                            if (!AllowOverlapping && (CompareOffset - _Offset + MatchedLength) > 0)
                            {
                                MatchedLength = _Offset - CompareOffset;
                                //continue;
                            }

                            if (MatchedLength >= MinSize)
                            {
                                if (FindSequenceResult.Size < MatchedLength)
                                {
                                    FindSequenceResult.Size   = MatchedLength;
                                    FindSequenceResult.Offset = CompareOffset;
                                }

                                if (MatchedLength == MaxSize)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(FindSequenceResult);
        }