Пример #1
0
        /// <summary>
        /// Loads the results for the current page.
        /// </summary>
        private void LoadScanResults()
        {
            Snapshot snapshot = SnapshotManager.GetInstance().GetActiveSnapshot(createIfNone: false);
            ObservableCollection <ScanResult> newAddresses = new ObservableCollection <ScanResult>();

            if (snapshot == null)
            {
                this.addresses = newAddresses;
                this.RaisePropertyChanged(nameof(this.Addresses));
                return;
            }

            UInt64 startIndex = Math.Min(ScanResultsViewModel.PageSize * this.CurrentPage, snapshot.ElementCount);
            UInt64 endIndex   = Math.Min((ScanResultsViewModel.PageSize * this.CurrentPage) + ScanResultsViewModel.PageSize, snapshot.ElementCount);

            for (UInt64 index = startIndex; index < endIndex; index++)
            {
                SnapshotElementIterator element = snapshot[index];
                String label = String.Empty;

                if (element.GetElementLabel() != null)
                {
                    label = element.GetElementLabel().ToString();
                }

                String currentValue = String.Empty;
                if (element.HasCurrentValue())
                {
                    currentValue = element.GetCurrentValue().ToString();
                }

                String previousValue = String.Empty;
                if (element.HasPreviousValue())
                {
                    previousValue = element.GetPreviousValue().ToString();
                }

                newAddresses.Add(new ScanResult(element.BaseAddress, currentValue, previousValue, label));
            }

            this.addresses = newAddresses;
            this.RaisePropertyChanged(nameof(this.Addresses));

            // Ensure results are visible
            this.IsVisible  = true;
            this.IsSelected = true;
            this.IsActive   = true;
        }
        public void ApplyThreshold()
        {
            lock (this.SnapshotLock)
            {
                if (this.Snapshot == null)
                {
                    return;
                }
            }

            Object lowerValue = this.Histogram.Keys[this.LowerIndex];
            Object upperValue = this.Histogram.Keys[this.UpperIndex];

            lock (this.SnapshotLock)
            {
                if (!this.Inverted)
                {
                    this.Snapshot.SetAllValidBits(false);

                    foreach (SnapshotRegion region in this.Snapshot)
                    {
                        for (IEnumerator <SnapshotElementIterator> enumerator = region.IterateElements(PointerIncrementMode.LabelsOnly); enumerator.MoveNext();)
                        {
                            SnapshotElementIterator element = enumerator.Current;

                            dynamic label = element.GetElementLabel();

                            if (label >= lowerValue && label <= upperValue)
                            {
                                element.SetValid(true);
                            }
                        }
                    }
                }
                else
                {
                    this.Snapshot.SetAllValidBits(true);

                    foreach (SnapshotRegion region in this.Snapshot)
                    {
                        for (IEnumerator <SnapshotElementIterator> enumerator = region.IterateElements(PointerIncrementMode.LabelsOnly); enumerator.MoveNext();)
                        {
                            SnapshotElementIterator element = enumerator.Current;

                            dynamic label = element.GetElementLabel();

                            if (label >= lowerValue && label <= upperValue)
                            {
                                element.SetValid(false);
                            }
                        }
                    }
                }

                this.Snapshot.DiscardInvalidRegions();
            }

            SnapshotManager.GetInstance().SaveSnapshot(this.Snapshot);
            this.UpdateHistogram(forceUpdate: true);
        }
        /// <summary>
        /// Called when the scan updates.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token for handling canceled tasks.</param>
        protected override void OnUpdate(CancellationToken cancellationToken)
        {
            ConcurrentDictionary <Object, Int64> histogram = new ConcurrentDictionary <Object, Int64>();
            Int32 processedPages = 0;

            lock (this.SnapshotLock)
            {
                if (this.Snapshot == null)
                {
                    this.Cancel();
                    return;
                }

                Parallel.ForEach(
                    this.Snapshot.Cast <SnapshotRegion>(),
                    SettingsViewModel.GetInstance().ParallelSettingsFast,
                    (region) =>
                {
                    if (region.ElementLabels == null || region.ElementCount <= 0)
                    {
                        return;
                    }

                    for (IEnumerator <SnapshotElementIterator> enumerator = region.IterateElements(PointerIncrementMode.LabelsOnly); enumerator.MoveNext();)
                    {
                        SnapshotElementIterator element = enumerator.Current;

                        lock (this.ItemLock)
                        {
                            Object label = element.GetElementLabel();

                            if (histogram.ContainsKey(label))
                            {
                                histogram[label]++;
                            }
                            else
                            {
                                histogram.TryAdd(label, 1);
                            }
                        }
                    }

                    lock (this.ProgressLock)
                    {
                        processedPages++;
                        this.UpdateProgress(processedPages, this.Snapshot.RegionCount, canFinalize: false);
                    }
                    //// End foreach element
                });
                //// End foreach region
            }

            this.Histogram = new SortedList <Object, Int64>(histogram);
            this.UpdateHistogram();
            this.Cancel();
        }