Add support for byte addressable images to detection.

This commit is contained in:
2021-11-14 03:52:44 +00:00
parent 3f6fd587a1
commit 5e733abc8f
22 changed files with 2872 additions and 2842 deletions

View File

@@ -636,7 +636,7 @@ namespace Aaru.Core.Devices.Dumping
UpdateStatus?.Invoke("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError)

View File

@@ -62,7 +62,7 @@ namespace Aaru.Core.Devices.Dumping
_dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
totalChkDuration = 0;
ErrorNumber opened = inputPlugin.Open(filter);

View File

@@ -693,7 +693,7 @@ namespace Aaru.Core.Devices.Dumping
_dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError)

View File

@@ -561,7 +561,7 @@ namespace Aaru.Core.Devices.Dumping
_dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError)

View File

@@ -1314,7 +1314,7 @@ namespace Aaru.Core.Devices.Dumping
_dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError)

View File

@@ -985,7 +985,7 @@ namespace Aaru.Core.Devices.Dumping
_dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError)

View File

@@ -782,7 +782,7 @@ namespace Aaru.Core.Devices.Dumping
_dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath);
IMediaImage inputPlugin = ImageFormat.Detect(filter);
IMediaImage inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError)

View File

@@ -36,21 +36,21 @@ using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
using Aaru.Console;
namespace Aaru.Core
{
namespace Aaru.Core;
/// <summary>Core media image format operations</summary>
public static class ImageFormat
{
/// <summary>Detects the image plugin that recognizes the data inside a filter</summary>
/// <param name="imageFilter">Filter</param>
/// <returns>Detected image plugin</returns>
public static IMediaImage Detect(IFilter imageFilter)
public static IBaseImage Detect(IFilter imageFilter)
{
try
{
PluginBase plugins = GetPluginBase.Instance;
IMediaImage imageFormat = null;
IBaseImage imageFormat = null;
// Check all but RAW plugin
foreach(IMediaImage imagePlugin in plugins.ImagePluginsList.Values.Where(imagePlugin =>
@@ -75,6 +75,29 @@ namespace Aaru.Core
if(imageFormat != null)
return imageFormat;
// Check all but RAW plugin
foreach(IByteAddressableImage imagePlugin in plugins.ByteAddressableImages.Values.Where(imagePlugin =>
imagePlugin.Id != new Guid("12345678-AAAA-BBBB-CCCC-123456789000")))
try
{
AaruConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imagePlugin.Name);
if(!imagePlugin.Identify(imageFilter))
continue;
imageFormat = imagePlugin;
break;
}
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
catch
{
// ignored
}
if(imageFormat != null)
return imageFormat;
// Check only RAW plugin
foreach(IMediaImage imagePlugin in plugins.ImagePluginsList.Values.Where(imagePlugin =>
imagePlugin.Id == new Guid("12345678-AAAA-BBBB-CCCC-123456789000")))
@@ -104,4 +127,3 @@ namespace Aaru.Core
}
}
}
}

View File

@@ -523,7 +523,7 @@ namespace Aaru.Gui.ViewModels.Windows
try
{
IMediaImage imageFormat = ImageFormat.Detect(inputFilter);
IMediaImage imageFormat = ImageFormat.Detect(inputFilter) as IMediaImage;
if(imageFormat == null)
{

View File

@@ -47,7 +47,7 @@ namespace Aaru.Tests.Filesystems
Assert.IsNotNull(inputFilter, $"Filter: {testFile}");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, $"Image format: {testFile}");
@@ -123,7 +123,7 @@ namespace Aaru.Tests.Filesystems
Assert.IsNotNull(inputFilter, $"Filter: {testFile}");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, $"Image format: {testFile}");
@@ -162,7 +162,7 @@ namespace Aaru.Tests.Filesystems
Assert.IsNotNull(inputFilter, $"Filter: {testFile}");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, $"Image format: {testFile}");

View File

@@ -48,7 +48,7 @@ namespace Aaru.Tests.Filesystems
Assert.IsNotNull(inputFilter, $"Filter: {testFile}");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, $"Image format: {testFile}");
@@ -163,7 +163,7 @@ namespace Aaru.Tests.Filesystems
var filtersList = new FiltersList();
IFilter inputFilter = filtersList.GetFilter(testFile);
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
ErrorNumber opened = image.Open(inputFilter);
if(opened != ErrorNumber.NoError)

