Esempio n. 1
0
        /// <summary>
        /// Sets the default compare action to use for this element.
        /// </summary>
        /// <param name="compareActionConstraint">The constraint to use for the element quick action.</param>
        /// <param name="compareActionValue">The value to use for the element quick action.</param>
        private void SetCompareAction(ScanConstraintManager scanConstraintManager)
        {
            foreach (ScanConstraint scanConstraint in scanConstraintManager)
            {
                switch (scanConstraint.Constraint)
                {
                case ScanConstraint.ConstraintType.Unchanged:
                    this.Compare = this.Unchanged;
                    break;

                case ScanConstraint.ConstraintType.Changed:
                    this.Compare = this.Changed;
                    break;

                case ScanConstraint.ConstraintType.Increased:
                    this.Compare = this.Increased;
                    break;

                case ScanConstraint.ConstraintType.Decreased:
                    this.Compare = this.Decreased;
                    break;

                case ScanConstraint.ConstraintType.IncreasedByX:
                    this.Compare = () => this.IncreasedByValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.DecreasedByX:
                    this.Compare = () => this.DecreasedByValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.Equal:
                    this.Compare = () => this.EqualToValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.NotEqual:
                    this.Compare = () => this.NotEqualToValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.GreaterThan:
                    this.Compare = () => this.GreaterThanValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.GreaterThanOrEqual:
                    this.Compare = () => this.GreaterThanOrEqualToValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.LessThan:
                    this.Compare = () => this.LessThanValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.LessThanOrEqual:
                    this.Compare = () => this.LessThanValue(scanConstraint.ConstraintValue);
                    break;
                }
            }
        }
        /// <summary>
        /// Starts the scan using the current constraints.
        /// </summary>
        private void StartScan()
        {
            // Create a constraint manager that includes the current active constraint
            ScanConstraintManager allScanConstraints = this.ScanConstraintManager.Clone();

            allScanConstraints.AddConstraint(this.CurrentScanConstraint);

            ManualScannerModel.SetScanConstraintManager(allScanConstraints);
            ManualScannerModel.Begin();
        }
        /// <summary>
        /// Updates the active type.
        /// </summary>
        /// <param name="activeType">The new active type.</param>
        public void Update(Type activeType)
        {
            // Create a temporary manager to update our current constraint
            ScanConstraintManager manager = new ScanConstraintManager();

            manager.AddConstraint(this.CurrentScanConstraint);
            manager.SetElementType(activeType);

            this.ScanConstraintManager.SetElementType(activeType);
            this.UpdateAllProperties();
        }
