Use ST.Hashing for SHA1

This commit is contained in:
Deterous
2024-03-05 15:15:40 +09:00
parent 0dbc483a91
commit e8f4d88711
3 changed files with 10 additions and 45 deletions
+6 -3
View File
@@ -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)
{
-29
View File
@@ -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>