Remove all image thrown exceptions.

This commit is contained in:
2021-09-21 04:55:28 +01:00
parent f0c3653158
commit 42597b89cf
49 changed files with 934 additions and 395 deletions

View File

@@ -33,6 +33,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
@@ -50,7 +51,7 @@ namespace Aaru.Filesystems
var defsReader = var defsReader =
XmlReader.Create(Assembly.GetExecutingAssembly(). XmlReader.Create(Assembly.GetExecutingAssembly().
GetManifestResourceStream("Aaru.Filesystems.CPM.cpmdefs.xml") ?? GetManifestResourceStream("Aaru.Filesystems.CPM.cpmdefs.xml") ??
throw new InvalidOperationException()); new MemoryStream());
var defsSerializer = new XmlSerializer(typeof(CpmDefinitions)); var defsSerializer = new XmlSerializer(typeof(CpmDefinitions));
_definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader); _definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader);

View File

@@ -43,7 +43,6 @@ using System.Xml.Serialization;
using Aaru.Checksums; using Aaru.Checksums;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Console; using Aaru.Console;
using Aaru.Decoders; using Aaru.Decoders;
@@ -639,8 +638,10 @@ namespace Aaru.DiscImages
break; break;
default: default:
throw new ErrorMessage =
ImageNotSupportedException($"Found unsupported compression algorithm {(ushort)ddtHeader.compression}"); $"Found unsupported compression algorithm {(ushort)ddtHeader.compression}";
return false;
} }
if(IsTape) if(IsTape)
@@ -706,8 +707,10 @@ namespace Aaru.DiscImages
break; break;
default: default:
throw new ErrorMessage =
ImageNotSupportedException($"Found unsupported compression algorithm {(ushort)ddtHeader.compression}"); $"Found unsupported compression algorithm {(ushort)ddtHeader.compression}";
return false;
} }
uint[] cdDdt = MemoryMarshal.Cast<byte, uint>(decompressedDdt).ToArray(); uint[] cdDdt = MemoryMarshal.Cast<byte, uint>(decompressedDdt).ToArray();

View File

@@ -37,7 +37,6 @@ using System.Linq;
using System.Text; using System.Text;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Decoders.CD; using Aaru.Decoders.CD;
@@ -1491,13 +1490,8 @@ namespace Aaru.DiscImages
} }
/// <inheritdoc /> /// <inheritdoc />
public List<CommonTypes.Structs.Track> GetSessionTracks(CommonTypes.Structs.Session session) public List<CommonTypes.Structs.Track> GetSessionTracks(CommonTypes.Structs.Session session) =>
{ Sessions.Contains(session) ? GetSessionTracks(session.Sequence) : null;
if(Sessions.Contains(session))
return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image");
}
/// <inheritdoc /> /// <inheritdoc />
public List<CommonTypes.Structs.Track> GetSessionTracks(ushort session) public List<CommonTypes.Structs.Track> GetSessionTracks(ushort session)

View File

@@ -33,7 +33,6 @@
using System.IO; using System.IO;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -93,8 +92,7 @@ namespace Aaru.DiscImages
case RecordType.Sector: case RecordType.Sector:
if(record.compression != CompressType.Compressed && if(record.compression != CompressType.Compressed &&
record.compression != CompressType.Uncompresed) record.compression != CompressType.Uncompresed)
throw new return ErrorNumber.NotSupported;
ImageNotSupportedException($"Found record with unknown compression type 0x{(ushort)record.compression:X4} at {stream.Position}");
AaruConsole.DebugWriteLine("Apridisk plugin", AaruConsole.DebugWriteLine("Apridisk plugin",
"Found {4} sector record at {0} for cylinder {1} head {2} sector {3}", "Found {4} sector record at {0} for cylinder {1} head {2} sector {3}",
@@ -114,9 +112,7 @@ namespace Aaru.DiscImages
stream.Seek(record.headerSize - recordSize + record.dataSize, SeekOrigin.Current); stream.Seek(record.headerSize - recordSize + record.dataSize, SeekOrigin.Current);
break; break;
default: default: return ErrorNumber.NotSupported;
throw new
ImageNotSupportedException($"Found record with unknown type 0x{(uint)record.type:X8} at {stream.Position}");
} }
} }
@@ -125,7 +121,7 @@ namespace Aaru.DiscImages
if(totalCylinders <= 0 || if(totalCylinders <= 0 ||
totalHeads <= 0) totalHeads <= 0)
throw new ImageNotSupportedException("No cylinders or heads found"); return ErrorNumber.NotSupported;
_sectorsData = new byte[totalCylinders][][][]; _sectorsData = new byte[totalCylinders][][][];

View File

@@ -38,7 +38,6 @@ using System.Linq;
using System.Text; using System.Text;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Console; using Aaru.Console;
@@ -826,8 +825,7 @@ namespace Aaru.DiscImages
return ErrorNumber.NoError; return ErrorNumber.NoError;
} }
default: default: return ErrorNumber.NotSupported;
throw new FeatureSupportedButNotImplementedImageException("Feature not supported by image format");
} }
} }
@@ -1243,7 +1241,7 @@ namespace Aaru.DiscImages
if(Sessions.Contains(session)) if(Sessions.Contains(session))
return GetSessionTracks(session.Sequence); return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -38,7 +38,6 @@ using System.Linq;
using System.Text; using System.Text;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.CommonTypes.Structs.Devices.SCSI.Modes; using Aaru.CommonTypes.Structs.Devices.SCSI.Modes;
@@ -2215,7 +2214,7 @@ namespace Aaru.DiscImages
if(Sessions.Contains(session)) if(Sessions.Contains(session))
return GetSessionTracks(session.Sequence); return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -84,7 +84,7 @@ namespace Aaru.DiscImages
{ {
string line = _tocStream.ReadLine(); string line = _tocStream.ReadLine();
Match dm = dr.Match(line ?? throw new InvalidOperationException()); Match dm = dr.Match(line ?? "");
Match cm = cr.Match(line); Match cm = cr.Match(line);
// Skip comments at start of file // Skip comments at start of file

View File

@@ -121,7 +121,7 @@ namespace Aaru.DiscImages
lineNumber++; lineNumber++;
line = _tocStream.ReadLine(); line = _tocStream.ReadLine();
matchDiskType = regexDiskType.Match(line ?? throw new InvalidOperationException()); matchDiskType = regexDiskType.Match(line ?? "");
matchComment = regexComment.Match(line); matchComment = regexComment.Match(line);
// Skip comments at start of file // Skip comments at start of file
@@ -149,7 +149,7 @@ namespace Aaru.DiscImages
lineNumber++; lineNumber++;
line = _tocStream.ReadLine(); line = _tocStream.ReadLine();
matchComment = regexComment.Match(line ?? throw new InvalidOperationException()); matchComment = regexComment.Match(line ?? "");
matchDiskType = regexDiskType.Match(line); matchDiskType = regexDiskType.Match(line);
Match matchMcn = regexMcn.Match(line); Match matchMcn = regexMcn.Match(line);
Match matchTrack = regexTrack.Match(line); Match matchTrack = regexTrack.Match(line);
@@ -1532,7 +1532,7 @@ namespace Aaru.DiscImages
if(session == 1) if(session == 1)
return Tracks; return Tracks;
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
} }
} }

View File

