From aadd192a6728ae835bf509450b3def9bcb4e3c3a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 1 Sep 2014 03:44:39 +0100 Subject: [PATCH] Implement "decode" verb. --- DiscImageChef/Commands/Decode.cs | 83 ++++++++++++++++++++++++++++++ DiscImageChef/DiscImageChef.csproj | 1 + DiscImageChef/Main.cs | 6 +++ DiscImageChef/Options.cs | 26 ++++++++++ 4 files changed, 116 insertions(+) create mode 100644 DiscImageChef/Commands/Decode.cs diff --git a/DiscImageChef/Commands/Decode.cs b/DiscImageChef/Commands/Decode.cs new file mode 100644 index 00000000..31585d2e --- /dev/null +++ b/DiscImageChef/Commands/Decode.cs @@ -0,0 +1,83 @@ +using System; +using DiscImageChef.ImagePlugins; + +namespace DiscImageChef.Commands +{ + public static class Decode + { + public static void doDecode(DecodeSubOptions options) + { + if (MainClass.isDebug) + { + Console.WriteLine("--debug={0}", options.Debug); + Console.WriteLine("--verbose={0}", options.Verbose); + Console.WriteLine("--input={0}", options.InputFile); + Console.WriteLine("--start={0}", options.StartSector); + Console.WriteLine("--length={0}", options.Length); + Console.WriteLine("--disk-tags={0}", options.DiskTags); + Console.WriteLine("--sector-tags={0}", options.SectorTags); + } + + ImagePlugin inputFormat = ImageFormat.Detect(options.InputFile); + + if (inputFormat == null) + { + Console.WriteLine("Unable to recognize image format, not verifying"); + return; + } + + inputFormat.OpenImage(options.InputFile); + + if (options.DiskTags) + { + if (inputFormat.ImageInfo.readableDiskTags.Count == 0) + Console.WriteLine("There are no disk tags in chosen disc image."); + else + { + foreach (DiskTagType tag in inputFormat.ImageInfo.readableDiskTags) + { + switch (tag) + { + default: + Console.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.", tag); + break; + } + } + } + } + + if (options.SectorTags) + { + UInt64 length; + + if (options.Length.ToLowerInvariant() == "all") + length = inputFormat.GetSectors() - 1; + else + { + if (!UInt64.TryParse(options.Length, out length)) + { + Console.WriteLine("Value \"{0}\" is not a valid number for length.", options.Length); + Console.WriteLine("Not decoding sectors tags"); + return; + } + } + + if (inputFormat.ImageInfo.readableSectorTags.Count == 0) + Console.WriteLine("There are no sector tags in chosen disc image."); + else + { + foreach (SectorTagType tag in inputFormat.ImageInfo.readableSectorTags) + { + switch (tag) + { + default: + Console.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.", tag); + break; + } + } + } + } + } + } +} + diff --git a/DiscImageChef/DiscImageChef.csproj b/DiscImageChef/DiscImageChef.csproj index 89d824cc..46bace2a 100644 --- a/DiscImageChef/DiscImageChef.csproj +++ b/DiscImageChef/DiscImageChef.csproj @@ -99,6 +99,7 @@ + diff --git a/DiscImageChef/Main.cs b/DiscImageChef/Main.cs index cf15c157..186f725b 100644 --- a/DiscImageChef/Main.cs +++ b/DiscImageChef/Main.cs @@ -111,6 +111,12 @@ namespace DiscImageChef isVerbose = PrintHexOptions.Verbose; Commands.PrintHex.doPrintHex(PrintHexOptions); break; + case "decode": + DecodeSubOptions DecodeOptions = (DecodeSubOptions)invokedVerbInstance; + isDebug = DecodeOptions.Debug; + isVerbose = DecodeOptions.Verbose; + Commands.Decode.doDecode(DecodeOptions); + break; case "formats": FormatsSubOptions FormatsOptions = (FormatsSubOptions)invokedVerbInstance; isVerbose = FormatsOptions.Verbose; diff --git a/DiscImageChef/Options.cs b/DiscImageChef/Options.cs index 6f1729c4..ddd0467a 100644 --- a/DiscImageChef/Options.cs +++ b/DiscImageChef/Options.cs @@ -154,6 +154,28 @@ namespace DiscImageChef public string InputFile { get; set; } } + public class DecodeSubOptions : CommonSubOptions + { + [Option('s', "start", DefaultValue = (ulong)0, + HelpText = "Start sector.")] + public ulong StartSector { get; set; } + + [Option('l', "length", DefaultValue = "all", + HelpText = "How many sectors to decode, or \"all\".")] + public string Length { get; set; } + + [Option('k', "disk-tags", DefaultValue = true, + HelpText = "Decode disk tags.")] + public bool DiskTags { get; set; } + + [Option('t', "sector-tags", DefaultValue = true, + HelpText = "Decode sector tags.")] + public bool SectorTags { get; set; } + + [Option('i', "input", Required = true, HelpText = "Disc image.")] + public string InputFile { get; set; } + } + public class FormatsSubOptions : CommonSubOptions { } @@ -168,6 +190,7 @@ namespace DiscImageChef VerifyVerb = new VerifySubOptions(); FormatsVerb = new FormatsSubOptions(); PrintHexVerb = new PrintHexSubOptions(); + DecodeVerb = new DecodeSubOptions(); } [VerbOption("analyze", HelpText = "Analyzes a disc image and searches for partitions and/or filesystems.")] @@ -185,6 +208,9 @@ namespace DiscImageChef [VerbOption("printhex", HelpText = "Prints a sector, in hexadecimal values, to the console.")] public PrintHexSubOptions PrintHexVerb { get; set; } + [VerbOption("decode", HelpText = "Decodes and pretty prints disk and/or sector tags.")] + public DecodeSubOptions DecodeVerb { get; set; } + [VerbOption("formats", HelpText = "Lists all supported disc images, partition schemes and file systems.")] public FormatsSubOptions FormatsVerb { get; set; }