Esempio n. 1
0
        public Func <Vector <Byte> > GetSearchKernel(SnapshotElementVectorComparer snapshotElementVectorComparer)
        {
            return(new Func <Vector <Byte> >(() =>
            {
                Vector <UInt32> z = Vector.AsVectorUInt32(snapshotElementVectorComparer.CurrentValues);
                Vector <UInt32> heapRoot = new Vector <UInt32>(this.LowerBounds[0]);
                Vector <UInt32> P = Vector.ConditionalSelect(Vector.GreaterThanOrEqual(z, heapRoot), this.Two, Vector <UInt32> .One);
                Int32 l = this.L;

                while (l > 1)
                {
                    for (Int32 index = 0; index < Vectors.VectorSize / sizeof(UInt32); index++)
                    {
                        this.YArray[index] = this.LowerBounds[P[index]];
                    }

                    Vector <UInt32> YP = new Vector <UInt32>(this.YArray);
                    Vector <UInt32> Q = Vector.ConditionalSelect(Vector.GreaterThanOrEqual(z, YP), this.Two, Vector <UInt32> .One);

                    P = Vector.Add(Vector.Multiply(P, this.Two), Q);
                    l--;
                }

                Vector <UInt32> i = Vector.BitwiseAnd(P, M);

                for (Int32 index = 0; index < Vectors.VectorSize / sizeof(UInt32); index++)
                {
                    UInt32 newIndex = i[index];
                    this.LArray[index] = this.LowerBounds[newIndex];
                    this.UArray[index] = this.UpperBounds[newIndex];
                }

                return Vector.AsVectorByte(Vector.Negate(Vector.BitwiseAnd(Vector.GreaterThanOrEqual(z, new Vector <UInt32>(this.LArray)), Vector.LessThanOrEqual(z, new Vector <UInt32>(this.UArray)))));
            }));
        }
Esempio n. 2
0
        public Func <Vector <Byte> > GetSearchKernel(SnapshotElementVectorComparer snapshotElementVectorComparer)
        {
            return(new Func <Vector <Byte> >(() =>
            {
                UInt32 halfIndex = this.PowerOf2Padding >> 1;
                Vector <UInt32> currentValues = Vector.AsVectorUInt32(snapshotElementVectorComparer.CurrentValues);
                Vector <UInt32> discoveredIndicies = Vector.ConditionalSelect(Vector.GreaterThan(currentValues, new Vector <UInt32>(this.UpperBounds[halfIndex])), new Vector <UInt32>(halfIndex), Vector <UInt32> .Zero);

                while (halfIndex > 1)
                {
                    halfIndex >>= 1;

                    for (Int32 index = 0; index < Vectors.VectorSize / sizeof(UInt32); index++)
                    {
                        this.UArray[index] = this.UpperBounds[discoveredIndicies[index] + halfIndex];
                    }

                    discoveredIndicies = Vector.Add(discoveredIndicies, Vector.ConditionalSelect(Vector.GreaterThan(currentValues, new Vector <UInt32>(this.UArray)), new Vector <UInt32>(halfIndex), Vector <UInt32> .Zero));
                }

                for (Int32 index = 0; index < Vectors.VectorSize / sizeof(UInt32); index++)
                {
                    this.LArray[index] = this.LowerBounds[discoveredIndicies[index]];
                    this.UArray[index] = this.UpperBounds[discoveredIndicies[index]];
                }

                return Vector.AsVectorByte(Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LArray)), Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UArray))));
            }));
        }
Esempio n. 3
0
        public Func <Vector <Byte> > GetSearchKernel(SnapshotElementVectorComparer snapshotElementVectorComparer)
        {
            return(new Func <Vector <Byte> >(() =>
            {
                Span <UInt32> lowerBounds = this.LowerBounds;
                Span <UInt32> upperBounds = this.UpperBounds;
                Vector <UInt32> currentValues = Vector.AsVectorUInt32(snapshotElementVectorComparer.CurrentValues);

                for (Int32 index = 0; index < Vectors.VectorSize / sizeof(UInt32); index++)
                {
                    Int32 targetIndex = lowerBounds.BinarySearch(currentValues[index], this.Comparer);
                    this.LArray[index] = this.LowerBounds[targetIndex];
                    this.UArray[index] = this.UpperBounds[targetIndex];
                }

                return Vector.AsVectorByte(Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LArray)), Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UArray))));
            }));
        }