@@ -40,7 +40,7 @@ namespace Aaru.DiscImages
{ {
public sealed partial class CdrWin public sealed partial class CdrWin
{ {
// Due to .cue format, this method must parse whole file, ignoring errors (those will be thrown by OpenImage()). // Due to .cue format, this method must parse whole file, ignoring errors (those will be returned by OpenImage()).
/// <inheritdoc /> /// <inheritdoc />
public bool Identify(IFilter imageFilter) public bool Identify(IFilter imageFilter)
{ {
@@ -91,7 +91,7 @@ namespace Aaru.DiscImages
var tr = new Regex(REGEX_CDTEXT); var tr = new Regex(REGEX_CDTEXT);
// First line must be SESSION, REM, CATALOG, FILE or CDTEXTFILE. // First line must be SESSION, REM, CATALOG, FILE or CDTEXTFILE.
Match sm = sr.Match(line ?? throw new InvalidOperationException()); Match sm = sr.Match(line ?? "");
Match rm = rr.Match(line); Match rm = rr.Match(line);
Match cm = cr.Match(line); Match cm = cr.Match(line);
Match fm = fr.Match(line); Match fm = fr.Match(line);

View File

@@ -38,7 +38,6 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Console; using Aaru.Console;
@@ -144,14 +143,21 @@ namespace Aaru.DiscImages
uint trackSeq = uint.Parse(matchTrack.Groups[1].Value); uint trackSeq = uint.Parse(matchTrack.Groups[1].Value);
if(trackCount + 1 != trackSeq) if(trackCount + 1 != trackSeq)
throw new {
FeatureUnsupportedImageException($"Found TRACK {trackSeq} out of order in line {lineNumber}"); AaruConsole.ErrorWriteLine($"Found TRACK {trackSeq} out of order in line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
trackCount++; trackCount++;
} }
if(trackCount == 0) if(trackCount == 0)
throw new FeatureUnsupportedImageException("No tracks found"); {
AaruConsole.ErrorWriteLine("No tracks found");
return ErrorNumber.InvalidArgument;
}
CdrWinTrack[] cueTracks = new CdrWinTrack[trackCount]; CdrWinTrack[] cueTracks = new CdrWinTrack[trackCount];
@@ -458,8 +464,12 @@ namespace Aaru.DiscImages
if(!inTrack) if(!inTrack)
_discImage.Barcode = matchBarCode.Groups[1].Value; _discImage.Barcode = matchBarCode.Groups[1].Value;
else else
throw new {
FeatureUnsupportedImageException($"Found barcode field in incorrect place at line {lineNumber}"); AaruConsole.
ErrorWriteLine($"Found barcode field in incorrect place at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
} }
else if(matchCdText.Success) else if(matchCdText.Success)
{ {
@@ -468,8 +478,12 @@ namespace Aaru.DiscImages
if(!inTrack) if(!inTrack)
_discImage.CdTextFile = matchCdText.Groups[1].Value; _discImage.CdTextFile = matchCdText.Groups[1].Value;
else else
throw new {
FeatureUnsupportedImageException($"Found CD-Text file field in incorrect place at line {lineNumber}"); AaruConsole.
ErrorWriteLine($"Found CD-Text file field in incorrect place at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
} }
else if(matchComposer.Success) else if(matchComposer.Success)
{ {
@@ -487,8 +501,12 @@ namespace Aaru.DiscImages
if(!inTrack) if(!inTrack)
_discImage.DiscId = matchDiskId.Groups[1].Value; _discImage.DiscId = matchDiskId.Groups[1].Value;
else else
throw new {
FeatureUnsupportedImageException($"Found CDDB ID field in incorrect place at line {lineNumber}"); AaruConsole.
ErrorWriteLine($"Found CDDB ID field in incorrect place at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
} }
else if(matchFile.Success) else if(matchFile.Success)
{ {
@@ -541,13 +559,20 @@ namespace Aaru.DiscImages
currentFile.DataFilter = filtersList.GetFilter(path); currentFile.DataFilter = filtersList.GetFilter(path);
if(currentFile.DataFilter == null) if(currentFile.DataFilter == null)
throw new {
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found."); AaruConsole.
ErrorWriteLine($"File \"{matchFile.Groups[1].Value}\" not found.");
return ErrorNumber.NoSuchFile;
}
} }
} }
else else
throw new {
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found."); AaruConsole.ErrorWriteLine($"File \"{matchFile.Groups[1].Value}\" not found.");
return ErrorNumber.NoSuchFile;
}
} }
else if((datafile[1] == ':' && datafile[2] == '\\') || else if((datafile[1] == ':' && datafile[2] == '\\') ||
(datafile[0] == '\\' && datafile[1] == '\\') || (datafile[0] == '\\' && datafile[1] == '\\') ||
@@ -571,13 +596,20 @@ namespace Aaru.DiscImages
currentFile.DataFilter = filtersList.GetFilter(path); currentFile.DataFilter = filtersList.GetFilter(path);
if(currentFile.DataFilter == null) if(currentFile.DataFilter == null)
throw new {
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found."); AaruConsole.
ErrorWriteLine($"File \"{matchFile.Groups[1].Value}\" not found.");
return ErrorNumber.NoSuchFile;
}
} }
} }
else else
throw new {
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found."); AaruConsole.ErrorWriteLine($"File \"{matchFile.Groups[1].Value}\" not found.");
return ErrorNumber.NoSuchFile;
}
} }
else else
{ {
@@ -585,8 +617,11 @@ namespace Aaru.DiscImages
currentFile.DataFilter = filtersList.GetFilter(path); currentFile.DataFilter = filtersList.GetFilter(path);
if(currentFile.DataFilter == null) if(currentFile.DataFilter == null)
throw new {
FeatureUnsupportedImageException($"File \"{matchFile.Groups[1].Value}\" not found."); AaruConsole.ErrorWriteLine($"File \"{matchFile.Groups[1].Value}\" not found.");
return ErrorNumber.NoSuchFile;
}
} }
// File does exist, process it // File does exist, process it
@@ -600,11 +635,13 @@ namespace Aaru.DiscImages
case CDRWIN_DISK_TYPE_AIFF: case CDRWIN_DISK_TYPE_AIFF:
case CDRWIN_DISK_TYPE_RIFF: case CDRWIN_DISK_TYPE_RIFF:
case CDRWIN_DISK_TYPE_MP3: case CDRWIN_DISK_TYPE_MP3:
throw new AaruConsole.ErrorWriteLine($"Unsupported file type {currentFile.FileType}");
FeatureSupportedButNotImplementedImageException($"Unsupported file type {currentFile.FileType}");
return ErrorNumber.NotImplemented;
default: default:
throw new AaruConsole.ErrorWriteLine($"Unknown file type {currentFile.FileType}");
FeatureUnsupportedImageException($"Unknown file type {currentFile.FileType}");
return ErrorNumber.InvalidArgument;
} }
currentFile.Offset = 0; currentFile.Offset = 0;
@@ -615,8 +652,12 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("CDRWin plugin", "Found FLAGS at line {0}", lineNumber); AaruConsole.DebugWriteLine("CDRWin plugin", "Found FLAGS at line {0}", lineNumber);
if(!inTrack) if(!inTrack)
throw new {
FeatureUnsupportedImageException($"Found FLAGS field in incorrect place at line {lineNumber}"); AaruConsole.
ErrorWriteLine($"Found FLAGS field in incorrect place at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
currentTrack.FlagDcp |= matchFlags.Groups["dcp"].Value == "DCP"; currentTrack.FlagDcp |= matchFlags.Groups["dcp"].Value == "DCP";
currentTrack.Flag4Ch |= matchFlags.Groups["quad"].Value == "4CH"; currentTrack.Flag4Ch |= matchFlags.Groups["quad"].Value == "4CH";
@@ -637,7 +678,11 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("CDRWin plugin", "Found INDEX at line {0}", lineNumber); AaruConsole.DebugWriteLine("CDRWin plugin", "Found INDEX at line {0}", lineNumber);
if(!inTrack) if(!inTrack)
throw new FeatureUnsupportedImageException($"Found INDEX before a track {lineNumber}"); {
AaruConsole.ErrorWriteLine($"Found INDEX before a track {lineNumber}");
return ErrorNumber.InvalidArgument;
}
ushort index = ushort.Parse(matchIndex.Groups[1].Value); ushort index = ushort.Parse(matchIndex.Groups[1].Value);
int offset = CdrWinMsfToLba(matchIndex.Groups[2].Value) + cumulativeEmptyPregap; int offset = CdrWinMsfToLba(matchIndex.Groups[2].Value) + cumulativeEmptyPregap;
@@ -645,8 +690,11 @@ namespace Aaru.DiscImages
if(index != 0 && if(index != 0 &&
index != 1 && index != 1 &&
currentTrack.Indexes.Count == 0) currentTrack.Indexes.Count == 0)
throw new {
FeatureUnsupportedImageException($"Found INDEX {index} before INDEX 00 or INDEX 01"); AaruConsole.ErrorWriteLine($"Found INDEX {index} before INDEX 00 or INDEX 01");
return ErrorNumber.InvalidArgument;
}
if(index == 0 || if(index == 0 ||
(index == 1 && !currentTrack.Indexes.ContainsKey(0))) (index == 1 && !currentTrack.Indexes.ContainsKey(0)))
@@ -714,7 +762,11 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("CDRWin plugin", "Found ISRC at line {0}", lineNumber); AaruConsole.DebugWriteLine("CDRWin plugin", "Found ISRC at line {0}", lineNumber);
if(!inTrack) if(!inTrack)
throw new FeatureUnsupportedImageException($"Found ISRC before a track {lineNumber}"); {
AaruConsole.ErrorWriteLine($"Found ISRC before a track {lineNumber}");
return ErrorNumber.InvalidArgument;
}
currentTrack.Isrc = matchIsrc.Groups[1].Value; currentTrack.Isrc = matchIsrc.Groups[1].Value;
} }
@@ -725,8 +777,12 @@ namespace Aaru.DiscImages
if(!inTrack) if(!inTrack)
_discImage.Mcn = matchMcn.Groups[1].Value; _discImage.Mcn = matchMcn.Groups[1].Value;
else else
throw new {
FeatureUnsupportedImageException($"Found CATALOG field in incorrect place at line {lineNumber}"); AaruConsole.
ErrorWriteLine($"Found CATALOG field in incorrect place at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
} }
else if(matchPerformer.Success) else if(matchPerformer.Success)
{ {
@@ -744,16 +800,22 @@ namespace Aaru.DiscImages
if(inTrack) if(inTrack)
currentTrack.Postgap = CdrWinMsfToLba(matchPostgap.Groups[1].Value); currentTrack.Postgap = CdrWinMsfToLba(matchPostgap.Groups[1].Value);
else else
throw new {
FeatureUnsupportedImageException($"Found POSTGAP field before a track at line {lineNumber}"); AaruConsole.ErrorWriteLine($"Found POSTGAP field before a track at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
} }
else if(matchPregap.Success) else if(matchPregap.Success)
{ {
AaruConsole.DebugWriteLine("CDRWin plugin", "Found PREGAP at line {0}", lineNumber); AaruConsole.DebugWriteLine("CDRWin plugin", "Found PREGAP at line {0}", lineNumber);
if(!inTrack) if(!inTrack)
throw new {
FeatureUnsupportedImageException($"Found PREGAP field before a track at line {lineNumber}"); AaruConsole.ErrorWriteLine($"Found PREGAP field before a track at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
currentEmptyPregap = CdrWinMsfToLba(matchPregap.Groups[1].Value); currentEmptyPregap = CdrWinMsfToLba(matchPregap.Groups[1].Value);
} }
@@ -780,8 +842,12 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("CDRWin plugin", "Found TRACK at line {0}", lineNumber); AaruConsole.DebugWriteLine("CDRWin plugin", "Found TRACK at line {0}", lineNumber);
if(currentFile.DataFilter == null) if(currentFile.DataFilter == null)
throw new {
FeatureUnsupportedImageException($"Found TRACK field before a file is defined at line {lineNumber}"); AaruConsole.
ErrorWriteLine($"Found TRACK field before a file is defined at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
if(inTrack) if(inTrack)
{ {
@@ -1317,12 +1383,20 @@ namespace Aaru.DiscImages
{ {
if(_discImage.Tracks[i].Sequence == 1 && if(_discImage.Tracks[i].Sequence == 1 &&
i != 0) i != 0)
throw new ImageNotSupportedException("Unordered tracks"); {
AaruConsole.ErrorWriteLine("Unordered tracks");
return ErrorNumber.InvalidArgument;
}
var partition = new Partition(); var partition = new Partition();
if(!_discImage.Tracks[i].Indexes.TryGetValue(1, out _)) if(!_discImage.Tracks[i].Indexes.TryGetValue(1, out _))
throw new ImageNotSupportedException($"Track {_discImage.Tracks[i].Sequence} lacks index 01"); {
AaruConsole.ErrorWriteLine($"Track {_discImage.Tracks[i].Sequence} lacks index 01");
return ErrorNumber.InvalidArgument;
}
// Index 01 // Index 01
partition.Description = $"Track {_discImage.Tracks[i].Sequence}."; partition.Description = $"Track {_discImage.Tracks[i].Sequence}.";
@@ -1506,43 +1580,47 @@ namespace Aaru.DiscImages
leadouts.Count == 0 && leadouts.Count == 0 &&
!_discImage.IsRedumpGigadisc && !_discImage.IsRedumpGigadisc &&
_isCd) _isCd)
throw new
FeatureUnsupportedImageException("This image is missing vital multi-session data and cannot be read correctly.");
if(!_isCd)
{ {
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorSync); AaruConsole.
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorHeader); ErrorWriteLine("This image is missing vital multi-session data and cannot be read correctly.");
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorSubHeader);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEcc);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEccP);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEccQ);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEdc);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdTrackFlags);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdTrackIsrc);
sessions = _discImage.Sessions.ToArray(); return ErrorNumber.InvalidArgument;
}
foreach(CdrWinTrack track in _discImage.Tracks) if(_isCd)
return ErrorNumber.NoError;
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorSync);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorHeader);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorSubHeader);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEcc);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEccP);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEccQ);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdSectorEdc);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdTrackFlags);
_imageInfo.ReadableSectorTags.Remove(SectorTagType.CdTrackIsrc);
sessions = _discImage.Sessions.ToArray();
foreach(CdrWinTrack track in _discImage.Tracks)
{
track.Indexes.Remove(0);
track.Pregap = 0;
for(int s = 0; s < sessions.Length; s++)
{ {
track.Indexes.Remove(0); if(sessions[s].Sequence > 1 &&
track.Pregap = 0; track.Sequence == sessions[s].StartTrack)
for(int s = 0; s < sessions.Length; s++)
{ {
if(sessions[s].Sequence > 1 && track.TrackFile.Offset += 307200;
track.Sequence == sessions[s].StartTrack) track.Sectors -= 150;
{ sessions[s].StartSector = (ulong)track.Indexes[1];
track.TrackFile.Offset += 307200;
track.Sectors -= 150;
sessions[s].StartSector = (ulong)track.Indexes[1];
}
} }
} }
_discImage.Sessions = sessions.ToList();
} }
_discImage.Sessions = sessions.ToList();
return ErrorNumber.NoError; return ErrorNumber.NoError;
} }
catch(Exception ex) catch(Exception ex)
@@ -2262,7 +2340,7 @@ namespace Aaru.DiscImages
if(_discImage.Sessions.Contains(session)) if(_discImage.Sessions.Contains(session))
return GetSessionTracks(session.Sequence); return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -34,8 +34,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Aaru.CommonTypes.Exceptions; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
using SharpCompress.Compressors; using SharpCompress.Compressors;
using SharpCompress.Compressors.Deflate; using SharpCompress.Compressors.Deflate;
@@ -61,10 +62,10 @@ namespace Aaru.DiscImages
return (aaruTrack?.StartSector ?? 0) + relativeSector; return (aaruTrack?.StartSector ?? 0) + relativeSector;
} }
byte[] GetHunk(ulong hunkNo) ErrorNumber GetHunk(ulong hunkNo, out byte[] buffer)
{ {
if(_hunkCache.TryGetValue(hunkNo, out byte[] hunk)) if(_hunkCache.TryGetValue(hunkNo, out buffer))
return hunk; return ErrorNumber.NoError;
switch(_mapVersion) switch(_mapVersion)
{ {
@@ -77,18 +78,26 @@ namespace Aaru.DiscImages
_imageStream.Read(compHunk, 0, compHunk.Length); _imageStream.Read(compHunk, 0, compHunk.Length);
if(length == _sectorsPerHunk * _imageInfo.SectorSize) if(length == _sectorsPerHunk * _imageInfo.SectorSize)
hunk = compHunk; buffer = compHunk;
else if((Compression)_hdrCompression > Compression.Zlib) else if((Compression)_hdrCompression > Compression.Zlib)
throw new ImageNotSupportedException($"Unsupported compression {(Compression)_hdrCompression}"); {
AaruConsole.ErrorWriteLine($"Unsupported compression {(Compression)_hdrCompression}");
return ErrorNumber.InvalidArgument;
}
else else
{ {
var zStream = new DeflateStream(new MemoryStream(compHunk), CompressionMode.Decompress); var zStream = new DeflateStream(new MemoryStream(compHunk), CompressionMode.Decompress);
hunk = new byte[_sectorsPerHunk * _imageInfo.SectorSize]; buffer = new byte[_sectorsPerHunk * _imageInfo.SectorSize];
int read = zStream.Read(hunk, 0, (int)(_sectorsPerHunk * _imageInfo.SectorSize)); int read = zStream.Read(buffer, 0, (int)(_sectorsPerHunk * _imageInfo.SectorSize));
if(read != _sectorsPerHunk * _imageInfo.SectorSize) if(read != _sectorsPerHunk * _imageInfo.SectorSize)
throw new {
IOException($"Unable to decompress hunk correctly, got {read} bytes, expected {_sectorsPerHunk * _imageInfo.SectorSize}"); AaruConsole.
ErrorWriteLine($"Unable to decompress hunk correctly, got {read} bytes, expected {_sectorsPerHunk * _imageInfo.SectorSize}");
return ErrorNumber.InOutError;
}
zStream.Close(); zStream.Close();
} }
@@ -101,7 +110,10 @@ namespace Aaru.DiscImages
switch((EntryFlagsV3)(entry.flags & 0x0F)) switch((EntryFlagsV3)(entry.flags & 0x0F))
{ {
case EntryFlagsV3.Invalid: throw new ArgumentException("Invalid hunk found."); case EntryFlagsV3.Invalid:
AaruConsole.ErrorWriteLine("Invalid hunk found.");
return ErrorNumber.InvalidArgument;
case EntryFlagsV3.Compressed: case EntryFlagsV3.Compressed:
switch((Compression)_hdrCompression) switch((Compression)_hdrCompression)
{ {
@@ -117,74 +129,96 @@ namespace Aaru.DiscImages
var zStream = var zStream =
new DeflateStream(new MemoryStream(zHunk), CompressionMode.Decompress); new DeflateStream(new MemoryStream(zHunk), CompressionMode.Decompress);
hunk = new byte[_bytesPerHunk]; buffer = new byte[_bytesPerHunk];
int read = zStream.Read(hunk, 0, (int)_bytesPerHunk); int read = zStream.Read(buffer, 0, (int)_bytesPerHunk);
if(read != _bytesPerHunk) if(read != _bytesPerHunk)
throw new {
IOException($"Unable to decompress hunk correctly, got {read} bytes, expected {_bytesPerHunk}"); AaruConsole.
ErrorWriteLine($"Unable to decompress hunk correctly, got {read} bytes, expected {_bytesPerHunk}");
return ErrorNumber.InOutError;
}
zStream.Close(); zStream.Close();
} }
// TODO: Guess wth is MAME doing with these hunks // TODO: Guess wth is MAME doing with these hunks
else else
throw new {
ImageNotSupportedException("Compressed CD/GD-ROM hunks are not yet supported"); AaruConsole.ErrorWriteLine("Compressed CD/GD-ROM hunks are not yet supported");
return ErrorNumber.NotImplemented;
}
break; break;
case Compression.Av: case Compression.Av:
throw new AaruConsole.
ImageNotSupportedException($"Unsupported compression {(Compression)_hdrCompression}"); ErrorWriteLine($"Unsupported compression {(Compression)_hdrCompression}");
return ErrorNumber.NotImplemented;
} }
break; break;
case EntryFlagsV3.Uncompressed: case EntryFlagsV3.Uncompressed:
uncompressedV3: uncompressedV3:
hunk = new byte[_bytesPerHunk]; buffer = new byte[_bytesPerHunk];
_imageStream.Seek((long)entry.offset, SeekOrigin.Begin); _imageStream.Seek((long)entry.offset, SeekOrigin.Begin);
_imageStream.Read(hunk, 0, hunk.Length); _imageStream.Read(buffer, 0, buffer.Length);
break; break;
case EntryFlagsV3.Mini: case EntryFlagsV3.Mini:
hunk = new byte[_bytesPerHunk]; buffer = new byte[_bytesPerHunk];
byte[] mini; byte[] mini;
mini = BigEndianBitConverter.GetBytes(entry.offset); mini = BigEndianBitConverter.GetBytes(entry.offset);
for(int i = 0; i < _bytesPerHunk; i++) for(int i = 0; i < _bytesPerHunk; i++)
hunk[i] = mini[i % 8]; buffer[i] = mini[i % 8];
break; break;
case EntryFlagsV3.SelfHunk: return GetHunk(entry.offset); case EntryFlagsV3.SelfHunk: return GetHunk(entry.offset, out buffer);
case EntryFlagsV3.ParentHunk: case EntryFlagsV3.ParentHunk:
throw new ImageNotSupportedException("Parent images are not supported"); AaruConsole.ErrorWriteLine("Parent images are not supported");
return ErrorNumber.NotImplemented;
case EntryFlagsV3.SecondCompressed: case EntryFlagsV3.SecondCompressed:
throw new ImageNotSupportedException("FLAC is not supported"); AaruConsole.ErrorWriteLine("FLAC is not supported");
return ErrorNumber.NotImplemented;
default: default:
throw new ImageNotSupportedException($"Hunk type {entry.flags & 0xF} is not supported"); AaruConsole.ErrorWriteLine($"Hunk type {entry.flags & 0xF} is not supported");
return ErrorNumber.NotSupported;
} }
break; break;
case 5: case 5:
if(_hdrCompression == 0) if(_hdrCompression == 0)
{ {
hunk = new byte[_bytesPerHunk]; buffer = new byte[_bytesPerHunk];
_imageStream.Seek(_hunkTableSmall[hunkNo] * _bytesPerHunk, SeekOrigin.Begin); _imageStream.Seek(_hunkTableSmall[hunkNo] * _bytesPerHunk, SeekOrigin.Begin);
_imageStream.Read(hunk, 0, hunk.Length); _imageStream.Read(buffer, 0, buffer.Length);
} }
else else
throw new ImageNotSupportedException("Compressed v5 hunks not yet supported"); {
AaruConsole.ErrorWriteLine("Compressed v5 hunks not yet supported");
return ErrorNumber.NotSupported;
}
break; break;
default: throw new ImageNotSupportedException($"Unsupported hunk map version {_mapVersion}"); default:
AaruConsole.ErrorWriteLine($"Unsupported hunk map version {_mapVersion}");
return ErrorNumber.NotSupported;
} }
if(_hunkCache.Count >= _maxBlockCache) if(_hunkCache.Count >= _maxBlockCache)
_hunkCache.Clear(); _hunkCache.Clear();
_hunkCache.Add(hunkNo, hunk); _hunkCache.Add(hunkNo, buffer);
return hunk; return ErrorNumber.NoError;
} }
} }
} }

