mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Start introducing concept of internal hashes
This commit is contained in:
@@ -12,6 +12,30 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AaruFormat : BaseFile
|
public class AaruFormat : BaseFile
|
||||||
{
|
{
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal MD5 hash of the file
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? InternalMD5 { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal SHA-1 hash of the file
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? InternalSHA1 { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal SHA-256 hash of the file
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? InternalSHA256 { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal SpamSum fuzzy hash of the file
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? InternalSpamSum { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
#region Header
|
#region Header
|
||||||
@@ -113,24 +137,19 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AaruFormat aif = new();
|
var aif = new AaruFormat();
|
||||||
|
|
||||||
#if NET20 || NET35 || NET40
|
aif.Identifier = stream.ReadUInt64();
|
||||||
using (BinaryReader br = new(stream, Encoding.Default))
|
byte[] applicationBytes = stream.ReadBytes(64);
|
||||||
#else
|
aif.Application = Encoding.Unicode.GetString(applicationBytes);
|
||||||
using (BinaryReader br = new(stream, Encoding.Default, true))
|
aif.ImageMajorVersion = stream.ReadByteValue();
|
||||||
#endif
|
aif.ImageMinorVersion = stream.ReadByteValue();
|
||||||
{
|
aif.ApplicationMajorVersion = stream.ReadByteValue();
|
||||||
aif.Identifier = br.ReadUInt64();
|
aif.ApplicationMinorVersion = stream.ReadByteValue();
|
||||||
aif.Application = Encoding.Unicode.GetString(br.ReadBytes(64), 0, 64);
|
aif.MediaType = (AaruMediaType)stream.ReadUInt32();
|
||||||
aif.ImageMajorVersion = br.ReadByte();
|
aif.IndexOffset = stream.ReadUInt64();
|
||||||
aif.ImageMinorVersion = br.ReadByte();
|
aif.CreationTime = stream.ReadInt64();
|
||||||
aif.ApplicationMajorVersion = br.ReadByte();
|
aif.LastWrittenTime = stream.ReadInt64();
|
||||||
aif.ApplicationMinorVersion = br.ReadByte();
|
|
||||||
aif.MediaType = (AaruMediaType)br.ReadUInt32();
|
|
||||||
aif.IndexOffset = br.ReadUInt64();
|
|
||||||
aif.CreationTime = br.ReadInt64();
|
|
||||||
aif.LastWrittenTime = br.ReadInt64();
|
|
||||||
|
|
||||||
// If the offset is bigger than the stream, we can't read it
|
// If the offset is bigger than the stream, we can't read it
|
||||||
if (aif.IndexOffset > (ulong)stream.Length)
|
if (aif.IndexOffset > (ulong)stream.Length)
|
||||||
@@ -193,15 +212,19 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
break;
|
break;
|
||||||
case AaruChecksumAlgorithm.Md5:
|
case AaruChecksumAlgorithm.Md5:
|
||||||
aif.MD5 = checksumEntry.checksum;
|
aif.MD5 = checksumEntry.checksum;
|
||||||
|
aif.InternalMD5 = checksumEntry.checksum;
|
||||||
break;
|
break;
|
||||||
case AaruChecksumAlgorithm.Sha1:
|
case AaruChecksumAlgorithm.Sha1:
|
||||||
aif.SHA1 = checksumEntry.checksum;
|
aif.SHA1 = checksumEntry.checksum;
|
||||||
|
aif.InternalSHA1 = checksumEntry.checksum;
|
||||||
break;
|
break;
|
||||||
case AaruChecksumAlgorithm.Sha256:
|
case AaruChecksumAlgorithm.Sha256:
|
||||||
aif.SHA256 = checksumEntry.checksum;
|
aif.SHA256 = checksumEntry.checksum;
|
||||||
|
aif.InternalSHA256 = checksumEntry.checksum;
|
||||||
break;
|
break;
|
||||||
case AaruChecksumAlgorithm.SpamSum:
|
case AaruChecksumAlgorithm.SpamSum:
|
||||||
aif.SpamSum = checksumEntry.checksum;
|
aif.SpamSum = checksumEntry.checksum;
|
||||||
|
aif.InternalSpamSum = checksumEntry.checksum;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +233,6 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
return aif;
|
return aif;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return aif;
|
return aif;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using SabreTools.IO.Extensions;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes.Aaru
|
namespace SabreTools.FileTypes.Aaru
|
||||||
{
|
{
|
||||||
@@ -25,19 +25,12 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
{
|
{
|
||||||
var checksumEntry = new ChecksumEntry();
|
var checksumEntry = new ChecksumEntry();
|
||||||
|
|
||||||
#if NET20 || NET35 || NET40
|
checksumEntry.type = (AaruChecksumAlgorithm)stream.ReadByteValue();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
checksumEntry.length = stream.ReadUInt32();
|
||||||
#else
|
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
|
|
||||||
checksumEntry.length = br.ReadUInt32();
|
|
||||||
if (checksumEntry.length == 0)
|
if (checksumEntry.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
checksumEntry.checksum = br.ReadBytes((int)checksumEntry.length);
|
checksumEntry.checksum = stream.ReadBytes((int)checksumEntry.length);
|
||||||
}
|
|
||||||
|
|
||||||
return checksumEntry;
|
return checksumEntry;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using SabreTools.IO.Extensions;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes.Aaru
|
namespace SabreTools.FileTypes.Aaru
|
||||||
{
|
{
|
||||||
@@ -24,18 +24,11 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
/// <returns>Populated ChecksumHeader, null on failure</returns>
|
/// <returns>Populated ChecksumHeader, null on failure</returns>
|
||||||
public static ChecksumHeader Deserialize(Stream stream)
|
public static ChecksumHeader Deserialize(Stream stream)
|
||||||
{
|
{
|
||||||
ChecksumHeader checksumHeader = new ChecksumHeader();
|
var checksumHeader = new ChecksumHeader();
|
||||||
|
|
||||||
#if NET20 || NET35 || NET40
|
checksumHeader.identifier = (AaruBlockType)stream.ReadUInt32();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
checksumHeader.length = stream.ReadUInt32();
|
||||||
#else
|
checksumHeader.entries = stream.ReadByteValue();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
checksumHeader.identifier = (AaruBlockType)br.ReadUInt32();
|
|
||||||
checksumHeader.length = br.ReadUInt32();
|
|
||||||
checksumHeader.entries = br.ReadByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
return checksumHeader;
|
return checksumHeader;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using SabreTools.IO.Extensions;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes.Aaru
|
namespace SabreTools.FileTypes.Aaru
|
||||||
{
|
{
|
||||||
@@ -23,18 +23,11 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
/// <returns>Populated IndexHeader, null on failure</returns>
|
/// <returns>Populated IndexHeader, null on failure</returns>
|
||||||
public static IndexEntry Deserialize(Stream stream)
|
public static IndexEntry Deserialize(Stream stream)
|
||||||
{
|
{
|
||||||
IndexEntry indexEntry = new IndexEntry();
|
var indexEntry = new IndexEntry();
|
||||||
|
|
||||||
#if NET20 || NET35 || NET40
|
indexEntry.blockType = (AaruBlockType)stream.ReadUInt32();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
indexEntry.dataType = (AaruDataType)stream.ReadUInt16();
|
||||||
#else
|
indexEntry.offset = stream.ReadUInt64();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
indexEntry.blockType = (AaruBlockType)br.ReadUInt32();
|
|
||||||
indexEntry.dataType = (AaruDataType)br.ReadUInt16();
|
|
||||||
indexEntry.offset = br.ReadUInt64();
|
|
||||||
}
|
|
||||||
|
|
||||||
return indexEntry;
|
return indexEntry;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using SabreTools.IO.Extensions;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes.Aaru
|
namespace SabreTools.FileTypes.Aaru
|
||||||
{
|
{
|
||||||
@@ -25,16 +25,9 @@ namespace SabreTools.FileTypes.Aaru
|
|||||||
{
|
{
|
||||||
var indexHeader = new IndexHeader();
|
var indexHeader = new IndexHeader();
|
||||||
|
|
||||||
#if NET20 || NET35 || NET40
|
indexHeader.identifier = (AaruBlockType)stream.ReadUInt32();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default))
|
indexHeader.entries = stream.ReadUInt16();
|
||||||
#else
|
indexHeader.crc64 = stream.ReadUInt64();
|
||||||
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
indexHeader.identifier = (AaruBlockType)br.ReadUInt32();
|
|
||||||
indexHeader.entries = br.ReadUInt16();
|
|
||||||
indexHeader.crc64 = br.ReadUInt64();
|
|
||||||
}
|
|
||||||
|
|
||||||
return indexHeader;
|
return indexHeader;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,20 @@ namespace SabreTools.FileTypes.CHD
|
|||||||
{
|
{
|
||||||
public class CHDFile : BaseFile
|
public class CHDFile : BaseFile
|
||||||
{
|
{
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal MD5 hash of the file
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? InternalMD5 { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal SHA-1 hash of the file
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? InternalSHA1 { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -37,11 +51,38 @@ namespace SabreTools.FileTypes.CHD
|
|||||||
var header = Serialization.Deserializers.CHD.DeserializeStream(stream);
|
var header = Serialization.Deserializers.CHD.DeserializeStream(stream);
|
||||||
return header switch
|
return header switch
|
||||||
{
|
{
|
||||||
HeaderV1 v1 => new CHDFile { _header = header, MD5 = v1.MD5 },
|
HeaderV1 v1 => new CHDFile
|
||||||
HeaderV2 v2 => new CHDFile { _header = header, MD5 = v2.MD5 },
|
{
|
||||||
HeaderV3 v3 => new CHDFile { _header = header, MD5 = v3.MD5, SHA1 = v3.SHA1 },
|
_header = header,
|
||||||
HeaderV4 v4 => new CHDFile { _header = header, SHA1 = v4.SHA1 },
|
MD5 = v1.MD5,
|
||||||
HeaderV5 v5 => new CHDFile { _header = header, SHA1 = v5.SHA1 },
|
InternalMD5 = v1.MD5,
|
||||||
|
},
|
||||||
|
HeaderV2 v2 => new CHDFile
|
||||||
|
{
|
||||||
|
_header = header,
|
||||||
|
MD5 = v2.MD5,
|
||||||
|
InternalMD5 = v2.MD5,
|
||||||
|
},
|
||||||
|
HeaderV3 v3 => new CHDFile
|
||||||
|
{
|
||||||
|
_header = header,
|
||||||
|
MD5 = v3.MD5,
|
||||||
|
InternalMD5 = v3.MD5,
|
||||||
|
SHA1 = v3.SHA1,
|
||||||
|
InternalSHA1 = v3.SHA1,
|
||||||
|
},
|
||||||
|
HeaderV4 v4 => new CHDFile
|
||||||
|
{
|
||||||
|
_header = header,
|
||||||
|
SHA1 = v4.SHA1,
|
||||||
|
InternalSHA1 = v4.SHA1,
|
||||||
|
},
|
||||||
|
HeaderV5 v5 => new CHDFile
|
||||||
|
{
|
||||||
|
_header = header,
|
||||||
|
SHA1 = v5.SHA1,
|
||||||
|
InternalSHA1 = v5.SHA1,
|
||||||
|
},
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user