mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Implement "printhex" verb to print a/several sector(s) as
hexadecimal values on console.
This commit is contained in:
97
DiscImageChef/Commands/PrintHex.cs
Normal file
97
DiscImageChef/Commands/PrintHex.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
The Disc Image Chef
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Filename : PrintHex.cs
|
||||||
|
Version : 1.0
|
||||||
|
Author(s) : Natalia Portillo
|
||||||
|
|
||||||
|
Component : Verbs.
|
||||||
|
|
||||||
|
Revision : $Revision$
|
||||||
|
Last change by : $Author$
|
||||||
|
Date : $Date$
|
||||||
|
|
||||||
|
--[ Description ] ----------------------------------------------------------
|
||||||
|
|
||||||
|
Implements the 'printhex' verb.
|
||||||
|
|
||||||
|
--[ License ] --------------------------------------------------------------
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2011-2014 Claunia.com
|
||||||
|
****************************************************************************/
|
||||||
|
//$Id$
|
||||||
|
using System;
|
||||||
|
using DiscImageChef.ImagePlugins;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public static class PrintHex
|
||||||
|
{
|
||||||
|
public static void doPrintHex(PrintHexSubOptions 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("--long-sectors={0}", options.LongSectors);
|
||||||
|
Console.WriteLine("--WidthBytes={0}", options.WidthBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImagePlugin inputFormat = ImageFormat.Detect(options.InputFile);
|
||||||
|
|
||||||
|
if (inputFormat == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to recognize image format, not verifying");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inputFormat.OpenImage(options.InputFile);
|
||||||
|
|
||||||
|
for(ulong i = 0; i < options.Length; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Sector {0}", options.StartSector + i);
|
||||||
|
byte[] sector;
|
||||||
|
|
||||||
|
if (inputFormat.ImageInfo.readableSectorTags == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Requested sectors with tags, unsupported by underlying image format, printing only user data.");
|
||||||
|
options.LongSectors = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (inputFormat.ImageInfo.readableSectorTags.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Requested sectors with tags, unsupported by underlying image format, printing only user data.");
|
||||||
|
options.LongSectors = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.LongSectors)
|
||||||
|
sector = inputFormat.ReadSectorLong(options.StartSector + i);
|
||||||
|
else
|
||||||
|
sector = inputFormat.ReadSector(options.StartSector + i);
|
||||||
|
|
||||||
|
DiscImageChef.PrintHex.PrintHexArray(sector, options.WidthBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -98,6 +98,7 @@
|
|||||||
<Compile Include="Checksums\CRC16Context.cs" />
|
<Compile Include="Checksums\CRC16Context.cs" />
|
||||||
<Compile Include="Checksums\CDChecksums.cs" />
|
<Compile Include="Checksums\CDChecksums.cs" />
|
||||||
<Compile Include="Checksums\ReedSolomon.cs" />
|
<Compile Include="Checksums\ReedSolomon.cs" />
|
||||||
|
<Compile Include="Commands\PrintHex.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -105,6 +105,12 @@ namespace DiscImageChef
|
|||||||
isVerbose = VerifyOptions.Verbose;
|
isVerbose = VerifyOptions.Verbose;
|
||||||
Commands.Verify.doVerify(VerifyOptions);
|
Commands.Verify.doVerify(VerifyOptions);
|
||||||
break;
|
break;
|
||||||
|
case "printhex":
|
||||||
|
PrintHexSubOptions PrintHexOptions = (PrintHexSubOptions)invokedVerbInstance;
|
||||||
|
isDebug = PrintHexOptions.Debug;
|
||||||
|
isVerbose = PrintHexOptions.Verbose;
|
||||||
|
Commands.PrintHex.doPrintHex(PrintHexOptions);
|
||||||
|
break;
|
||||||
case "formats":
|
case "formats":
|
||||||
FormatsSubOptions FormatsOptions = (FormatsSubOptions)invokedVerbInstance;
|
FormatsSubOptions FormatsOptions = (FormatsSubOptions)invokedVerbInstance;
|
||||||
isVerbose = FormatsOptions.Verbose;
|
isVerbose = FormatsOptions.Verbose;
|
||||||
|
|||||||
@@ -132,6 +132,28 @@ namespace DiscImageChef
|
|||||||
public string InputFile { get; set; }
|
public string InputFile { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PrintHexSubOptions : CommonSubOptions
|
||||||
|
{
|
||||||
|
[Option('s', "start", Required = true,
|
||||||
|
HelpText = "Start sector.")]
|
||||||
|
public ulong StartSector { get; set; }
|
||||||
|
|
||||||
|
[Option('l', "length", DefaultValue = (ulong)1,
|
||||||
|
HelpText = "How many sectors to print.")]
|
||||||
|
public ulong Length { get; set; }
|
||||||
|
|
||||||
|
[Option('r', "long-sectors", DefaultValue = false,
|
||||||
|
HelpText = "Print sectors with tags included.")]
|
||||||
|
public bool LongSectors { get; set; }
|
||||||
|
|
||||||
|
[Option('w', "width", DefaultValue = (ushort)32,
|
||||||
|
HelpText = "How many bytes to print per line.")]
|
||||||
|
public ushort WidthBytes { get; set; }
|
||||||
|
|
||||||
|
[Option('i', "input", Required = true, HelpText = "Disc image.")]
|
||||||
|
public string InputFile { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class FormatsSubOptions : CommonSubOptions
|
public class FormatsSubOptions : CommonSubOptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -145,6 +167,7 @@ namespace DiscImageChef
|
|||||||
ChecksumVerb = new ChecksumSubOptions();
|
ChecksumVerb = new ChecksumSubOptions();
|
||||||
VerifyVerb = new VerifySubOptions();
|
VerifyVerb = new VerifySubOptions();
|
||||||
FormatsVerb = new FormatsSubOptions();
|
FormatsVerb = new FormatsSubOptions();
|
||||||
|
PrintHexVerb = new PrintHexSubOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
[VerbOption("analyze", HelpText = "Analyzes a disc image and searches for partitions and/or filesystems.")]
|
[VerbOption("analyze", HelpText = "Analyzes a disc image and searches for partitions and/or filesystems.")]
|
||||||
@@ -159,6 +182,9 @@ namespace DiscImageChef
|
|||||||
[VerbOption("verify", HelpText = "Verifies a disc image integrity, and if supported, sector integrity.")]
|
[VerbOption("verify", HelpText = "Verifies a disc image integrity, and if supported, sector integrity.")]
|
||||||
public VerifySubOptions VerifyVerb { get; set; }
|
public VerifySubOptions VerifyVerb { get; set; }
|
||||||
|
|
||||||
|
[VerbOption("printhex", HelpText = "Prints a sector, in hexadecimal values, to the console.")]
|
||||||
|
public PrintHexSubOptions PrintHexVerb { get; set; }
|
||||||
|
|
||||||
[VerbOption("formats", HelpText = "Lists all supported disc images, partition schemes and file systems.")]
|
[VerbOption("formats", HelpText = "Lists all supported disc images, partition schemes and file systems.")]
|
||||||
public FormatsSubOptions FormatsVerb { get; set; }
|
public FormatsSubOptions FormatsVerb { get; set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user