View File

@@ -66,7 +66,8 @@ namespace Aaru.DiscImages
if(_isHdd) if(_isHdd)
return null; return null;
throw new NotImplementedException(); // TODO: Implement
return null;
} }
} }

View File

@@ -39,7 +39,6 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.CommonTypes.Structs.Devices.ATA; using Aaru.CommonTypes.Structs.Devices.ATA;
@@ -339,7 +338,7 @@ namespace Aaru.DiscImages
// TODO: Check why reading is misaligned // TODO: Check why reading is misaligned
AaruConsole.ErrorWriteLine("CHD version 5 is not yet supported."); AaruConsole.ErrorWriteLine("CHD version 5 is not yet supported.");
return ErrorNumber.NotSupported; return ErrorNumber.NotImplemented;
HeaderV5 hdrV5 = Marshal.ByteArrayToStructureBigEndian<HeaderV5>(buffer); HeaderV5 hdrV5 = Marshal.ByteArrayToStructureBigEndian<HeaderV5>(buffer);
@@ -1359,7 +1358,10 @@ namespace Aaru.DiscImages
ulong hunkNo = sectorAddress / _sectorsPerHunk; ulong hunkNo = sectorAddress / _sectorsPerHunk;
ulong secOff = sectorAddress * sectorSize % (_sectorsPerHunk * sectorSize); ulong secOff = sectorAddress * sectorSize % (_sectorsPerHunk * sectorSize);
byte[] hunk = GetHunk(hunkNo); ErrorNumber errno = GetHunk(hunkNo, out byte[] hunk);
if(errno != ErrorNumber.NoError)
return errno;
sector = new byte[_imageInfo.SectorSize]; sector = new byte[_imageInfo.SectorSize];
Array.Copy(hunk, (int)secOff, sector, 0, sector.Length); Array.Copy(hunk, (int)secOff, sector, 0, sector.Length);
@@ -1490,7 +1492,10 @@ namespace Aaru.DiscImages
ulong hunkNo = sectorAddress / _sectorsPerHunk; ulong hunkNo = sectorAddress / _sectorsPerHunk;
ulong secOff = sectorAddress * sectorSize % (_sectorsPerHunk * sectorSize); ulong secOff = sectorAddress * sectorSize % (_sectorsPerHunk * sectorSize);
byte[] hunk = GetHunk(hunkNo); ErrorNumber errno = GetHunk(hunkNo, out byte[] hunk);
if(errno != ErrorNumber.NoError)
return errno;
sector = new byte[_imageInfo.SectorSize]; sector = new byte[_imageInfo.SectorSize];
Array.Copy(hunk, (int)secOff, sector, 0, sector.Length); Array.Copy(hunk, (int)secOff, sector, 0, sector.Length);
@@ -1795,7 +1800,10 @@ namespace Aaru.DiscImages
ulong hunkNo = sectorAddress / _sectorsPerHunk; ulong hunkNo = sectorAddress / _sectorsPerHunk;
ulong secOff = sectorAddress * sectorSize % (_sectorsPerHunk * sectorSize); ulong secOff = sectorAddress * sectorSize % (_sectorsPerHunk * sectorSize);
byte[] hunk = GetHunk(hunkNo); ErrorNumber errno = GetHunk(hunkNo, out byte[] hunk);
if(errno != ErrorNumber.NoError)
return errno;
sector = new byte[_imageInfo.SectorSize]; sector = new byte[_imageInfo.SectorSize];
Array.Copy(hunk, (int)secOff, sector, 0, sector.Length); Array.Copy(hunk, (int)secOff, sector, 0, sector.Length);
@@ -1921,22 +1929,11 @@ namespace Aaru.DiscImages
} }
/// <inheritdoc /> /// <inheritdoc />
public List<Track> GetSessionTracks(Session session) public List<Track> GetSessionTracks(Session session) => _isHdd ? null : GetSessionTracks(session.Sequence);
{
if(_isHdd)
throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image");
return GetSessionTracks(session.Sequence);
}
/// <inheritdoc /> /// <inheritdoc />
public List<Track> GetSessionTracks(ushort session) public List<Track> GetSessionTracks(ushort session) =>
{ _isHdd ? null : _tracks.Values.Where(track => track.Session == session).ToList();
if(_isHdd)
throw new FeaturedNotSupportedByDiscImageException("Cannot access optical tracks on a hard disk image");
return _tracks.Values.Where(track => track.Session == session).ToList();
}
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSector(ulong sectorAddress, uint track, out byte[] buffer) public ErrorNumber ReadSector(ulong sectorAddress, uint track, out byte[] buffer)

View File

@@ -145,7 +145,14 @@ namespace Aaru.DiscImages
var sha1Ctx = new Sha1Context(); var sha1Ctx = new Sha1Context();
for(uint i = 0; i < _totalHunks; i++) for(uint i = 0; i < _totalHunks; i++)
sha1Ctx.Update(GetHunk(i)); {
ErrorNumber errno = GetHunk(i, out byte[] buffer);
if(errno != ErrorNumber.NoError)
return null;
sha1Ctx.Update(buffer);
}
calculated = sha1Ctx.Final(); calculated = sha1Ctx.Final();
} }
@@ -154,7 +161,14 @@ namespace Aaru.DiscImages
var md5Ctx = new Md5Context(); var md5Ctx = new Md5Context();
for(uint i = 0; i < _totalHunks; i++) for(uint i = 0; i < _totalHunks; i++)
md5Ctx.Update(GetHunk(i)); {
ErrorNumber errno = GetHunk(i, out byte[] buffer);
if(errno != ErrorNumber.NoError)
return null;
md5Ctx.Update(buffer);
}
calculated = md5Ctx.Final(); calculated = md5Ctx.Final();
} }

View File

@@ -34,7 +34,6 @@ using System;
using System.IO; using System.IO;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -67,7 +66,10 @@ namespace Aaru.DiscImages
tracks = 160; tracks = 160;
break; break;
default: throw new ImageNotSupportedException($"Incorrect disk type {(byte)type}"); default:
AaruConsole.ErrorWriteLine($"Incorrect disk type {(byte)type}");
return ErrorNumber.InvalidArgument;
} }
byte[] trackBytes = new byte[tracks]; byte[] trackBytes = new byte[tracks];
@@ -76,7 +78,11 @@ namespace Aaru.DiscImages
var cmpr = (Compression)stream.ReadByte(); var cmpr = (Compression)stream.ReadByte();
if(cmpr != Compression.None) if(cmpr != Compression.None)
throw new FeatureSupportedButNotImplementedImageException("Compressed images are not supported."); {
AaruConsole.ErrorWriteLine("Compressed images are not supported.");
return ErrorNumber.NotImplemented;
}
int trackSize = 0; int trackSize = 0;

View File

@@ -83,7 +83,7 @@ namespace Aaru.DiscImages
var hdr = new Regex(CCD_IDENTIFIER); var hdr = new Regex(CCD_IDENTIFIER);
Match hdm = hdr.Match(line ?? throw new InvalidOperationException()); Match hdm = hdr.Match(line ?? "");
return hdm.Success; return hdm.Success;
} }

View File

@@ -1385,7 +1385,7 @@ namespace Aaru.DiscImages
if(Sessions.Contains(session)) if(Sessions.Contains(session))
return GetSessionTracks(session.Sequence); return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -355,7 +355,11 @@ namespace Aaru.DiscImages
_descriptorStream.WriteLine("PreGapMode=2"); _descriptorStream.WriteLine("PreGapMode=2");
break; break;
default: throw new ArgumentOutOfRangeException(); default:
ErrorMessage =
$"Unexpected first session track type {firstSessionTrack?.Type.ToString() ?? "null"}";
return false;
} }
_descriptorStream.WriteLine("PreGapSubC=0"); _descriptorStream.WriteLine("PreGapSubC=0");

View File

@@ -35,7 +35,6 @@ using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Compression; using Aaru.Compression;
using Aaru.Console; using Aaru.Console;
@@ -161,7 +160,9 @@ namespace Aaru.DiscImages
temp = new byte[l]; temp = new byte[l];
stream.Read(temp, 0, temp.Length); stream.Read(temp, 0, temp.Length);
throw new ImageNotSupportedException("LZH Compressed images not yet supported"); AaruConsole.ErrorWriteLine("LZH Compressed images not yet supported");
return ErrorNumber.NotImplemented;
} }
} }
} }
@@ -328,7 +329,8 @@ namespace Aaru.DiscImages
ReadSectors(sectorAddress, 1, out buffer); ReadSectors(sectorAddress, 1, out buffer);
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer) => ReadSectorsTag(sectorAddress, 1, tag, out buffer); public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer) =>
ReadSectorsTag(sectorAddress, 1, tag, out buffer);
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer) public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
@@ -394,7 +396,7 @@ namespace Aaru.DiscImages
if(errno != ErrorNumber.NoError) if(errno != ErrorNumber.NoError)
return errno; return errno;
errno = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag, out byte[] tags); errno = ReadSectorsTag(sectorAddress, length, SectorTagType.AppleSectorTag, out byte[] tags);
if(errno != ErrorNumber.NoError) if(errno != ErrorNumber.NoError)
return errno; return errno;

View File

