示例#1
0
        /// <summary>
        /// Writes a result block to the file.
        /// </summary>
        /// <param name="block">The result block to add.</param>
        private void AppendBlockToFile(ScanResultBlock block)
        {
            Contract.Requires(block != null);

            using var bw = new BinaryWriter(fileStream, Encoding.Unicode, true);
            bw.Write(block.Start);
            bw.Write(block.End);
            bw.Write(block.Results.Count);

            foreach (var result in block.Results)
            {
                WriteSearchResult(bw, result);
            }
        }
示例#2
0
        /// <summary>
        /// Creates a result block from the scan results and adjusts the result offset.
        /// </summary>
        /// <param name="results">The results in this block.</param>
        /// <param name="previousStartAddress">The start address of the previous block or section.</param>
        /// <param name="valueSize">The size of the value type.</param>
        /// <returns>The new result block.</returns>
        private static ScanResultBlock CreateResultBlock(IReadOnlyList <ScanResult> results, IntPtr previousStartAddress, int valueSize)
        {
            // Calculate start and end address
            var startAddress = results.First().Address.Add(previousStartAddress);
            var endAddress   = results.Last().Address.Add(previousStartAddress) + valueSize;

            // Adjust the offsets of the results
            var firstOffset = results.First().Address;

            foreach (var result in results)
            {
                result.Address = result.Address.Sub(firstOffset);
            }

            var block = new ScanResultBlock(
                startAddress,
                endAddress,
                results
                );

            return(block);
        }
示例#3
0
        /// <summary>
        /// Adds a result block to the store. If the result count exceed the <see cref="MaximumMemoryResultsCount"/> limit,
        /// the results are stored in temporary files.
        /// </summary>
        /// <param name="block">The result block to add.</param>
        public void AddBlock(ScanResultBlock block)
        {
            Contract.Requires(block != null);

            lock (store)
            {
                TotalResultCount += block.Results.Count;

                if (mode == StorageMode.Memory)
                {
                    if (TotalResultCount > MaximumMemoryResultsCount)
                    {
                        mode = StorageMode.File;

                        fileStream = File.OpenWrite(storePath);

                        foreach (var b in store)
                        {
                            AppendBlockToFile(b);
                        }
                        store.Clear();
                        store.TrimExcess();

                        AppendBlockToFile(block);
                    }
                    else
                    {
                        store.Add(block);
                    }
                }
                else
                {
                    AppendBlockToFile(block);
                }
            }
        }