Example #1
0
        public HexCachedBufferStreamImpl(HexSimpleBufferStream simpleStream, bool disposeStream)
        {
            if (simpleStream == null)
            {
                throw new ArgumentNullException(nameof(simpleStream));
            }
            lockObj            = new object();
            this.simpleStream  = simpleStream;
            this.disposeStream = disposeStream;
            pageSize           = simpleStream.PageSize;
            Debug.Assert(pageSize == 0 || IsPowerOfTwo(pageSize));
            if (pageSize == 0 || !IsPowerOfTwo(pageSize))
            {
                pageSize = DEFAULT_PAGE_SIZE;
            }
            if (pageSize > MAX_PAGE_SIZE)
            {
                pageSize = MAX_PAGE_SIZE;
            }
            Debug.Assert(pageSize >= MIN_PAGE_SIZE);
            if (pageSize < MIN_PAGE_SIZE)
            {
                pageSize = MIN_PAGE_SIZE;
            }
            Debug.Assert(IsPowerOfTwo(pageSize));
            pageSizeMask = pageSize - 1;

            int numCachedPages = (int)((CACHE_SIZE + pageSizeMask) / pageSize);

            cachedPages = new CachedPage[numCachedPages];
            for (int i = 0; i < cachedPages.Length; i++)
            {
                cachedPages[i] = new CachedPage(i, (int)pageSize);
            }
        }
 public override HexCachedBufferStream CreateCached(HexSimpleBufferStream simpleStream, bool disposeStream)
 {
     if (simpleStream == null)
     {
         throw new ArgumentNullException(nameof(simpleStream));
     }
     return(new HexCachedBufferStreamImpl(simpleStream, disposeStream));
 }
Example #3
0
 protected override void DisposeCore()
 {
     if (disposeStream)
     {
         simpleStream?.Dispose();
     }
     simpleStream = null;
 }
Example #4
0
        public override void Read(IntPtr hProcess, HexPosition position, byte[] destination, long destinationIndex, long length)
        {
            if (hProcess == IntPtr.Zero)
            {
                throw new ArgumentException();
            }
            if (position >= HexPosition.MaxEndPosition)
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }
            if (destinationIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(destinationIndex));
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            if (new HexPosition(destinationIndex) + length > destination.LongLength)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            HexSimpleBufferStream processStream = null;
            HexBufferStream       cachedStream  = null;

            try {
                processStream = hexBufferStreamFactoryService.CreateSimpleProcessStream(hProcess);
                cachedStream  = hexBufferStreamFactoryService.CreateCached(processStream, disposeStream: false);
                cachedStream.ReadBytes(position, destination, destinationIndex, length);
            }
            finally {
                processStream?.Dispose();
                cachedStream?.Dispose();
            }
        }