@@ -41,12 +41,6 @@ namespace Aaru.DiscImages
{ {
public sealed partial class Dim public sealed partial class Dim
{ {
public List<Partition> Partitions =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public List<Track> Tracks =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public List<Session> Sessions =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
/// <inheritdoc /> /// <inheritdoc />
public string Name => "DIM Disk Image"; public string Name => "DIM Disk Image";
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -37,7 +37,6 @@ using System.Linq;
using System.Text; using System.Text;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Console; using Aaru.Console;
@@ -390,7 +389,10 @@ namespace Aaru.DiscImages
currentOffset += trackLen * (ulong)(track.RawBytesPerSector + 96); currentOffset += trackLen * (ulong)(track.RawBytesPerSector + 96);
break; break;
default: throw new ImageNotSupportedException($"Unknown read mode {readMode}"); default:
AaruConsole.ErrorWriteLine($"Unknown read mode {readMode}");
return ErrorNumber.InvalidArgument;
} }
break; break;
@@ -416,8 +418,9 @@ namespace Aaru.DiscImages
break; break;
case 1: case 1:
throw AaruConsole.ErrorWriteLine($"Invalid read mode {readMode} for this track");
new ImageNotSupportedException($"Invalid read mode {readMode} for this track");
return ErrorNumber.InvalidArgument;
case 2: case 2:
track.RawBytesPerSector = 2352; track.RawBytesPerSector = 2352;
currentOffset += trackLen * (ulong)track.RawBytesPerSector; currentOffset += trackLen * (ulong)track.RawBytesPerSector;
@@ -505,7 +508,10 @@ namespace Aaru.DiscImages
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc); _imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc);
break; break;
default: throw new ImageNotSupportedException($"Unknown read mode {readMode}"); default:
AaruConsole.ErrorWriteLine($"Unknown read mode {readMode}");
return ErrorNumber.InvalidArgument;
} }
break; break;
@@ -521,8 +527,9 @@ namespace Aaru.DiscImages
switch(readMode) switch(readMode)
{ {
case 0: case 0:
throw AaruConsole.ErrorWriteLine($"Invalid read mode {readMode} for this track");
new ImageNotSupportedException($"Invalid read mode {readMode} for this track");
return ErrorNumber.InvalidArgument;
case 1: case 1:
track.RawBytesPerSector = 2336; track.RawBytesPerSector = 2336;
@@ -584,11 +591,17 @@ namespace Aaru.DiscImages
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); _imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader);
break; break;
default: throw new ImageNotSupportedException($"Unknown read mode {readMode}"); default:
AaruConsole.ErrorWriteLine($"Unknown read mode {readMode}");
return ErrorNumber.InvalidArgument;
} }
break; break;
default: throw new ImageNotSupportedException($"Unknown track mode {trackMode}"); default:
AaruConsole.ErrorWriteLine($"Unknown track mode {trackMode}");
return ErrorNumber.InvalidArgument;
} }
track.File = imageFilter.Filename; track.File = imageFilter.Filename;
@@ -1340,7 +1353,7 @@ namespace Aaru.DiscImages
if(Sessions.Contains(session)) if(Sessions.Contains(session))
return GetSessionTracks(session.Sequence); return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -40,7 +40,7 @@ namespace Aaru.DiscImages
{ {
public sealed partial class Gdi public sealed partial class Gdi
{ {
// Due to .gdi format, this method must parse whole file, ignoring errors (those will be thrown by OpenImage()). // Due to .gdi format, this method must parse whole file, ignoring errors (those will be returned by OpenImage()).
/// <inheritdoc /> /// <inheritdoc />
public bool Identify(IFilter imageFilter) public bool Identify(IFilter imageFilter)
{ {
@@ -95,7 +95,7 @@ namespace Aaru.DiscImages
{ {
var regexTrack = new Regex(REGEX_TRACK); var regexTrack = new Regex(REGEX_TRACK);
Match trackMatch = regexTrack.Match(line ?? throw new InvalidOperationException()); Match trackMatch = regexTrack.Match(line ?? "");
if(!trackMatch.Success) if(!trackMatch.Success)
return false; return false;

View File

@@ -37,7 +37,6 @@ using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Console; using Aaru.Console;
@@ -85,14 +84,22 @@ namespace Aaru.DiscImages
if(lineNumber == 1) if(lineNumber == 1)
{ {
if(!int.TryParse(line, out _)) if(!int.TryParse(line, out _))
throw new ImageNotSupportedException("Not a correct Dreamcast GDI image"); {
AaruConsole.ErrorWriteLine("Not a correct Dreamcast GDI image");
return ErrorNumber.InvalidArgument;
}
} }
else else
{ {
Match trackMatch = regexTrack.Match(line ?? throw new InvalidOperationException()); Match trackMatch = regexTrack.Match(line ?? "");
if(!trackMatch.Success) if(!trackMatch.Success)
throw new ImageNotSupportedException($"Unknown line \"{line}\" at line {lineNumber}"); {
AaruConsole.ErrorWriteLine($"Unknown line \"{line}\" at line {lineNumber}");
return ErrorNumber.InvalidArgument;
}
AaruConsole.DebugWriteLine("GDI plugin", AaruConsole.DebugWriteLine("GDI plugin",
"Found track {0} starts at {1} flags {2} type {3} file {4} offset {5} at line {6}", "Found track {0} starts at {1} flags {2} type {3} file {4} offset {5} at line {6}",
@@ -132,7 +139,11 @@ namespace Aaru.DiscImages
} }
if((currentTrack.TrackFilter.DataForkLength - currentTrack.Offset) % currentTrack.Bps != 0) if((currentTrack.TrackFilter.DataForkLength - currentTrack.Offset) % currentTrack.Bps != 0)
throw new ImageNotSupportedException("Track size not a multiple of sector size"); {
AaruConsole.ErrorWriteLine("Track size not a multiple of sector size");
return ErrorNumber.InvalidArgument;
}
currentTrack.Sectors = (ulong)((currentTrack.TrackFilter.DataForkLength - currentTrack.Offset) / currentTrack.Sectors = (ulong)((currentTrack.TrackFilter.DataForkLength - currentTrack.Offset) /
currentTrack.Bps); currentTrack.Bps);
@@ -257,7 +268,11 @@ namespace Aaru.DiscImages
{ {
if(_discImage.Tracks[i].Sequence == 1 && if(_discImage.Tracks[i].Sequence == 1 &&
i != 0) i != 0)
throw new ImageNotSupportedException("Unordered tracks"); {
AaruConsole.ErrorWriteLine("Unordered tracks");
return ErrorNumber.InvalidArgument;
}
// Index 01 // Index 01
var partition = new Partition var partition = new Partition
@@ -856,7 +871,7 @@ namespace Aaru.DiscImages
if(_discImage.Sessions.Contains(session)) if(_discImage.Sessions.Contains(session))
return GetSessionTracks(session.Sequence); return GetSessionTracks(session.Sequence);
throw new ImageNotSupportedException("Session does not exist in disc image"); return null;
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -875,7 +890,7 @@ namespace Aaru.DiscImages
expectedDensity = true; expectedDensity = true;
break; break;
default: throw new ImageNotSupportedException("Session does not exist in disc image"); default: return null;
} }
foreach(GdiTrack gdiTrack in _discImage.Tracks) foreach(GdiTrack gdiTrack in _discImage.Tracks)

View File

@@ -31,14 +31,17 @@
// ****************************************************************************/ // ****************************************************************************/
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
namespace Aaru.DiscImages namespace Aaru.DiscImages
{ {
public sealed partial class Gdi public sealed partial class Gdi
{ {
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer) => public ErrorNumber ReadMediaTag(MediaTagType tag, out byte[] buffer)
throw new FeatureSupportedButNotImplementedImageException("Feature not supported by image format"); {
buffer = null;
return ErrorNumber.NoData;
}
} }
} }

View File

@@ -33,6 +33,8 @@
using System; using System;
using System.IO; using System.IO;
using Aaru.CommonTypes.Enums;
using Aaru.Console;
namespace Aaru.DiscImages namespace Aaru.DiscImages
{ {
@@ -96,14 +98,18 @@ namespace Aaru.DiscImages
return true; return true;
} }
void ReadTrackIntoCache(Stream stream, int trackNum) ErrorNumber ReadTrackIntoCache(Stream stream, int trackNum)
{ {
byte[] trackData = new byte[_imageInfo.SectorSize * _imageInfo.SectorsPerTrack]; byte[] trackData = new byte[_imageInfo.SectorSize * _imageInfo.SectorsPerTrack];
byte[] blkHeader = new byte[3]; byte[] blkHeader = new byte[3];
// check that track is present // check that track is present
if(_trackOffset[trackNum] == -1) if(_trackOffset[trackNum] == -1)
throw new InvalidDataException("Tried reading a track that is not present in image"); {
AaruConsole.ErrorWriteLine("Tried reading a track that is not present in image");
return ErrorNumber.SectorNotFound;
}
stream.Seek(_trackOffset[trackNum], SeekOrigin.Begin); stream.Seek(_trackOffset[trackNum], SeekOrigin.Begin);
@@ -135,10 +141,16 @@ namespace Aaru.DiscImages
// check that the number of bytes decompressed matches a whole track // check that the number of bytes decompressed matches a whole track
if(dIndex != _imageInfo.SectorSize * _imageInfo.SectorsPerTrack) if(dIndex != _imageInfo.SectorSize * _imageInfo.SectorsPerTrack)
throw new InvalidDataException("Track decompression yielded incomplete data"); {
AaruConsole.ErrorWriteLine("Track decompression yielded incomplete data");
return ErrorNumber.InOutError;
}
// store track in cache // store track in cache
_trackCache[trackNum] = trackData; _trackCache[trackNum] = trackData;
return ErrorNumber.NoError;
} }
} }
} }

View File

@@ -137,7 +137,12 @@ namespace Aaru.DiscImages
{ {
// track is present in file, make sure it has been loaded // track is present in file, make sure it has been loaded
if(!_trackCache.ContainsKey(trackNum)) if(!_trackCache.ContainsKey(trackNum))
ReadTrackIntoCache(_hdcpImageFilter.GetDataForkStream(), trackNum); {
ErrorNumber errno = ReadTrackIntoCache(_hdcpImageFilter.GetDataForkStream(), trackNum);
if(errno != ErrorNumber.NoError)
return errno;
}
Array.Copy(_trackCache[trackNum], sectorOffset * _imageInfo.SectorSize, buffer, 0, Array.Copy(_trackCache[trackNum], sectorOffset * _imageInfo.SectorSize, buffer, 0,
_imageInfo.SectorSize); _imageInfo.SectorSize);

View File

@@ -35,7 +35,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -158,7 +157,10 @@ namespace Aaru.DiscImages
track.Add(idmap[i], data); track.Add(idmap[i], data);
break; break;
default: throw new ImageNotSupportedException($"Invalid sector type {(byte)type}"); default:
AaruConsole.ErrorWriteLine($"Invalid sector type {(byte)type}");
return ErrorNumber.InvalidArgument;
} }
} }
@@ -217,12 +219,14 @@ namespace Aaru.DiscImages
} }
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) => ReadSectors(sectorAddress, 1, out buffer); public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
ReadSectors(sectorAddress, 1, out buffer);
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer) public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
{ {
buffer = null; buffer = null;
if(sectorAddress > _imageInfo.Sectors - 1) if(sectorAddress > _imageInfo.Sectors - 1)
return ErrorNumber.OutOfRange; return ErrorNumber.OutOfRange;

View File

@@ -125,10 +125,11 @@ namespace Aaru.DiscImages
break; break;
} }
var trackFilter = new ZZZNoFilter(); var trackFilter = new ZZZNoFilter();
ErrorNumber errno = trackFilter.Open(trackfile);
if(trackFilter.Open(trackfile) != ErrorNumber.NoError) if(errno != ErrorNumber.NoError)
throw new IOException("Could not open KryoFlux track file."); return errno;
_imageInfo.CreationTime = DateTime.MaxValue; _imageInfo.CreationTime = DateTime.MaxValue;
_imageInfo.LastModificationTime = DateTime.MinValue; _imageInfo.LastModificationTime = DateTime.MinValue;

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Linq; using System.Linq;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Compression; using Aaru.Compression;
using Aaru.Console; using Aaru.Console;
@@ -149,13 +148,17 @@ namespace Aaru.DiscImages
switch(bChnk.type) switch(bChnk.type)
{ {
case CHUNK_TYPE_KENCODE: case CHUNK_TYPE_KENCODE:
throw new AaruConsole.ErrorWriteLine("Chunks compressed with KenCode are not yet supported.");
ImageNotSupportedException("Chunks compressed with KenCode are not yet supported.");
return ErrorNumber.NotImplemented;
case CHUNK_TYPE_LZH: case CHUNK_TYPE_LZH:
throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported."); AaruConsole.ErrorWriteLine("Chunks compressed with LZH are not yet supported.");
return ErrorNumber.NotImplemented;
case CHUNK_TYPE_STUFFIT: case CHUNK_TYPE_STUFFIT:
throw new AaruConsole.ErrorWriteLine("Chunks compressed with StuffIt! are not yet supported.");
ImageNotSupportedException("Chunks compressed with StuffIt! are not yet supported.");
return ErrorNumber.NotImplemented;
} }
// TODO: Handle compressed chunks // TODO: Handle compressed chunks
@@ -163,7 +166,11 @@ namespace Aaru.DiscImages
(bChnk.type > CHUNK_TYPE_ADC && bChnk.type < CHUNK_TYPE_STUFFIT) || (bChnk.type > CHUNK_TYPE_ADC && bChnk.type < CHUNK_TYPE_STUFFIT) ||
(bChnk.type > CHUNK_TYPE_STUFFIT && bChnk.type < CHUNK_TYPE_END) || (bChnk.type > CHUNK_TYPE_STUFFIT && bChnk.type < CHUNK_TYPE_END) ||
bChnk.type == 1) bChnk.type == 1)
throw new ImageNotSupportedException($"Unsupported chunk type 0x{bChnk.type:X8} found"); {
AaruConsole.ErrorWriteLine($"Unsupported chunk type 0x{bChnk.type:X8} found");
return ErrorNumber.InvalidArgument;
}
_chunks.Add(bChnk.sector, bChnk); _chunks.Add(bChnk.sector, bChnk);
} }
@@ -172,10 +179,18 @@ namespace Aaru.DiscImages
} }
if(_header.segmented > 0) if(_header.segmented > 0)
throw new ImageNotSupportedException("Segmented images are not yet supported."); {
AaruConsole.ErrorWriteLine("Segmented images are not yet supported.");
return ErrorNumber.NotImplemented;
}
if(_header.encrypted > 0) if(_header.encrypted > 0)
throw new ImageNotSupportedException("Encrypted images are not yet supported."); {
AaruConsole.ErrorWriteLine("Encrypted images are not yet supported.");
return ErrorNumber.NotImplemented;
}
switch(_imageInfo.Sectors) switch(_imageInfo.Sectors)
{ {

View File

@@ -113,8 +113,7 @@ namespace Aaru.DiscImages
buffer = null; buffer = null;
if(sectorAddress > _imageInfo.Sectors - 1) if(sectorAddress > _imageInfo.Sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), return ErrorNumber.OutOfRange;
$"Sector address {sectorAddress} not found");
if(_empty) if(_empty)
{ {

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Linq; using System.Linq;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Extents; using Aaru.CommonTypes.Extents;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
@@ -82,7 +81,11 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("PartClone plugin", "pHdr.bitmagic = {0}", StringHandlers.CToString(bitmagic)); AaruConsole.DebugWriteLine("PartClone plugin", "pHdr.bitmagic = {0}", StringHandlers.CToString(bitmagic));
if(!_biTmAgIc.SequenceEqual(bitmagic)) if(!_biTmAgIc.SequenceEqual(bitmagic))
throw new ImageNotSupportedException("Could not find partclone BiTmAgIc, not continuing..."); {
AaruConsole.ErrorWriteLine("Could not find partclone BiTmAgIc, not continuing...");
return ErrorNumber.InvalidArgument;
}
_dataOff = stream.Position; _dataOff = stream.Position;
AaruConsole.DebugWriteLine("PartClone plugin", "pHdr.dataOff = {0}", _dataOff); AaruConsole.DebugWriteLine("PartClone plugin", "pHdr.dataOff = {0}", _dataOff);

View File

@@ -35,7 +35,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Extents; using Aaru.CommonTypes.Extents;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
@@ -72,7 +71,11 @@ namespace Aaru.DiscImages
// TODO: Support multifile volumes // TODO: Support multifile volumes
if(_cVolumeHeader.volumeNumber > 0) if(_cVolumeHeader.volumeNumber > 0)
throw new FeatureSupportedButNotImplementedImageException("Support for multiple volumes not supported"); {
AaruConsole.ErrorWriteLine("Support for multiple volumes not supported");
return ErrorNumber.NotImplemented;
}
hdrB = new byte[Marshal.SizeOf<MainHeader>()]; hdrB = new byte[Marshal.SizeOf<MainHeader>()];
stream.Read(hdrB, 0, Marshal.SizeOf<MainHeader>()); stream.Read(hdrB, 0, Marshal.SizeOf<MainHeader>());
@@ -204,7 +207,11 @@ namespace Aaru.DiscImages
// partimage 0.6.1 does not support them either // partimage 0.6.1 does not support them either
if(_cMainHeader.dwEncryptAlgo != PEncryption.None) if(_cMainHeader.dwEncryptAlgo != PEncryption.None)
throw new ImageNotSupportedException("Encrypted images are currently not supported."); {
AaruConsole.ErrorWriteLine("Encrypted images are currently not supported.");
return ErrorNumber.NotImplemented;
}
string magic; string magic;
@@ -216,7 +223,11 @@ namespace Aaru.DiscImages
magic = StringHandlers.CToString(hdrB); magic = StringHandlers.CToString(hdrB);
if(!magic.Equals(MAGIC_BEGIN_MBRBACKUP)) if(!magic.Equals(MAGIC_BEGIN_MBRBACKUP))
throw new ImageNotSupportedException("Cannot find MBRs"); {
AaruConsole.ErrorWriteLine("Cannot find MBRs");
return ErrorNumber.InvalidArgument;
}
stream.Seek(_cMainHeader.dwMbrSize * _cMainHeader.dwMbrCount, SeekOrigin.Current); stream.Seek(_cMainHeader.dwMbrSize * _cMainHeader.dwMbrCount, SeekOrigin.Current);
} }
@@ -229,7 +240,11 @@ namespace Aaru.DiscImages
magic = StringHandlers.CToString(hdrB); magic = StringHandlers.CToString(hdrB);
if(!magic.Equals(MAGIC_BEGIN_LOCALHEADER)) if(!magic.Equals(MAGIC_BEGIN_LOCALHEADER))
throw new ImageNotSupportedException("Cannot find local header"); {
AaruConsole.ErrorWriteLine("Cannot find local header");
return ErrorNumber.InvalidArgument;
}
hdrB = new byte[Marshal.SizeOf<CLocalHeader>()]; hdrB = new byte[Marshal.SizeOf<CLocalHeader>()];
stream.Read(hdrB, 0, Marshal.SizeOf<CLocalHeader>()); stream.Read(hdrB, 0, Marshal.SizeOf<CLocalHeader>());
@@ -259,7 +274,11 @@ namespace Aaru.DiscImages
magic = StringHandlers.CToString(hdrB); magic = StringHandlers.CToString(hdrB);
if(!magic.Equals(MAGIC_BEGIN_BITMAP)) if(!magic.Equals(MAGIC_BEGIN_BITMAP))
throw new ImageNotSupportedException("Cannot find bitmap"); {
AaruConsole.ErrorWriteLine("Cannot find bitmap");
return ErrorNumber.InvalidArgument;
}
_bitmap = new byte[localHeader.qwBitmapSize]; _bitmap = new byte[localHeader.qwBitmapSize];
stream.Read(_bitmap, 0, (int)localHeader.qwBitmapSize); stream.Read(_bitmap, 0, (int)localHeader.qwBitmapSize);
@@ -269,7 +288,11 @@ namespace Aaru.DiscImages
magic = StringHandlers.CToString(hdrB); magic = StringHandlers.CToString(hdrB);
if(!magic.Equals(MAGIC_BEGIN_INFO)) if(!magic.Equals(MAGIC_BEGIN_INFO))
throw new ImageNotSupportedException("Cannot find info block"); {
AaruConsole.ErrorWriteLine("Cannot find info block");
return ErrorNumber.InvalidArgument;
}
// Skip info block and its checksum // Skip info block and its checksum
stream.Seek(16384 + 4, SeekOrigin.Current); stream.Seek(16384 + 4, SeekOrigin.Current);
@@ -279,7 +302,11 @@ namespace Aaru.DiscImages
magic = StringHandlers.CToString(hdrB); magic = StringHandlers.CToString(hdrB);
if(!magic.Equals(MAGIC_BEGIN_DATABLOCKS)) if(!magic.Equals(MAGIC_BEGIN_DATABLOCKS))
throw new ImageNotSupportedException("Cannot find data blocks"); {
AaruConsole.ErrorWriteLine("Cannot find data blocks");
return ErrorNumber.InvalidArgument;
}
_dataOff = stream.Position; _dataOff = stream.Position;
@@ -293,8 +320,11 @@ namespace Aaru.DiscImages
magic = StringHandlers.CToString(hdrB); magic = StringHandlers.CToString(hdrB);
if(!magic.Equals(MAGIC_BEGIN_TAIL)) if(!magic.Equals(MAGIC_BEGIN_TAIL))
throw new {
ImageNotSupportedException("Cannot find tail. Multiple volumes are not supported or image is corrupt."); AaruConsole.ErrorWriteLine("Cannot find tail. Multiple volumes are not supported or image is corrupt.");
return ErrorNumber.InvalidArgument;
}
AaruConsole.DebugWriteLine("Partimage plugin", "Filling extents"); AaruConsole.DebugWriteLine("Partimage plugin", "Filling extents");
DateTime start = DateTime.Now; DateTime start = DateTime.Now;

View File

@@ -73,31 +73,57 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l1_table_offset = {0}", _qHdr.l1_table_offset); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.l1_table_offset = {0}", _qHdr.l1_table_offset);
if(_qHdr.size <= 1) if(_qHdr.size <= 1)
throw new ArgumentOutOfRangeException(nameof(_qHdr.size), "Image size is too small"); {
AaruConsole.ErrorWriteLine("Image size is too small");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.cluster_bits < 9 || if(_qHdr.cluster_bits < 9 ||
_qHdr.cluster_bits > 16) _qHdr.cluster_bits > 16)
throw new ArgumentOutOfRangeException(nameof(_qHdr.cluster_bits), {
"Cluster size must be between 512 bytes and 64 Kbytes"); AaruConsole.ErrorWriteLine("Cluster size must be between 512 bytes and 64 Kbytes");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.l2_bits < 9 - 3 || if(_qHdr.l2_bits < 9 - 3 ||
_qHdr.l2_bits > 16 - 3) _qHdr.l2_bits > 16 - 3)
throw new ArgumentOutOfRangeException(nameof(_qHdr.l2_bits), {
"L2 size must be between 512 bytes and 64 Kbytes"); AaruConsole.ErrorWriteLine("L2 size must be between 512 bytes and 64 Kbytes");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.crypt_method > QCOW_ENCRYPTION_AES) if(_qHdr.crypt_method > QCOW_ENCRYPTION_AES)
throw new ArgumentOutOfRangeException(nameof(_qHdr.crypt_method), "Invalid encryption method"); {
AaruConsole.ErrorWriteLine("Invalid encryption method");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.crypt_method > QCOW_ENCRYPTION_NONE) if(_qHdr.crypt_method > QCOW_ENCRYPTION_NONE)
throw new NotImplementedException("AES encrypted images not yet supported"); {
AaruConsole.ErrorWriteLine("AES encrypted images not yet supported");
return ErrorNumber.NotImplemented;
}
if(_qHdr.backing_file_offset != 0) if(_qHdr.backing_file_offset != 0)
throw new NotImplementedException("Differencing images not yet supported"); {
AaruConsole.ErrorWriteLine("Differencing images not yet supported");
return ErrorNumber.NotImplemented;
}
int shift = _qHdr.cluster_bits + _qHdr.l2_bits; int shift = _qHdr.cluster_bits + _qHdr.l2_bits;
if(_qHdr.size > ulong.MaxValue - (ulong)(1 << shift)) if(_qHdr.size > ulong.MaxValue - (ulong)(1 << shift))
throw new ArgumentOutOfRangeException(nameof(_qHdr.size), "Image is too large"); {
AaruConsole.ErrorWriteLine("Image is too large");
return ErrorNumber.InvalidArgument;
}
_clusterSize = 1 << _qHdr.cluster_bits; _clusterSize = 1 << _qHdr.cluster_bits;
_clusterSectors = 1 << (_qHdr.cluster_bits - 9); _clusterSectors = 1 << (_qHdr.cluster_bits - 9);

