示例#1
0
        public void VhdFooter_Checksum()
        {
            HardDiskFooter target        = new HardDiskFooter();
            var            firstChecksum = BitConverter.ToString(target.Checksum);

            target.BeginUpdate();
            target.UniqueId = Guid.NewGuid();
            Assert.AreEqual(firstChecksum, BitConverter.ToString(target.Checksum));
            Assert.AreEqual(false, target.IsChecksumCorrect);
            target.EndUpdate();
            Assert.AreNotEqual(firstChecksum, BitConverter.ToString(target.Checksum));
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
        private bool CreateVhd()
        {
            using (var stream = new FileStream(this.FileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 1, FileOptions.WriteThrough)) {
                ReFS.RemoveIntegrityStream(stream.SafeFileHandle);

                var footer = new HardDiskFooter();
                footer.BeginUpdate();
                footer.CreatorApplication = VhdCreatorApplication.JosipMedvedVhdAttach;
                footer.CreatorVersion     = Medo.Reflection.EntryAssembly.Version;
                footer.SetSize((UInt64)this.SizeInBytes);
                footer.OriginalSize = footer.CurrentSize;
                footer.DiskType     = VhdDiskType.FixedHardDisk;

                footer.EndUpdate();

                var    lastReport = DateTime.UtcNow;
                byte[] buffer     = new byte[Settings.WriteBufferSize];
                ulong  remaining  = footer.CurrentSize;
                while (remaining > 0)
                {
                    if (bgw.CancellationPending)
                    {
                        stream.Dispose();
                        File.Delete(this.FileName);
                        return(false);
                    }
                    ulong count = (ulong)buffer.Length;
                    if ((ulong)count > remaining)
                    {
                        count = remaining;
                    }
                    stream.Write(buffer, 0, (int)count);
                    remaining -= count;
                    if (lastReport.AddSeconds(1) < DateTime.UtcNow)
                    {
                        bgw.ReportProgress(100 - (int)(remaining * 100 / footer.CurrentSize));
                        lastReport = DateTime.UtcNow;
                    }
                }
                buffer = footer.Bytes;
                stream.Write(buffer, 0, buffer.Length);
            }
            return(true);
        }
示例#3
0
        public void VhdFooter_CreateEmpty()
        {
            HardDiskFooter target = new HardDiskFooter();

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.NoFeaturesEnabled, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual((UInt64)0xFFFFFFFFFFFFFFFF, target.DataOffset);
            Assert.AreEqual(VhdCreatorApplication.None, target.CreatorApplication);
            Assert.AreEqual(new Version(0, 0), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)0, target.OriginalSize);
            Assert.AreEqual((UInt64)0, target.CurrentSize);
            Assert.AreEqual(0, target.DiskGeometryCylinders);
            Assert.AreEqual(0, target.DiskGeometryHeads);
            Assert.AreEqual(0, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.None, target.DiskType);
            Assert.AreNotEqual(Guid.Empty, target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
示例#4
0
        public void VhdFooter_Create6()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)512;
            target.TimeStamp          = new DateTime(2012, 1, 5, 16, 23, 53, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)1022999998464);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.DynamicHardDisk;
            target.UniqueId     = new Guid("5077d87d-9bfa-42a6-9033-c39796a69ae5");
            target.SavedState   = false;
            Assert.AreEqual(65535, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-16-98-8B-19-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-EE-2F-8D-30-00-00-00-00-EE-2F-8D-30-00-FF-FF-10-FF-00-00-00-03-FF-FF-E8-44-7D-D8-77-50-FA-9B-A6-42-90-33-C3-97-96-A6-9A-E5-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
示例#5
0
        public void VhdFooter_Create4()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)512;
            target.TimeStamp          = new DateTime(2011, 12, 14, 17, 14, 30, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.OracleVirtualBox;
            target.CreatorVersion     = new Version(4, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)21474836480);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.DynamicHardDisk;
            target.UniqueId     = new Guid("8542aad1-1b60-44fe-8805-147ad188b510");
            target.SavedState   = false;
            Assert.AreEqual(41610, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(63, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-16-7B-95-F6-76-62-6F-78-00-04-00-01-57-69-32-6B-00-00-00-05-00-00-00-00-00-00-00-05-00-00-00-00-A2-8A-10-3F-00-00-00-03-FF-FF-EE-A0-D1-AA-42-85-60-1B-FE-44-88-05-14-7A-D1-88-B5-10-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
示例#6
0
        public void VhdFooter_Create3()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = 0xFFFFFFFFFFFFFFFF;
            target.TimeStamp          = new DateTime(2011, 12, 6, 14, 14, 48, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)107374182400);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.FixedHardDisk;
            target.UniqueId     = new Guid("b7afc1bd-aee1-47ac-b7f2-8bc5269f0af2");
            target.SavedState   = false;
            Assert.AreEqual(51400, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-16-70-DF-D8-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-19-00-00-00-00-00-00-00-19-00-00-00-00-C8-C8-10-FF-00-00-00-02-FF-FF-E2-A5-BD-C1-AF-B7-E1-AE-AC-47-B7-F2-8B-C5-26-9F-0A-F2-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
示例#7
0
        public void VhdFooter_Create2()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)0xFFFFFFFFFFFFFFFF;
            target.TimeStamp          = new DateTime(2011, 5, 29, 2, 41, 12, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)34359738368);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.FixedHardDisk;
            target.UniqueId     = new Guid("a9fda548-8174-4d23-b389-e941d2337ef7");
            target.SavedState   = false;
            Assert.AreEqual(16448, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-15-74-6E-C8-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-08-00-00-00-00-00-00-00-08-00-00-00-00-40-40-10-FF-00-00-00-02-FF-FF-E5-9D-48-A5-FD-A9-74-81-23-4D-B3-89-E9-41-D2-33-7E-F7-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
示例#8
0
        public void VhdFooter_Create1()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)0xFFFFFFFFFFFFFFFF;
            target.TimeStamp          = new DateTime(2011, 8, 16, 5, 31, 12, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftWindows;
            target.CreatorVersion     = new Version(6, 1);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)3221225472);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.FixedHardDisk;
            target.UniqueId     = new Guid("5ea9e33a-1ddd-49a3-bd6d-3cd7905ab670");
            target.SavedState   = false;
            Assert.AreEqual(6241, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(63, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-15-DC-BD-20-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-00-C0-00-00-00-00-00-00-00-C0-00-00-00-18-61-10-3F-00-00-00-02-FF-FF-E5-66-3A-E3-A9-5E-DD-1D-A3-49-BD-6D-3C-D7-90-5A-B6-70-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
示例#9
0
        public void VhdFooter_Create5()
        {
            HardDiskFooter target = new HardDiskFooter();

            target.Cookie             = "conectix";
            target.Features           = VhdFeature.Reserved;
            target.FileFormatVersion  = new Version(1, 0);
            target.DataOffset         = (UInt64)512;
            target.TimeStamp          = new DateTime(2011, 2, 2, 10, 53, 33, DateTimeKind.Utc);
            target.CreatorApplication = VhdCreatorApplication.MicrosoftSysinternalsDisk2Vhd;
            target.CreatorVersion     = new Version(1, 0);
            target.CreatorHostOs      = VhdCreatorHostOs.Windows;
            target.SetSize((UInt64)160041885696);
            target.OriginalSize = target.CurrentSize;
            target.DiskType     = VhdDiskType.DynamicHardDisk;
            target.UniqueId     = new Guid("53cd1f52-a439-4be5-92f2-889948b7bc27");
            target.SavedState   = false;
            Assert.AreEqual(65535, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(target.CurrentSize, target.OriginalSize);
            Assert.AreEqual("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-14-DB-F4-2D-64-32-76-00-00-01-00-00-57-69-32-6B-00-00-00-25-43-3D-60-00-00-00-00-25-43-3D-60-00-FF-FF-10-FF-00-00-00-03-FF-FF-EA-E4-52-1F-CD-53-39-A4-E5-4B-92-F2-88-99-48-B7-BC-27-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString(target.Bytes));
        }
示例#10
0
        public void VhdFooter_Parse4()
        {
            byte[]         bytes  = GetBytesFromHex("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-16-7B-95-F6-76-62-6F-78-00-04-00-01-57-69-32-6B-00-00-00-05-00-00-00-00-00-00-00-05-00-00-00-00-A2-8A-10-3F-00-00-00-03-FF-FF-EE-A0-D1-AA-42-85-60-1B-FE-44-88-05-14-7A-D1-88-B5-10-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00");
            HardDiskFooter target = new HardDiskFooter(bytes);

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.Reserved, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual((UInt64)512, target.DataOffset);
            Assert.AreEqual(new DateTime(2011, 12, 14, 17, 14, 30, DateTimeKind.Utc), target.TimeStamp);
            Assert.AreEqual(VhdCreatorApplication.OracleVirtualBox, target.CreatorApplication);
            Assert.AreEqual(new Version(4, 1), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)21474836480, target.OriginalSize);
            Assert.AreEqual((UInt64)21474836480, target.CurrentSize);
            Assert.AreEqual(41610, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(63, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.DynamicHardDisk, target.DiskType);
            Assert.AreEqual("FF-FF-EE-A0", BitConverter.ToString(target.Checksum));
            Assert.AreEqual(new Guid("8542aad1-1b60-44fe-8805-147ad188b510"), target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
示例#11
0
        public void VhdFooter_Parse3()
        {
            byte[]         bytes  = GetBytesFromHex("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-16-70-DF-D8-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-19-00-00-00-00-00-00-00-19-00-00-00-00-C8-C8-10-FF-00-00-00-02-FF-FF-E2-A5-BD-C1-AF-B7-E1-AE-AC-47-B7-F2-8B-C5-26-9F-0A-F2-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00");
            HardDiskFooter target = new HardDiskFooter(bytes);

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.Reserved, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual(0xFFFFFFFFFFFFFFFF, target.DataOffset);
            Assert.AreEqual(new DateTime(2011, 12, 6, 14, 14, 48, DateTimeKind.Utc), target.TimeStamp);
            Assert.AreEqual(VhdCreatorApplication.MicrosoftWindows, target.CreatorApplication);
            Assert.AreEqual(new Version(6, 1), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)107374182400, target.OriginalSize);
            Assert.AreEqual((UInt64)107374182400, target.CurrentSize);
            Assert.AreEqual(51400, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.FixedHardDisk, target.DiskType);
            Assert.AreEqual("FF-FF-E2-A5", BitConverter.ToString(target.Checksum));
            Assert.AreEqual(new Guid("b7afc1bd-aee1-47ac-b7f2-8bc5269f0af2"), target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
示例#12
0
        public void VhdFooter_Parse2()
        {
            byte[]         bytes  = GetBytesFromHex("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-15-74-6E-C8-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-08-00-00-00-00-00-00-00-08-00-00-00-00-40-40-10-FF-00-00-00-02-FF-FF-E5-9D-48-A5-FD-A9-74-81-23-4D-B3-89-E9-41-D2-33-7E-F7-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00");
            HardDiskFooter target = new HardDiskFooter(bytes);

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.Reserved, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual((UInt64)0xFFFFFFFFFFFFFFFF, target.DataOffset);
            Assert.AreEqual(new DateTime(2011, 5, 29, 2, 41, 12, DateTimeKind.Utc), target.TimeStamp);
            Assert.AreEqual(VhdCreatorApplication.MicrosoftWindows, target.CreatorApplication);
            Assert.AreEqual(new Version(6, 1), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)34359738368, target.OriginalSize);
            Assert.AreEqual((UInt64)34359738368, target.CurrentSize);
            Assert.AreEqual(16448, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.FixedHardDisk, target.DiskType);
            Assert.AreEqual("FF-FF-E5-9D", BitConverter.ToString(target.Checksum));
            Assert.AreEqual(new Guid("a9fda548-8174-4d23-b389-e941d2337ef7"), target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
示例#13
0
        public void VhdFooter_Parse1()
        {
            byte[]         bytes  = GetBytesFromHex("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-FF-FF-FF-FF-FF-FF-FF-FF-15-DC-BD-20-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-00-C0-00-00-00-00-00-00-00-C0-00-00-00-18-61-10-3F-00-00-00-02-FF-FF-E5-66-3A-E3-A9-5E-DD-1D-A3-49-BD-6D-3C-D7-90-5A-B6-70-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00");
            HardDiskFooter target = new HardDiskFooter(bytes);

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.Reserved, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual((UInt64)0xFFFFFFFFFFFFFFFF, target.DataOffset);
            Assert.AreEqual(new DateTime(2011, 8, 16, 5, 31, 12, DateTimeKind.Utc), target.TimeStamp);
            Assert.AreEqual(VhdCreatorApplication.MicrosoftWindows, target.CreatorApplication);
            Assert.AreEqual(new Version(6, 1), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)3221225472, target.OriginalSize);
            Assert.AreEqual((UInt64)3221225472, target.CurrentSize);
            Assert.AreEqual(6241, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(63, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.FixedHardDisk, target.DiskType);
            Assert.AreEqual("FF-FF-E5-66", BitConverter.ToString(target.Checksum));
            Assert.AreEqual(new Guid("5ea9e33a-1ddd-49a3-bd6d-3cd7905ab670"), target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
示例#14
0
        public void VhdFooter_ParseInvalid1()
        {
            byte[]         bytes  = GetBytesFromHex("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-16-98-8B-19-77-69-6E-20-00-06-00-01-57-69-32-6B-00-00-00-EE-2F-8D-30-00-00-00-00-EE-2F-8D-30-00-FF-FF-10-FF-00-00-00-03-FF-FF-E8-44-7D-D8-77-50-FA-9B-A6-42-90-33-C3-97-96-A6-9A-E5-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-01");
            HardDiskFooter target = new HardDiskFooter(bytes);

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.Reserved, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual((UInt64)512, target.DataOffset);
            Assert.AreEqual(new DateTime(2012, 1, 5, 16, 23, 53, DateTimeKind.Utc), target.TimeStamp);
            Assert.AreEqual(VhdCreatorApplication.MicrosoftWindows, target.CreatorApplication);
            Assert.AreEqual(new Version(6, 1), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)1022999998464, target.OriginalSize);
            Assert.AreEqual((UInt64)1022999998464, target.CurrentSize);
            Assert.AreEqual(65535, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.DynamicHardDisk, target.DiskType);
            Assert.AreEqual("FF-FF-E8-44", BitConverter.ToString(target.Checksum));
            Assert.AreEqual(new Guid("5077d87d-9bfa-42a6-9033-c39796a69ae5"), target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(false, target.IsChecksumCorrect);
        }
示例#15
0
        public void VhdFooter_Parse5()
        {
            byte[]         bytes  = GetBytesFromHex("63-6F-6E-65-63-74-69-78-00-00-00-02-00-01-00-00-00-00-00-00-00-00-02-00-14-DB-F4-2D-64-32-76-00-00-01-00-00-57-69-32-6B-00-00-00-25-43-3D-60-00-00-00-00-25-43-3D-60-00-FF-FF-10-FF-00-00-00-03-FF-FF-EA-E4-52-1F-CD-53-39-A4-E5-4B-92-F2-88-99-48-B7-BC-27-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00");
            HardDiskFooter target = new HardDiskFooter(bytes);

            Assert.AreEqual("conectix", target.Cookie);
            Assert.AreEqual(VhdFeature.Reserved, target.Features);
            Assert.AreEqual(new Version(1, 0), target.FileFormatVersion);
            Assert.AreEqual((UInt64)512, target.DataOffset);
            Assert.AreEqual(new DateTime(2011, 2, 2, 10, 53, 33, DateTimeKind.Utc), target.TimeStamp);
            Assert.AreEqual(VhdCreatorApplication.MicrosoftSysinternalsDisk2Vhd, target.CreatorApplication);
            Assert.AreEqual(new Version(1, 0), target.CreatorVersion);
            Assert.AreEqual(VhdCreatorHostOs.Windows, target.CreatorHostOs);
            Assert.AreEqual((UInt64)160041885696, target.OriginalSize);
            Assert.AreEqual((UInt64)160041885696, target.CurrentSize);
            Assert.AreEqual(65535, target.DiskGeometryCylinders);
            Assert.AreEqual(16, target.DiskGeometryHeads);
            Assert.AreEqual(255, target.DiskGeometrySectors);
            Assert.AreEqual(VhdDiskType.DynamicHardDisk, target.DiskType);
            Assert.AreEqual("FF-FF-EA-E4", BitConverter.ToString(target.Checksum));
            Assert.AreEqual(new Guid("53cd1f52-a439-4be5-92f2-889948b7bc27"), target.UniqueId);
            Assert.AreEqual(false, target.SavedState);
            Assert.AreEqual(true, target.IsChecksumCorrect);
        }
示例#16
0
文件: Write.cs 项目: morefun0302/Aaru
        public bool Close()
        {
            if (!IsWriting)
            {
                ErrorMessage = "Image is not opened for writing";

                return(false);
            }

            Version thisVersion = GetType().Assembly.GetName().Version;

            if (_imageInfo.Cylinders == 0)
            {
                _imageInfo.Cylinders       = (uint)(_imageInfo.Sectors / 16 / 63);
                _imageInfo.Heads           = 16;
                _imageInfo.SectorsPerTrack = 63;

                while (_imageInfo.Cylinders == 0)
                {
                    _imageInfo.Heads--;

                    if (_imageInfo.Heads == 0)
                    {
                        _imageInfo.SectorsPerTrack--;
                        _imageInfo.Heads = 16;
                    }

                    _imageInfo.Cylinders = (uint)(_imageInfo.Sectors / _imageInfo.Heads / _imageInfo.SectorsPerTrack);

                    if (_imageInfo.Cylinders == 0 &&
                        _imageInfo.Heads == 0 &&
                        _imageInfo.SectorsPerTrack == 0)
                    {
                        break;
                    }
                }
            }

            var footer = new HardDiskFooter
            {
                Cookie             = IMAGE_COOKIE,
                Features           = FEATURES_RESERVED,
                Version            = VERSION1,
                Timestamp          = (uint)(DateTime.Now - new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds,
                CreatorApplication = CREATOR_AARU,
                CreatorVersion     = (uint)(((thisVersion.Major & 0xFF) << 24) + ((thisVersion.Minor & 0xFF) << 16) +
                                            ((thisVersion.Build & 0xFF) << 8) + (thisVersion.Revision & 0xFF)),
                CreatorHostOs = DetectOS.GetRealPlatformID() == PlatformID.MacOSX ? CREATOR_MACINTOSH : CREATOR_WINDOWS,
                DiskType      = TYPE_FIXED,
                UniqueId      = Guid.NewGuid(),
                DiskGeometry  = ((_imageInfo.Cylinders & 0xFFFF) << 16) + ((_imageInfo.Heads & 0xFF) << 8) +
                                (_imageInfo.SectorsPerTrack & 0xFF),
                OriginalSize = _imageInfo.Sectors * 512,
                CurrentSize  = _imageInfo.Sectors * 512
            };

            footer.Offset = footer.DiskType == TYPE_FIXED ? ulong.MaxValue : 512;

            byte[] footerBytes = new byte[512];
            Array.Copy(BigEndianBitConverter.GetBytes(footer.Cookie), 0, footerBytes, 0x00, 8);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.Features), 0, footerBytes, 0x08, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.Version), 0, footerBytes, 0x0C, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.Offset), 0, footerBytes, 0x10, 8);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.Timestamp), 0, footerBytes, 0x18, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.CreatorApplication), 0, footerBytes, 0x1C, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.CreatorVersion), 0, footerBytes, 0x20, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.CreatorHostOs), 0, footerBytes, 0x24, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.OriginalSize), 0, footerBytes, 0x28, 8);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.CurrentSize), 0, footerBytes, 0x30, 8);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.DiskGeometry), 0, footerBytes, 0x38, 4);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.DiskType), 0, footerBytes, 0x3C, 4);
            Array.Copy(footer.UniqueId.ToByteArray(), 0, footerBytes, 0x44, 4);

            footer.Checksum = VhdChecksum(footerBytes);
            Array.Copy(BigEndianBitConverter.GetBytes(footer.Checksum), 0, footerBytes, 0x40, 4);

            _writingStream.Seek((long)(footer.DiskType == TYPE_FIXED ? footer.OriginalSize : 0), SeekOrigin.Begin);
            _writingStream.Write(footerBytes, 0, 512);

            _writingStream.Flush();
            _writingStream.Close();

            IsWriting    = false;
            ErrorMessage = "";

            return(true);
        }