View File

@@ -48,7 +48,7 @@ namespace Aaru.Tests.Issues
PluginBase plugins = GetPluginBase.Instance;
IMediaImage imageFormat = ImageFormat.Detect(inputFilter);
IMediaImage imageFormat = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.NotNull(imageFormat, "Image format not identified, not proceeding with analysis.");

View File

@@ -42,7 +42,7 @@ namespace Aaru.Tests.Issues
PluginBase plugins = GetPluginBase.Instance;
IMediaImage imageFormat = ImageFormat.Detect(inputFilter);
IMediaImage imageFormat = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.NotNull(imageFormat, "Image format not identified, not proceeding with analysis.");

View File

@@ -29,7 +29,7 @@ namespace Aaru.Tests.Issues
Assert.IsNotNull(inputFilter, "Filter for test file is not detected");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, "Image format for test file is not detected");

View File

@@ -55,7 +55,7 @@ namespace Aaru.Tests.Issues
Assert.IsFalse(File.Exists(outputPath), "Output file already exists, not continuing.");
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
IMediaImage inputFormat = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(inputFormat, "Input image format not identified, not proceeding with conversion.");

View File

@@ -31,7 +31,7 @@ namespace Aaru.Tests.Issues
Assert.IsNotNull(inputFilter, "Filter for test file is not detected");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, "Image format for test file is not detected");

View File

@@ -36,7 +36,7 @@ namespace Aaru.Tests.Partitions
Assert.IsNotNull(inputFilter, $"Filter: {testFile}");
IMediaImage image = ImageFormat.Detect(inputFilter);
IMediaImage image = ImageFormat.Detect(inputFilter) as IMediaImage;
Assert.IsNotNull(image, $"Image format: {testFile}");

View File

