Beispiel #1
0
        protected override void DoRun()
        {
            VolumeManager volMgr = new VolumeManager();

            foreach (string disk in _diskFiles.Values)
            {
                volMgr.AddDisk(VirtualDisk.OpenDisk(disk, _diskType.IsPresent ? _diskType.Value : null, FileAccess.Read, UserName, Password));
            }


            VolumeInfo volInfo = null;

            if (!string.IsNullOrEmpty(VolumeId))
            {
                volInfo = volMgr.GetVolume(VolumeId);
            }
            else if (Partition >= 0)
            {
                volInfo = volMgr.GetPhysicalVolumes()[Partition];
            }
            else
            {
                volInfo = volMgr.GetLogicalVolumes()[0];
            }


            DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectDefaultFileSystems(volInfo)[0];


            using (DiscFileSystem fs = fsInfo.Open(volInfo))
            {
                using (Stream source = fs.OpenFile(_inFilePath.Value, FileMode.Open, FileAccess.Read))
                {
                    using (FileStream outFile = new FileStream(_outFilePath.Value, FileMode.Create, FileAccess.ReadWrite))
                    {
                        PumpStreams(source, outFile);
                    }

                    if (_hexDump.IsPresent)
                    {
                        source.Position = 0;
                        HexDump.Generate(source, Console.Out);
                    }
                }
            }
        }
        protected override void DoRun()
        {
            Console.OutputEncoding = Encoding.UTF8;

            List <VirtualDisk> disks = new List <VirtualDisk>();

            foreach (var path in _inFiles.Values)
            {
                VirtualDisk disk = VirtualDisk.OpenDisk(path, _diskType.IsPresent ? _diskType.Value : null, FileAccess.Read, UserName, Password);
                disks.Add(disk);

                Console.WriteLine();
                Console.WriteLine("DISK: " + path);
                Console.WriteLine();
                Console.WriteLine("       Capacity: {0:X16}", disk.Capacity);
                Console.WriteLine("       Geometry: {0}", disk.Geometry);
                Console.WriteLine("  BIOS Geometry: {0}", disk.BiosGeometry);
                Console.WriteLine("      Signature: {0:X8}", disk.Signature);
                if (disk.IsPartitioned)
                {
                    Console.WriteLine("           GUID: {0}", disk.Partitions.DiskGuid);
                }
                Console.WriteLine();

                if (!_hideExtents.IsPresent)
                {
                    Console.WriteLine();
                    Console.WriteLine("  Stored Extents");
                    Console.WriteLine();
                    foreach (var extent in disk.Content.Extents)
                    {
                        Console.WriteLine("    {0:X16} - {1:X16}", extent.Start, extent.Start + extent.Length);
                    }
                    Console.WriteLine();
                }


                if (_showBootCode.IsPresent)
                {
                    Console.WriteLine();
                    Console.WriteLine("  Master Boot Record (MBR)");
                    Console.WriteLine();
                    try
                    {
                        byte[] mbr = new byte[512];
                        disk.Content.Position = 0;
                        disk.Content.Read(mbr, 0, 512);
                        HexDump.Generate(mbr, Console.Out);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                    Console.WriteLine();
                }


                Console.WriteLine();
                Console.WriteLine("  Partitions");
                Console.WriteLine();
                if (disk.IsPartitioned)
                {
                    Console.WriteLine("    T   Start (bytes)     End (bytes)       Type");
                    Console.WriteLine("    ==  ================  ================  ==================");
                    foreach (var partition in disk.Partitions.Partitions)
                    {
                        Console.WriteLine("    {0:X2}  {1:X16}  {2:X16}  {3}", partition.BiosType, partition.FirstSector * 512, partition.LastSector * 512 + 512, partition.TypeAsString);

                        BiosPartitionInfo bpi = partition as BiosPartitionInfo;
                        if (bpi != null)
                        {
                            Console.WriteLine("        {0,-16}  {1}", bpi.Start.ToString(), bpi.End.ToString());
                            Console.WriteLine();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("    No partitions");
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("VOLUMES");
            Console.WriteLine();
            VolumeManager volMgr = new VolumeManager();

            foreach (var disk in disks)
            {
                volMgr.AddDisk(disk);
            }

            try
            {
                Console.WriteLine();
                Console.WriteLine("  Physical Volumes");
                Console.WriteLine();
                foreach (var vol in volMgr.GetPhysicalVolumes())
                {
                    Console.WriteLine("  " + vol.Identity);
                    Console.WriteLine("    Type: " + vol.VolumeType);
                    Console.WriteLine("    BIOS Type: " + vol.BiosType.ToString("X2") + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]");
                    Console.WriteLine("    Size: " + vol.Length);
                    Console.WriteLine("    Disk Id: " + vol.DiskIdentity);
                    Console.WriteLine("    Disk Sig: " + vol.DiskSignature.ToString("X8"));
                    Console.WriteLine("    Partition: " + vol.PartitionIdentity);
                    Console.WriteLine("    Disk Geometry: " + vol.PhysicalGeometry);
                    Console.WriteLine("    BIOS Geometry: " + vol.BiosGeometry);
                    Console.WriteLine("    First Sector: " + vol.PhysicalStartSector);
                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                Console.WriteLine();
                Console.WriteLine("  Logical Volumes");
                Console.WriteLine();
                foreach (var vol in volMgr.GetLogicalVolumes())
                {
                    Console.WriteLine("  " + vol.Identity);
                    Console.WriteLine("    BIOS Type: " + vol.BiosType.ToString("X2") + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]");
                    Console.WriteLine("    Status: " + vol.Status);
                    Console.WriteLine("    Size: " + vol.Length);
                    Console.WriteLine("    Disk Geometry: " + vol.PhysicalGeometry);
                    Console.WriteLine("    BIOS Geometry: " + vol.BiosGeometry);
                    Console.WriteLine("    First Sector: " + vol.PhysicalStartSector);

                    if (vol.Status == LogicalVolumeStatus.Failed)
                    {
                        Console.WriteLine("    File Systems: <unknown - failed volume>");
                        Console.WriteLine();
                        continue;
                    }

                    DiscUtils.FileSystemInfo[] fileSystemInfos = FileSystemManager.DetectDefaultFileSystems(vol);
                    Console.WriteLine("    File Systems: " + string.Join <DiscUtils.FileSystemInfo>(", ", fileSystemInfos));

                    Console.WriteLine();

                    if (_showVolContent.IsPresent)
                    {
                        Console.WriteLine("    Binary Contents...");
                        try
                        {
                            using (Stream s = vol.Open())
                            {
                                HexDump.Generate(s, Console.Out);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        Console.WriteLine();
                    }

                    if (_showBootCode.IsPresent)
                    {
                        foreach (var fsi in fileSystemInfos)
                        {
                            Console.WriteLine("    Boot Code: {0}", fsi.Name);
                            try
                            {
                                using (DiscFileSystem fs = fsi.Open(vol, FileSystemParameters))
                                {
                                    byte[] bootCode = fs.ReadBootCode();
                                    if (bootCode != null)
                                    {
                                        HexDump.Generate(bootCode, Console.Out);
                                    }
                                    else
                                    {
                                        Console.WriteLine("      <file system reports no boot code>");
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("      Unable to show boot code: " + e.Message);
                            }
                            Console.WriteLine();
                        }
                    }

                    if (_showFiles.IsPresent)
                    {
                        foreach (var fsi in fileSystemInfos)
                        {
                            using (DiscFileSystem fs = fsi.Open(vol, FileSystemParameters))
                            {
                                Console.WriteLine("    {0} Volume Label: {1}", fsi.Name, fs.VolumeLabel);
                                Console.WriteLine("    Files ({0})...", fsi.Name);
                                ShowDir(fs.Root, 6);
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                bool foundDynDisk = false;
                DynamicDiskManager dynDiskManager = new DynamicDiskManager();
                foreach (var disk in disks)
                {
                    if (DynamicDiskManager.IsDynamicDisk(disk))
                    {
                        dynDiskManager.Add(disk);
                        foundDynDisk = true;
                    }
                }
                if (foundDynDisk)
                {
                    Console.WriteLine();
                    Console.WriteLine("  Logical Disk Manager Info");
                    Console.WriteLine();
                    dynDiskManager.Dump(Console.Out, "  ");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            if (_showContent.IsPresent)
            {
                foreach (var path in _inFiles.Values)
                {
                    VirtualDisk disk = VirtualDisk.OpenDisk(path, FileAccess.Read, UserName, Password);

                    Console.WriteLine();
                    Console.WriteLine("DISK CONTENTS ({0})", path);
                    Console.WriteLine();
                    HexDump.Generate(disk.Content, Console.Out);
                    Console.WriteLine();
                }
            }
        }