Use ST.Hashing for SHA1
This commit is contained in:
+4
-13
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using CommandLine;
|
||||
@@ -954,19 +953,13 @@ namespace IRDKit
|
||||
else if (ids.Count > 1)
|
||||
{
|
||||
// More than one result for the CRC32 hash, compute SHA1 hash instead
|
||||
byte[] sha1;
|
||||
using (FileStream fs = File.OpenRead(isoPath))
|
||||
{
|
||||
SHA1 hasher = SHA1.Create();
|
||||
sha1 = hasher.ComputeHash(fs);
|
||||
}
|
||||
string sha1_hash = LibIRD.IRD.ByteArrayToHexString(sha1).ToLower();
|
||||
string sha1String = HashTool.GetFileHash(isoPath, HashType.SHA1);
|
||||
|
||||
// Search redump.org for SHA1 hash
|
||||
#if !NETFRAMEWORK
|
||||
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1_hash).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1String).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
#else
|
||||
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1_hash);
|
||||
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1String);
|
||||
#endif
|
||||
if (ids2.Count == 0)
|
||||
{
|
||||
@@ -1044,9 +1037,7 @@ namespace IRDKit
|
||||
if (ird.ExtraConfig != 0x0001)
|
||||
throw new ArgumentException($"{irdPath} is not a redump-style IRD");
|
||||
|
||||
string filename = GetDatFilename(ird, datfile);
|
||||
if (filename == null)
|
||||
throw new ArgumentException($"Cannot determine DAT filename for {irdPath}");
|
||||
string filename = GetDatFilename(ird, datfile) ?? throw new ArgumentException($"Cannot determine DAT filename for {irdPath}");
|
||||
if (serial)
|
||||
filename += $" [{ird.TitleID.Substring(0, 4)}-{ird.TitleID.Substring(5, 5)}]";
|
||||
if (crc)
|
||||
|
||||
+6
-3
@@ -758,7 +758,8 @@ namespace LibIRD
|
||||
// PS3UPDAT.PUP file begins at first byte of dedicated cluster
|
||||
UpdateOffset = SectorSize * updateClusters[0].Offset;
|
||||
// Update file ends at the last byte of the last cluster
|
||||
UpdateEnd = SectorSize * updateClusters[updateClusters.Length - 1].Offset + updateClusters[updateClusters.Length - 1].Count;
|
||||
int lastExtent = updateClusters.Length - 1;
|
||||
UpdateEnd = SectorSize * updateClusters[lastExtent].Offset + updateClusters[lastExtent].Count;
|
||||
|
||||
// Check PUP file Magic
|
||||
fs.Seek(UpdateOffset, SeekOrigin.Begin);
|
||||
@@ -905,7 +906,8 @@ namespace LibIRD
|
||||
// Remove header from first region
|
||||
RegionStart[0] = FirstDataSector;
|
||||
// Remove footer from last region
|
||||
RegionEnd[RegionEnd.Length - 1] = (UpdateEnd / SectorSize) - 1;
|
||||
int lastRegion = RegionEnd.Length - 1;
|
||||
RegionEnd[lastRegion] = (UpdateEnd / SectorSize) - 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1210,7 +1212,8 @@ namespace LibIRD
|
||||
}
|
||||
|
||||
// Check if current file has ended in this buffer (assumes last extent contains last byte)
|
||||
long lastByte = SectorSize * FileExtents[i][FileExtents[i].Length - 1].Offset + FileExtents[i][FileExtents[i].Length - 1].Count;
|
||||
int lastExtent = FileExtents[i].Length - 1;
|
||||
long lastByte = SectorSize * FileExtents[i][lastExtent].Offset + FileExtents[i][lastExtent].Count;
|
||||
if (lastByte < SectorSize * (currentSector + bufSectors)
|
||||
&& lastByte > SectorSize * currentSector)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.Hashing;
|
||||
|
||||
namespace LibIRD
|
||||
{
|
||||
@@ -231,34 +230,6 @@ namespace LibIRD
|
||||
return pic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates the UID field by computing the CRC32 hash of the ISO
|
||||
/// </summary>
|
||||
/// <param name="isoPath">Path to the ISO</param>
|
||||
/// <exception cref="FileNotFoundException"></exception>
|
||||
private static uint GenerateUID(string isoPath)
|
||||
{
|
||||
// Check file exists
|
||||
FileInfo iso;
|
||||
try
|
||||
{
|
||||
iso = new FileInfo(isoPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArgumentException("Invalid ISO Path: " + e.Message);
|
||||
}
|
||||
if (!iso.Exists)
|
||||
throw new FileNotFoundException(nameof(isoPath));
|
||||
|
||||
// Compute CRC32 hash
|
||||
string crc32String = HashTool.GetFileHash(isoPath, HashType.CRC32); // TODO: Output byte[] once ST.Hashing supports it
|
||||
byte[] crc32 = HexStringToByteArray(crc32String);
|
||||
|
||||
// Redump ISO CRC32 hash is used as the Unique ID in the reproducible IRD
|
||||
return BitConverter.ToUInt32(crc32, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates ISO file size
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user