Beispiel #1
0
        public XmlWindowsImageMetadata Load(Stream stream)
        {
            Log.Verbose("Getting WIM stream");

            WimMetadata metadata;

            try
            {
                metadata = (WimMetadata)Serializer.Deserialize(GetXmlMetadataStream(stream));
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidWimFileException("Could not read the metadata from the WIM file. Please, check it's a valid .WIM file", e);
            }

            Log.Verbose("Wim metadata deserialized correctly {@Metadata}", metadata);

            return(new XmlWindowsImageMetadata
            {
                Images = metadata.Images.Select(x => new DiskImageMetadata
                {
                    Architecture = WindowsImageMetadataReader.GetArchitecture(x.Windows.Arch),
                    Build = x.Windows.Version.Build,
                    DisplayName = x.Name,
                    Index = int.Parse(x.Index)
                }).ToList()
            });
        }
Beispiel #2
0
        protected override Stream GetXmlMetadataStream(Stream wim)
        {
            var outputstream = new MemoryStream();
            var wimwriter    = new BinaryWriter(outputstream);

            using (var wimsecstream = wim)
            {
                using (var wimsecreader = new BinaryReader(wimsecstream))
                {
                    var bytes = new byte[]
                    {
                        0x4D, 0x53, 0x57, 0x49, 0x4D
                    };

                    Log.Verbose("(WIM) Finding Magic Bytes...");

                    var start = WindowsImageMetadataReader.FindPosition(wimsecstream, bytes);

                    Log.Verbose("(WIM) Found Magic Bytes at " + start);

                    Log.Verbose("(WIM) Finding WIM XML Data...");

                    var endbytes = new byte[]
                    {
                        0x3C, 0x00, 0x2F, 0x00, 0x57, 0x00, 0x49, 0x00, 0x4D, 0x00, 0x3E, 0x00
                    };

                    wimsecstream.Seek(start + 72, SeekOrigin.Begin);
                    var buffer = new byte[24];
                    wimsecstream.Read(buffer, 0, 24);
                    var may = WindowsImageMetadataReader.ToInt64LittleEndian(buffer, 8);
                    wimsecstream.Seek(start, SeekOrigin.Begin);

                    Log.Verbose("(WIM) Found WIM XML Data at " + start + may + 2);

                    wimsecstream.Seek(start + may + 2, SeekOrigin.Begin);

                    for (var i = wimsecstream.Position; i < wimsecstream.Length - endbytes.Length; i++)
                    {
                        if (BitConverter.ToString(wimsecreader.ReadBytes(12)) == BitConverter.ToString(endbytes))
                        {
                            wimwriter.Write(endbytes);
                            break;
                        }

                        wimsecstream.Seek(-12, SeekOrigin.Current);
                        wimwriter.Write(wimsecreader.ReadBytes(1));
                    }
                }
            }

            outputstream.Seek(0, SeekOrigin.Begin);
            return(outputstream);
        }