Add Aaruformat validation and media item type (#29)

* Initial `media` and AaruFormat code

* But... why?

* Fix AIF reading

* Fix D2D, Logiqx cleanup

* Minor cleanup

* Final cleanup round
This commit is contained in:
Matt Nadareski
2020-08-27 16:57:22 -07:00
committed by GitHub
parent 3b481de3b9
commit 4d0a3f55eb
51 changed files with 2853 additions and 908 deletions

View File

@@ -0,0 +1,41 @@
using System.IO;
using System.Text;
namespace SabreTools.Library.FileTypes.Aaru
{
/// <summary>
/// Checksum entry, followed by checksum data itself
/// </summary>
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
public class ChecksumEntry
{
/// <summary>Checksum algorithm</summary>
public AaruChecksumAlgorithm type;
/// <summary>Length in bytes of checksum that follows this structure</summary>
public uint length;
/// <summary>Checksum that follows this structure</summary>
public byte[] checksum;
/// <summary>
/// Read a stream as an v
/// </summary>
/// <param name="stream">ChecksumEntry as a stream</param>
/// <returns>Populated ChecksumEntry, null on failure</returns>
public static ChecksumEntry Deserialize(Stream stream)
{
ChecksumEntry checksumEntry = new ChecksumEntry();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
checksumEntry.length = br.ReadUInt32();
if (checksumEntry.length == 0)
return null;
checksumEntry.checksum = br.ReadBytes((int)checksumEntry.length);
}
return checksumEntry;
}
}
}

View File

@@ -0,0 +1,39 @@
using System.IO;
using System.Text;
namespace SabreTools.Library.FileTypes.Aaru
{
/// <summary>
/// Checksum block, contains a checksum of all user data sectors
/// (except for optical discs that is 2352 bytes raw sector if available
/// </summary>
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
public class ChecksumHeader
{
/// <summary>Identifier, <see cref="BlockType.ChecksumBlock" /></summary>
public AaruBlockType identifier;
/// <summary>Length in bytes of the block</summary>
public uint length;
/// <summary>How many checksums follow</summary>
public byte entries;
/// <summary>
/// Read a stream as an ChecksumHeader
/// </summary>
/// <param name="stream">ChecksumHeader as a stream</param>
/// <returns>Populated ChecksumHeader, null on failure</returns>
public static ChecksumHeader Deserialize(Stream stream)
{
ChecksumHeader checksumHeader = new ChecksumHeader();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
checksumHeader.identifier = (AaruBlockType)br.ReadUInt32();
checksumHeader.length = br.ReadUInt32();
checksumHeader.entries = br.ReadByte();
}
return checksumHeader;
}
}
}

View File

@@ -0,0 +1,38 @@
using System.IO;
using System.Text;
namespace SabreTools.Library.FileTypes.Aaru
{
/// <summary>
/// Index entry
/// </summary>
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
public class IndexEntry
{
/// <summary>Type of item pointed by this entry</summary>
public AaruBlockType blockType;
/// <summary>Type of data contained by the block pointed by this entry</summary>
public AaruDataType dataType;
/// <summary>Offset in file where item is stored</summary>
public ulong offset;
/// <summary>
/// Read a stream as an IndexHeader
/// </summary>
/// <param name="stream">IndexHeader as a stream</param>
/// <returns>Populated IndexHeader, null on failure</returns>
public static IndexEntry Deserialize(Stream stream)
{
IndexEntry indexEntry = new IndexEntry();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
indexEntry.blockType = (AaruBlockType)br.ReadUInt32();
indexEntry.dataType = (AaruDataType)br.ReadUInt16();
indexEntry.offset = br.ReadUInt64();
}
return indexEntry;
}
}
}

View File

@@ -0,0 +1,38 @@
using System.IO;
using System.Text;
namespace SabreTools.Library.FileTypes.Aaru
{
/// <summary>
/// Header for the index, followed by entries
/// </summary>
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
public class IndexHeader
{
/// <summary>Identifier, <see cref="BlockType.Index" /></summary>
public AaruBlockType identifier;
/// <summary>How many entries follow this header</summary>
public ushort entries;
/// <summary>CRC64-ECMA of the index</summary>
public ulong crc64;
/// <summary>
/// Read a stream as an IndexHeader
/// </summary>
/// <param name="stream">IndexHeader as a stream</param>
/// <returns>Populated IndexHeader, null on failure</returns>
public static IndexHeader Deserialize(Stream stream)
{
IndexHeader indexHeader = new IndexHeader();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
indexHeader.identifier = (AaruBlockType)br.ReadUInt32();
indexHeader.entries = br.ReadUInt16();
indexHeader.crc64 = br.ReadUInt64();
}
return indexHeader;
}
}
}