Esempio n. 1
0
        public override byte[] GetDataBytes()
        {
            int dataLength = 0;

            dataLength += VarULongSize(DiskId);
            dataLength += Name.Length + 1;
            if (RecordRevision == 3)
            {
                dataLength += 20; // fixed length components
                dataLength += DiskGuid.ToString().Length + 1;
                dataLength += LastDeviceName.Length + 1;
            }
            else // RecordRevision == 4
            {
                dataLength += 53; // fixed length components
            }

            byte[] data   = new byte[dataLength];
            int    offset = 0x00;

            WriteCommonFields(data, ref offset);
            if (RecordRevision == 3)
            {
                WriteVarString(data, ref offset, DiskGuid.ToString());
            }
            else // RecordRevision == 4
            {
                BigEndianWriter.WriteGuid(data, ref offset, DiskGuid);
                BigEndianWriter.WriteGuid(data, ref offset, AltGuidRev4);
            }
            WriteVarString(data, ref offset, LastDeviceName);
            BigEndianWriter.WriteUInt32(data, ref offset, (uint)DiskFlags);
            BigEndianWriter.WriteUInt64(data, ref offset, CommitTransactionID);
            return(data);
        }
Esempio n. 2
0
        public byte[] GetBytes()
        {
            byte[] buffer = new byte[Length];
            ByteWriter.WriteAnsiString(buffer, 0x00, Cookie, 8);
            BigEndianWriter.WriteUInt32(buffer, 0x08, Features);
            BigEndianWriter.WriteUInt32(buffer, 0x0C, FileFormatVersion);
            BigEndianWriter.WriteUInt64(buffer, 0x10, DataOffset);
            BigEndianWriter.WriteUInt32(buffer, 0x18, TimeStamp);
            ByteWriter.WriteAnsiString(buffer, 0x1C, CreatorApplication, 4);
            BigEndianWriter.WriteUInt32(buffer, 0x20, CreatorVersion);
            BigEndianWriter.WriteUInt32(buffer, 0x24, CreatorHostOS);
            BigEndianWriter.WriteUInt64(buffer, 0x28, OriginalSize);
            BigEndianWriter.WriteUInt64(buffer, 0x30, CurrentSize);
            BigEndianWriter.WriteUInt32(buffer, 0x38, DiskGeometry);
            BigEndianWriter.WriteUInt32(buffer, 0x3C, (uint)DiskType);
            // We'll write the checksum later
            BigEndianWriter.WriteGuid(buffer, 0x44, UniqueId);
            ByteWriter.WriteByte(buffer, 0x54, SavedState);

            uint checksum = CalculateChecksum(buffer);

            BigEndianWriter.WriteUInt32(buffer, 0x40, checksum);

            return(buffer);
        }
Esempio n. 3
0
        public byte[] GetBytes()
        {
            byte[] buffer = new byte[Length];
            ByteWriter.WriteAnsiString(buffer, 0x00, Cookie, 8);
            BigEndianWriter.WriteUInt64(buffer, 0x08, DataOffset);
            BigEndianWriter.WriteUInt64(buffer, 0x10, TableOffset);
            BigEndianWriter.WriteUInt32(buffer, 0x18, HeaderVersion);
            BigEndianWriter.WriteUInt32(buffer, 0x1C, MaxTableEntries);
            BigEndianWriter.WriteUInt32(buffer, 0x20, BlockSize);
            // We'll write the checksum later
            BigEndianWriter.WriteGuid(buffer, 0x28, ParentUniqueID);
            BigEndianWriter.WriteUInt32(buffer, 0x38, ParentTimeStamp);
            BigEndianWriter.WriteUInt32(buffer, 0x3C, Reserved);
            ByteWriter.WriteUTF16String(buffer, 0x40, ParentUnicodeName, 256);
            ParentLocatorEntry1.WriteBytes(buffer, 0x240);
            ParentLocatorEntry2.WriteBytes(buffer, 0x258);
            ParentLocatorEntry3.WriteBytes(buffer, 0x270);
            ParentLocatorEntry4.WriteBytes(buffer, 0x288);
            ParentLocatorEntry5.WriteBytes(buffer, 0x2A0);
            ParentLocatorEntry6.WriteBytes(buffer, 0x2B8);
            ParentLocatorEntry7.WriteBytes(buffer, 0x2D0);
            ParentLocatorEntry8.WriteBytes(buffer, 0x2E8);

            uint checksum = VHDFooter.CalculateChecksum(buffer);

            BigEndianWriter.WriteUInt32(buffer, 0x24, checksum);

            return(buffer);
        }
Esempio n. 4
0
        public override byte[] GetDataBytes()
        {
            int dataLength = 8; // header fixed length components

            dataLength += VarULongSize(DiskGroupId);
            dataLength += Name.Length + 1;
            if (RecordRevision == 3)
            {
                dataLength += 12; // fixed length components
                dataLength += DiskGroupGuid.ToString().Length + 1;
            }
            else // RecordRevision == 4
            {
                dataLength += 44; // fixed length components
            }

            if (HasNumberOfCopiesFlag)
            {
                dataLength += VarUIntSize(NumberOfConfigCopies);
                dataLength += VarUIntSize(NumberOfLogCopies);
            }

            if (HasMinorsFlag)
            {
                dataLength += VarUIntSize(MinorsGreaterThanOrEqualTo);
            }

            byte[] data   = new byte[dataLength];
            int    offset = 0x00;

            WriteCommonFields(data, ref offset);
            if (RecordRevision == 3)
            {
                WriteVarString(data, ref offset, DiskGroupGuid.ToString());
            }
            else
            {
                BigEndianWriter.WriteGuid(data, ref offset, DiskGroupGuid);
                BigEndianWriter.WriteGuid(data, ref offset, DiskSetGuid);
            }
            offset += 4;
            BigEndianWriter.WriteUInt64(data, ref offset, CommitTransactionID);

            if (HasNumberOfCopiesFlag)
            {
                WriteVarUInt(data, ref offset, NumberOfConfigCopies);
                WriteVarUInt(data, ref offset, NumberOfLogCopies);
            }

            if (HasMinorsFlag)
            {
                WriteVarUInt(data, ref offset, MinorsGreaterThanOrEqualTo);
            }

            return(data);
        }
