mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Hashing
This commit is contained in:
@@ -21,6 +21,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public long? Size { get; set; }
|
||||
public byte[] CRC { get; set; }
|
||||
public byte[] MD5 { get; set; }
|
||||
public byte[] RIPEMD160 { get; set; }
|
||||
public byte[] SHA1 { get; set; }
|
||||
public byte[] SHA256 { get; set; }
|
||||
public byte[] SHA384 { get; set; }
|
||||
@@ -49,13 +50,13 @@ namespace SabreTools.Library.FileTypes
|
||||
if (getHashes)
|
||||
{
|
||||
BaseFile temp = Utilities.GetFileInfo(this.Filename);
|
||||
|
||||
if (temp != null)
|
||||
{
|
||||
this.Parent = temp.Parent;
|
||||
this.Date = temp.Date;
|
||||
this.CRC = temp.CRC;
|
||||
this.MD5 = temp.MD5;
|
||||
this.RIPEMD160 = temp.RIPEMD160;
|
||||
this.SHA1 = temp.SHA1;
|
||||
this.SHA256 = temp.SHA256;
|
||||
this.SHA384 = temp.SHA384;
|
||||
@@ -77,13 +78,13 @@ namespace SabreTools.Library.FileTypes
|
||||
if (getHashes)
|
||||
{
|
||||
BaseFile temp = Utilities.GetStreamInfo(stream, stream.Length);
|
||||
|
||||
if(temp != null)
|
||||
{
|
||||
this.Parent = temp.Parent;
|
||||
this.Date = temp.Date;
|
||||
this.CRC = temp.CRC;
|
||||
this.MD5 = temp.MD5;
|
||||
this.RIPEMD160 = temp.RIPEMD160;
|
||||
this.SHA1 = temp.SHA1;
|
||||
this.SHA256 = temp.SHA256;
|
||||
this.SHA384 = temp.SHA384;
|
||||
@@ -93,31 +94,6 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new BaseFile from the given metadata
|
||||
/// </summary>
|
||||
/// <param name="filename">Name of the file to use</param>
|
||||
/// <param name="parent">Parent folder or archive</param>
|
||||
/// <param name="date">File date</param>
|
||||
/// <param name="crc">CRC hash as a byte array</param>
|
||||
/// <param name="md5">MD5 hash as a byte array</param>
|
||||
/// <param name="sha1">SHA-1 hash as a byte array</param>
|
||||
/// <param name="sha256">SHA-256 hash as a byte array</param>
|
||||
/// <param name="sha384">SHA-384 hash as a byte array</param>
|
||||
/// <param name="sha512">SHA-512 hash as a byte array</param>
|
||||
public BaseFile(string filename, string parent, string date, byte[] crc, byte[] md5, byte[] sha1, byte[] sha256, byte[] sha384, byte[] sha512)
|
||||
{
|
||||
this.Filename = filename;
|
||||
this.Parent = parent;
|
||||
this.Date = date;
|
||||
this.CRC = crc;
|
||||
this.MD5 = md5;
|
||||
this.SHA1 = sha1;
|
||||
this.SHA256 = sha256;
|
||||
this.SHA384 = sha384;
|
||||
this.SHA512 = sha512;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,21 +158,15 @@ namespace SabreTools.Library.FileTypes
|
||||
m_br = new BinaryReader(chdstream);
|
||||
|
||||
_headerVersion = ValidateHeaderVersion();
|
||||
|
||||
if (_headerVersion != null)
|
||||
{
|
||||
byte[] hash = GetHashFromHeader();
|
||||
|
||||
if (hash != null)
|
||||
{
|
||||
if (hash.Length == Constants.MD5Length)
|
||||
{
|
||||
this.MD5 = hash;
|
||||
}
|
||||
else if (hash.Length == Constants.SHA1Length)
|
||||
{
|
||||
this.SHA1 = hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,9 +191,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If no signature could be read, return null
|
||||
if (m_signature == null || m_signature.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!m_signature.StartsWith(Constants.CHDSignature, exact: true))
|
||||
{
|
||||
|
||||
@@ -243,7 +243,7 @@ namespace SabreTools.Library.FileTypes
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
BaseFile gzipEntryRom = Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
|
||||
BaseFile gzipEntryRom = Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan);
|
||||
gzipEntryRom.Filename = gz.Filename(0);
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (date && gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace SabreTools.Library.FileTypes
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
BaseFile rarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
BaseFile rarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan);
|
||||
rarEntryRom.Filename = entry.Key;
|
||||
rarEntryRom.Parent = gamename;
|
||||
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
@@ -328,7 +328,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true);
|
||||
BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.UncompressedSize(i), omitFromScan, true);
|
||||
zipEntryRom.Filename = zf.Filename(i);
|
||||
zipEntryRom.Parent = gamename;
|
||||
found.Add(zipEntryRom);
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace SabreTools.Library.FileTypes
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
BaseFile tarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
BaseFile tarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan);
|
||||
tarEntryRom.Filename = entry.Key;
|
||||
tarEntryRom.Parent = gamename;
|
||||
tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
@@ -328,7 +328,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true);
|
||||
BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.UncompressedSize(i), omitFromScan, true);
|
||||
zipEntryRom.Filename = zf.Filename(i);
|
||||
zipEntryRom.Parent = gamename;
|
||||
string convertedDate = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
Reference in New Issue
Block a user