Esempio n. 1
0
        /// <summary>
        /// Opens the specified file.
        /// </summary>
        /// <param name="path">The full path of the file to open.</param>
        /// <param name="mode">The file mode for the created stream.</param>
        /// <param name="access">The access permissions for the created stream.</param>
        /// <returns>The new stream.</returns>
        public override SparseStream OpenFile(string path, FileMode mode, FileAccess access)
        {
            if (mode != FileMode.Open && mode != FileMode.OpenOrCreate)
            {
                throw new NotSupportedException("No write support for WIM files");
            }

            if (access != FileAccess.Read)
            {
                throw new NotSupportedException("No write support for WIM files");
            }

            byte[] streamHash       = GetFileHash(path);
            ShortResourceHeader hdr = _file.LocateResource(streamHash);

            if (hdr == null)
            {
                if (Utilities.IsAllZeros(streamHash, 0, streamHash.Length))
                {
                    return(new ZeroStream(0));
                }

                throw new IOException("Unable to locate file contents");
            }

            return(_file.OpenResourceStream(hdr));
        }
Esempio n. 2
0
        public FileResourceStream(Stream baseStream, ShortResourceHeader header, bool lzxCompression, int chunkSize)
        {
            _baseStream     = baseStream;
            _header         = header;
            _lzxCompression = lzxCompression;
            _chunkSize      = chunkSize;

            if (baseStream.Length > uint.MaxValue)
            {
                throw new NotImplementedException("Large files >4GB");
            }

            int numChunks = (int)Utilities.Ceil(header.OriginalSize, _chunkSize);

            _chunkOffsets = new long[numChunks];
            _chunkLength  = new long[numChunks];
            for (int i = 1; i < numChunks; ++i)
            {
                _chunkOffsets[i]    = Utilities.ToUInt32LittleEndian(Utilities.ReadFully(_baseStream, 4), 0);
                _chunkLength[i - 1] = _chunkOffsets[i] - _chunkOffsets[i - 1];
            }

            _chunkLength[numChunks - 1] = (_baseStream.Length - _baseStream.Position) - _chunkOffsets[numChunks - 1];
            _offsetDelta = _baseStream.Position;

            _currentChunk = -1;
        }
Esempio n. 3
0
        public void Read(byte[] buffer, int offset)
        {
            Tag             = Utilities.BytesToString(buffer, offset, 8);
            HeaderSize      = Utilities.ToUInt32LittleEndian(buffer, 8);
            Version         = Utilities.ToUInt32LittleEndian(buffer, 12);
            Flags           = (FileFlags)Utilities.ToUInt32LittleEndian(buffer, 16);
            CompressionSize = Utilities.ToInt32LittleEndian(buffer, 20);
            WimGuid         = Utilities.ToGuidLittleEndian(buffer, 24);
            PartNumber      = Utilities.ToUInt16LittleEndian(buffer, 40);
            TotalParts      = Utilities.ToUInt16LittleEndian(buffer, 42);
            ImageCount      = Utilities.ToUInt32LittleEndian(buffer, 44);

            OffsetTableHeader = new ShortResourceHeader();
            OffsetTableHeader.Read(buffer, 48);

            XmlDataHeader = new ShortResourceHeader();
            XmlDataHeader.Read(buffer, 72);

            BootMetaData = new ShortResourceHeader();
            BootMetaData.Read(buffer, 96);

            BootIndex = Utilities.ToUInt32LittleEndian(buffer, 120);

            IntegrityHeader = new ShortResourceHeader();
            IntegrityHeader.Read(buffer, 124);
        }
Esempio n. 4
0
 public void Read(byte[] buffer, int offset)
 {
     Header = new ShortResourceHeader();
     Header.Read(buffer, offset);
     PartNumber = Utilities.ToUInt16LittleEndian(buffer, offset + ShortResourceHeader.Size);
     RefCount   = Utilities.ToUInt32LittleEndian(buffer, offset + ShortResourceHeader.Size + 2);
     Hash       = new byte[20];
     Array.Copy(buffer, offset + ShortResourceHeader.Size + 6, Hash, 0, 20);
 }
Esempio n. 5
0
        internal SparseStream OpenResourceStream(ShortResourceHeader hdr)
        {
            SparseStream fileSectionStream = new SubStream(_fileStream, Ownership.None, hdr.FileOffset, hdr.CompressedSize);

            if ((hdr.Flags & ResourceFlags.Compressed) == 0)
            {
                return(fileSectionStream);
            }

            return(new FileResourceStream(fileSectionStream, hdr, (_fileHeader.Flags & FileFlags.LzxCompression) != 0, _fileHeader.CompressionSize));
        }
Esempio n. 6
0
        internal WimFileSystem(WimFile file, int index)
        {
            _file = file;

            ShortResourceHeader metaDataFileInfo = _file.LocateImage(index);

            if (metaDataFileInfo == null)
            {
                throw new ArgumentException("No such image: " + index, "index");
            }

            _metaDataStream = _file.OpenResourceStream(metaDataFileInfo);
            ReadSecurityDescriptors();

            _dirCache = new ObjectCache <long, List <DirectoryEntry> >();
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the reparse point data associated with a file or directory.
        /// </summary>
        /// <param name="path">The file to query</param>
        /// <returns>The reparse point information</returns>
        public ReparsePoint GetReparsePoint(string path)
        {
            DirectoryEntry dirEntry = GetEntry(path);

            ShortResourceHeader hdr = _file.LocateResource(dirEntry.Hash);

            if (hdr == null)
            {
                throw new IOException("No reparse point");
            }

            using (Stream s = _file.OpenResourceStream(hdr))
            {
                byte[] buffer = new byte[s.Length];
                s.Read(buffer, 0, buffer.Length);
                return(new ReparsePoint((int)dirEntry.ReparseTag, buffer));
            }
        }