View File

@@ -185,8 +185,11 @@ namespace Aaru.DiscImages
ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift; ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift;
if((long)l1Off >= _l1Table.LongLength) if((long)l1Off >= _l1Table.LongLength)
throw new ArgumentOutOfRangeException(nameof(l1Off), {
$"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}"); ErrorMessage = $"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}";
return false;
}
if(_l1Table[l1Off] == 0) if(_l1Table[l1Off] == 0)
{ {

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -87,26 +86,49 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.header_length = {0}", _qHdr.header_length); AaruConsole.DebugWriteLine("QCOW plugin", "qHdr.header_length = {0}", _qHdr.header_length);
if((_qHdr.features & QCOW_FEATURE_MASK) != 0) if((_qHdr.features & QCOW_FEATURE_MASK) != 0)
throw new {
ImageNotSupportedException($"Unknown incompatible features {_qHdr.features & QCOW_FEATURE_MASK:X} enabled, not proceeding."); AaruConsole.
ErrorWriteLine($"Unknown incompatible features {_qHdr.features & QCOW_FEATURE_MASK:X} enabled, not proceeding.");
return ErrorNumber.InvalidArgument;
}
} }
if(_qHdr.size <= 1) if(_qHdr.size <= 1)
throw new ArgumentOutOfRangeException(nameof(_qHdr.size), "Image size is too small"); {
AaruConsole.ErrorWriteLine("Image size is too small");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.cluster_bits < 9 || if(_qHdr.cluster_bits < 9 ||
_qHdr.cluster_bits > 16) _qHdr.cluster_bits > 16)
throw new ArgumentOutOfRangeException(nameof(_qHdr.cluster_bits), {
"Cluster size must be between 512 bytes and 64 Kbytes"); AaruConsole.ErrorWriteLine("Cluster size must be between 512 bytes and 64 Kbytes");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.crypt_method > QCOW_ENCRYPTION_AES) if(_qHdr.crypt_method > QCOW_ENCRYPTION_AES)
throw new ArgumentOutOfRangeException(nameof(_qHdr.crypt_method), "Invalid encryption method"); {
AaruConsole.ErrorWriteLine("Invalid encryption method");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.crypt_method > QCOW_ENCRYPTION_NONE) if(_qHdr.crypt_method > QCOW_ENCRYPTION_NONE)
throw new NotImplementedException("AES encrypted images not yet supported"); {
AaruConsole.ErrorWriteLine("AES encrypted images not yet supported");
return ErrorNumber.NotImplemented;
}
if(_qHdr.backing_file_offset != 0) if(_qHdr.backing_file_offset != 0)
throw new NotImplementedException("Differencing images not yet supported"); {
AaruConsole.ErrorWriteLine("Differencing images not yet supported");
return ErrorNumber.NotImplemented;
}
_clusterSize = 1 << (int)_qHdr.cluster_bits; _clusterSize = 1 << (int)_qHdr.cluster_bits;
_clusterSectors = 1 << ((int)_qHdr.cluster_bits - 9); _clusterSectors = 1 << ((int)_qHdr.cluster_bits - 9);

View File

@@ -213,8 +213,11 @@ namespace Aaru.DiscImages
ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift; ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift;
if((long)l1Off >= _l1Table.LongLength) if((long)l1Off >= _l1Table.LongLength)
throw new ArgumentOutOfRangeException(nameof(l1Off), {
$"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}"); ErrorMessage = $"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}";
return false;
}
if(_l1Table[l1Off] == 0) if(_l1Table[l1Off] == 0)
{ {

View File

@@ -70,31 +70,46 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("QED plugin", "qHdr.backing_file_size = {0}", _qHdr.backing_file_size); AaruConsole.DebugWriteLine("QED plugin", "qHdr.backing_file_size = {0}", _qHdr.backing_file_size);
if(_qHdr.image_size <= 1) if(_qHdr.image_size <= 1)
throw new ArgumentOutOfRangeException(nameof(_qHdr.image_size), "Image size is too small"); {
AaruConsole.ErrorWriteLine("Image size is too small");
return ErrorNumber.InvalidArgument;
}
if(!IsPowerOfTwo(_qHdr.cluster_size)) if(!IsPowerOfTwo(_qHdr.cluster_size))
throw new ArgumentOutOfRangeException(nameof(_qHdr.cluster_size), "Cluster size must be a power of 2"); {
AaruConsole.ErrorWriteLine("Cluster size must be a power of 2");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.cluster_size < 4096 || if(_qHdr.cluster_size < 4096 ||
_qHdr.cluster_size > 67108864) _qHdr.cluster_size > 67108864)
throw new ArgumentOutOfRangeException(nameof(_qHdr.cluster_size), {
"Cluster size must be between 4 Kbytes and 64 Mbytes"); AaruConsole.ErrorWriteLine("Cluster size must be between 4 Kbytes and 64 Mbytes");
return ErrorNumber.InvalidArgument;
}
if(!IsPowerOfTwo(_qHdr.table_size)) if(!IsPowerOfTwo(_qHdr.table_size))
throw new ArgumentOutOfRangeException(nameof(_qHdr.table_size), "Table size must be a power of 2"); {
AaruConsole.ErrorWriteLine("Table size must be a power of 2");
return ErrorNumber.InvalidArgument;
}
if(_qHdr.table_size < 1 || if(_qHdr.table_size < 1 ||
_qHdr.table_size > 16) _qHdr.table_size > 16)
throw new ArgumentOutOfRangeException(nameof(_qHdr.table_size), {
AaruConsole.ErrorWriteLine(
"Table size must be between 1 and 16 clusters"); "Table size must be between 1 and 16 clusters");
return ErrorNumber.InvalidArgument;
}
if((_qHdr.features & QED_FEATURE_MASK) > 0) if((_qHdr.features & QED_FEATURE_MASK) > 0)
throw new ArgumentOutOfRangeException(nameof(_qHdr.features), {
AaruConsole.ErrorWriteLine(
$"Image uses unknown incompatible features {_qHdr.features & QED_FEATURE_MASK:X}"); $"Image uses unknown incompatible features {_qHdr.features & QED_FEATURE_MASK:X}");
return ErrorNumber.InvalidArgument;
}
if((_qHdr.features & QED_FEATURE_BACKING_FILE) == QED_FEATURE_BACKING_FILE) if((_qHdr.features & QED_FEATURE_BACKING_FILE) == QED_FEATURE_BACKING_FILE)
throw new NotImplementedException("Differencing images not yet supported"); {
AaruConsole.ErrorWriteLine("Differencing images not yet supported");
return ErrorNumber.NotImplemented;
}
_clusterSectors = _qHdr.cluster_size / 512; _clusterSectors = _qHdr.cluster_size / 512;
_tableSize = _qHdr.cluster_size * _qHdr.table_size / 8; _tableSize = _qHdr.cluster_size * _qHdr.table_size / 8;

View File

@@ -176,8 +176,11 @@ namespace Aaru.DiscImages
ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift; ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift;
if((long)l1Off >= _l1Table.LongLength) if((long)l1Off >= _l1Table.LongLength)
throw new ArgumentOutOfRangeException(nameof(l1Off), {
$"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}"); ErrorMessage = $"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}";
return false;
}
if(_l1Table[l1Off] == 0) if(_l1Table[l1Off] == 0)
{ {

View File

@@ -32,7 +32,7 @@
using System; using System;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Exceptions; using Aaru.CommonTypes.Enums;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -69,9 +69,10 @@ namespace Aaru.DiscImages
return crc; return crc;
} }
static byte[] DecodeTeleDiskData(byte sectorSize, byte encodingType, byte[] encodedData) static ErrorNumber DecodeTeleDiskData(byte sectorSize, byte encodingType, byte[] encodedData,
out byte[] decodedData)
{ {
byte[] decodedData; decodedData = null;
switch(sectorSize) switch(sectorSize)
{ {
@@ -103,7 +104,10 @@ namespace Aaru.DiscImages
decodedData = new byte[8192]; decodedData = new byte[8192];
break; break;
default: throw new ImageNotSupportedException($"Sector size {sectorSize} is incorrect."); default:
AaruConsole.ErrorWriteLine($"Sector size {sectorSize} is incorrect.");
return ErrorNumber.InvalidArgument;
} }
switch(encodingType) switch(encodingType)
@@ -189,10 +193,13 @@ namespace Aaru.DiscImages
break; break;
} }
default: throw new ImageNotSupportedException($"Data encoding {encodingType} is incorrect."); default:
AaruConsole.ErrorWriteLine($"Data encoding {encodingType} is incorrect.");
return ErrorNumber.InvalidArgument;
} }
return decodedData; return ErrorNumber.NoError;
} }
MediaType DecodeTeleDiskDiskType() MediaType DecodeTeleDiskDiskType()

