mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
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:
41
SabreTools.Library/FileTypes/Aaru/ChecksumEntry.cs
Normal file
41
SabreTools.Library/FileTypes/Aaru/ChecksumEntry.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
SabreTools.Library/FileTypes/Aaru/ChecksumHeader.cs
Normal file
39
SabreTools.Library/FileTypes/Aaru/ChecksumHeader.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
SabreTools.Library/FileTypes/Aaru/IndexEntry.cs
Normal file
38
SabreTools.Library/FileTypes/Aaru/IndexEntry.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
SabreTools.Library/FileTypes/Aaru/IndexHeader.cs
Normal file
38
SabreTools.Library/FileTypes/Aaru/IndexHeader.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user