예제 #1
0
        /// <inheritdoc/>
        public IImageStream Create(FileOffset offset, long length)
        {
            if ((long)offset < 0 || length < 0)
            {
                return(MemoryImageStream.CreateEmpty());
            }

            int offs = (int)Math.Min((long)Length, (long)offset);
            int len  = (int)Math.Min((long)Length - offs, length);

            return(new MemoryImageStream((FileOffset)((long)fileOffset + (long)offset), data, dataOffset + offs, len));
        }
        /// <inheritdoc/>
        public unsafe IImageStream Create(FileOffset offset, long length)
        {
            if (offset < 0 || length < 0)
            {
                return(MemoryImageStream.CreateEmpty());
            }

            long offs = Math.Min((long)dataLength, (long)offset);
            long len  = Math.Min((long)dataLength - offs, length);

            return(new UnmanagedMemoryImageStream(this, offset, offs, len));
        }
        /// <inheritdoc/>
        public unsafe IImageStream Create(FileOffset offset, long length)
        {
            if ((long)offset < 0 || length < 0)
            {
                return(MemoryImageStream.CreateEmpty());
            }

            long offs = Math.Min(Length, (long)offset);
            long len  = Math.Min(Length - offs, length);

            return(new UnmanagedMemoryImageStream(owner, (FileOffset)((long)fileOffset + (long)offset), startAddr + (long)offs, len));
        }
예제 #4
0
        /// <summary>
        /// Creates a <see cref="IImageStream"/>
        /// </summary>
        /// <param name="fileName">Filename</param>
        /// <param name="mapAsImage"><c>true</c> if we should map it as an executable. Not supported
        /// on Linux/Mac</param>
        /// <returns>A new <see cref="IImageStream"/> instance</returns>
        public static IImageStream CreateImageStream(string fileName, bool mapAsImage)
        {
            var creator = CreateMemoryMappedFileStreamCreator(fileName, mapAsImage);

            try
            {
                if (creator != null)
                {
                    return(new UnmanagedMemoryImageStream(creator));
                }
                return(MemoryImageStream.Create(File.ReadAllBytes(fileName)));
            }
            catch
            {
                if (creator != null)
                {
                    creator.Dispose();
                }
                throw;
            }
        }