示例#17
0
        public bool Open(IFilter imageFilter)
        {
            Stream imageStream = imageFilter.GetDataForkStream();

            byte[] header = new byte[512];
            byte[] footer;

            imageStream.Seek(0, SeekOrigin.Begin);
            imageStream.Read(header, 0, 512);

            if (imageStream.Length % 2 == 0)
            {
                footer = new byte[512];
                imageStream.Seek(-512, SeekOrigin.End);
                imageStream.Read(footer, 0, 512);
            }
            else
            {
                footer = new byte[511];
                imageStream.Seek(-511, SeekOrigin.End);
                imageStream.Read(footer, 0, 511);
            }

            BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;

            uint  headerChecksum = BigEndianBitConverter.ToUInt32(header, 0x40);
            uint  footerChecksum = BigEndianBitConverter.ToUInt32(footer, 0x40);
            ulong headerCookie   = BigEndianBitConverter.ToUInt64(header, 0);
            ulong footerCookie   = BigEndianBitConverter.ToUInt64(footer, 0);

            header[0x40] = 0;
            header[0x41] = 0;
            header[0x42] = 0;
            header[0x43] = 0;
            footer[0x40] = 0;
            footer[0x41] = 0;
            footer[0x42] = 0;
            footer[0x43] = 0;

            uint headerCalculatedChecksum = VhdChecksum(header);
            uint footerCalculatedChecksum = VhdChecksum(footer);

            DicConsole.DebugWriteLine("VirtualPC plugin", "Header checksum = 0x{0:X8}, calculated = 0x{1:X8}",
                                      headerChecksum, headerCalculatedChecksum);
            DicConsole.DebugWriteLine("VirtualPC plugin", "Header checksum = 0x{0:X8}, calculated = 0x{1:X8}",
                                      footerChecksum, footerCalculatedChecksum);

            byte[] usableHeader;
            uint   usableChecksum;

            if (headerCookie == IMAGE_COOKIE && headerChecksum == headerCalculatedChecksum)
            {
                usableHeader   = header;
                usableChecksum = headerChecksum;
            }
            else if (footerCookie == IMAGE_COOKIE && footerChecksum == footerCalculatedChecksum)
            {
                usableHeader   = footer;
                usableChecksum = footerChecksum;
            }
            else
            {
                throw new
                      ImageNotSupportedException("(VirtualPC plugin): Both header and footer are corrupt, image cannot be opened.");
            }

            thisFooter = new HardDiskFooter
            {
                Cookie             = BigEndianBitConverter.ToUInt64(usableHeader, 0x00),
                Features           = BigEndianBitConverter.ToUInt32(usableHeader, 0x08),
                Version            = BigEndianBitConverter.ToUInt32(usableHeader, 0x0C),
                Offset             = BigEndianBitConverter.ToUInt64(usableHeader, 0x10),
                Timestamp          = BigEndianBitConverter.ToUInt32(usableHeader, 0x18),
                CreatorApplication = BigEndianBitConverter.ToUInt32(usableHeader, 0x1C),
                CreatorVersion     = BigEndianBitConverter.ToUInt32(usableHeader, 0x20),
                CreatorHostOs      = BigEndianBitConverter.ToUInt32(usableHeader, 0x24),
                OriginalSize       = BigEndianBitConverter.ToUInt64(usableHeader, 0x28),
                CurrentSize        = BigEndianBitConverter.ToUInt64(usableHeader, 0x30),
                DiskGeometry       = BigEndianBitConverter.ToUInt32(usableHeader, 0x38),
                DiskType           = BigEndianBitConverter.ToUInt32(usableHeader, 0x3C),
                Checksum           = usableChecksum,
                UniqueId           = BigEndianBitConverter.ToGuid(usableHeader, 0x44),
                SavedState         = usableHeader[0x54],
                Reserved           = new byte[usableHeader.Length - 0x55]
            };
            Array.Copy(usableHeader, 0x55, thisFooter.Reserved, 0, usableHeader.Length - 0x55);

            thisDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            thisDateTime = thisDateTime.AddSeconds(thisFooter.Timestamp);

            Sha1Context sha1Ctx = new Sha1Context();

            sha1Ctx.Update(thisFooter.Reserved);

            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.cookie = 0x{0:X8}", thisFooter.Cookie);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.features = 0x{0:X8}", thisFooter.Features);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.version = 0x{0:X8}", thisFooter.Version);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.offset = {0}", thisFooter.Offset);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.timestamp = 0x{0:X8} ({1})", thisFooter.Timestamp,
                                      thisDateTime);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.creatorApplication = 0x{0:X8} (\"{1}\")",
                                      thisFooter.CreatorApplication,
                                      Encoding.ASCII.GetString(BigEndianBitConverter.GetBytes(thisFooter
                                                                                              .CreatorApplication)));
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.creatorVersion = 0x{0:X8}",
                                      thisFooter.CreatorVersion);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.creatorHostOS = 0x{0:X8} (\"{1}\")",
                                      thisFooter.CreatorHostOs,
                                      Encoding.ASCII.GetString(BigEndianBitConverter
                                                               .GetBytes(thisFooter.CreatorHostOs)));
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.originalSize = {0}", thisFooter.OriginalSize);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.currentSize = {0}", thisFooter.CurrentSize);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.diskGeometry = 0x{0:X8} (C/H/S: {1}/{2}/{3})",
                                      thisFooter.DiskGeometry, (thisFooter.DiskGeometry & 0xFFFF0000) >> 16,
                                      (thisFooter.DiskGeometry & 0xFF00) >> 8,
                                      thisFooter.DiskGeometry & 0xFF);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.diskType = 0x{0:X8}", thisFooter.DiskType);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.checksum = 0x{0:X8}", thisFooter.Checksum);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.uniqueId = {0}", thisFooter.UniqueId);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.savedState = 0x{0:X2}", thisFooter.SavedState);
            DicConsole.DebugWriteLine("VirtualPC plugin", "footer.reserved's SHA1 = 0x{0}", sha1Ctx.End());

            if (thisFooter.Version == VERSION1)
            {
                imageInfo.Version = "1.0";
            }
            else
            {
                throw new
                      ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {thisFooter.DiskType} found. Please submit a bug with an example image.");
            }

            switch (thisFooter.CreatorApplication)
            {
            case CREATOR_QEMU:
            {
                imageInfo.Application = "QEMU";
                // QEMU always set same version
                imageInfo.ApplicationVersion = "Unknown";

                break;
            }

            case CREATOR_VIRTUAL_BOX:
            {
                imageInfo.ApplicationVersion =
                    $"{(thisFooter.CreatorVersion & 0xFFFF0000) >> 16}.{thisFooter.CreatorVersion & 0x0000FFFF:D2}";
                switch (thisFooter.CreatorHostOs)
                {
                case CREATOR_MACINTOSH:
                case CREATOR_MACINTOSH_OLD:
                    imageInfo.Application = "VirtualBox for Mac";
                    break;

                case CREATOR_WINDOWS:
                    // VirtualBox uses Windows creator for any other OS
                    imageInfo.Application = "VirtualBox";
                    break;

                default:
                    imageInfo.Application =
                        $"VirtualBox for unknown OS \"{Encoding.ASCII.GetString(BigEndianBitConverter.GetBytes(thisFooter.CreatorHostOs))}\"";
                    break;
                }

                break;
            }

            case CREATOR_VIRTUAL_SERVER:
            {
                imageInfo.Application = "Microsoft Virtual Server";
                switch (thisFooter.CreatorVersion)
                {
                case VERSION_VIRTUAL_SERVER2004:
                    imageInfo.ApplicationVersion = "2004";
                    break;

                default:
                    imageInfo.ApplicationVersion = $"Unknown version 0x{thisFooter.CreatorVersion:X8}";
                    break;
                }

                break;
            }

            case CREATOR_VIRTUAL_PC:
            {
                switch (thisFooter.CreatorHostOs)
                {
                case CREATOR_MACINTOSH:
                case CREATOR_MACINTOSH_OLD:
                    switch (thisFooter.CreatorVersion)
                    {
                    case VERSION_VIRTUAL_PC_MAC:
                        imageInfo.Application        = "Connectix Virtual PC";
                        imageInfo.ApplicationVersion = "5, 6 or 7";
                        break;

                    default:
                        imageInfo.ApplicationVersion = $"Unknown version 0x{thisFooter.CreatorVersion:X8}";
                        break;
                    }

                    break;

                case CREATOR_WINDOWS:
                    switch (thisFooter.CreatorVersion)
                    {
                    case VERSION_VIRTUAL_PC_MAC:
                        imageInfo.Application        = "Connectix Virtual PC";
                        imageInfo.ApplicationVersion = "5, 6 or 7";
                        break;

                    case VERSION_VIRTUAL_PC2004:
                        imageInfo.Application        = "Microsoft Virtual PC";
                        imageInfo.ApplicationVersion = "2004";
                        break;

                    case VERSION_VIRTUAL_PC2007:
                        imageInfo.Application        = "Microsoft Virtual PC";
                        imageInfo.ApplicationVersion = "2007";
                        break;

                    default:
                        imageInfo.ApplicationVersion = $"Unknown version 0x{thisFooter.CreatorVersion:X8}";
                        break;
                    }

                    break;

                default:
                    imageInfo.Application =
                        $"Virtual PC for unknown OS \"{Encoding.ASCII.GetString(BigEndianBitConverter.GetBytes(thisFooter.CreatorHostOs))}\"";
                    imageInfo.ApplicationVersion = $"Unknown version 0x{thisFooter.CreatorVersion:X8}";
                    break;
                }

                break;
            }

            case CREATOR_DISCIMAGECHEF:
            {
                imageInfo.Application        = "DiscImageChef";
                imageInfo.ApplicationVersion =
                    $"{(thisFooter.CreatorVersion & 0xFF000000) >> 24}.{(thisFooter.CreatorVersion & 0xFF0000) >> 16}.{(thisFooter.CreatorVersion & 0xFF00) >> 8}.{thisFooter.CreatorVersion & 0xFF}";
            }
            break;

            default:
            {
                imageInfo.Application =
                    $"Unknown application \"{Encoding.ASCII.GetString(BigEndianBitConverter.GetBytes(thisFooter.CreatorHostOs))}\"";
                imageInfo.ApplicationVersion = $"Unknown version 0x{thisFooter.CreatorVersion:X8}";
                break;
            }
            }

            thisFilter           = imageFilter;
            imageInfo.ImageSize  = thisFooter.CurrentSize;
            imageInfo.Sectors    = thisFooter.CurrentSize / 512;
            imageInfo.SectorSize = 512;

            imageInfo.CreationTime         = imageFilter.GetCreationTime();
            imageInfo.LastModificationTime = thisDateTime;
            imageInfo.MediaTitle           = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());

            imageInfo.Cylinders       = (thisFooter.DiskGeometry & 0xFFFF0000) >> 16;
            imageInfo.Heads           = (thisFooter.DiskGeometry & 0xFF00) >> 8;
            imageInfo.SectorsPerTrack = thisFooter.DiskGeometry & 0xFF;

            if (thisFooter.DiskType == TYPE_DYNAMIC || thisFooter.DiskType == TYPE_DIFFERENCING)
            {
                imageStream.Seek((long)thisFooter.Offset, SeekOrigin.Begin);
                byte[] dynamicBytes = new byte[1024];
                imageStream.Read(dynamicBytes, 0, 1024);

                uint dynamicChecksum = BigEndianBitConverter.ToUInt32(dynamicBytes, 0x24);

                dynamicBytes[0x24] = 0;
                dynamicBytes[0x25] = 0;
                dynamicBytes[0x26] = 0;
                dynamicBytes[0x27] = 0;

                uint dynamicChecksumCalculated = VhdChecksum(dynamicBytes);

                DicConsole.DebugWriteLine("VirtualPC plugin",
                                          "Dynamic header checksum = 0x{0:X8}, calculated = 0x{1:X8}", dynamicChecksum,
                                          dynamicChecksumCalculated);

                if (dynamicChecksum != dynamicChecksumCalculated)
                {
                    throw new
                          ImageNotSupportedException("(VirtualPC plugin): Both header and footer are corrupt, image cannot be opened.");
                }

                thisDynamic =
                    new DynamicDiskHeader {
                    LocatorEntries = new ParentLocatorEntry[8], Reserved2 = new byte[256]
                };

                for (int i = 0; i < 8; i++)
                {
                    thisDynamic.LocatorEntries[i] = new ParentLocatorEntry();
                }

                thisDynamic.Cookie          = BigEndianBitConverter.ToUInt64(dynamicBytes, 0x00);
                thisDynamic.DataOffset      = BigEndianBitConverter.ToUInt64(dynamicBytes, 0x08);
                thisDynamic.TableOffset     = BigEndianBitConverter.ToUInt64(dynamicBytes, 0x10);
                thisDynamic.HeaderVersion   = BigEndianBitConverter.ToUInt32(dynamicBytes, 0x18);
                thisDynamic.MaxTableEntries = BigEndianBitConverter.ToUInt32(dynamicBytes, 0x1C);
                thisDynamic.BlockSize       = BigEndianBitConverter.ToUInt32(dynamicBytes, 0x20);
                thisDynamic.Checksum        = dynamicChecksum;
                thisDynamic.ParentId        = BigEndianBitConverter.ToGuid(dynamicBytes, 0x28);
                thisDynamic.ParentTimestamp = BigEndianBitConverter.ToUInt32(dynamicBytes, 0x38);
                thisDynamic.Reserved        = BigEndianBitConverter.ToUInt32(dynamicBytes, 0x3C);
                thisDynamic.ParentName      = Encoding.BigEndianUnicode.GetString(dynamicBytes, 0x40, 512);

                for (int i = 0; i < 8; i++)
                {
                    thisDynamic.LocatorEntries[i].PlatformCode =
                        BigEndianBitConverter.ToUInt32(dynamicBytes, 0x240 + 0x00 + 24 * i);
                    thisDynamic.LocatorEntries[i].PlatformDataSpace =
                        BigEndianBitConverter.ToUInt32(dynamicBytes, 0x240 + 0x04 + 24 * i);
                    thisDynamic.LocatorEntries[i].PlatformDataLength =
                        BigEndianBitConverter.ToUInt32(dynamicBytes, 0x240 + 0x08 + 24 * i);
                    thisDynamic.LocatorEntries[i].Reserved =
                        BigEndianBitConverter.ToUInt32(dynamicBytes, 0x240 + 0x0C + 24 * i);
                    thisDynamic.LocatorEntries[i].PlatformDataOffset =
                        BigEndianBitConverter.ToUInt64(dynamicBytes, 0x240 + 0x10 + 24 * i);
                }

                Array.Copy(dynamicBytes, 0x300, thisDynamic.Reserved2, 0, 256);

                parentDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                parentDateTime = parentDateTime.AddSeconds(thisDynamic.ParentTimestamp);

                sha1Ctx = new Sha1Context();
                sha1Ctx.Update(thisDynamic.Reserved2);

                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.cookie = 0x{0:X8}", thisDynamic.Cookie);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.dataOffset = {0}", thisDynamic.DataOffset);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.tableOffset = {0}", thisDynamic.TableOffset);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.headerVersion = 0x{0:X8}",
                                          thisDynamic.HeaderVersion);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.maxTableEntries = {0}",
                                          thisDynamic.MaxTableEntries);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.blockSize = {0}", thisDynamic.BlockSize);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.checksum = 0x{0:X8}", thisDynamic.Checksum);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.parentID = {0}", thisDynamic.ParentId);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.parentTimestamp = 0x{0:X8} ({1})",
                                          thisDynamic.ParentTimestamp, parentDateTime);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.reserved = 0x{0:X8}", thisDynamic.Reserved);
                for (int i = 0; i < 8; i++)
                {
                    DicConsole.DebugWriteLine("VirtualPC plugin",
                                              "dynamic.locatorEntries[{0}].platformCode = 0x{1:X8} (\"{2}\")", i,
                                              thisDynamic.LocatorEntries[i].PlatformCode,
                                              Encoding.ASCII.GetString(BigEndianBitConverter.GetBytes(thisDynamic
                                                                                                      .LocatorEntries[i]
                                                                                                      .PlatformCode)));
                    DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.locatorEntries[{0}].platformDataSpace = {1}",
                                              i, thisDynamic.LocatorEntries[i].PlatformDataSpace);
                    DicConsole.DebugWriteLine("VirtualPC plugin",
                                              "dynamic.locatorEntries[{0}].platformDataLength = {1}", i,
                                              thisDynamic.LocatorEntries[i].PlatformDataLength);
                    DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.locatorEntries[{0}].reserved = 0x{1:X8}", i,
                                              thisDynamic.LocatorEntries[i].Reserved);
                    DicConsole.DebugWriteLine("VirtualPC plugin",
                                              "dynamic.locatorEntries[{0}].platformDataOffset = {1}", i,
                                              thisDynamic.LocatorEntries[i].PlatformDataOffset);
                }

                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.parentName = \"{0}\"",
                                          thisDynamic.ParentName);
                DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.reserved2's SHA1 = 0x{0}", sha1Ctx.End());

                if (thisDynamic.HeaderVersion != VERSION1)
                {
                    throw new
                          ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {thisFooter.DiskType} found. Please submit a bug with an example image.");
                }

                DateTime startTime = DateTime.UtcNow;

                blockAllocationTable = new uint[thisDynamic.MaxTableEntries];

                // Safe and slow code. It takes 76,572 ms to fill a 30720 entries BAT

                /*
                 * byte[] bat = new byte[thisDynamic.maxTableEntries * 4];
                 * imageStream.Seek((long)thisDynamic.tableOffset, SeekOrigin.Begin);
                 * imageStream.Read(bat, 0, (int)(thisDynamic.maxTableEntries * 4));
                 * for (int i = 0; i < thisDynamic.maxTableEntries; i++)
                 *  blockAllocationTable[i] = BigEndianBitConverter.ToUInt32(bat, 4 * i);
                 *
                 * DateTime endTime = DateTime.UtcNow;
                 * DicConsole.DebugWriteLine("VirtualPC plugin", "Filling the BAT took {0} seconds", (endTime-startTime).TotalSeconds);
                 */

                // How many sectors uses the BAT
                uint batSectorCount = (uint)Math.Ceiling((double)thisDynamic.MaxTableEntries * 4 / 512);

                byte[] batSectorBytes = new byte[512];

                // Unsafe and fast code. It takes 4 ms to fill a 30720 entries BAT
                for (int i = 0; i < batSectorCount; i++)
                {
                    imageStream.Seek((long)thisDynamic.TableOffset + i * 512, SeekOrigin.Begin);
                    imageStream.Read(batSectorBytes, 0, 512);
                    // This does the big-endian trick but reverses the order of elements also
                    Array.Reverse(batSectorBytes);
                    GCHandle  handle    = GCHandle.Alloc(batSectorBytes, GCHandleType.Pinned);
                    BatSector batSector =
                        (BatSector)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(BatSector));
                    handle.Free();
                    // This restores the order of elements
                    Array.Reverse(batSector.blockPointer);
                    if (blockAllocationTable.Length >= i * 512 / 4 + 512 / 4)
                    {
                        Array.Copy(batSector.blockPointer, 0, blockAllocationTable, i * 512 / 4, 512 / 4);
                    }
                    else
                    {
                        Array.Copy(batSector.blockPointer, 0, blockAllocationTable, i * 512 / 4,
                                   blockAllocationTable.Length - i * 512 / 4);
                    }
                }

                DateTime endTime = DateTime.UtcNow;
                DicConsole.DebugWriteLine("VirtualPC plugin", "Filling the BAT took {0} seconds",
                                          (endTime - startTime).TotalSeconds);

                // Too noisy

                /*
                 *  for (int i = 0; i < thisDynamic.maxTableEntries; i++)
                 *      DicConsole.DebugWriteLine("VirtualPC plugin", "blockAllocationTable[{0}] = {1}", i, blockAllocationTable[i]);
                 */

                // Get the roundest number of sectors needed to store the block bitmap
                bitmapSize = (uint)Math.Ceiling((double)thisDynamic.BlockSize / 512
                                                // 1 bit per sector on the bitmap
                                                / 8
                                                // and aligned to 512 byte boundary
                                                / 512);
                DicConsole.DebugWriteLine("VirtualPC plugin", "Bitmap is {0} sectors", bitmapSize);
            }

            imageInfo.XmlMediaType = XmlMediaType.BlockMedia;

            switch (thisFooter.DiskType)
            {
            case TYPE_FIXED:
            case TYPE_DYNAMIC:
            {
                // Nothing to do here, really.
                return(true);
            }

            case TYPE_DIFFERENCING:
            {
                locatorEntriesData = new byte[8][];
                for (int i = 0; i < 8; i++)
                {
                    if (thisDynamic.LocatorEntries[i].PlatformCode != 0x00000000)
                    {
                        locatorEntriesData[i] = new byte[thisDynamic.LocatorEntries[i].PlatformDataLength];
                        imageStream.Seek((long)thisDynamic.LocatorEntries[i].PlatformDataOffset, SeekOrigin.Begin);
                        imageStream.Read(locatorEntriesData[i], 0,
                                         (int)thisDynamic.LocatorEntries[i].PlatformDataLength);

                        switch (thisDynamic.LocatorEntries[i].PlatformCode)
                        {
                        case PLATFORM_CODE_WINDOWS_ABSOLUTE:
                        case PLATFORM_CODE_WINDOWS_RELATIVE:
                            DicConsole.DebugWriteLine("VirtualPC plugin",
                                                      "dynamic.locatorEntries[{0}] = \"{1}\"", i,
                                                      Encoding.ASCII.GetString(locatorEntriesData[i]));
                            break;

                        case PLATFORM_CODE_WINDOWS_ABSOLUTE_U:
                        case PLATFORM_CODE_WINDOWS_RELATIVE_U:
                            DicConsole.DebugWriteLine("VirtualPC plugin",
                                                      "dynamic.locatorEntries[{0}] = \"{1}\"", i,
                                                      Encoding.BigEndianUnicode
                                                      .GetString(locatorEntriesData[i]));
                            break;

                        case PLATFORM_CODE_MACINTOSH_URI:
                            DicConsole.DebugWriteLine("VirtualPC plugin",
                                                      "dynamic.locatorEntries[{0}] = \"{1}\"", i,
                                                      Encoding.UTF8.GetString(locatorEntriesData[i]));
                            break;

                        default:
                            DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.locatorEntries[{0}] =", i);
                            PrintHex.PrintHexArray(locatorEntriesData[i], 64);
                            break;
                        }
                    }
                }

                int    currentLocator = 0;
                bool   locatorFound   = false;
                string parentPath     = null;

                while (!locatorFound && currentLocator < 8)
                {
                    switch (thisDynamic.LocatorEntries[currentLocator].PlatformCode)
                    {
                    case PLATFORM_CODE_WINDOWS_ABSOLUTE:
                    case PLATFORM_CODE_WINDOWS_RELATIVE:
                        parentPath = Encoding.ASCII.GetString(locatorEntriesData[currentLocator]);
                        break;

                    case PLATFORM_CODE_WINDOWS_ABSOLUTE_U:
                    case PLATFORM_CODE_WINDOWS_RELATIVE_U:
                        parentPath = Encoding.BigEndianUnicode.GetString(locatorEntriesData[currentLocator]);
                        break;

                    case PLATFORM_CODE_MACINTOSH_URI:
                        parentPath =
                            Uri.UnescapeDataString(Encoding.UTF8.GetString(locatorEntriesData[currentLocator]));
                        if (parentPath.StartsWith("file://localhost", StringComparison.InvariantCulture))
                        {
                            parentPath = parentPath.Remove(0, 16);
                        }
                        else
                        {
                            DicConsole.DebugWriteLine("VirtualPC plugin",
                                                      "Unsupported protocol classified found in URI parent path: \"{0}\"",
                                                      parentPath);
                            parentPath = null;
                        }

                        break;
                    }

                    if (parentPath != null)
                    {
                        DicConsole.DebugWriteLine("VirtualPC plugin", "Possible parent path: \"{0}\"", parentPath);
                        IFilter parentFilter =
                            new FiltersList().GetFilter(Path.Combine(imageFilter.GetParentFolder(), parentPath));

                        if (parentFilter != null)
                        {
                            locatorFound = true;
                        }

                        if (!locatorFound)
                        {
                            parentPath = null;
                        }
                    }

                    currentLocator++;
                }

                if (!locatorFound)
                {
                    throw new
                          FileNotFoundException("(VirtualPC plugin): Cannot find parent file for differencing disk image");
                }

                {
                    parentImage = new Vhd();
                    IFilter parentFilter =
                        new FiltersList().GetFilter(Path.Combine(imageFilter.GetParentFolder(), parentPath));

                    if (parentFilter == null)
                    {
                        throw new ImageNotSupportedException("(VirtualPC plugin): Cannot find parent image filter");
                    }

                    /*                            PluginBase plugins = new PluginBase();
                     *                          plugins.RegisterAllPlugins();
                     *                          if (!plugins.ImagePluginsList.TryGetValue(Name.ToLower(), out parentImage))
                     *                              throw new SystemException("(VirtualPC plugin): Unable to open myself");*/

                    if (!parentImage.Identify(parentFilter))
                    {
                        throw new
                              ImageNotSupportedException("(VirtualPC plugin): Parent image is not a Virtual PC disk image");
                    }

                    if (!parentImage.Open(parentFilter))
                    {
                        throw new ImageNotSupportedException("(VirtualPC plugin): Cannot open parent disk image");
                    }

                    // While specification says that parent and child disk images should contain UUID relationship
                    // in reality it seems that old differencing disk images stored a parent UUID that, nonetheless
                    // the parent never stored itself. So the only real way to know that images are related is
                    // because the parent IS found and SAME SIZE. Ugly...
                    // More funny even, tested parent images show an empty host OS, and child images a correct one.
                    if (parentImage.Info.Sectors != imageInfo.Sectors)
                    {
                        throw new
                              ImageNotSupportedException("(VirtualPC plugin): Parent image is of different size");
                    }
                }

                return(true);
            }

            case TYPE_DEPRECATED1:
            case TYPE_DEPRECATED2:
            case TYPE_DEPRECATED3:
            {
                throw new
                      ImageNotSupportedException("(VirtualPC plugin): Deprecated image type found. Please submit a bug with an example image.");
            }

            default:
            {
                throw new
                      ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {thisFooter.DiskType} found. Please submit a bug with an example image.");
            }
            }
        }