Esempio n. 5
0
        /// <summary>
        /// Private header may need to be padded with zeros in order to fill an entire sector
        /// </summary>
        public byte[] GetBytes()
        {
            byte[] buffer = new byte[Length];
            ByteWriter.WriteAnsiString(buffer, 0x00, Signature, 8);
            // we'll write the checksum later
            BigEndianWriter.WriteUInt16(buffer, 0x0C, MajorVersion);
            BigEndianWriter.WriteUInt16(buffer, 0x0E, MinorVersion);
            BigEndianWriter.WriteInt64(buffer, 0x10, LastUpdateDT.ToFileTimeUtc());
            BigEndianWriter.WriteUInt64(buffer, 0x18, UpdateSequenceNumber);
            BigEndianWriter.WriteUInt64(buffer, 0x20, PrimaryPrivateHeaderLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x28, SecondaryPrivateHeaderLBA);
            ByteWriter.WriteAnsiString(buffer, 0x30, DiskGuidString, 0x40);
            ByteWriter.WriteAnsiString(buffer, 0x70, HostGuidString, 0x40);
            ByteWriter.WriteAnsiString(buffer, 0xB0, DiskGroupGuidString, 0x40);
            ByteWriter.WriteAnsiString(buffer, 0xF0, DiskGroupName, 31);
            BigEndianWriter.WriteUInt32(buffer, 0x10F, BytesPerSector);
            BigEndianWriter.WriteUInt32(buffer, 0x113, (uint)Flags);

            BigEndianWriter.WriteUInt16(buffer, 0x117, PublicRegionSliceNumber);
            BigEndianWriter.WriteUInt16(buffer, 0x119, PrivateRegionSliceNumber);
            BigEndianWriter.WriteUInt64(buffer, 0x11B, PublicRegionStartLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x123, PublicRegionSizeLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x12B, PrivateRegionStartLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x133, PrivateRegionSizeLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x13B, PrimaryTocLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x143, SecondaryTocLBA);

            BigEndianWriter.WriteUInt32(buffer, 0x14B, NumberOfConfigs);
            BigEndianWriter.WriteUInt32(buffer, 0x14F, NumberOfLogs);
            BigEndianWriter.WriteUInt64(buffer, 0x153, ConfigSizeLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x15B, LogSizeLBA);

            BigEndianWriter.WriteUInt32(buffer, 0x163, DiskSignature);
            BigEndianWriter.WriteGuid(buffer, 0x167, DiskSetGuid);
            BigEndianWriter.WriteGuid(buffer, 0x177, DiskSetGuidRepeat);

            uint checksum = CalculateChecksum(buffer);

            BigEndianWriter.WriteUInt32(buffer, 0x08, checksum);

            return(buffer);
        }
Esempio n. 6
0
        public override byte[] GetDataBytes()
        {
            int dataLength = 64; // fixed length components

            dataLength += VarULongSize(VolumeId);
            dataLength += Name.Length + 1;
            dataLength += VolumeTypeString.Length + 1;
            dataLength += DisableDriverLetterAssignmentString.Length + 1;
            dataLength += VarUIntSize(VolumeNumber);
            dataLength += VarUIntSize(NumberOfComponents);
            dataLength += PaddedVarULongSize(SizeLBA);

            if (HasUnknownID1Flag)
            {
                dataLength += VarULongSize(UnknownID1);
            }

            if (HasUnknownID2Flag)
            {
                dataLength += VarULongSize(UnknownID2);
            }

            if (HasColumnSizeFlag)
            {
                dataLength += PaddedVarULongSize(ColumnSizeLBA);
            }

            if (HasMountHintFlag)
            {
                dataLength += MountHint.Length + 1;
            }

            byte[] data   = new byte[dataLength];
            int    offset = 0x00;

            WriteCommonFields(data, ref offset);
            WriteVarString(data, ref offset, VolumeTypeString);
            WriteVarString(data, ref offset, DisableDriverLetterAssignmentString);
            ByteWriter.WriteAnsiString(data, ref offset, StateString, 14);

            ByteWriter.WriteByte(data, ref offset, (byte)ReadPolicy);
            WriteVarUInt(data, ref offset, VolumeNumber);
            BigEndianWriter.WriteUInt32(data, ref offset, (uint)VolumeFlags);
            WriteVarUInt(data, ref offset, NumberOfComponents);
            BigEndianWriter.WriteUInt64(data, ref offset, CommitTransactionID);
            BigEndianWriter.WriteUInt64(data, ref offset, UnknownTransactionID);
            WritePaddedVarULong(data, ref offset, SizeLBA);
            offset += 4;
            ByteWriter.WriteByte(data, ref offset, (byte)PartitionType);
            BigEndianWriter.WriteGuid(data, ref offset, VolumeGuid);

            if (HasUnknownID1Flag)
            {
                WriteVarULong(data, ref offset, UnknownID1);
            }

            if (HasUnknownID2Flag)
            {
                WriteVarULong(data, ref offset, UnknownID2);
            }

            if (HasColumnSizeFlag)
            {
                WritePaddedVarULong(data, ref offset, ColumnSizeLBA);
            }

            if (HasMountHintFlag)
            {
                WriteVarString(data, ref offset, MountHint);
            }

            return(data);
        }