Esempio n. 4
0
        public Func <Vector <Byte> > GetSearchKernel(SnapshotElementVectorComparer snapshotElementVectorComparer)
        {
            return(new Func <Vector <Byte> >(() =>
            {
                Vector <UInt32> result = Vector <UInt32> .Zero;
                Vector <UInt32> currentValues = Vector.AsVectorUInt32(snapshotElementVectorComparer.CurrentValues);

                for (Int32 boundsIndex = 0; boundsIndex < this.LowerBounds.Length; boundsIndex += LinearSearchKernel.UnrollSize)
                {
                    Vector <UInt32> result0 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 0])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 0])));
                    Vector <UInt32> result1 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 1])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 1])));
                    Vector <UInt32> result2 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 2])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 2])));
                    Vector <UInt32> result3 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 3])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 3])));
                    Vector <UInt32> result4 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 4])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 4])));
                    Vector <UInt32> result5 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 5])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 5])));
                    Vector <UInt32> result6 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 6])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 6])));
                    Vector <UInt32> result7 = Vector.BitwiseAnd(Vector.GreaterThanOrEqual(currentValues, new Vector <UInt32>(this.LowerBounds[boundsIndex + 7])),
                                                                Vector.LessThanOrEqual(currentValues, new Vector <UInt32>(this.UpperBounds[boundsIndex + 7])));

                    // Where is your god now
                    result = Vector.BitwiseOr(result,
                                              Vector.BitwiseOr(
                                                  Vector.BitwiseOr(
                                                      Vector.BitwiseOr(result0, result1),
                                                      Vector.BitwiseOr(result2, result3)),
                                                  Vector.BitwiseOr(
                                                      Vector.BitwiseOr(result4, result5),
                                                      Vector.BitwiseOr(result6, result7))));
                }

                return Vector.AsVectorByte(result);
            }));
        }
Esempio n. 5
0
        /// <summary>
        /// Filters the given snapshot to find all values that are valid pointers.
        /// </summary>
        /// <param name="snapshot">The snapshot on which to perfrom the scan.</param>
        /// <returns></returns>
        public static TrackableTask <Snapshot> Filter(TrackableTask parentTask, Snapshot snapshot, IVectorSearchKernel searchKernel, PointerSize pointerSize, Snapshot DEBUG, UInt32 RADIUS_DEBUG)
        {
            return(TrackableTask <Snapshot>
                   .Create(PointerFilter.Name, out UpdateProgress updateProgress, out CancellationToken cancellationToken)
                   .With(Task <Snapshot> .Run(() =>
            {
                try
                {
                    parentTask.CancellationToken.ThrowIfCancellationRequested();

                    ConcurrentBag <IList <SnapshotRegion> > regions = new ConcurrentBag <IList <SnapshotRegion> >();

                    ParallelOptions options = ParallelSettings.ParallelSettingsFastest.Clone();
                    options.CancellationToken = parentTask.CancellationToken;

                    // ISearchKernel DEBUG_KERNEL = new SpanSearchKernel(DEBUG, RADIUS_DEBUG);

                    Parallel.ForEach(
                        snapshot.OptimizedSnapshotRegions,
                        options,
                        (region) =>
                    {
                        // Check for canceled scan
                        parentTask.CancellationToken.ThrowIfCancellationRequested();

                        if (!region.ReadGroup.CanCompare(null))
                        {
                            return;
                        }

                        ScanConstraints constraints = new ScanConstraints(pointerSize.ToDataType(), null);
                        SnapshotElementVectorComparer vectorComparer = new SnapshotElementVectorComparer(region: region, constraints: constraints);
                        vectorComparer.SetCustomCompareAction(searchKernel.GetSearchKernel(vectorComparer));

                        // SnapshotElementVectorComparer DEBUG_COMPARER = new SnapshotElementVectorComparer(region: region);
                        // DEBUG_COMPARER.SetCustomCompareAction(DEBUG_KERNEL.GetSearchKernel(DEBUG_COMPARER));

                        IList <SnapshotRegion> results = vectorComparer.Compare();

                        // When debugging, these results should be the same as the results above
                        // IList<SnapshotRegion> DEBUG_RESULTS = vectorComparer.Compare();

                        if (!results.IsNullOrEmpty())
                        {
                            regions.Add(results);
                        }
                    });

                    // Exit if canceled
                    parentTask.CancellationToken.ThrowIfCancellationRequested();

                    snapshot = new Snapshot(PointerFilter.Name, regions.SelectMany(region => region));
                }
                catch (OperationCanceledException ex)
                {
                    Logger.Log(LogLevel.Warn, "Pointer filtering canceled", ex);
                    throw ex;
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.Error, "Error performing pointer filtering", ex);
                    return null;
                }

                return snapshot;
            }, parentTask.CancellationToken)));
        }