Esempio n. 4
0
        /// <summary>
        /// Compares this snapshot region against the given
        /// </summary>
        /// <param name="scanConstraints"></param>
        /// <returns></returns>
        public IList <SnapshotRegion> CompareAll(ScanConstraintManager scanConstraints)
        {
            if (!this.ReadGroup.CanCompare(scanConstraints.HasRelativeConstraint()))
            {
                return(null);
            }

            SnapshotElementVectorComparer vectorComparer = new SnapshotElementVectorComparer(region: this, scanConstraints: scanConstraints);

            return(vectorComparer.Compare());
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the enumerator for an element reference within this snapshot region.
        /// </summary>
        /// <param name="pointerIncrementMode">The method for incrementing pointers.</param>
        /// <param name="compareActionConstraint">The constraint to use for the element quick action.</param>
        /// <param name="compareActionValue">The value to use for the element quick action.</param>
        /// <returns>The enumerator for an element reference within this snapshot region.</returns>
        public IEnumerator <SnapshotElementComparer> IterateComparer(
            SnapshotElementComparer.PointerIncrementMode pointerIncrementMode,
            ScanConstraintManager scanConstraintManager)
        {
            Int32 elementCount = this.ElementCount;
            SnapshotElementComparer snapshotElement = new SnapshotElementComparer(region: this, pointerIncrementMode: pointerIncrementMode, scanConstraintManager: scanConstraintManager);

            for (Int32 elementIndex = 0; elementIndex < elementCount; elementIndex++)
            {
                yield return(snapshotElement);

                snapshotElement.IncrementPointers();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotElementComparer" /> class.
        /// </summary>
        /// <param name="region">The parent region that contains this element.</param>
        /// <param name="elementIndex">The index of the element to begin pointing to.</param>
        /// <param name="compareActionConstraint">The constraint to use for the element quick action.</param>
        /// <param name="compareActionValue">The value to use for the element quick action.</param>
        /// <param name="pointerIncrementMode">The method by which to increment element pointers.</param>
        public unsafe SnapshotElementComparer(
            SnapshotRegion region,
            PointerIncrementMode pointerIncrementMode,
            ScanConstraintManager scanConstraintManager)
        {
            this.Region = region;

            // The garbage collector can relocate variables at runtime. Since we use unsafe pointers, we need to keep these pinned
            this.CurrentValuesHandle  = GCHandle.Alloc(this.Region.ReadGroup.CurrentValues, GCHandleType.Pinned);
            this.PreviousValuesHandle = GCHandle.Alloc(this.Region.ReadGroup.PreviousValues, GCHandleType.Pinned);

            this.InitializePointers();
            this.SetConstraintFunctions();
            this.SetPointerFunction(pointerIncrementMode);
            this.SetCompareAction(scanConstraintManager);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SnapshotElementVectorComparer" /> class.
        /// </summary>
        /// <param name="region">The parent region that contains this element.</param>
        /// <param name="vectorSize">The size of vectors on the system.</param>
        /// <param name="scanConstraints">The set of constraints to use for the element comparisons.</param>
        public unsafe SnapshotElementVectorComparer(
            SnapshotRegion region,
            ScanConstraintManager scanConstraints)
        {
            this.Region          = region;
            this.VectorSize      = EngineCore.GetInstance().Architecture.GetVectorSize();
            this.VectorReadBase  = this.Region.ReadGroupOffset - this.Region.ReadGroupOffset % this.VectorSize;
            this.VectorReadIndex = 0;
            this.DataTypeSize    = Conversions.SizeOf(this.Region.ReadGroup.ElementDataType);

            // Initialize capacity to 1/16 elements
            this.ResultRegions = new List <SnapshotRegion>(unchecked ((Int32)(this.Region.ElementCount)) / 16);

            this.SetConstraintFunctions();
            this.SetCompareAction(scanConstraints);
        }
Esempio n. 8
0
        /// <summary>
        /// Starts the scan using the current constraints.
        /// </summary>
        private void StartScan()
        {
            // Create a constraint manager that includes the current active constraint
            ScanConstraintManager allScanConstraints = this.ScanConstraintManager.Clone();

            allScanConstraints.AddConstraint(this.CurrentScanConstraint);

            if (!allScanConstraints.IsValid())
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Unable to start scan with given constraints");
                return;
            }

            ManualScannerModel.SetScanConstraintManager(allScanConstraints);
            ManualScannerModel.Start();
        }
Esempio n. 9
0
 /// <summary>
 /// Sets the scan constraints for this scan.
 /// </summary>
 /// <param name="scanConstraintManager">The scan constraint manager, which contains all scan constraints.</param>
 public void SetScanConstraintManager(ScanConstraintManager scanConstraintManager)
 {
     this.ScanConstraintManager = scanConstraintManager.Clone();
 }
Esempio n. 10
0
        /// <summary>
        /// Sets the default compare action to use for this element.
        /// </summary>
        /// <param name="scanConstraints">The constraint to use for the element quick action.</param>
        /// <param name="compareActionValue">The value to use for the element quick action.</param>
        private void SetCompareAction(ScanConstraintManager scanConstraints)
        {
            foreach (ScanConstraint scanConstraint in scanConstraints)
            {
                Func <Vector <Byte> > vectorCompare = null;

                switch (scanConstraint.Constraint)
                {
                case ScanConstraint.ConstraintType.Unchanged:
                    vectorCompare = this.Unchanged;
                    break;

                case ScanConstraint.ConstraintType.Changed:
                    vectorCompare = this.Changed;
                    break;

                case ScanConstraint.ConstraintType.Increased:
                    vectorCompare = this.Increased;
                    break;

                case ScanConstraint.ConstraintType.Decreased:
                    vectorCompare = this.Decreased;
                    break;

                case ScanConstraint.ConstraintType.IncreasedByX:
                    vectorCompare = () => this.IncreasedByValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.DecreasedByX:
                    vectorCompare = () => this.DecreasedByValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.Equal:
                    vectorCompare = () => this.EqualToValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.NotEqual:
                    vectorCompare = () => this.NotEqualToValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.GreaterThan:
                    vectorCompare = () => this.GreaterThanValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.GreaterThanOrEqual:
                    vectorCompare = () => this.GreaterThanOrEqualToValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.LessThan:
                    vectorCompare = () => this.LessThanValue(scanConstraint.ConstraintValue);
                    break;

                case ScanConstraint.ConstraintType.LessThanOrEqual:
                    vectorCompare = () => this.LessThanOrEqualToValue(scanConstraint.ConstraintValue);
                    break;

                default:
                    throw new Exception("Unknown constraint type");
                }

                if (this.VectorCompare == null)
                {
                    this.VectorCompare = vectorCompare;
                }
                else
                {
                    // We have multiple constraints -- the best way to enforce this is to simply AND the scan results together
                    Func <Vector <Byte> > currentCompare = this.VectorCompare;
                    this.VectorCompare = () => Vector.BitwiseAnd(currentCompare.Invoke(), vectorCompare.Invoke());
                }
            }
        }