inVtero.net.Scanner.BackwardsValueScan C# (CSharp) Method

BackwardsValueScan() public static method

Scan for a class configured variable "HexScanDword" This is a specialized thing we are trying to avoid over scanning Turns out the physical memory run data maintained by the OS is typically very deep physically So in start-up we may use this depending on input file
public static BackwardsValueScan ( String Filename, int ScanFor, int ExitAfter ) : IEnumerable
Filename String
ScanFor int
ExitAfter int
return IEnumerable
        public static IEnumerable<long> BackwardsValueScan(String Filename, int ScanFor, int ExitAfter = 0)
        {
            List<long> FoundValueOffsets = new List<long>();
            var FileSize = new FileInfo(Filename).Length;

            long ReadSize = 1024 * 1024 * 8;
            var ValueReadCount = (int)ReadSize / 4;
            var RevMapSize = ReadSize;

            var ShortFirstChunkSize = (int)(FileSize & (ReadSize - 1));
            var ShortFirstChunkBase = FileSize - ShortFirstChunkSize;

            if (ShortFirstChunkSize != 0)
            {
                var found = MapScanFile(Filename, ShortFirstChunkBase, ScanFor, ShortFirstChunkSize / 4);
                foreach (var offset in found)
                    yield return offset;

                if(ShortFirstChunkBase == 0)
                    yield break;
            }

            var RevCurrWindowBase = FileSize - ShortFirstChunkSize;

            RevCurrWindowBase -= RevMapSize;
            var ChunkCount = (FileSize / RevMapSize) + 1;

            bool StopRunning = false;

            long localOffset = ShortFirstChunkBase - ReadSize;

            for (long i = ChunkCount; i > 0; i--)
            {
                if (!StopRunning)
                {

                    if(Vtero.VerboseLevel > 1)
                        WriteColor($"Scanning From {localOffset:X} To {(localOffset + ReadSize):X} bytes");

                    var results = MapScanFile(Filename, localOffset, ScanFor, ValueReadCount);

                    foreach (var offset in results)
                        yield return offset;

                    CurrWindowBase += (1 * ReadSize);
                    var progress = Convert.ToInt32((Convert.ToDouble(CurrWindowBase) / Convert.ToDouble(FileSize) * 100.0) + 0.5);
                    if (progress != ProgressBarz.Progress)
                        ProgressBarz.RenderConsoleProgress(progress);

                    localOffset -= RevMapSize;
                    if (localOffset < 0 && !StopRunning)
                    {
                        localOffset = 0;
                        StopRunning = true;

                    }
                }
            }
            yield break;
        }
    }