@@ -46,8 +46,8 @@ using JetBrains.Annotations;
using Spectre.Console;
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
namespace Aaru.Commands.Filesystem
{
namespace Aaru.Commands.Filesystem;
internal sealed class ExtractFilesCommand : Command
{
const long BUFFER_SIZE = 16777216;
@@ -193,23 +193,31 @@ namespace Aaru.Commands.Filesystem
try
{
IMediaImage imageFormat = null;
IBaseImage baseImage = null;
Core.Spectre.ProgressSingleSpinner(ctx =>
{
ctx.AddTask("Identifying image format...").IsIndeterminate();
imageFormat = ImageFormat.Detect(inputFilter);
baseImage = ImageFormat.Detect(inputFilter);
imageFormat = baseImage as IMediaImage;
});
if(imageFormat == null)
if(baseImage == null)
{
AaruConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return (int)ErrorNumber.UnrecognizedFormat;
}
if(imageFormat == null)
{
AaruConsole.WriteLine("Command not supported for this image type.");
return (int)ErrorNumber.InvalidArgument;
}
if(verbose)
AaruConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name,
imageFormat.Id);
AaruConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name, imageFormat.Id);
else
AaruConsole.WriteLine("Image format identified by {0}.", imageFormat.Name);
@@ -253,8 +261,7 @@ namespace Aaru.Commands.Filesystem
AaruConsole.DebugWriteLine("Extract-Files command", "Image without headers is {0} bytes.",
imageFormat.Info.ImageSize);
AaruConsole.DebugWriteLine("Extract-Files command", "Image has {0} sectors.",
imageFormat.Info.Sectors);
AaruConsole.DebugWriteLine("Extract-Files command", "Image has {0} sectors.", imageFormat.Info.Sectors);
AaruConsole.DebugWriteLine("Extract-Files command", "Image identifies disk type as {0}.",
imageFormat.Info.MediaType);
@@ -349,8 +356,7 @@ namespace Aaru.Commands.Filesystem
Statistics.AddFilesystem(fs.XmlFsType.Type);
}
else
AaruConsole.ErrorWriteLine("Unable to mount device, error {0}",
error.ToString());
AaruConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString());
}
}
else
@@ -398,8 +404,8 @@ namespace Aaru.Commands.Filesystem
return (int)ErrorNumber.NoError;
}
static void ExtractFilesInDir(string path, [NotNull] IReadOnlyFilesystem fs, string volumeName,
string outputDir, bool doXattrs)
static void ExtractFilesInDir(string path, [NotNull] IReadOnlyFilesystem fs, string volumeName, string outputDir,
bool doXattrs)
{
if(path.StartsWith('/'))
path = path.Substring(1);
@@ -500,8 +506,7 @@ namespace Aaru.Commands.Filesystem
if(error != ErrorNumber.NoError)
continue;
outputPath = Path.Combine(outputDir, fs.XmlFsType.Type, volumeName, ".xattrs", path,
xattr);
outputPath = Path.Combine(outputDir, fs.XmlFsType.Type, volumeName, ".xattrs", path, xattr);
Directory.CreateDirectory(outputPath);
@@ -513,8 +518,8 @@ namespace Aaru.Commands.Filesystem
{
ctx.AddTask("Writing extended attribute...").IsIndeterminate();
outputFile = new FileStream(outputPath, FileMode.CreateNew,
FileAccess.ReadWrite, FileShare.None);
outputFile = new FileStream(outputPath, FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.None);
outputFile.Write(xattrBuf, 0, xattrBuf.Length);
outputFile.Close();
@@ -571,12 +576,11 @@ namespace Aaru.Commands.Filesystem
{
long position = 0;
outputFile = new FileStream(outputPath, FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.None);
outputFile = new FileStream(outputPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
AnsiConsole.Progress().AutoClear(true).HideCompleted(true).
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(),
new PercentageColumn()).Start(ctx =>
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
Start(ctx =>
{
ProgressTask task = ctx.AddTask($"Reading file {Markup.Escape(entry)}...");
@@ -654,4 +658,3 @@ namespace Aaru.Commands.Filesystem
}
}
}
}

View File

@@ -42,8 +42,8 @@ using Aaru.Console;
using Aaru.Core;
using Spectre.Console;
namespace Aaru.Commands.Filesystem
{
namespace Aaru.Commands.Filesystem;
internal sealed class FilesystemInfoCommand : Command
{
public FilesystemInfoCommand() : base("info",
@@ -165,23 +165,31 @@ namespace Aaru.Commands.Filesystem
try
{
IMediaImage imageFormat = null;
IBaseImage baseImage = null;
Core.Spectre.ProgressSingleSpinner(ctx =>
{
ctx.AddTask("Identifying image format...").IsIndeterminate();
imageFormat = ImageFormat.Detect(inputFilter);
baseImage = ImageFormat.Detect(inputFilter);
imageFormat = baseImage as IMediaImage;
});
if(imageFormat == null)
if(baseImage == null)
{
AaruConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return (int)ErrorNumber.UnrecognizedFormat;
}
if(imageFormat == null)
{
AaruConsole.WriteLine("Command not supported for this image type.");
return (int)ErrorNumber.InvalidArgument;
}
if(verbose)
AaruConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name,
imageFormat.Id);
AaruConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name, imageFormat.Id);
else
AaruConsole.WriteLine("Image format identified by {0}.", imageFormat.Name);
@@ -269,8 +277,7 @@ namespace Aaru.Commands.Filesystem
table.AddRow("Type", Markup.Escape(partitionsList[i].Type ?? ""));
table.AddRow("Start", $"sector {partitionsList[i].Start}, byte {partitionsList[i].Offset}");
table.AddRow("Length",
$"{partitionsList[i].Length} sectors, {partitionsList[i].Size} bytes");
table.AddRow("Length", $"{partitionsList[i].Length} sectors, {partitionsList[i].Size} bytes");
table.AddRow("Scheme", Markup.Escape(partitionsList[i].Scheme ?? ""));
table.AddRow("Description", Markup.Escape(partitionsList[i].Description ?? ""));
@@ -377,4 +384,3 @@ namespace Aaru.Commands.Filesystem
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -45,8 +45,8 @@ using Aaru.Core;
using JetBrains.Annotations;
using Spectre.Console;
namespace Aaru.Commands.Filesystem
{
namespace Aaru.Commands.Filesystem;
internal sealed class LsCommand : Command
{
public LsCommand() : base("list", "Lists files in disc image.")
@@ -182,23 +182,31 @@ namespace Aaru.Commands.Filesystem
try
{
IMediaImage imageFormat = null;
IBaseImage baseImage = null;
Core.Spectre.ProgressSingleSpinner(ctx =>
{
ctx.AddTask("Identifying image format...").IsIndeterminate();
imageFormat = ImageFormat.Detect(inputFilter);
baseImage = ImageFormat.Detect(inputFilter);
imageFormat = baseImage as IMediaImage;
});
if(imageFormat == null)
if(baseImage == null)
{
AaruConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return (int)ErrorNumber.UnrecognizedFormat;
}
if(imageFormat == null)
{
AaruConsole.WriteLine("Command not supported for this image type.");
return (int)ErrorNumber.InvalidArgument;
}
if(verbose)
AaruConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name,
imageFormat.Id);
AaruConsole.VerboseWriteLine("Image format identified by {0} ({1}).", imageFormat.Name, imageFormat.Id);
else
AaruConsole.WriteLine("Image format identified by {0}.", imageFormat.Name);
@@ -320,8 +328,7 @@ namespace Aaru.Commands.Filesystem
Statistics.AddFilesystem(fs.XmlFsType.Type);
}
else
AaruConsole.ErrorWriteLine("Unable to mount device, error {0}",
error.ToString());
AaruConsole.ErrorWriteLine("Unable to mount device, error {0}", error.ToString());
}
}
else
@@ -395,8 +402,7 @@ namespace Aaru.Commands.Filesystem
Dictionary<string, FileEntryInfo> stats = new();
AnsiConsole.Progress().AutoClear(true).HideCompleted(true).
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
Start(ctx =>
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).Start(ctx =>
{
ProgressTask task = ctx.AddTask("Retrieving file information...");
task.MaxValue = directory.Count;
@@ -420,9 +426,8 @@ namespace Aaru.Commands.Filesystem
AaruConsole.WriteLine("{0, 10:d} {0, 12:T} {1, -20} {2}", entry.Value.CreationTimeUtc,
"<DIR>", Markup.Escape(entry.Key));
else
AaruConsole.WriteLine("{0, 10:d} {0, 12:T} {1, 6}{2, 14:N0} {3}",
entry.Value.CreationTimeUtc, entry.Value.Inode, entry.Value.Length,
Markup.Escape(entry.Key));
AaruConsole.WriteLine("{0, 10:d} {0, 12:T} {1, 6}{2, 14:N0} {3}", entry.Value.CreationTimeUtc,
entry.Value.Inode, entry.Value.Length, Markup.Escape(entry.Key));
error = fs.ListXAttr(path + "/" + entry.Key, out List<string> xattrs);
@@ -455,4 +460,3 @@ namespace Aaru.Commands.Filesystem
ListFilesInDir(path + "/" + subdirectory.Key, fs, longFormat);
}
}
}

View File

@@ -53,8 +53,8 @@ using ImageInfo = Aaru.CommonTypes.Structs.ImageInfo;
using MediaType = Aaru.CommonTypes.MediaType;
using Version = Aaru.CommonTypes.Interop.Version;
namespace Aaru.Commands.Image
{
namespace Aaru.Commands.Image;
internal sealed class ConvertImageCommand : Command
{
public ConvertImageCommand() : base("convert", "Converts one image to another format.")
@@ -109,8 +109,7 @@ namespace Aaru.Commands.Image
Required = false
});
Add(new Option("--drive-serial",
"Serial number of the drive used to read the media represented by the image.")
Add(new Option("--drive-serial", "Serial number of the drive used to read the media represented by the image.")
{
Argument = new Argument<string>(() => null),
Required = false
@@ -267,9 +266,9 @@ namespace Aaru.Commands.Image
public static int Invoke(bool verbose, bool debug, string cicmXml, string comments, int count, string creator,
string driveFirmwareRevision, string driveManufacturer, string driveModel,
string driveSerialNumber, bool force, string inputPath, int lastMediaSequence,
string mediaBarcode, string mediaManufacturer, string mediaModel,
string mediaPartNumber, int mediaSequence, string mediaSerialNumber, string mediaTitle,
string outputPath, string options, string resumeFile, string format, string geometry,
string mediaBarcode, string mediaManufacturer, string mediaModel, string mediaPartNumber,
int mediaSequence, string mediaSerialNumber, string mediaTitle, string outputPath,
string options, string resumeFile, string format, string geometry,
bool fixSubchannelPosition, bool fixSubchannel, bool fixSubchannelCrc,
bool generateSubchannels)
{
@@ -469,11 +468,13 @@ namespace Aaru.Commands.Image
PluginBase plugins = GetPluginBase.Instance;
IMediaImage inputFormat = null;
IBaseImage baseImage = null;
Core.Spectre.ProgressSingleSpinner(ctx =>
{
ctx.AddTask("Identifying image format...").IsIndeterminate();
inputFormat = ImageFormat.Detect(inputFilter);
baseImage = ImageFormat.Detect(inputFilter);
inputFormat = baseImage as IMediaImage;
});
if(inputFormat == null)
@@ -483,6 +484,14 @@ namespace Aaru.Commands.Image
return (int)ErrorNumber.UnrecognizedFormat;
}
// TODO: Implement
if(inputFormat == null)
{
AaruConsole.WriteLine("Command not yet supported for this image type.");
return (int)ErrorNumber.InvalidArgument;
}
if(verbose)
AaruConsole.VerboseWriteLine("Input image format identified by {0} ({1}).", inputFormat.Name,
inputFormat.Id);
@@ -744,8 +753,7 @@ namespace Aaru.Commands.Image
AaruConsole.ErrorWriteLine("Error {0} reading media tag, continuing...", errno);
else
{
AaruConsole.ErrorWriteLine("Error {0} writing media tag, not continuing...",
errno);
AaruConsole.ErrorWriteLine("Error {0} writing media tag, not continuing...", errno);
ErrorNumber = errno;
}
@@ -781,8 +789,7 @@ namespace Aaru.Commands.Image
{
if(!outputOptical.SetTracks(inputOptical.Tracks))
{
AaruConsole.ErrorWriteLine("Error {0} sending tracks list to output image.",
outputFormat.ErrorMessage);
AaruConsole.ErrorWriteLine("Error {0} sending tracks list to output image.", outputFormat.ErrorMessage);
return (int)ErrorNumber.WriteError;
}
@@ -844,8 +851,8 @@ namespace Aaru.Commands.Image
if(force)
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, continuing...",
errno, doneSectors + track.StartSector);
ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
doneSectors + track.StartSector);
else
{
AaruConsole.
@@ -897,8 +904,8 @@ namespace Aaru.Commands.Image
if(force)
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, continuing...",
errno, doneSectors + track.StartSector);
ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
doneSectors + track.StartSector);
else
{
AaruConsole.
@@ -914,8 +921,7 @@ namespace Aaru.Commands.Image
if(!result)
if(force)
AaruConsole.
ErrorWriteLine("Error {0} writing sector {1}, continuing...",
AaruConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
outputFormat.ErrorMessage,
doneSectors + track.StartSector);
else
@@ -970,8 +976,8 @@ namespace Aaru.Commands.Image
tracks[i].Indexes[idx.Key] = idx.Value;
}
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.
Where(t => t == SectorTagType.CdTrackIsrc).OrderBy(t => t))
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.Where(t => t == SectorTagType.CdTrackIsrc).
OrderBy(t => t))
{
foreach(Track track in tracks)
{
@@ -1006,8 +1012,7 @@ namespace Aaru.Commands.Image
subchannelExtents.Add((int)s);
}
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.OrderBy(t => t).
TakeWhile(tag => useLong))
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.OrderBy(t => t).TakeWhile(tag => useLong))
{
switch(tag)
{
@@ -1054,6 +1059,7 @@ namespace Aaru.Commands.Image
if(errno == ErrorNumber.NoData)
{
errno = ErrorNumber.NoError;
continue;
}
@@ -1063,15 +1069,13 @@ namespace Aaru.Commands.Image
{
if(force)
{
AaruConsole.
ErrorWriteLine("Error {0} writing tag, continuing...",
AaruConsole.ErrorWriteLine("Error {0} writing tag, continuing...",
outputFormat.ErrorMessage);
continue;
}
AaruConsole.
ErrorWriteLine("Error {0} writing tag, not continuing...",
AaruConsole.ErrorWriteLine("Error {0} writing tag, not continuing...",
outputFormat.ErrorMessage);
errno = ErrorNumber.WriteError;
@@ -1081,8 +1085,7 @@ namespace Aaru.Commands.Image
if(!result)
if(force)
AaruConsole.
ErrorWriteLine("Error {0} writing tag, continuing...",
AaruConsole.ErrorWriteLine("Error {0} writing tag, continuing...",
outputFormat.ErrorMessage);
else
{
@@ -1113,8 +1116,8 @@ namespace Aaru.Commands.Image
trackTask.Description =
string.Format("Converting tag {3} for sectors {0} to {1} in track {2}",
doneSectors + track.StartSector,
doneSectors + sectorsToDo + track.StartSector,
track.Sequence, tag);
doneSectors + sectorsToDo + track.StartSector, track.Sequence,
tag);
if(sectorsToDo == 1)
{
@@ -1130,9 +1133,9 @@ namespace Aaru.Commands.Image
MmcSubchannel.Raw, sector,
doneSectors + track.StartSector, 1, null, isrcs,
(byte)track.Sequence, ref mcn, tracks,
subchannelExtents, fixSubchannelPosition,
outputFormat, fixSubchannel, fixSubchannelCrc,
null, null, smallestPregapLbaPerTrack, false);
subchannelExtents, fixSubchannelPosition, outputFormat,
fixSubchannel, fixSubchannelCrc, null, null,
smallestPregapLbaPerTrack, false);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());
@@ -1176,9 +1179,9 @@ namespace Aaru.Commands.Image
MmcSubchannel.Raw, sector,
doneSectors + track.StartSector, sectorsToDo, null,
isrcs, (byte)track.Sequence, ref mcn, tracks,
subchannelExtents, fixSubchannelPosition,
outputFormat, fixSubchannel, fixSubchannelCrc,
null, null, smallestPregapLbaPerTrack, false);
subchannelExtents, fixSubchannelPosition, outputFormat,
fixSubchannel, fixSubchannelCrc, null, null,
smallestPregapLbaPerTrack, false);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());
@@ -1236,7 +1239,8 @@ namespace Aaru.Commands.Image
}
});
if(errno != ErrorNumber.NoError && !force)
if(errno != ErrorNumber.NoError &&
!force)
return (int)errno;
}
@@ -1265,21 +1269,19 @@ namespace Aaru.Commands.Image
inputFormat.Info.MediaType == MediaType.VCD || inputFormat.Info.MediaType == MediaType.SVCD ||
inputFormat.Info.MediaType == MediaType.PCD || inputFormat.Info.MediaType == MediaType.DTSCD ||
inputFormat.Info.MediaType == MediaType.CDMIDI || inputFormat.Info.MediaType == MediaType.CDV ||
inputFormat.Info.MediaType == MediaType.CDIREADY ||
inputFormat.Info.MediaType == MediaType.FMTOWNS || inputFormat.Info.MediaType == MediaType.PS1CD ||
inputFormat.Info.MediaType == MediaType.PS2CD || inputFormat.Info.MediaType == MediaType.MEGACD ||
inputFormat.Info.MediaType == MediaType.SATURNCD || inputFormat.Info.MediaType == MediaType.GDROM ||
inputFormat.Info.MediaType == MediaType.GDR || inputFormat.Info.MediaType == MediaType.MilCD ||
inputFormat.Info.MediaType == MediaType.SuperCDROM2 ||
inputFormat.Info.MediaType == MediaType.JaguarCD ||
inputFormat.Info.MediaType == MediaType.ThreeDO || inputFormat.Info.MediaType == MediaType.PCFX ||
inputFormat.Info.MediaType == MediaType.NeoGeoCD || inputFormat.Info.MediaType == MediaType.CDTV ||
inputFormat.Info.MediaType == MediaType.CD32 || inputFormat.Info.MediaType == MediaType.Playdia ||
inputFormat.Info.MediaType == MediaType.Pippin ||
inputFormat.Info.MediaType == MediaType.CDIREADY || inputFormat.Info.MediaType == MediaType.FMTOWNS ||
inputFormat.Info.MediaType == MediaType.PS1CD || inputFormat.Info.MediaType == MediaType.PS2CD ||
inputFormat.Info.MediaType == MediaType.MEGACD || inputFormat.Info.MediaType == MediaType.SATURNCD ||
inputFormat.Info.MediaType == MediaType.GDROM || inputFormat.Info.MediaType == MediaType.GDR ||
inputFormat.Info.MediaType == MediaType.MilCD || inputFormat.Info.MediaType == MediaType.SuperCDROM2 ||
inputFormat.Info.MediaType == MediaType.JaguarCD || inputFormat.Info.MediaType == MediaType.ThreeDO ||
inputFormat.Info.MediaType == MediaType.PCFX || inputFormat.Info.MediaType == MediaType.NeoGeoCD ||
inputFormat.Info.MediaType == MediaType.CDTV || inputFormat.Info.MediaType == MediaType.CD32 ||
inputFormat.Info.MediaType == MediaType.Playdia || inputFormat.Info.MediaType == MediaType.Pippin ||
inputFormat.Info.MediaType == MediaType.VideoNow ||
inputFormat.Info.MediaType == MediaType.VideoNowColor ||
inputFormat.Info.MediaType == MediaType.VideoNowXp ||
inputFormat.Info.MediaType == MediaType.CVD) && generateSubchannels)
inputFormat.Info.MediaType == MediaType.VideoNowXp || inputFormat.Info.MediaType == MediaType.CVD) &&
generateSubchannels)
{
Core.Spectre.ProgressSingleSpinner(ctx =>
{
@@ -1342,23 +1344,20 @@ namespace Aaru.Commands.Image
: inputFormat.ReadSectorsLong(doneSectors, sectorsToDo, out sector);
if(errno == ErrorNumber.NoError)
result = sectorsToDo == 1
? outputFormat.WriteSectorLong(sector, doneSectors)
: outputFormat.WriteSectorsLong(sector, doneSectors,
sectorsToDo);
result = sectorsToDo == 1 ? outputFormat.WriteSectorLong(sector, doneSectors)
: outputFormat.WriteSectorsLong(sector, doneSectors, sectorsToDo);
else
{
result = true;
if(force)
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
doneSectors);
AaruConsole.ErrorWriteLine("Error {0} reading sector {1}, continuing...",
errno, doneSectors);
else
{
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, not continuing...",
errno, doneSectors);
ErrorWriteLine("Error {0} reading sector {1}, not continuing...", errno,
doneSectors);
return;
}
@@ -1377,14 +1376,13 @@ namespace Aaru.Commands.Image
result = true;
if(force)
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
doneSectors);
AaruConsole.ErrorWriteLine("Error {0} reading sector {1}, continuing...",
errno, doneSectors);
else
{
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, not continuing...",
errno, doneSectors);
ErrorWriteLine("Error {0} reading sector {1}, not continuing...", errno,
doneSectors);
return;
}
@@ -1397,8 +1395,7 @@ namespace Aaru.Commands.Image
outputFormat.ErrorMessage, doneSectors);
else
{
AaruConsole.
ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
AaruConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
errno = ErrorNumber.WriteError;
@@ -1412,8 +1409,7 @@ namespace Aaru.Commands.Image
mediaTask.StopTask();
foreach(SectorTagType tag in
inputFormat.Info.ReadableSectorTags.TakeWhile(tag => useLong))
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.TakeWhile(tag => useLong))
{
switch(tag)
{
@@ -1454,29 +1450,26 @@ namespace Aaru.Commands.Image
bool result;
errno = sectorsToDo == 1
? inputFormat.ReadSectorTag(doneSectors, tag, out sector)
: inputFormat.ReadSectorsTag(doneSectors, sectorsToDo, tag,
out sector);
errno = sectorsToDo == 1 ? inputFormat.ReadSectorTag(doneSectors, tag, out sector)
: inputFormat.ReadSectorsTag(doneSectors, sectorsToDo, tag, out sector);
if(errno == ErrorNumber.NoError)
result = sectorsToDo == 1
? outputFormat.WriteSectorTag(sector, doneSectors, tag)
: outputFormat.WriteSectorsTag(sector, doneSectors,
sectorsToDo, tag);
: outputFormat.WriteSectorsTag(sector, doneSectors, sectorsToDo,
tag);
else
{
result = true;
if(force)
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, continuing...", errno,
doneSectors);
AaruConsole.ErrorWriteLine("Error {0} reading sector {1}, continuing...",
errno, doneSectors);
else
{
AaruConsole.
ErrorWriteLine("Error {0} reading sector {1}, not continuing...",
errno, doneSectors);
ErrorWriteLine("Error {0} reading sector {1}, not continuing...", errno,
doneSectors);
return;
}
@@ -1484,8 +1477,7 @@ namespace Aaru.Commands.Image
if(!result)
if(force)
AaruConsole.
ErrorWriteLine("Error {0} writing sector {1}, continuing...",
AaruConsole.ErrorWriteLine("Error {0} writing sector {1}, continuing...",
outputFormat.ErrorMessage, doneSectors);
else
{
@@ -1598,4 +1590,3 @@ namespace Aaru.Commands.Image
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -42,8 +42,8 @@ using Aaru.Decoders.CD;
using Aaru.Decoders.SCSI;
using Spectre.Console;
namespace Aaru.Commands.Image
{
namespace Aaru.Commands.Image;
internal sealed class DecodeCommand : Command
{
public DecodeCommand() : base("decode", "Decodes and pretty prints disk and/or sector tags.")
@@ -94,8 +94,8 @@ namespace Aaru.Commands.Image
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)));
}
public static int Invoke(bool verbose, bool debug, bool diskTags, string imagePath, string length,
bool sectorTags, ulong startSector)
public static int Invoke(bool verbose, bool debug, bool diskTags, string imagePath, string length, bool sectorTags,
ulong startSector)
{
MainClass.PrintCopyright();
@@ -151,20 +151,29 @@ namespace Aaru.Commands.Image
}
IMediaImage inputFormat = null;
IBaseImage baseImage = null;
Core.Spectre.ProgressSingleSpinner(ctx =>
{
ctx.AddTask("Identifying image format...").IsIndeterminate();
inputFormat = ImageFormat.Detect(inputFilter);
baseImage = ImageFormat.Detect(inputFilter);
inputFormat = baseImage as IMediaImage;
});
if(inputFormat == null)
if(baseImage == null)
{
AaruConsole.ErrorWriteLine("Unable to recognize image format, not decoding");
return (int)ErrorNumber.UnrecognizedFormat;
}
if(inputFormat == null)
{
AaruConsole.WriteLine("Command not supported for this image type.");
return (int)ErrorNumber.InvalidArgument;
}
ErrorNumber opened = ErrorNumber.NoData;
Core.Spectre.ProgressSingleSpinner(ctx =>
@@ -197,8 +206,7 @@ namespace Aaru.Commands.Image
errno = inputFormat.ReadMediaTag(MediaTagType.SCSI_INQUIRY, out byte[] inquiry);
if(inquiry == null)
AaruConsole.WriteLine("Error {0} reading SCSI INQUIRY response from disc image",
errno);
AaruConsole.WriteLine("Error {0} reading SCSI INQUIRY response from disc image", errno);
else
{
AaruConsole.WriteLine("[bold]SCSI INQUIRY command response:[/]");
@@ -219,8 +227,7 @@ namespace Aaru.Commands.Image
errno = inputFormat.ReadMediaTag(MediaTagType.ATA_IDENTIFY, out byte[] identify);
if(errno != ErrorNumber.NoError)
AaruConsole.
WriteLine("Error {0} reading ATA IDENTIFY DEVICE response from disc image",
AaruConsole.WriteLine("Error {0} reading ATA IDENTIFY DEVICE response from disc image",
errno);
else
{
@@ -388,8 +395,7 @@ namespace Aaru.Commands.Image
break;
}
default:
AaruConsole.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.",
tag);
AaruConsole.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.", tag);
break;
}
@@ -415,8 +421,7 @@ namespace Aaru.Commands.Image
switch(tag)
{
default:
AaruConsole.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.",
tag);
AaruConsole.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.", tag);
break;
}
@@ -427,4 +432,3 @@ namespace Aaru.Commands.Image
return (int)ErrorNumber.NoError;
}
}
}