mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
* DiscImageChef/Main.cs:
* DiscImageChef/Commands/Verify.cs: * DiscImageChef/Commands/Formats.cs: * DiscImageChef/Commands/Analyze.cs: * DiscImageChef/Commands/Compare.cs: * DiscImageChef/Commands/Commands.cs: * DiscImageChef/Commands/Checksum.cs: * DiscImageChef/DiscImageChef.csproj: Move all commands to separate classes. * DiscImageChef/AssemblyInfo.cs: Let mono create random revision and build. * DiscImageChef/Options.cs: Make options public
This commit is contained in:
@@ -54,7 +54,7 @@ using System.Reflection;
|
|||||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
[assembly: AssemblyVersion("1.1.0.*")]
|
[assembly: AssemblyVersion("1.1.*")]
|
||||||
|
|
||||||
// The following attributes are used to specify the signing key for the assembly,
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
// if desired. See the Mono documentation for more information about signing.
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|||||||
239
DiscImageChef/Commands/Analyze.cs
Normal file
239
DiscImageChef/Commands/Analyze.cs
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DiscImageChef.Plugins;
|
||||||
|
using DiscImageChef.ImagePlugins;
|
||||||
|
using DiscImageChef.PartPlugins;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public static class Analyze
|
||||||
|
{
|
||||||
|
public static void doAnalyze(AnalyzeSubOptions options)
|
||||||
|
{
|
||||||
|
if (MainClass.isDebug)
|
||||||
|
{
|
||||||
|
Console.WriteLine("--debug={0}", options.Debug);
|
||||||
|
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||||
|
Console.WriteLine("--input={0}", options.InputFile);
|
||||||
|
Console.WriteLine("--filesystems={0}", options.SearchForFilesystems);
|
||||||
|
Console.WriteLine("--partitions={0}", options.SearchForPartitions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!System.IO.File.Exists(options.InputFile))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Specified file does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginBase plugins = new PluginBase();
|
||||||
|
plugins.RegisterAllPlugins();
|
||||||
|
|
||||||
|
List<string> id_plugins;
|
||||||
|
Plugin _plugin;
|
||||||
|
string information;
|
||||||
|
bool checkraw = false;
|
||||||
|
ImagePlugin _imageFormat;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_imageFormat = null;
|
||||||
|
|
||||||
|
// Check all but RAW plugin
|
||||||
|
foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
||||||
|
{
|
||||||
|
if(_imageplugin.PluginUUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||||
|
{
|
||||||
|
if (_imageplugin.IdentifyImage(options.InputFile))
|
||||||
|
{
|
||||||
|
_imageFormat = _imageplugin;
|
||||||
|
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check only RAW plugin
|
||||||
|
if (_imageFormat == null)
|
||||||
|
{
|
||||||
|
foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
||||||
|
{
|
||||||
|
if(_imageplugin.PluginUUID == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||||
|
{
|
||||||
|
if (_imageplugin.IdentifyImage(options.InputFile))
|
||||||
|
{
|
||||||
|
_imageFormat = _imageplugin;
|
||||||
|
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Still not recognized
|
||||||
|
if (_imageFormat == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Image format not identified, not proceeding.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_imageFormat.OpenImage(options.InputFile))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to open image format");
|
||||||
|
Console.WriteLine("No error given");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MainClass.isDebug)
|
||||||
|
{
|
||||||
|
Console.WriteLine("DEBUG: Correctly opened image file.");
|
||||||
|
Console.WriteLine("DEBUG: Image without headers is {0} bytes.", _imageFormat.GetImageSize());
|
||||||
|
Console.WriteLine("DEBUG: Image has {0} sectors.", _imageFormat.GetSectors());
|
||||||
|
Console.WriteLine("DEBUG: Image identifies disk type as {0}.", _imageFormat.GetDiskType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to open image format");
|
||||||
|
Console.WriteLine("Error: {0}", ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Image identified as {0}.", _imageFormat.GetImageFormat());
|
||||||
|
|
||||||
|
if (options.SearchForPartitions)
|
||||||
|
{
|
||||||
|
List<Partition> partitions = new List<Partition>();
|
||||||
|
string partition_scheme = "";
|
||||||
|
|
||||||
|
// TODO: Solve possibility of multiple partition schemes (CUE + MBR, MBR + RDB, CUE + APM, etc)
|
||||||
|
foreach (PartPlugin _partplugin in plugins.PartPluginsList.Values)
|
||||||
|
{
|
||||||
|
List<Partition> _partitions;
|
||||||
|
|
||||||
|
if (_partplugin.GetInformation(_imageFormat, out _partitions))
|
||||||
|
{
|
||||||
|
partition_scheme = _partplugin.Name;
|
||||||
|
partitions = _partitions;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_imageFormat.ImageHasPartitions())
|
||||||
|
{
|
||||||
|
partition_scheme = _imageFormat.GetImageFormat();
|
||||||
|
partitions = _imageFormat.GetPartitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (partition_scheme == "")
|
||||||
|
{
|
||||||
|
if(MainClass.isDebug)
|
||||||
|
Console.WriteLine("DEBUG: No partitions found");
|
||||||
|
if (!options.SearchForFilesystems)
|
||||||
|
{
|
||||||
|
Console.WriteLine("No partitions founds, not searching for filesystems");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkraw = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Partition scheme identified as {0}", partition_scheme);
|
||||||
|
Console.WriteLine("{0} partitions found.", partitions.Count);
|
||||||
|
|
||||||
|
for (int i = 0; i < partitions.Count; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Partition {0}:", partitions[i].PartitionSequence);
|
||||||
|
Console.WriteLine("Partition name: {0}", partitions[i].PartitionName);
|
||||||
|
Console.WriteLine("Partition type: {0}", partitions[i].PartitionType);
|
||||||
|
Console.WriteLine("Partition start: sector {0}, byte {1}", partitions[i].PartitionStartSector, partitions[i].PartitionStart);
|
||||||
|
Console.WriteLine("Partition length: {0} sectors, {1} bytes", partitions[i].PartitionSectors, partitions[i].PartitionLength);
|
||||||
|
Console.WriteLine("Partition description:");
|
||||||
|
Console.WriteLine(partitions[i].PartitionDescription);
|
||||||
|
|
||||||
|
if (options.SearchForFilesystems)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Identifying filesystem on partition");
|
||||||
|
|
||||||
|
IdentifyFilesystems(_imageFormat, out id_plugins, partitions[i].PartitionStartSector);
|
||||||
|
if (id_plugins.Count == 0)
|
||||||
|
Console.WriteLine("Filesystem not identified");
|
||||||
|
else if (id_plugins.Count > 1)
|
||||||
|
{
|
||||||
|
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
||||||
|
|
||||||
|
foreach (string plugin_name in id_plugins)
|
||||||
|
{
|
||||||
|
if (plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
||||||
|
{
|
||||||
|
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
||||||
|
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStartSector, out information);
|
||||||
|
Console.Write(information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
||||||
|
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
||||||
|
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStartSector, out information);
|
||||||
|
Console.Write(information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkraw)
|
||||||
|
{
|
||||||
|
IdentifyFilesystems(_imageFormat, out id_plugins, 0);
|
||||||
|
if (id_plugins.Count == 0)
|
||||||
|
Console.WriteLine("Filesystem not identified");
|
||||||
|
else if (id_plugins.Count > 1)
|
||||||
|
{
|
||||||
|
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
||||||
|
|
||||||
|
foreach (string plugin_name in id_plugins)
|
||||||
|
{
|
||||||
|
if (plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
||||||
|
{
|
||||||
|
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
||||||
|
_plugin.GetInformation(_imageFormat, 0, out information);
|
||||||
|
Console.Write(information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
||||||
|
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
||||||
|
_plugin.GetInformation(_imageFormat, 0, out information);
|
||||||
|
Console.Write(information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(String.Format("Error reading file: {0}", ex.Message));
|
||||||
|
if (MainClass.isDebug)
|
||||||
|
Console.WriteLine(ex.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void IdentifyFilesystems(ImagePlugin imagePlugin, out List<string> id_plugins, ulong partitionOffset)
|
||||||
|
{
|
||||||
|
id_plugins = new List<string>();
|
||||||
|
PluginBase plugins = new PluginBase();
|
||||||
|
plugins.RegisterAllPlugins();
|
||||||
|
|
||||||
|
foreach (Plugin _plugin in plugins.PluginsList.Values)
|
||||||
|
{
|
||||||
|
if (_plugin.Identify(imagePlugin, partitionOffset))
|
||||||
|
id_plugins.Add(_plugin.Name.ToLower());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
25
DiscImageChef/Commands/Checksum.cs
Normal file
25
DiscImageChef/Commands/Checksum.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public static class Checksum
|
||||||
|
{
|
||||||
|
public static void doChecksum(ChecksumSubOptions options)
|
||||||
|
{
|
||||||
|
if (MainClass.isDebug)
|
||||||
|
{
|
||||||
|
Console.WriteLine("--debug={0}", options.Debug);
|
||||||
|
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||||
|
Console.WriteLine("--separated-tracks={0}", options.SeparatedTracks);
|
||||||
|
Console.WriteLine("--whole-disc={0}", options.WholeDisc);
|
||||||
|
Console.WriteLine("--input={0}", options.InputFile);
|
||||||
|
Console.WriteLine("--crc32={0}", options.DoCRC32);
|
||||||
|
Console.WriteLine("--md5={0}", options.DoMD5);
|
||||||
|
Console.WriteLine("--sha1={0}", options.DoSHA1);
|
||||||
|
Console.WriteLine("--fuzzy={0}", options.DoFuzzy);
|
||||||
|
}
|
||||||
|
throw new NotImplementedException("Checksumming not yet implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
12
DiscImageChef/Commands/Commands.cs
Normal file
12
DiscImageChef/Commands/Commands.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public partial class Commands
|
||||||
|
{
|
||||||
|
public Commands()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
20
DiscImageChef/Commands/Compare.cs
Normal file
20
DiscImageChef/Commands/Compare.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public static class Compare
|
||||||
|
{
|
||||||
|
public static void doCompare(CompareSubOptions options)
|
||||||
|
{
|
||||||
|
if (MainClass.isDebug)
|
||||||
|
{
|
||||||
|
Console.WriteLine("--debug={0}", options.Debug);
|
||||||
|
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||||
|
Console.WriteLine("--input1={0}", options.InputFile1);
|
||||||
|
Console.WriteLine("--input2={0}", options.InputFile2);
|
||||||
|
}
|
||||||
|
throw new NotImplementedException("Comparing not yet implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
30
DiscImageChef/Commands/Formats.cs
Normal file
30
DiscImageChef/Commands/Formats.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DiscImageChef.ImagePlugins;
|
||||||
|
using DiscImageChef.PartPlugins;
|
||||||
|
using DiscImageChef.Plugins;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public static class Formats
|
||||||
|
{
|
||||||
|
public static void ListFormats()
|
||||||
|
{
|
||||||
|
PluginBase plugins = new PluginBase();
|
||||||
|
plugins.RegisterAllPlugins();
|
||||||
|
|
||||||
|
Console.WriteLine("Supported images:");
|
||||||
|
foreach (KeyValuePair<string, ImagePlugin> kvp in plugins.ImagePluginsList)
|
||||||
|
Console.WriteLine(kvp.Value.Name);
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Supported filesystems:");
|
||||||
|
foreach (KeyValuePair<string, Plugin> kvp in plugins.PluginsList)
|
||||||
|
Console.WriteLine(kvp.Value.Name);
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Supported partitions:");
|
||||||
|
foreach (KeyValuePair<string, PartPlugin> kvp in plugins.PartPluginsList)
|
||||||
|
Console.WriteLine(kvp.Value.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
21
DiscImageChef/Commands/Verify.cs
Normal file
21
DiscImageChef/Commands/Verify.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Commands
|
||||||
|
{
|
||||||
|
public static class Verify
|
||||||
|
{
|
||||||
|
public static void doVerify(VerifySubOptions options)
|
||||||
|
{
|
||||||
|
if (MainClass.isDebug)
|
||||||
|
{
|
||||||
|
Console.WriteLine("--debug={0}", options.Debug);
|
||||||
|
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||||
|
Console.WriteLine("--input={0}", options.InputFile);
|
||||||
|
Console.WriteLine("--verify-disc={0}", options.VerifyDisc);
|
||||||
|
Console.WriteLine("--verify-sectors={0}", options.VerifySectors);
|
||||||
|
}
|
||||||
|
throw new NotImplementedException("Verifying not yet implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -78,12 +78,19 @@
|
|||||||
<Compile Include="PrintHex.cs" />
|
<Compile Include="PrintHex.cs" />
|
||||||
<Compile Include="ImagePlugins\ZZZRawImage.cs" />
|
<Compile Include="ImagePlugins\ZZZRawImage.cs" />
|
||||||
<Compile Include="Options.cs" />
|
<Compile Include="Options.cs" />
|
||||||
|
<Compile Include="Commands\Formats.cs" />
|
||||||
|
<Compile Include="Commands\Analyze.cs" />
|
||||||
|
<Compile Include="Commands\Compare.cs" />
|
||||||
|
<Compile Include="Commands\Checksum.cs" />
|
||||||
|
<Compile Include="Commands\Verify.cs" />
|
||||||
|
<Compile Include="Commands\Commands.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Plugins\" />
|
<Folder Include="Plugins\" />
|
||||||
<Folder Include="PartPlugins\" />
|
<Folder Include="PartPlugins\" />
|
||||||
<Folder Include="ImagePlugins\" />
|
<Folder Include="ImagePlugins\" />
|
||||||
|
<Folder Include="Commands\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<MonoDevelop>
|
<MonoDevelop>
|
||||||
|
|||||||
@@ -47,14 +47,12 @@ namespace DiscImageChef
|
|||||||
{
|
{
|
||||||
class MainClass
|
class MainClass
|
||||||
{
|
{
|
||||||
static PluginBase plugins;
|
|
||||||
public static bool isDebug;
|
public static bool isDebug;
|
||||||
public static bool isVerbose;
|
public static bool isVerbose;
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
plugins = new PluginBase();
|
|
||||||
|
|
||||||
string invokedVerb = "";
|
string invokedVerb = "";
|
||||||
object invokedVerbInstance = null;
|
object invokedVerbInstance = null;
|
||||||
|
|
||||||
@@ -87,310 +85,33 @@ namespace DiscImageChef
|
|||||||
AnalyzeSubOptions AnalyzeOptions = (AnalyzeSubOptions)invokedVerbInstance;
|
AnalyzeSubOptions AnalyzeOptions = (AnalyzeSubOptions)invokedVerbInstance;
|
||||||
isDebug = AnalyzeOptions.Debug;
|
isDebug = AnalyzeOptions.Debug;
|
||||||
isVerbose = AnalyzeOptions.Verbose;
|
isVerbose = AnalyzeOptions.Verbose;
|
||||||
Analyze(AnalyzeOptions);
|
Commands.Analyze.doAnalyze(AnalyzeOptions);
|
||||||
break;
|
break;
|
||||||
case "compare":
|
case "compare":
|
||||||
CompareSubOptions CompareOptions = (CompareSubOptions)invokedVerbInstance;
|
CompareSubOptions CompareOptions = (CompareSubOptions)invokedVerbInstance;
|
||||||
isDebug = CompareOptions.Debug;
|
isDebug = CompareOptions.Debug;
|
||||||
isVerbose = CompareOptions.Verbose;
|
isVerbose = CompareOptions.Verbose;
|
||||||
Compare(CompareOptions);
|
Commands.Compare.doCompare(CompareOptions);
|
||||||
break;
|
break;
|
||||||
case "checksum":
|
case "checksum":
|
||||||
ChecksumSubOptions ChecksumOptions = (ChecksumSubOptions)invokedVerbInstance;
|
ChecksumSubOptions ChecksumOptions = (ChecksumSubOptions)invokedVerbInstance;
|
||||||
isDebug = ChecksumOptions.Debug;
|
isDebug = ChecksumOptions.Debug;
|
||||||
isVerbose = ChecksumOptions.Verbose;
|
isVerbose = ChecksumOptions.Verbose;
|
||||||
Checksum(ChecksumOptions);
|
Commands.Checksum.doChecksum(ChecksumOptions);
|
||||||
break;
|
break;
|
||||||
case "verify":
|
case "verify":
|
||||||
VerifySubOptions VerifyOptions = (VerifySubOptions)invokedVerbInstance;
|
VerifySubOptions VerifyOptions = (VerifySubOptions)invokedVerbInstance;
|
||||||
isDebug = VerifyOptions.Debug;
|
isDebug = VerifyOptions.Debug;
|
||||||
isVerbose = VerifyOptions.Verbose;
|
isVerbose = VerifyOptions.Verbose;
|
||||||
Verify(VerifyOptions);
|
Commands.Verify.doVerify(VerifyOptions);
|
||||||
break;
|
break;
|
||||||
case "formats":
|
case "formats":
|
||||||
ListFormats();
|
Commands.Formats.ListFormats();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("Should never arrive here!");
|
throw new ArgumentException("Should never arrive here!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ListFormats()
|
|
||||||
{
|
|
||||||
plugins.RegisterAllPlugins();
|
|
||||||
|
|
||||||
Console.WriteLine("Supported images:");
|
|
||||||
foreach (KeyValuePair<string, ImagePlugin> kvp in plugins.ImagePluginsList)
|
|
||||||
Console.WriteLine(kvp.Value.Name);
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("Supported filesystems:");
|
|
||||||
foreach (KeyValuePair<string, Plugin> kvp in plugins.PluginsList)
|
|
||||||
Console.WriteLine(kvp.Value.Name);
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("Supported partitions:");
|
|
||||||
foreach (KeyValuePair<string, PartPlugin> kvp in plugins.PartPluginsList)
|
|
||||||
Console.WriteLine(kvp.Value.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Compare(CompareSubOptions options)
|
|
||||||
{
|
|
||||||
if (isDebug)
|
|
||||||
{
|
|
||||||
Console.WriteLine("--debug={0}", options.Debug);
|
|
||||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
|
||||||
Console.WriteLine("--input1={0}", options.InputFile1);
|
|
||||||
Console.WriteLine("--input2={0}", options.InputFile2);
|
|
||||||
}
|
|
||||||
throw new NotImplementedException("Comparing not yet implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Checksum(ChecksumSubOptions options)
|
|
||||||
{
|
|
||||||
if (isDebug)
|
|
||||||
{
|
|
||||||
Console.WriteLine("--debug={0}", options.Debug);
|
|
||||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
|
||||||
Console.WriteLine("--separated-tracks={0}", options.SeparatedTracks);
|
|
||||||
Console.WriteLine("--whole-disc={0}", options.WholeDisc);
|
|
||||||
Console.WriteLine("--input={0}", options.InputFile);
|
|
||||||
Console.WriteLine("--crc32={0}", options.DoCRC32);
|
|
||||||
Console.WriteLine("--md5={0}", options.DoMD5);
|
|
||||||
Console.WriteLine("--sha1={0}", options.DoSHA1);
|
|
||||||
Console.WriteLine("--fuzzy={0}", options.DoFuzzy);
|
|
||||||
}
|
|
||||||
throw new NotImplementedException("Checksumming not yet implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Verify(VerifySubOptions options)
|
|
||||||
{
|
|
||||||
if (isDebug)
|
|
||||||
{
|
|
||||||
Console.WriteLine("--debug={0}", options.Debug);
|
|
||||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
|
||||||
Console.WriteLine("--input={0}", options.InputFile);
|
|
||||||
Console.WriteLine("--verify-disc={0}", options.VerifyDisc);
|
|
||||||
Console.WriteLine("--verify-sectors={0}", options.VerifySectors);
|
|
||||||
}
|
|
||||||
throw new NotImplementedException("Verifying not yet implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Analyze(AnalyzeSubOptions options)
|
|
||||||
{
|
|
||||||
if (isDebug)
|
|
||||||
{
|
|
||||||
Console.WriteLine("--debug={0}", options.Debug);
|
|
||||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
|
||||||
Console.WriteLine("--input={0}", options.InputFile);
|
|
||||||
Console.WriteLine("--filesystems={0}", options.SearchForFilesystems);
|
|
||||||
Console.WriteLine("--partitions={0}", options.SearchForPartitions);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.RegisterAllPlugins();
|
|
||||||
|
|
||||||
List<string> id_plugins;
|
|
||||||
Plugin _plugin;
|
|
||||||
string information;
|
|
||||||
bool checkraw = false;
|
|
||||||
ImagePlugin _imageFormat;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_imageFormat = null;
|
|
||||||
|
|
||||||
// Check all but RAW plugin
|
|
||||||
foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
|
||||||
{
|
|
||||||
if(_imageplugin.PluginUUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
||||||
{
|
|
||||||
if (_imageplugin.IdentifyImage(options.InputFile))
|
|
||||||
{
|
|
||||||
_imageFormat = _imageplugin;
|
|
||||||
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check only RAW plugin
|
|
||||||
if (_imageFormat == null)
|
|
||||||
{
|
|
||||||
foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values)
|
|
||||||
{
|
|
||||||
if(_imageplugin.PluginUUID == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
|
||||||
{
|
|
||||||
if (_imageplugin.IdentifyImage(options.InputFile))
|
|
||||||
{
|
|
||||||
_imageFormat = _imageplugin;
|
|
||||||
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Still not recognized
|
|
||||||
if (_imageFormat == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Image format not identified, not proceeding.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_imageFormat.OpenImage(options.InputFile))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Unable to open image format");
|
|
||||||
Console.WriteLine("No error given");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDebug)
|
|
||||||
{
|
|
||||||
Console.WriteLine("DEBUG: Correctly opened image file.");
|
|
||||||
Console.WriteLine("DEBUG: Image without headers is {0} bytes.", _imageFormat.GetImageSize());
|
|
||||||
Console.WriteLine("DEBUG: Image has {0} sectors.", _imageFormat.GetSectors());
|
|
||||||
Console.WriteLine("DEBUG: Image identifies disk type as {0}.", _imageFormat.GetDiskType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Unable to open image format");
|
|
||||||
Console.WriteLine("Error: {0}", ex.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Image identified as {0}.", _imageFormat.GetImageFormat());
|
|
||||||
|
|
||||||
if (options.SearchForPartitions)
|
|
||||||
{
|
|
||||||
List<Partition> partitions = new List<Partition>();
|
|
||||||
string partition_scheme = "";
|
|
||||||
|
|
||||||
// TODO: Solve possibility of multiple partition schemes (CUE + MBR, MBR + RDB, CUE + APM, etc)
|
|
||||||
foreach (PartPlugin _partplugin in plugins.PartPluginsList.Values)
|
|
||||||
{
|
|
||||||
List<Partition> _partitions;
|
|
||||||
|
|
||||||
if (_partplugin.GetInformation(_imageFormat, out _partitions))
|
|
||||||
{
|
|
||||||
partition_scheme = _partplugin.Name;
|
|
||||||
partitions = _partitions;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_imageFormat.ImageHasPartitions())
|
|
||||||
{
|
|
||||||
partition_scheme = _imageFormat.GetImageFormat();
|
|
||||||
partitions = _imageFormat.GetPartitions();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (partition_scheme == "")
|
|
||||||
{
|
|
||||||
if(MainClass.isDebug)
|
|
||||||
Console.WriteLine("DEBUG: No partitions found");
|
|
||||||
if (!options.SearchForFilesystems)
|
|
||||||
{
|
|
||||||
Console.WriteLine("No partitions founds, not searching for filesystems");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
checkraw = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Partition scheme identified as {0}", partition_scheme);
|
|
||||||
Console.WriteLine("{0} partitions found.", partitions.Count);
|
|
||||||
|
|
||||||
for (int i = 0; i < partitions.Count; i++)
|
|
||||||
{
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("Partition {0}:", partitions[i].PartitionSequence);
|
|
||||||
Console.WriteLine("Partition name: {0}", partitions[i].PartitionName);
|
|
||||||
Console.WriteLine("Partition type: {0}", partitions[i].PartitionType);
|
|
||||||
Console.WriteLine("Partition start: sector {0}, byte {1}", partitions[i].PartitionStartSector, partitions[i].PartitionStart);
|
|
||||||
Console.WriteLine("Partition length: {0} sectors, {1} bytes", partitions[i].PartitionSectors, partitions[i].PartitionLength);
|
|
||||||
Console.WriteLine("Partition description:");
|
|
||||||
Console.WriteLine(partitions[i].PartitionDescription);
|
|
||||||
|
|
||||||
if (options.SearchForFilesystems)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Identifying filesystem on partition");
|
|
||||||
|
|
||||||
Identify(_imageFormat, out id_plugins, partitions[i].PartitionStartSector);
|
|
||||||
if (id_plugins.Count == 0)
|
|
||||||
Console.WriteLine("Filesystem not identified");
|
|
||||||
else if (id_plugins.Count > 1)
|
|
||||||
{
|
|
||||||
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
|
||||||
|
|
||||||
foreach (string plugin_name in id_plugins)
|
|
||||||
{
|
|
||||||
if (plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
|
||||||
{
|
|
||||||
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
|
||||||
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStartSector, out information);
|
|
||||||
Console.Write(information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
|
||||||
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
|
||||||
_plugin.GetInformation(_imageFormat, partitions[i].PartitionStartSector, out information);
|
|
||||||
Console.Write(information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkraw)
|
|
||||||
{
|
|
||||||
Identify(_imageFormat, out id_plugins, 0);
|
|
||||||
if (id_plugins.Count == 0)
|
|
||||||
Console.WriteLine("Filesystem not identified");
|
|
||||||
else if (id_plugins.Count > 1)
|
|
||||||
{
|
|
||||||
Console.WriteLine(String.Format("Identified by {0} plugins", id_plugins.Count));
|
|
||||||
|
|
||||||
foreach (string plugin_name in id_plugins)
|
|
||||||
{
|
|
||||||
if (plugins.PluginsList.TryGetValue(plugin_name, out _plugin))
|
|
||||||
{
|
|
||||||
Console.WriteLine(String.Format("As identified by {0}.", _plugin.Name));
|
|
||||||
_plugin.GetInformation(_imageFormat, 0, out information);
|
|
||||||
Console.Write(information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
plugins.PluginsList.TryGetValue(id_plugins[0], out _plugin);
|
|
||||||
Console.WriteLine(String.Format("Identified by {0}.", _plugin.Name));
|
|
||||||
_plugin.GetInformation(_imageFormat, 0, out information);
|
|
||||||
Console.Write(information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(String.Format("Error reading file: {0}", ex.Message));
|
|
||||||
if (isDebug)
|
|
||||||
Console.WriteLine(ex.StackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Identify(ImagePlugin imagePlugin, out List<string> id_plugins, ulong partitionOffset)
|
|
||||||
{
|
|
||||||
id_plugins = new List<string>();
|
|
||||||
|
|
||||||
foreach (Plugin _plugin in plugins.PluginsList.Values)
|
|
||||||
{
|
|
||||||
if (_plugin.Identify(imagePlugin, partitionOffset))
|
|
||||||
id_plugins.Add(_plugin.Name.ToLower());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using CommandLine.Text;
|
|||||||
|
|
||||||
namespace DiscImageChef
|
namespace DiscImageChef
|
||||||
{
|
{
|
||||||
abstract class CommonSubOptions
|
public abstract class CommonSubOptions
|
||||||
{
|
{
|
||||||
[Option('v', "verbose", DefaultValue = false, HelpText = "Shows verbose output")]
|
[Option('v', "verbose", DefaultValue = false, HelpText = "Shows verbose output")]
|
||||||
public bool Verbose { get; set; }
|
public bool Verbose { get; set; }
|
||||||
@@ -12,7 +12,7 @@ namespace DiscImageChef
|
|||||||
public bool Debug { get; set; }
|
public bool Debug { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class AnalyzeSubOptions : CommonSubOptions
|
public class AnalyzeSubOptions : CommonSubOptions
|
||||||
{
|
{
|
||||||
[Option('p', "partitions", DefaultValue = true,
|
[Option('p', "partitions", DefaultValue = true,
|
||||||
HelpText = "Searches and interprets partitions.")]
|
HelpText = "Searches and interprets partitions.")]
|
||||||
@@ -26,7 +26,7 @@ namespace DiscImageChef
|
|||||||
public string InputFile { get; set; }
|
public string InputFile { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompareSubOptions : CommonSubOptions
|
public class CompareSubOptions : CommonSubOptions
|
||||||
{
|
{
|
||||||
[Option("input1", Required = true, HelpText = "First disc image.")]
|
[Option("input1", Required = true, HelpText = "First disc image.")]
|
||||||
public string InputFile1 { get; set; }
|
public string InputFile1 { get; set; }
|
||||||
@@ -35,7 +35,7 @@ namespace DiscImageChef
|
|||||||
public string InputFile2 { get; set; }
|
public string InputFile2 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChecksumSubOptions : CommonSubOptions
|
public class ChecksumSubOptions : CommonSubOptions
|
||||||
{
|
{
|
||||||
[Option('t', "separated-tracks", DefaultValue = true,
|
[Option('t', "separated-tracks", DefaultValue = true,
|
||||||
HelpText = "Checksums each track separately.")]
|
HelpText = "Checksums each track separately.")]
|
||||||
@@ -65,7 +65,7 @@ namespace DiscImageChef
|
|||||||
public string InputFile { get; set; }
|
public string InputFile { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class VerifySubOptions : CommonSubOptions
|
public class VerifySubOptions : CommonSubOptions
|
||||||
{
|
{
|
||||||
[Option('w', "verify-disc", DefaultValue = true,
|
[Option('w', "verify-disc", DefaultValue = true,
|
||||||
HelpText = "Verify disc image if supported.")]
|
HelpText = "Verify disc image if supported.")]
|
||||||
@@ -79,11 +79,11 @@ namespace DiscImageChef
|
|||||||
public string InputFile { get; set; }
|
public string InputFile { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormatsSubOptions
|
public class FormatsSubOptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class Options
|
public class Options
|
||||||
{
|
{
|
||||||
public Options()
|
public Options()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user