View File

@@ -34,7 +34,6 @@ using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Compression; using Aaru.Compression;
using Aaru.Console; using Aaru.Console;
@@ -281,7 +280,11 @@ namespace Aaru.DiscImages
if(totalCylinders <= 0 || if(totalCylinders <= 0 ||
totalHeads <= 0) totalHeads <= 0)
throw new ImageNotSupportedException("No cylinders or heads found"); {
AaruConsole.ErrorWriteLine("No cylinders or heads found");
return ErrorNumber.InvalidArgument;
}
bool hasLeadOutOnHead0 = false; bool hasLeadOutOnHead0 = false;
bool hasLeadOutOnHead1 = false; bool hasLeadOutOnHead1 = false;
@@ -451,7 +454,11 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("TeleDisk plugin", "\t\tData encoding: 0x{0:X2}", AaruConsole.DebugWriteLine("TeleDisk plugin", "\t\tData encoding: 0x{0:X2}",
teleDiskData.DataEncoding); teleDiskData.DataEncoding);
decodedData = DecodeTeleDiskData(teleDiskSector.SectorSize, teleDiskData.DataEncoding, data); ErrorNumber errno = DecodeTeleDiskData(teleDiskSector.SectorSize, teleDiskData.DataEncoding,
data, out decodedData);
if(errno != ErrorNumber.NoError)
return errno;
byte tdSectorCalculatedCrc = (byte)(TeleDiskCrc(0, decodedData) & 0xFF); byte tdSectorCalculatedCrc = (byte)(TeleDiskCrc(0, decodedData) & 0xFF);

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Linq; using System.Linq;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Compression; using Aaru.Compression;
using Aaru.Console; using Aaru.Console;
@@ -77,7 +76,11 @@ namespace Aaru.DiscImages
_footer = Marshal.ByteArrayToStructureBigEndian<Footer>(footerB); _footer = Marshal.ByteArrayToStructureBigEndian<Footer>(footerB);
if(_footer.signature != UDIF_SIGNATURE) if(_footer.signature != UDIF_SIGNATURE)
throw new Exception("Unable to find UDIF signature."); {
AaruConsole.ErrorWriteLine("Unable to find UDIF signature.");
return ErrorNumber.InvalidArgument;
}
AaruConsole.VerboseWriteLine("Found obsolete UDIF format."); AaruConsole.VerboseWriteLine("Found obsolete UDIF format.");
} }
@@ -134,18 +137,30 @@ namespace Aaru.DiscImages
var rsrc = new ResourceFork(rsrcB); var rsrc = new ResourceFork(rsrcB);
if(!rsrc.ContainsKey(BLOCK_OS_TYPE)) if(!rsrc.ContainsKey(BLOCK_OS_TYPE))
throw new {
ImageNotSupportedException("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us."); AaruConsole.
ErrorWriteLine("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
Resource blkxRez = rsrc.GetResource(BLOCK_OS_TYPE); Resource blkxRez = rsrc.GetResource(BLOCK_OS_TYPE);
if(blkxRez == null) if(blkxRez == null)
throw new {
ImageNotSupportedException("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us."); AaruConsole.
ErrorWriteLine("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
if(blkxRez.GetIds().Length == 0) if(blkxRez.GetIds().Length == 0)
throw new {
ImageNotSupportedException("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us."); AaruConsole.
ErrorWriteLine("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
blkxList.AddRange(blkxRez.GetIds().Select(blkxId => blkxRez.GetResource(blkxId))); blkxList.AddRange(blkxRez.GetIds().Select(blkxId => blkxRez.GetResource(blkxId)));
@@ -165,25 +180,45 @@ namespace Aaru.DiscImages
var plist = (NSDictionary)XmlPropertyListParser.Parse(plistB); var plist = (NSDictionary)XmlPropertyListParser.Parse(plistB);
if(plist == null) if(plist == null)
throw new Exception("Could not parse property list."); {
AaruConsole.ErrorWriteLine("Could not parse property list.");
return ErrorNumber.InOutError;
}
if(!plist.TryGetValue(RESOURCE_FORK_KEY, out NSObject rsrcObj)) if(!plist.TryGetValue(RESOURCE_FORK_KEY, out NSObject rsrcObj))
throw new Exception("Could not retrieve resource fork."); {
AaruConsole.ErrorWriteLine("Could not retrieve resource fork.");
return ErrorNumber.InOutError;
}
var rsrc = (NSDictionary)rsrcObj; var rsrc = (NSDictionary)rsrcObj;
if(!rsrc.TryGetValue(BLOCK_KEY, out NSObject blkxObj)) if(!rsrc.TryGetValue(BLOCK_KEY, out NSObject blkxObj))
throw new Exception("Could not retrieve block chunks array."); {
AaruConsole.ErrorWriteLine("Could not retrieve block chunks array.");
return ErrorNumber.InOutError;
}
NSObject[] blkx = ((NSArray)blkxObj).GetArray(); NSObject[] blkx = ((NSArray)blkxObj).GetArray();
foreach(NSDictionary part in blkx.Cast<NSDictionary>()) foreach(NSDictionary part in blkx.Cast<NSDictionary>())
{ {
if(!part.TryGetValue("Name", out _)) if(!part.TryGetValue("Name", out _))
throw new Exception("Could not retrieve Name"); {
AaruConsole.ErrorWriteLine("Could not retrieve Name");
return ErrorNumber.InOutError;
}
if(!part.TryGetValue("Data", out NSObject dataObj)) if(!part.TryGetValue("Data", out NSObject dataObj))
throw new Exception("Could not retrieve Data"); {
AaruConsole.ErrorWriteLine("Could not retrieve Data");
return ErrorNumber.InOutError;
}
blkxList.Add(((NSData)dataObj).Bytes); blkxList.Add(((NSData)dataObj).Bytes);
} }
@@ -199,7 +234,11 @@ namespace Aaru.DiscImages
else else
{ {
if(imageFilter.ResourceForkLength == 0) if(imageFilter.ResourceForkLength == 0)
throw new Exception("This image needs the resource fork to work."); {
AaruConsole.ErrorWriteLine("This image needs the resource fork to work.");
return ErrorNumber.InvalidArgument;
}
AaruConsole.DebugWriteLine("UDIF plugin", "Reading resource fork."); AaruConsole.DebugWriteLine("UDIF plugin", "Reading resource fork.");
Stream rsrcStream = imageFilter.GetResourceForkStream(); Stream rsrcStream = imageFilter.GetResourceForkStream();
@@ -211,18 +250,30 @@ namespace Aaru.DiscImages
var rsrc = new ResourceFork(rsrcB); var rsrc = new ResourceFork(rsrcB);
if(!rsrc.ContainsKey(BLOCK_OS_TYPE)) if(!rsrc.ContainsKey(BLOCK_OS_TYPE))
throw new {
ImageNotSupportedException("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us."); AaruConsole.
ErrorWriteLine("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
Resource blkxRez = rsrc.GetResource(BLOCK_OS_TYPE); Resource blkxRez = rsrc.GetResource(BLOCK_OS_TYPE);
if(blkxRez == null) if(blkxRez == null)
throw new {
ImageNotSupportedException("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us."); AaruConsole.
ErrorWriteLine("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
if(blkxRez.GetIds().Length == 0) if(blkxRez.GetIds().Length == 0)
throw new {
ImageNotSupportedException("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us."); AaruConsole.
ErrorWriteLine("Image resource fork doesn't contain UDIF block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
blkxList.AddRange(blkxRez.GetIds().Select(blkxId => blkxRez.GetResource(blkxId))); blkxList.AddRange(blkxRez.GetIds().Select(blkxId => blkxRez.GetResource(blkxId)));
@@ -287,8 +338,11 @@ namespace Aaru.DiscImages
_imageInfo.Sectors = 0; _imageInfo.Sectors = 0;
if(blkxList.Count == 0) if(blkxList.Count == 0)
throw new {
ImageNotSupportedException("Could not retrieve block chunks. Please fill an issue and send it to us."); AaruConsole.ErrorWriteLine("Could not retrieve block chunks. Please fill an issue and send it to us.");
return ErrorNumber.InvalidArgument;
}
_buffersize = 0; _buffersize = 0;
@@ -354,19 +408,30 @@ namespace Aaru.DiscImages
// TODO: Handle compressed chunks // TODO: Handle compressed chunks
case CHUNK_TYPE_KENCODE: case CHUNK_TYPE_KENCODE:
throw new AaruConsole.ErrorWriteLine("Chunks compressed with KenCode are not yet supported.");
ImageNotSupportedException("Chunks compressed with KenCode are not yet supported.");
return ErrorNumber.NotImplemented;
case CHUNK_TYPE_LZH: case CHUNK_TYPE_LZH:
throw new ImageNotSupportedException("Chunks compressed with LZH are not yet supported."); AaruConsole.ErrorWriteLine("Chunks compressed with LZH are not yet supported.");
return ErrorNumber.NotImplemented;
case CHUNK_TYPE_LZFSE: case CHUNK_TYPE_LZFSE:
throw new ImageNotSupportedException("Chunks compressed with lzfse are not yet supported."); AaruConsole.ErrorWriteLine("Chunks compressed with lzfse are not yet supported.");
return ErrorNumber.NotImplemented;
case CHUNK_TYPE_LZMA: case CHUNK_TYPE_LZMA:
throw new ImageNotSupportedException("Chunks compressed with lzma are not yet supported."); AaruConsole.ErrorWriteLine("Chunks compressed with lzma are not yet supported.");
return ErrorNumber.NotImplemented;
} }
if((bChnk.type > CHUNK_TYPE_NOCOPY && bChnk.type < CHUNK_TYPE_COMMNT) || if((bChnk.type > CHUNK_TYPE_NOCOPY && bChnk.type < CHUNK_TYPE_COMMNT) ||
(bChnk.type > CHUNK_TYPE_LZMA && bChnk.type < CHUNK_TYPE_END)) (bChnk.type > CHUNK_TYPE_LZMA && bChnk.type < CHUNK_TYPE_END))
throw new ImageNotSupportedException($"Unsupported chunk type 0x{bChnk.type:X8} found"); {
AaruConsole.ErrorWriteLine($"Unsupported chunk type 0x{bChnk.type:X8} found");
return ErrorNumber.InvalidArgument;
}
if(bChnk.sectors > 0) if(bChnk.sectors > 0)
_chunks.Add(bChnk.sector, bChnk); _chunks.Add(bChnk.sector, bChnk);

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Marshal = Aaru.Helpers.Marshal; using Marshal = Aaru.Helpers.Marshal;
@@ -89,8 +88,11 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("VirtualBox plugin", "vHdr.logicalSectorSize = {0}", _vHdr.logicalSectorSize); AaruConsole.DebugWriteLine("VirtualBox plugin", "vHdr.logicalSectorSize = {0}", _vHdr.logicalSectorSize);
if(_vHdr.imageType != VdiImageType.Normal) if(_vHdr.imageType != VdiImageType.Normal)
throw new {
FeatureSupportedButNotImplementedImageException($"Support for image type {_vHdr.imageType} not yet implemented"); AaruConsole.ErrorWriteLine($"Support for image type {_vHdr.imageType} not yet implemented");
return ErrorNumber.InvalidArgument;
}
DateTime start = DateTime.UtcNow; DateTime start = DateTime.UtcNow;
AaruConsole.DebugWriteLine("VirtualBox plugin", "Reading Image Block Map"); AaruConsole.DebugWriteLine("VirtualBox plugin", "Reading Image Block Map");

View File

@@ -37,7 +37,6 @@ using System.Text;
using Aaru.Checksums; using Aaru.Checksums;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -108,8 +107,12 @@ namespace Aaru.DiscImages
usableChecksum = footerChecksum; usableChecksum = footerChecksum;
} }
else else
throw new {
ImageNotSupportedException("(VirtualPC plugin): Both header and footer are corrupt, image cannot be opened."); AaruConsole.
ErrorWriteLine("(VirtualPC plugin): Both header and footer are corrupt, image cannot be opened.");
return ErrorNumber.InvalidArgument;
}
_thisFooter = new HardDiskFooter _thisFooter = new HardDiskFooter
{ {
@@ -176,8 +179,12 @@ namespace Aaru.DiscImages
if(_thisFooter.Version == VERSION1) if(_thisFooter.Version == VERSION1)
_imageInfo.Version = "1.0"; _imageInfo.Version = "1.0";
else else
throw new {
ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image."); AaruConsole.
ErrorWriteLine($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image.");
return ErrorNumber.InvalidArgument;
}
switch(_thisFooter.CreatorApplication) switch(_thisFooter.CreatorApplication)
{ {
@@ -360,8 +367,12 @@ namespace Aaru.DiscImages
dynamicChecksumCalculated); dynamicChecksumCalculated);
if(dynamicChecksum != dynamicChecksumCalculated) if(dynamicChecksum != dynamicChecksumCalculated)
throw new {
ImageNotSupportedException("(VirtualPC plugin): Both header and footer are corrupt, image cannot be opened."); AaruConsole.
ErrorWriteLine("(VirtualPC plugin): Both header and footer are corrupt, image cannot be opened.");
return ErrorNumber.InvalidArgument;
}
_thisDynamic = new DynamicDiskHeader _thisDynamic = new DynamicDiskHeader
{ {
@@ -457,8 +468,12 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("VirtualPC plugin", "dynamic.reserved2's SHA1 = 0x{0}", sha1Ctx.End()); AaruConsole.DebugWriteLine("VirtualPC plugin", "dynamic.reserved2's SHA1 = 0x{0}", sha1Ctx.End());
if(_thisDynamic.HeaderVersion != VERSION1) if(_thisDynamic.HeaderVersion != VERSION1)
throw new {
ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image."); AaruConsole.
ErrorWriteLine($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image.");
return ErrorNumber.InvalidArgument;
}
DateTime startTime = DateTime.UtcNow; DateTime startTime = DateTime.UtcNow;
@@ -603,8 +618,12 @@ namespace Aaru.DiscImages
} }
if(!locatorFound) if(!locatorFound)
throw new {
FileNotFoundException("(VirtualPC plugin): Cannot find parent file for differencing disk image"); AaruConsole.
ErrorWriteLine("(VirtualPC plugin): Cannot find parent file for differencing disk image");
return ErrorNumber.NoSuchFile;
}
{ {
_parentImage = new Vhd(); _parentImage = new Vhd();
@@ -613,15 +632,26 @@ namespace Aaru.DiscImages
new FiltersList().GetFilter(Path.Combine(imageFilter.ParentFolder, parentPath)); new FiltersList().GetFilter(Path.Combine(imageFilter.ParentFolder, parentPath));
if(parentFilter == null) if(parentFilter == null)
throw new ImageNotSupportedException("(VirtualPC plugin): Cannot find parent image filter"); {
AaruConsole.ErrorWriteLine("(VirtualPC plugin): Cannot find parent image filter");
return ErrorNumber.NoSuchFile;
}
/* PluginBase plugins = new PluginBase(); /* PluginBase plugins = new PluginBase();
plugins.RegisterAllPlugins(); plugins.RegisterAllPlugins();
if (!plugins.ImagePluginsList.TryGetValue(Name.ToLower(), out parentImage)) if (!plugins.ImagePluginsList.TryGetValue(Name.ToLower(), out parentImage))
throw new SystemException("(VirtualPC plugin): Unable to open myself");*/ {
AaruConsole.ErrorWriteLine("(VirtualPC plugin): Unable to open myself");
return ErrorNumber.InvalidArgument;
}*/
if(!_parentImage.Identify(parentFilter)) if(!_parentImage.Identify(parentFilter))
throw new {
ImageNotSupportedException("(VirtualPC plugin): Parent image is not a Virtual PC disk image"); AaruConsole.
ErrorWriteLine("(VirtualPC plugin): Parent image is not a Virtual PC disk image");
return ErrorNumber.InvalidArgument;
}
ErrorNumber parentError = _parentImage.Open(parentFilter); ErrorNumber parentError = _parentImage.Open(parentFilter);
@@ -638,9 +668,12 @@ namespace Aaru.DiscImages
// the parent never stored itself. So the only real way to know that images are related is // the parent never stored itself. So the only real way to know that images are related is
// because the parent IS found and SAME SIZE. Ugly... // because the parent IS found and SAME SIZE. Ugly...
// More funny even, tested parent images show an empty host OS, and child images a correct one. // More funny even, tested parent images show an empty host OS, and child images a correct one.
if(_parentImage.Info.Sectors != _imageInfo.Sectors) if(_parentImage.Info.Sectors == _imageInfo.Sectors)
throw new return ErrorNumber.NoError;
ImageNotSupportedException("(VirtualPC plugin): Parent image is of different size");
AaruConsole.ErrorWriteLine("(VirtualPC plugin): Parent image is of different size");
return ErrorNumber.InvalidArgument;
} }
return ErrorNumber.NoError; return ErrorNumber.NoError;
@@ -649,16 +682,16 @@ namespace Aaru.DiscImages
case TYPE_DEPRECATED1: case TYPE_DEPRECATED1:
case TYPE_DEPRECATED2: case TYPE_DEPRECATED2:
case TYPE_DEPRECATED3: case TYPE_DEPRECATED3:
{ AaruConsole.
throw new ErrorWriteLine("(VirtualPC plugin): Deprecated image type found. Please submit a bug with an example image.");
ImageNotSupportedException("(VirtualPC plugin): Deprecated image type found. Please submit a bug with an example image.");
} return ErrorNumber.NotImplemented;
default: default:
{ AaruConsole.
throw new ErrorWriteLine($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image.");
ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image.");
} return ErrorNumber.InvalidArgument;
} }
} }
@@ -846,16 +879,16 @@ namespace Aaru.DiscImages
case TYPE_DEPRECATED1: case TYPE_DEPRECATED1:
case TYPE_DEPRECATED2: case TYPE_DEPRECATED2:
case TYPE_DEPRECATED3: case TYPE_DEPRECATED3:
{ AaruConsole.
throw new ErrorWriteLine("(VirtualPC plugin): Deprecated image type found. Please submit a bug with an example image.");
ImageNotSupportedException("(VirtualPC plugin): Deprecated image type found. Please submit a bug with an example image.");
} return ErrorNumber.NotImplemented;
default: default:
{ AaruConsole.
throw new ErrorWriteLine($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image.");
ImageNotSupportedException($"(VirtualPC plugin): Unknown image type {_thisFooter.DiskType} found. Please submit a bug with an example image.");
} return ErrorNumber.InvalidArgument;
} }
} }
} }

View File

@@ -36,7 +36,6 @@ using System.IO;
using System.Text; using System.Text;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -76,7 +75,11 @@ namespace Aaru.DiscImages
_vHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(vHdrB); _vHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(vHdrB);
if(_vHdr.Signature != VHDX_HEADER_SIG) if(_vHdr.Signature != VHDX_HEADER_SIG)
throw new ImageNotSupportedException("VHDX header not found"); {
AaruConsole.ErrorWriteLine("VHDX header not found");
return ErrorNumber.InvalidArgument;
}
} }
stream.Seek(192 * 1024, SeekOrigin.Begin); stream.Seek(192 * 1024, SeekOrigin.Begin);
@@ -92,7 +95,11 @@ namespace Aaru.DiscImages
_vRegHdr = Marshal.ByteArrayToStructureLittleEndian<RegionTableHeader>(vRegTableB); _vRegHdr = Marshal.ByteArrayToStructureLittleEndian<RegionTableHeader>(vRegTableB);
if(_vRegHdr.signature != VHDX_REGION_SIG) if(_vRegHdr.signature != VHDX_REGION_SIG)
throw new ImageNotSupportedException("VHDX region table not found"); {
AaruConsole.ErrorWriteLine("VHDX region table not found");
return ErrorNumber.InvalidArgument;
}
} }
_vRegs = new RegionTableEntry[_vRegHdr.entries]; _vRegs = new RegionTableEntry[_vRegHdr.entries];
@@ -108,15 +115,27 @@ namespace Aaru.DiscImages
else if(_vRegs[i].guid == _metadataGuid) else if(_vRegs[i].guid == _metadataGuid)
_metadataOffset = (long)_vRegs[i].offset; _metadataOffset = (long)_vRegs[i].offset;
else if((_vRegs[i].flags & REGION_FLAGS_REQUIRED) == REGION_FLAGS_REQUIRED) else if((_vRegs[i].flags & REGION_FLAGS_REQUIRED) == REGION_FLAGS_REQUIRED)
throw new {
ImageNotSupportedException($"Found unsupported and required region Guid {_vRegs[i].guid}, not proceeding with image."); AaruConsole.
ErrorWriteLine($"Found unsupported and required region Guid {_vRegs[i].guid}, not proceeding with image.");
return ErrorNumber.InvalidArgument;
}
} }
if(_batOffset == 0) if(_batOffset == 0)
throw new Exception("BAT not found, cannot continue."); {
AaruConsole.ErrorWriteLine("BAT not found, cannot continue.");
return ErrorNumber.InvalidArgument;
}
if(_metadataOffset == 0) if(_metadataOffset == 0)
throw new Exception("Metadata not found, cannot continue."); {
AaruConsole.ErrorWriteLine("Metadata not found, cannot continue.");
return ErrorNumber.InvalidArgument;
}
uint fileParamsOff = 0, vdSizeOff = 0, p83Off = 0, logOff = 0, physOff = 0, parentOff = 0; uint fileParamsOff = 0, vdSizeOff = 0, p83Off = 0, logOff = 0, physOff = 0, parentOff = 0;
@@ -146,8 +165,12 @@ namespace Aaru.DiscImages
else if(_vMets[i].itemId == _parentLocatorGuid) else if(_vMets[i].itemId == _parentLocatorGuid)
parentOff = _vMets[i].offset; parentOff = _vMets[i].offset;
else if((_vMets[i].flags & METADATA_FLAGS_REQUIRED) == METADATA_FLAGS_REQUIRED) else if((_vMets[i].flags & METADATA_FLAGS_REQUIRED) == METADATA_FLAGS_REQUIRED)
throw new {
ImageNotSupportedException($"Found unsupported and required metadata Guid {_vMets[i].itemId}, not proceeding with image."); AaruConsole.
ErrorWriteLine($"Found unsupported and required metadata Guid {_vMets[i].itemId}, not proceeding with image.");
return ErrorNumber.InvalidArgument;
}
} }
byte[] tmp; byte[] tmp;
@@ -165,7 +188,11 @@ namespace Aaru.DiscImages
}; };
} }
else else
throw new Exception("File parameters not found."); {
AaruConsole.ErrorWriteLine("File parameters not found.");
return ErrorNumber.InvalidArgument;
}
if(vdSizeOff != 0) if(vdSizeOff != 0)
{ {
@@ -175,7 +202,11 @@ namespace Aaru.DiscImages
_virtualDiskSize = BitConverter.ToUInt64(tmp, 0); _virtualDiskSize = BitConverter.ToUInt64(tmp, 0);
} }
else else
throw new Exception("Virtual disk size not found."); {
AaruConsole.ErrorWriteLine("Virtual disk size not found.");
return ErrorNumber.InvalidArgument;
}
if(p83Off != 0) if(p83Off != 0)
{ {
@@ -193,7 +224,11 @@ namespace Aaru.DiscImages
_logicalSectorSize = BitConverter.ToUInt32(tmp, 0); _logicalSectorSize = BitConverter.ToUInt32(tmp, 0);
} }
else else
throw new Exception("Logical sector size not found."); {
AaruConsole.ErrorWriteLine("Logical sector size not found.");
return ErrorNumber.InvalidArgument;
}
if(physOff != 0) if(physOff != 0)
{ {
@@ -203,7 +238,11 @@ namespace Aaru.DiscImages
_physicalSectorSize = BitConverter.ToUInt32(tmp, 0); _physicalSectorSize = BitConverter.ToUInt32(tmp, 0);
} }
else else
throw new Exception("Physical sector size not found."); {
AaruConsole.ErrorWriteLine("Physical sector size not found.");
return ErrorNumber.InvalidArgument;
}
if(parentOff != 0 && if(parentOff != 0 &&
(_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT) (_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT)
@@ -214,8 +253,12 @@ namespace Aaru.DiscImages
_vParHdr = Marshal.ByteArrayToStructureLittleEndian<ParentLocatorHeader>(vParHdrB); _vParHdr = Marshal.ByteArrayToStructureLittleEndian<ParentLocatorHeader>(vParHdrB);
if(_vParHdr.locatorType != _parentTypeVhdxGuid) if(_vParHdr.locatorType != _parentTypeVhdxGuid)
throw new {
ImageNotSupportedException($"Found unsupported and required parent locator type {_vParHdr.locatorType}, not proceeding with image."); AaruConsole.
ErrorWriteLine($"Found unsupported and required parent locator type {_vParHdr.locatorType}, not proceeding with image.");
return ErrorNumber.NotSupported;
}
_vPars = new ParentLocatorEntry[_vParHdr.keyValueCount]; _vPars = new ParentLocatorEntry[_vParHdr.keyValueCount];
@@ -227,7 +270,11 @@ namespace Aaru.DiscImages
} }
} }
else if((_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT) else if((_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT)
throw new Exception("Parent locator not found."); {
AaruConsole.ErrorWriteLine("Parent locator not found.");
return ErrorNumber.NoSuchFile;
}
if((_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT && if((_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT &&
_vParHdr.locatorType == _parentTypeVhdxGuid) _vParHdr.locatorType == _parentTypeVhdxGuid)
@@ -318,7 +365,11 @@ namespace Aaru.DiscImages
} }
if(!parentWorks) if(!parentWorks)
throw new Exception("Image is differential but parent cannot be opened."); {
AaruConsole.ErrorWriteLine("Image is differential but parent cannot be opened.");
return ErrorNumber.InOutError;
}
_hasParent = true; _hasParent = true;
} }
@@ -392,8 +443,12 @@ namespace Aaru.DiscImages
break; break;
default: default:
if((pt & BAT_FLAGS_MASK) != 0) if((pt & BAT_FLAGS_MASK) != 0)
throw new {
ImageNotSupportedException($"Unsupported sector bitmap block flags (0x{pt & BAT_FLAGS_MASK:X16}) found, not proceeding."); AaruConsole.
ErrorWriteLine($"Unsupported sector bitmap block flags (0x{pt & BAT_FLAGS_MASK:X16}) found, not proceeding.");
return ErrorNumber.InvalidArgument;
}
break; break;
} }
@@ -447,8 +502,11 @@ namespace Aaru.DiscImages
ulong blkFlags = blkPtr & BAT_FLAGS_MASK; ulong blkFlags = blkPtr & BAT_FLAGS_MASK;
if((blkPtr & BAT_RESERVED_MASK) != 0) if((blkPtr & BAT_RESERVED_MASK) != 0)
throw new {
ImageNotSupportedException($"Unknown flags (0x{blkPtr & BAT_RESERVED_MASK:X16}) set in block pointer"); AaruConsole.ErrorWriteLine($"Unknown flags (0x{blkPtr & BAT_RESERVED_MASK:X16}) set in block pointer");
return ErrorNumber.InvalidArgument;
}
switch(blkFlags & BAT_FLAGS_MASK) switch(blkFlags & BAT_FLAGS_MASK)
{ {

View File

@@ -38,7 +38,6 @@ using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Console; using Aaru.Console;
using Aaru.Helpers; using Aaru.Helpers;
@@ -84,7 +83,11 @@ namespace Aaru.DiscImages
if(_vmEHdr.descriptorOffset == 0 || if(_vmEHdr.descriptorOffset == 0 ||
_vmEHdr.descriptorSize == 0) _vmEHdr.descriptorSize == 0)
throw new Exception("Please open VMDK descriptor."); {
AaruConsole.ErrorWriteLine("Please open VMDK descriptor.");
return ErrorNumber.InvalidArgument;
}
byte[] ddfEmbed = new byte[_vmEHdr.descriptorSize * SECTOR_SIZE]; byte[] ddfEmbed = new byte[_vmEHdr.descriptorSize * SECTOR_SIZE];
@@ -106,7 +109,11 @@ namespace Aaru.DiscImages
stream.Read(ddfMagic, 0, 0x15); stream.Read(ddfMagic, 0, 0x15);
if(!_ddfMagicBytes.SequenceEqual(ddfMagic)) if(!_ddfMagicBytes.SequenceEqual(ddfMagic))
throw new Exception("Not a descriptor."); {
AaruConsole.ErrorWriteLine("Not a descriptor.");
return ErrorNumber.InvalidArgument;
}
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
byte[] ddfExternal = new byte[imageFilter.DataForkLength]; byte[] ddfExternal = new byte[imageFilter.DataForkLength];
@@ -274,7 +281,11 @@ namespace Aaru.DiscImages
} }
if(_extents.Count == 0) if(_extents.Count == 0)
throw new Exception("Did not find any extent"); {
AaruConsole.ErrorWriteLine("Did not find any extent");
return ErrorNumber.InvalidArgument;
}
switch(_imageType) switch(_imageType)
{ {
@@ -296,9 +307,14 @@ namespace Aaru.DiscImages
case VMFS_TYPE_RDMP: //"vmfsRDMP"; case VMFS_TYPE_RDMP: //"vmfsRDMP";
case VMFS_TYPE_RDMP_OLD: //"vmfsPassthroughRawDeviceMap"; case VMFS_TYPE_RDMP_OLD: //"vmfsPassthroughRawDeviceMap";
case VMFS_TYPE_RAW: //"vmfsRaw"; case VMFS_TYPE_RAW: //"vmfsRaw";
throw new AaruConsole.
ImageNotSupportedException("Raw device image files are not supported, try accessing the device directly."); ErrorWriteLine("Raw device image files are not supported, try accessing the device directly.");
default: throw new ImageNotSupportedException($"Dunno how to handle \"{_imageType}\" extents.");
return ErrorNumber.NotSupported;
default:
AaruConsole.ErrorWriteLine($"Dunno how to handle \"{_imageType}\" extents.");
return ErrorNumber.InvalidArgument;
} }
bool oneNoFlat = cowD; bool oneNoFlat = cowD;
@@ -306,10 +322,18 @@ namespace Aaru.DiscImages
foreach(Extent extent in _extents.Values) foreach(Extent extent in _extents.Values)
{ {
if(extent.Filter == null) if(extent.Filter == null)
throw new Exception($"Extent file {extent.Filename} not found."); {
AaruConsole.ErrorWriteLine($"Extent file {extent.Filename} not found.");
return ErrorNumber.NoSuchFile;
}
if(extent.Access == "NOACCESS") if(extent.Access == "NOACCESS")
throw new Exception("Cannot access NOACCESS extents ;)."); {
AaruConsole.ErrorWriteLine("Cannot access NOACCESS extents ;).");
return ErrorNumber.InvalidArgument;
}
if(extent.Type == "FLAT" || if(extent.Type == "FLAT" ||
extent.Type == "ZERO" || extent.Type == "ZERO" ||
@@ -321,22 +345,38 @@ namespace Aaru.DiscImages
extentStream.Seek(0, SeekOrigin.Begin); extentStream.Seek(0, SeekOrigin.Begin);
if(extentStream.Length < SECTOR_SIZE) if(extentStream.Length < SECTOR_SIZE)
throw new Exception($"Extent {extent.Filename} is too small."); {
AaruConsole.ErrorWriteLine($"Extent {extent.Filename} is too small.");
return ErrorNumber.InvalidArgument;
}
byte[] extentHdrB = new byte[Marshal.SizeOf<ExtentHeader>()]; byte[] extentHdrB = new byte[Marshal.SizeOf<ExtentHeader>()];
extentStream.Read(extentHdrB, 0, Marshal.SizeOf<ExtentHeader>()); extentStream.Read(extentHdrB, 0, Marshal.SizeOf<ExtentHeader>());
ExtentHeader extentHdr = Marshal.ByteArrayToStructureLittleEndian<ExtentHeader>(extentHdrB); ExtentHeader extentHdr = Marshal.ByteArrayToStructureLittleEndian<ExtentHeader>(extentHdrB);
if(extentHdr.magic != VMWARE_EXTENT_MAGIC) if(extentHdr.magic != VMWARE_EXTENT_MAGIC)
throw new Exception($"{extent.Filter} is not an VMware extent."); {
AaruConsole.ErrorWriteLine($"{extent.Filter} is not an VMware extent.");
return ErrorNumber.InvalidArgument;
}
if(extentHdr.capacity < extent.Sectors) if(extentHdr.capacity < extent.Sectors)
throw new {
Exception($"Extent contains incorrect number of sectors, {extentHdr.capacity}. {extent.Sectors} were expected"); AaruConsole.
ErrorWriteLine($"Extent contains incorrect number of sectors, {extentHdr.capacity}. {extent.Sectors} were expected");
return ErrorNumber.InvalidArgument;
}
// TODO: Support compressed extents // TODO: Support compressed extents
if(extentHdr.compression != COMPRESSION_NONE) if(extentHdr.compression != COMPRESSION_NONE)
throw new ImageNotSupportedException("Compressed extents are not yet supported."); {
AaruConsole.ErrorWriteLine("Compressed extents are not yet supported.");
return ErrorNumber.NotImplemented;
}
if(!vmEHdrSet) if(!vmEHdrSet)
{ {
@@ -351,8 +391,12 @@ namespace Aaru.DiscImages
if(oneNoFlat && if(oneNoFlat &&
!vmEHdrSet && !vmEHdrSet &&
!cowD) !cowD)
throw new {
Exception("There are sparse extents but there is no header to find the grain tables, cannot proceed."); AaruConsole.
ErrorWriteLine("There are sparse extents but there is no header to find the grain tables, cannot proceed.");
return ErrorNumber.InvalidArgument;
}
_imageInfo.Sectors = currentSector; _imageInfo.Sectors = currentSector;
@@ -437,7 +481,11 @@ namespace Aaru.DiscImages
{ {
if(grains == 0 || if(grains == 0 ||
gdEntries == 0) gdEntries == 0)
throw new Exception("Some error occurred setting GD sizes"); {
AaruConsole.ErrorWriteLine("Some error occurred setting GD sizes");
return ErrorNumber.InOutError;
}
AaruConsole.DebugWriteLine("VMware plugin", "{0} sectors in {1} grains in {2} tables", AaruConsole.DebugWriteLine("VMware plugin", "{0} sectors in {1} grains in {2} tables",
_imageInfo.Sectors, grains, gdEntries); _imageInfo.Sectors, grains, gdEntries);
@@ -485,7 +533,11 @@ namespace Aaru.DiscImages
IFilter parentFilter = new FiltersList().GetFilter(Path.Combine(imageFilter.ParentFolder, _parentName)); IFilter parentFilter = new FiltersList().GetFilter(Path.Combine(imageFilter.ParentFolder, _parentName));
if(parentFilter == null) if(parentFilter == null)
throw new Exception($"Cannot find parent \"{_parentName}\"."); {
AaruConsole.ErrorWriteLine($"Cannot find parent \"{_parentName}\".");
return ErrorNumber.NoSuchFile;
}
_parentImage = new VMware(); _parentImage = new VMware();
ErrorNumber parentError = _parentImage.Open(parentFilter); ErrorNumber parentError = _parentImage.Open(parentFilter);

View File

@@ -82,7 +82,12 @@ namespace Aaru.DiscImages
for(int cyl = 0; cyl < _imageInfo.Cylinders; cyl++) for(int cyl = 0; cyl < _imageInfo.Cylinders; cyl++)
{ {
for(int head = 0; head < _imageInfo.Heads; head++) for(int head = 0; head < _imageInfo.Heads; head++)
ReadTrack(stream, cyl, head); {
var errno =ReadTrack(stream, cyl, head);
if(errno != ErrorNumber.NoError)
return errno;
}
} }
/* if there are extra tracks, read them as well */ /* if there are extra tracks, read them as well */
@@ -129,7 +134,11 @@ namespace Aaru.DiscImages
SectorHeader sheader = Marshal.ByteArrayToStructureLittleEndian<SectorHeader>(sheaderBuffer); SectorHeader sheader = Marshal.ByteArrayToStructureLittleEndian<SectorHeader>(sheaderBuffer);
if(sheader.flag != SectorFlag.Comment) if(sheader.flag != SectorFlag.Comment)
throw new InvalidDataException($"Invalid sector type '{sheader.flag.ToString()}' encountered"); {
AaruConsole.ErrorWriteLine($"Invalid sector type '{sheader.flag.ToString()}' encountered");
return ErrorNumber.InvalidArgument;
}
byte[] comm = new byte[sheader.crc]; byte[] comm = new byte[sheader.crc];
stream.Read(comm, 0, sheader.crc); stream.Read(comm, 0, sheader.crc);
@@ -145,7 +154,11 @@ namespace Aaru.DiscImages
SectorHeader sheader = Marshal.ByteArrayToStructureLittleEndian<SectorHeader>(sheaderBuffer); SectorHeader sheader = Marshal.ByteArrayToStructureLittleEndian<SectorHeader>(sheaderBuffer);
if(sheader.flag != SectorFlag.Directory) if(sheader.flag != SectorFlag.Directory)
throw new InvalidDataException($"Invalid sector type '{sheader.flag.ToString()}' encountered"); {
AaruConsole.ErrorWriteLine($"Invalid sector type '{sheader.flag.ToString()}' encountered");
return ErrorNumber.InvalidArgument;
}
byte[] dir = new byte[sheader.crc]; byte[] dir = new byte[sheader.crc];
stream.Read(dir, 0, sheader.crc); stream.Read(dir, 0, sheader.crc);
@@ -226,7 +239,7 @@ namespace Aaru.DiscImages
/// <param name="stream">The stream to read from</param> /// <param name="stream">The stream to read from</param>
/// <param name="cyl">The cylinder number of the track being read.</param> /// <param name="cyl">The cylinder number of the track being read.</param>
/// <param name="head">The head number of the track being read.</param> /// <param name="head">The head number of the track being read.</param>
void ReadTrack(Stream stream, int cyl, int head) ErrorNumber ReadTrack(Stream stream, int cyl, int head)
{ {
byte[] sectorData; byte[] sectorData;
byte[] crc; byte[] crc;
@@ -244,8 +257,12 @@ namespace Aaru.DiscImages
if(sheader.cylinder != cyl || if(sheader.cylinder != cyl ||
sheader.head != head || sheader.head != head ||
sheader.sector != sect) sheader.sector != sect)
throw new {
InvalidDataException($"Unexpected sector encountered. Found CHS {sheader.cylinder},{sheader.head},{sheader.sector} but expected {cyl},{head},{sect}"); AaruConsole.
ErrorWriteLine($"Unexpected sector encountered. Found CHS {sheader.cylinder},{sheader.head},{sheader.sector} but expected {cyl},{head},{sect}");
return ErrorNumber.InvalidArgument;
}
sectorData = new byte[512]; sectorData = new byte[512];
@@ -290,9 +307,13 @@ namespace Aaru.DiscImages
break; break;
default: default:
throw new InvalidDataException($"Invalid sector type '{sheader.flag.ToString()}' encountered"); AaruConsole.ErrorWriteLine($"Invalid sector type '{sheader.flag.ToString()}' encountered");
return ErrorNumber.InvalidArgument;
} }
} }
return ErrorNumber.NoError;
} }
} }
} }

