From 6e529f00507a862ff457b05f80fd6e7bc1a08806 Mon Sep 17 00:00:00 2001
From: Deterous <138427222+Deterous@users.noreply.github.com>
Date: Fri, 16 Feb 2024 11:11:51 +0900
Subject: [PATCH] Reuse ISO hash if searching redump
---
IRDKit/Program.cs | 4 +++-
LibIRD/IRD.cs | 2 +-
LibIRD/ReIRD.cs | 5 +++--
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/IRDKit/Program.cs b/IRDKit/Program.cs
index c537a02..1354bd0 100644
--- a/IRDKit/Program.cs
+++ b/IRDKit/Program.cs
@@ -843,11 +843,13 @@ namespace IRDKit
// Compute CRC32 hash
byte[] crc32;
+ uint crc32UInt;
using (FileStream fs = File.OpenRead(isoPath))
{
Crc32 hasher = new();
hasher.Append(fs);
crc32 = hasher.GetCurrentHash();
+ crc32UInt = BitConverter.ToUInt32(crc32);
// Change endianness
Array.Reverse(crc32);
}
@@ -905,7 +907,7 @@ namespace IRDKit
Console.WriteLine($"Creating {irdPath} with Key from redump.org: {Convert.ToHexString(key)}");
try
{
- IRD ird = new ReIRD(isoPath, key, layerbreak);
+ IRD ird = new ReIRD(isoPath, key, layerbreak, crc32UInt);
ird.Write(irdPath);
if (verbose)
ird.Print();
diff --git a/LibIRD/IRD.cs b/LibIRD/IRD.cs
index db04f12..593d5e5 100644
--- a/LibIRD/IRD.cs
+++ b/LibIRD/IRD.cs
@@ -270,7 +270,7 @@ namespace LibIRD
///
/// MD5 hashes for all decrypted files in the image
///
- /// files, 16-bytes per hash, alternating with each entry
+ /// files, 16-bytes per hash, alternating with each entry
public byte[][] FileHashes { get; private set; }
///
diff --git a/LibIRD/ReIRD.cs b/LibIRD/ReIRD.cs
index 91cb40f..845b233 100644
--- a/LibIRD/ReIRD.cs
+++ b/LibIRD/ReIRD.cs
@@ -71,11 +71,12 @@ namespace LibIRD
/// Path to the ISO
/// Disc Key, redump-style (AES encrypted Data 1)
/// Layerbreak value, in sectors
+ /// Unique ID, crc32 hash of ISO
/// Disc Region
- public ReIRD(string isoPath, byte[] key, long? layerbreak = null, Region region = Region.NONE) : base()
+ public ReIRD(string isoPath, byte[] key, long? layerbreak = null, uint? uid = null, Region region = Region.NONE) : base()
{
// Generate Unique Identifier using ISO CRC32
- UID = GenerateUID(isoPath);
+ UID = uid == null ? GenerateUID(isoPath) : (uint)uid;
// Determine ISO file size
long size = CalculateSize(isoPath);