Esempio n. 6
0
        /// <summary>
        /// Begins the manual scan based on the provided snapshot and parameters.
        /// </summary>
        /// <param name="snapshot">The snapshot on which to perfrom the scan.</param>
        /// <param name="constraints">The collection of scan constraints to use in the manual scan.</param>
        /// <param name="taskIdentifier">The unique identifier to prevent duplicate tasks.</param>
        /// <returns></returns>
        public static TrackableTask <Snapshot> Scan(Snapshot snapshot, ConstraintNode constraints, String taskIdentifier = null)
        {
            try
            {
                return(TrackableTask <Snapshot>
                       .Create(ManualScanner.Name, taskIdentifier, out UpdateProgress updateProgress, out CancellationToken cancellationToken)
                       .With(Task <Snapshot> .Run(() =>
                {
                    Snapshot result = null;

                    try
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();

                        Int32 processedPages = 0;
                        ConcurrentBag <IList <SnapshotRegion> > regions = new ConcurrentBag <IList <SnapshotRegion> >();

                        ParallelOptions options = ParallelSettings.ParallelSettingsFastest.Clone();
                        options.CancellationToken = cancellationToken;

                        Parallel.ForEach(
                            snapshot.OptimizedSnapshotRegions,
                            options,
                            (region) =>
                        {
                            // Check for canceled scan
                            cancellationToken.ThrowIfCancellationRequested();

                            if (!region.ReadGroup.CanCompare(constraints.HasRelativeConstraint()))
                            {
                                return;
                            }

                            SnapshotElementVectorComparer vectorComparer = new SnapshotElementVectorComparer(region: region, constraints: constraints);
                            IList <SnapshotRegion> results = vectorComparer.Compare();

                            if (!results.IsNullOrEmpty())
                            {
                                regions.Add(results);
                            }

                            // Update progress every N regions
                            if (Interlocked.Increment(ref processedPages) % 32 == 0)
                            {
                                updateProgress((float)processedPages / (float)snapshot.RegionCount * 100.0f);
                            }
                        });
                        //// End foreach Region

                        // Exit if canceled
                        cancellationToken.ThrowIfCancellationRequested();

                        result = new Snapshot(ManualScanner.Name, regions.SelectMany(region => region));
                        stopwatch.Stop();
                        Logger.Log(LogLevel.Info, "Scan complete in: " + stopwatch.Elapsed);
                    }
                    catch (OperationCanceledException ex)
                    {
                        Logger.Log(LogLevel.Warn, "Scan canceled", ex);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogLevel.Error, "Error performing scan", ex);
                    }

                    return result;
                }, cancellationToken)));
            }
            catch (TaskConflictException ex)
            {
                Logger.Log(LogLevel.Warn, "Unable to start scan. Scan is already queued.");
                throw ex;
            }
        }