Beispiel #1
0
        /// <summary>
        /// Reads a stream into a VHD header
        /// </summary>
        /// <param name="S">Stream</param>
        private void FromStream(Stream S)
        {
            Encoding E = Encoding.Default;

            //The comments indicate the offset from the header start
            using (var BR = new BinaryReader(S, E, true))
            {
                //0
                Cookie = E.GetString(BR.ReadBytes(8));
                //8
                Features = (VhdFeatures)Tools.ToNetwork(BR.ReadUInt32());
                //12
                FileFormatVersion = new Version(Tools.ToNetwork(BR.ReadUInt16()), Tools.ToNetwork(BR.ReadUInt16()));
                //16
                DataOffset = Tools.ToNetwork(BR.ReadUInt64());
                //24
                TimeStamp = VHD.FromDiskTimestamp(Tools.ToNetwork(BR.ReadInt32()));
                //28
                CreatorApplication = E.GetString(BR.ReadBytes(4));
                //32
                CreatorVersion = new Version(Tools.ToNetwork(BR.ReadUInt16()), Tools.ToNetwork(BR.ReadUInt16()));
                //36
                CreatorHostOS = E.GetString(BR.ReadBytes(4));
                //40
                OriginalSize = Tools.ToNetwork(BR.ReadUInt64());
                //48
                CurrentSize = Tools.ToNetwork(BR.ReadUInt64());
                //56
                DiskGeometry = new CHS(
                    Tools.ToNetwork(BR.ReadUInt16()),
                    BR.ReadByte(),
                    BR.ReadByte()
                    );
                //60
                DiskType = (VhdType)Tools.ToNetwork(BR.ReadUInt32());
                //64
                Checksum = Tools.ToNetwork(BR.ReadInt32());
                //68
                DiskId = new Guid(BR.ReadBytes(16));
                //84
                SavedState = BR.ReadByte() == 1;
                //85
                Reserved = BR.ReadBytes(RESERVED_FIELD_SIZE);
                //512
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reads a stream into a VHD header
        /// </summary>
        /// <param name="S">Stream</param>
        private void FromStream(Stream S)
        {
            Encoding E = Encoding.Default;

            //The comments indicate the offset from the header start
            using (var BR = new BinaryReader(S, E, true))
            {
                //0
                Cookie = E.GetString(BR.ReadBytes(8));
                //8
                DataOffset = Tools.ToNetwork(BR.ReadUInt64());
                //16
                TableOffset = Tools.ToNetwork(BR.ReadUInt64());
                //24
                HeaderVersion = new Version(Tools.ToNetwork(BR.ReadUInt16()), Tools.ToNetwork(BR.ReadUInt16()));
                //28
                MaxTableEntries = Tools.ToNetwork(BR.ReadUInt32());
                //32
                BlockSize = Tools.ToNetwork(BR.ReadUInt32());
                //36
                Checksum = Tools.ToNetwork(BR.ReadInt32());
                //40
                ParentUniqueId = new Guid(BR.ReadBytes(16));
                //56
                ParentTimeStamp = VHD.FromDiskTimestamp(Tools.ToNetwork(BR.ReadUInt32()));
                //60
                Reserved1 = BR.ReadBytes(RESERVED1_FIELD_SIZE);
                //64
                ParentUnicodeName = Encoding.Unicode.GetString(BR.ReadBytes(UNICODE_PARENT_LENGTH));
                //576
                ParentLocatorEntries = Enumerable
                                       .Range(0, LOCATOR_ENTRY_COUNT)
                                       .Select(m => new LocatorEntry(BR.ReadBytes(LocatorEntry.ENTRY_SIZE)))
                                       .ToArray();
                //768
                Reserved2 = BR.ReadBytes(RESERVED2_FIELD_SIZE);
                //1024
            }
        }