Exemple #1
0
        private unsafe void ReadLookupTable()
        {
            _file.Position = _header.LookupTable.OffsetInWim;
            ulong entries = _header.LookupTable.OriginalSize / (ulong)sizeof(LookupEntry);

            var entryArray = new LookupEntry[entries];

            for (ulong i = 0; i < entries; i++)
            {
                byte[] bEntry = _reader.ReadBytes(sizeof(LookupEntry));
                fixed(byte *pEntry = bEntry)
                {
                    entryArray[i] = Marshal.PtrToStructure <LookupEntry>((IntPtr)pEntry);
                }
            }

            _lookupTable = new LookupTable(entryArray);
        }
Exemple #2
0
        private unsafe void LoadImageMetadata(int imageIndex)
        {
            if (_lookupTable == null)
            {
                ReadLookupTable();
            }

            if (imageIndex >= _header.ImageCount)
            {
                throw new ArgumentOutOfRangeException(nameof(imageIndex));
            }

            LookupEntry metadataEntry = _lookupTable.Entries.Where(l => (l.Flags & ResourceHeaderFlags.Metadata) == ResourceHeaderFlags.Metadata).OrderBy(l => l.OffsetInWim).Skip(imageIndex).First();

            _file.Position = metadataEntry.OffsetInWim;

            byte[] bTable = _reader.ReadBytes(sizeof(SecurityTableHeader));
            SecurityTableHeader stHeader;

            fixed(byte *pTable = bTable)
            {
                stHeader = Marshal.PtrToStructure <SecurityTableHeader>((IntPtr)pTable);
            }

            var sdLengths = new ulong[stHeader.EntryCount];

            for (int i = 0; i < sdLengths.Length; i++)
            {
                sdLengths[i] = _reader.ReadUInt64();
            }

            var sdDescriptors = new byte[stHeader.EntryCount][];

            for (int i = 0; i < sdLengths.Length; i++)
            {
                sdDescriptors[i] = _reader.ReadBytes((int)sdLengths[i]);
            }

            SecurityTable st = new SecurityTable(stHeader, sdDescriptors);

            var dirEntries = new List <DirectoryTableEntry>();

            while (_file.Position < metadataEntry.OffsetInWim + (long)metadataEntry.SizeInWim)
            {
                long           startPosition = _file.Position;
                byte[]         bdEntry       = _reader.ReadBytes(sizeof(DirectoryEntry));
                DirectoryEntry dEntry;
                fixed(byte *pdEntry = bdEntry)
                {
                    dEntry = Marshal.PtrToStructure <DirectoryEntry>((IntPtr)pdEntry);
                }

                string name = Encoding.Unicode.GetString(_reader.ReadBytes(dEntry.FileNameLength));

                var altStreams = new Dictionary <string, StreamEntry>(dEntry.Streams);
                for (int i = 0; i < dEntry.Streams; i++)
                {
                    byte[]      bsEntry = _reader.ReadBytes(sizeof(StreamEntry));
                    StreamEntry sEntry;
                    fixed(byte *psEntry = bsEntry)
                    {
                        sEntry = Marshal.PtrToStructure <StreamEntry>((IntPtr)psEntry);
                    }

                    string sName = Encoding.Unicode.GetString(_reader.ReadBytes(sEntry.StreamNameLength));

                    altStreams.Add(sName, sEntry);
                }

                dirEntries.Add(new DirectoryTableEntry(name, dEntry, altStreams));

                // TODO: Transveral logic
            }

            _images[imageIndex] = new WimImage(st, dirEntries.ToArray());
        }