View File

@@ -114,7 +114,7 @@ namespace Aaru.DiscImages
get get
{ {
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc) if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
throw new FeatureUnsupportedImageException("Feature not supported by image format"); return null;
var sess = new Session var sess = new Session
{ {

View File

@@ -37,7 +37,6 @@ using System.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Exceptions;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.CommonTypes.Structs.Devices.ATA; using Aaru.CommonTypes.Structs.Devices.ATA;
@@ -1217,7 +1216,7 @@ namespace Aaru.DiscImages
buffer = null; buffer = null;
if(_differentTrackZeroSize) if(_differentTrackZeroSize)
throw new NotImplementedException("Not yet implemented"); return ErrorNumber.NotImplemented;
if(sectorAddress > _imageInfo.Sectors - 1) if(sectorAddress > _imageInfo.Sectors - 1)
return ErrorNumber.OutOfRange; return ErrorNumber.OutOfRange;
@@ -1281,10 +1280,10 @@ namespace Aaru.DiscImages
public List<Track> GetSessionTracks(Session session) public List<Track> GetSessionTracks(Session session)
{ {
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc) if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
throw new FeatureUnsupportedImageException("Feature not supported by image format"); return null;
if(session.Sequence != 1) if(session.Sequence != 1)
throw new ArgumentOutOfRangeException(nameof(session), "Only a single session is supported"); return null;
var trk = new Track var trk = new Track
{ {
@@ -1314,10 +1313,10 @@ namespace Aaru.DiscImages
public List<Track> GetSessionTracks(ushort session) public List<Track> GetSessionTracks(ushort session)
{ {
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc) if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc)
throw new FeatureUnsupportedImageException("Feature not supported by image format"); return null;
if(session != 1) if(session != 1)
throw new ArgumentOutOfRangeException(nameof(session), "Only a single session is supported"); return null;
var trk = new Track var trk = new Track
{ {
@@ -1390,9 +1389,11 @@ namespace Aaru.DiscImages
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer) public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer)
{ {
buffer = null;
if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc || if(_imageInfo.XmlMediaType != XmlMediaType.OpticalDisc ||
(!_rawCompactDisc && tag != SectorTagType.CdTrackFlags)) (!_rawCompactDisc && tag != SectorTagType.CdTrackFlags))
throw new FeatureUnsupportedImageException("Feature not supported by image format"); return ErrorNumber.NotSupported;
return ReadSectorsTag(sectorAddress, 1, tag, out buffer); return ReadSectorsTag(sectorAddress, 1, tag, out buffer);
} }