private static WellKnownPartitionType GetPartitionType(PartitionInfo Partition) { switch (Partition.BiosType) { case BiosPartitionTypes.Fat16: case BiosPartitionTypes.Fat32: case BiosPartitionTypes.Fat32Lba: return(WellKnownPartitionType.WindowsFat); case BiosPartitionTypes.Ntfs: return(WellKnownPartitionType.WindowsNtfs); case BiosPartitionTypes.LinuxNative: return(WellKnownPartitionType.Linux); case BiosPartitionTypes.LinuxSwap: return(WellKnownPartitionType.LinuxSwap); case BiosPartitionTypes.LinuxLvm: return(WellKnownPartitionType.LinuxLvm); default: throw new ArgumentException( String.Format("Unsupported partition type: '{0}'", BiosPartitionTypes.ToString(Partition.BiosType)), "Partition"); } }
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(); } } }
public void Dump(TextWriter writer, string linePrefix) { writer.WriteLine(linePrefix + "DISK GROUP (" + _record.Name + ")"); writer.WriteLine(linePrefix + " Name: " + _record.Name); writer.WriteLine(linePrefix + " Flags: 0x" + (_record.Flags & 0xFFF0).ToString("X4", CultureInfo.InvariantCulture)); writer.WriteLine(linePrefix + " Database Id: " + _record.Id); writer.WriteLine(linePrefix + " Guid: " + _record.GroupGuidString); writer.WriteLine(); writer.WriteLine(linePrefix + " DISKS"); foreach (var disk in _database.Disks) { writer.WriteLine(linePrefix + " DISK (" + disk.Name + ")"); writer.WriteLine(linePrefix + " Name: " + disk.Name); writer.WriteLine(linePrefix + " Flags: 0x" + (disk.Flags & 0xFFF0).ToString("X4", CultureInfo.InvariantCulture)); writer.WriteLine(linePrefix + " Database Id: " + disk.Id); writer.WriteLine(linePrefix + " Guid: " + disk.DiskGuidString); DynamicDisk dynDisk; if (_disks.TryGetValue(new Guid(disk.DiskGuidString), out dynDisk)) { writer.WriteLine(linePrefix + " PRIVATE HEADER"); dynDisk.Dump(writer, linePrefix + " "); } } writer.WriteLine(linePrefix + " VOLUMES"); foreach (var vol in _database.Volumes) { writer.WriteLine(linePrefix + " VOLUME (" + vol.Name + ")"); writer.WriteLine(linePrefix + " Name: " + vol.Name); writer.WriteLine(linePrefix + " BIOS Type: " + vol.BiosType.ToString("X2", CultureInfo.InvariantCulture) + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]"); writer.WriteLine(linePrefix + " Flags: 0x" + (vol.Flags & 0xFFF0).ToString("X4", CultureInfo.InvariantCulture)); writer.WriteLine(linePrefix + " Database Id: " + vol.Id); writer.WriteLine(linePrefix + " Guid: " + vol.VolumeGuid); writer.WriteLine(linePrefix + " State: " + vol.ActiveString); writer.WriteLine(linePrefix + " Drive Hint: " + vol.MountHint); writer.WriteLine(linePrefix + " Num Components: " + vol.ComponentCount); writer.WriteLine(linePrefix + " Link Id: " + vol.PartitionComponentLink); writer.WriteLine(linePrefix + " COMPONENTS"); foreach (var cmpnt in _database.GetVolumeComponents(vol.Id)) { writer.WriteLine(linePrefix + " COMPONENT (" + cmpnt.Name + ")"); writer.WriteLine(linePrefix + " Name: " + cmpnt.Name); writer.WriteLine(linePrefix + " Flags: 0x" + (cmpnt.Flags & 0xFFF0).ToString("X4", CultureInfo.InvariantCulture)); writer.WriteLine(linePrefix + " Database Id: " + cmpnt.Id); writer.WriteLine(linePrefix + " State: " + cmpnt.StatusString); writer.WriteLine(linePrefix + " Mode: " + cmpnt.MergeType); writer.WriteLine(linePrefix + " Num Extents: " + cmpnt.NumExtents); writer.WriteLine(linePrefix + " Link Id: " + cmpnt.LinkId); writer.WriteLine(linePrefix + " Stripe Size: " + cmpnt.StripeSizeSectors + " (Sectors)"); writer.WriteLine(linePrefix + " Stripe Stride: " + cmpnt.StripeStride); writer.WriteLine(linePrefix + " EXTENTS"); foreach (var extent in _database.GetComponentExtents(cmpnt.Id)) { writer.WriteLine(linePrefix + " EXTENT (" + extent.Name + ")"); writer.WriteLine(linePrefix + " Name: " + extent.Name); writer.WriteLine(linePrefix + " Flags: 0x" + (extent.Flags & 0xFFF0).ToString("X4", CultureInfo.InvariantCulture)); writer.WriteLine(linePrefix + " Database Id: " + extent.Id); writer.WriteLine(linePrefix + " Disk Offset: " + extent.DiskOffsetLba + " (Sectors)"); writer.WriteLine(linePrefix + " Volume Offset: " + extent.OffsetInVolumeLba + " (Sectors)"); writer.WriteLine(linePrefix + " Size: " + extent.SizeLba + " (Sectors)"); writer.WriteLine(linePrefix + " Component Id: " + extent.ComponentId); writer.WriteLine(linePrefix + " Disk Id: " + extent.DiskId); writer.WriteLine(linePrefix + " Link Id: " + extent.PartitionComponentLink); writer.WriteLine(linePrefix + " Interleave Order: " + extent.InterleaveOrder); } } } }