9 Commits
Author SHA1 Message Date
DeterousandGitHub ce5b610f92 Print All option for info
`-a`/`--all` for irdkit info command
2025-08-19 11:37:11 +09:00
DeterousandGitHub 048d70b473 Bump version 2024-11-16 12:24:15 +09:00
Matt NadareskiandGitHub 0761450a8d Update SabreTools libraries and add .NET 9 support (#1)
* Update SabreTools libraries and add .NET 9 support

* Update build script

* Handle net9.0-specific complaints
2024-11-16 11:45:12 +09:00
Deterous 82d53db68f Bump version 2024-04-11 18:18:45 +09:00
Deterous f8a9c8515d Relax ISO requirements 2024-04-11 18:18:17 +09:00
Deterous 0ef06c36e9 Fix rename functionality, mention in reademe 2024-03-25 13:27:56 +09:00
Deterous c1c25b5f5e Fix issue from moving to ST.Hashing 2024-03-13 12:45:20 +09:00
Deterous c175fedbdb Fix bug for small encrypted regions 2024-03-12 19:42:23 +09:00
Deterous f7879bf9e8 Finalise old dotnet support 2024-03-12 19:08:42 +09:00
9 changed files with 344 additions and 100 deletions
+36
View File
@@ -0,0 +1,36 @@
name: Build
on:
push: {}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
project: [IRDKit]
runtime: [win-x86, win-x64, win-arm64, linux-x64, linux-arm64, osx-x64, osx-arm64]
framework: [net8.0]
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet publish ${{ matrix.project }}/${{ matrix.project }}.csproj -f ${{ matrix.framework }} -r ${{ matrix.runtime }} -c Release -p:DebugType=None -p:DebugSymbols=false
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.project }}_${{ matrix.framework }}_${{ matrix.runtime }}
path: ${{ matrix.project }}/bin/Release/${{ matrix.framework }}/${{ matrix.runtime }}/publish/*
+24
View File
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
+9 -6
View File
@@ -1,22 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<!-- Assembly Properties --> <!-- Assembly Properties -->
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetName>irdkit</TargetName> <TargetName>irdkit</TargetName>
<AssemblyName>irdkit</AssemblyName> <AssemblyName>irdkit</AssemblyName>
<TargetFrameworks>net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks> <TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<CheckEolTargetFramework>false</CheckEolTargetFramework> <CheckEolTargetFramework>false</CheckEolTargetFramework>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings> <SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.7.0</Version> <Version>0.9.5</Version>
<!-- Package Properties --> <!-- Package Properties -->
<Authors>Deterous</Authors> <Authors>Deterous</Authors>
<Description>Library for ISO Rebuild Data</Description> <Description>Library for ISO Rebuild Data</Description>
<Copyright>Copyright (c) Deterous 2023-2024</Copyright> <Copyright>Copyright (c) Deterous 2023-2025</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/Deterous/LibIRD</RepositoryUrl> <RepositoryUrl>https://github.com/Deterous/LibIRD</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
@@ -30,8 +33,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="SabreTools.Hashing" Version="1.1.3" /> <PackageReference Include="SabreTools.Hashing" Version="1.5.0" />
<PackageReference Include="SabreTools.RedumpLib" Version="1.3.4" /> <PackageReference Include="SabreTools.RedumpLib" Version="1.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+22 -25
View File
@@ -59,6 +59,9 @@ namespace IRDKit
[Option('o', "output", HelpText = "Path to the text or json file to be created (will overwrite)")] [Option('o', "output", HelpText = "Path to the text or json file to be created (will overwrite)")]
public string OutPath { get; set; } public string OutPath { get; set; }
[Option('a', "all", HelpText = "Print the entire contents of the IRD")]
public bool All { get; set; }
[Option('j', "json", HelpText = "Print IRD or ISO information as a JSON object")] [Option('j', "json", HelpText = "Print IRD or ISO information as a JSON object")]
public bool Json { get; set; } public bool Json { get; set; }
@@ -97,6 +100,9 @@ namespace IRDKit
[Option('s', "serial", HelpText = "Appends disc serial to new IRD filename")] [Option('s', "serial", HelpText = "Appends disc serial to new IRD filename")]
public bool Serial { get; set; } public bool Serial { get; set; }
[Option('e', "version", HelpText = "Appends disc version to new IRD filename")]
public bool Ver { get; set; }
[Option('c', "crc", HelpText = "Appends ISO CRC to new IRD filename")] [Option('c', "crc", HelpText = "Appends ISO CRC to new IRD filename")]
public bool CRC { get; set; } public bool CRC { get; set; }
@@ -280,7 +286,7 @@ namespace IRDKit
string lastIRD = irdFiles.Last(); string lastIRD = irdFiles.Last();
foreach (string file in irdFiles) foreach (string file in irdFiles)
{ {
PrintInfo(file, opt.Json, (noISO && file.Equals(lastIRD)), opt.OutPath); PrintInfo(file, opt.Json, (noISO && file.Equals(lastIRD)), opt.OutPath, opt.All);
} }
@@ -322,7 +328,7 @@ namespace IRDKit
} }
// Print info from given file // Print info from given file
PrintInfo(filePath, opt.Json, true, opt.OutPath); PrintInfo(filePath, opt.Json, true, opt.OutPath, opt.All);
if (opt.OutPath != null && opt.OutPath != "") if (opt.OutPath != null && opt.OutPath != "")
Console.WriteLine($"Info saved to {opt.OutPath}"); Console.WriteLine($"Info saved to {opt.OutPath}");
@@ -414,7 +420,7 @@ namespace IRDKit
{ {
try try
{ {
RenameIRD(file, datfile, serial: opt.Serial, crc: opt.CRC, verbose: opt.Verbose); RenameIRD(file, datfile, serial: opt.Serial, ver: opt.Ver, crc: opt.CRC, verbose: opt.Verbose);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -435,7 +441,7 @@ namespace IRDKit
// Rename provided IRD path // Rename provided IRD path
try try
{ {
RenameIRD(irdPath, datfile, serial: opt.Serial, crc: opt.CRC, verbose: opt.Verbose); RenameIRD(irdPath, datfile, serial: opt.Serial, ver: opt.Ver, crc: opt.CRC, verbose: opt.Verbose);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -461,8 +467,9 @@ namespace IRDKit
/// </summary> /// </summary>
/// <param name="inPath">File to retrieve info from</param> /// <param name="inPath">File to retrieve info from</param>
/// <param name="json">Whether to format output as JSON (true) or plain text (false)</param> /// <param name="json">Whether to format output as JSON (true) or plain text (false)</param>
/// <param name="single">Whether to print a single JSON object or not</param>
/// <param name="outPath">File to output info to</param> /// <param name="outPath">File to output info to</param>
public static void PrintInfo(string inPath, bool json, bool single = true, string outPath = null) public static void PrintInfo(string inPath, bool json, bool single = true, string outPath = null, bool printAll = false)
{ {
// Check if file is an ISO // Check if file is an ISO
bool isISO = String.Compare(Path.GetExtension(inPath), ".iso", StringComparison.OrdinalIgnoreCase) == 0; bool isISO = String.Compare(Path.GetExtension(inPath), ".iso", StringComparison.OrdinalIgnoreCase) == 0;
@@ -489,10 +496,10 @@ namespace IRDKit
File.AppendAllText(outPath, $"\"{Path.GetFileName(inPath)}\": "); File.AppendAllText(outPath, $"\"{Path.GetFileName(inPath)}\": ");
else else
Console.Write($"\"{Path.GetFileName(inPath)}\": "); Console.Write($"\"{Path.GetFileName(inPath)}\": ");
ird.PrintJson(outPath, single); ird.PrintJson(outPath, single, printAll);
} }
else else
IRD.Read(inPath).Print(outPath, Path.GetFileName(inPath)); IRD.Read(inPath).Print(outPath, Path.GetFileName(inPath), printAll);
if (json) if (json)
return; return;
@@ -515,6 +522,7 @@ namespace IRDKit
/// </summary> /// </summary>
/// <param name="isoPath">Path to ISO file</param> /// <param name="isoPath">Path to ISO file</param>
/// <param name="json">Whether to format output as JSON (true) or plain text (false)</param> /// <param name="json">Whether to format output as JSON (true) or plain text (false)</param>
/// <param name="single">Whether to print a single JSON object or not</param>
/// <param name="outPath">File to output info to</param> /// <param name="outPath">File to output info to</param>
/// <exception cref="FileNotFoundException"></exception> /// <exception cref="FileNotFoundException"></exception>
/// <exception cref="InvalidFileSystemException"></exception> /// <exception cref="InvalidFileSystemException"></exception>
@@ -941,13 +949,8 @@ namespace IRDKit
uint crc32UInt = BitConverter.ToUInt32(crc32, 0); uint crc32UInt = BitConverter.ToUInt32(crc32, 0);
// Search for ISO on redump.org // Search for ISO on redump.org
#if !NETFRAMEWORK RedumpClient redump = new();
RedumpHttpClient redump = new();
List<int> ids = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + crc32String).ConfigureAwait(false).GetAwaiter().GetResult(); List<int> ids = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + crc32String).ConfigureAwait(false).GetAwaiter().GetResult();
#else
RedumpWebClient redump = new();
List<int> ids = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + crc32String);
#endif
int id; int id;
if (ids.Count == 0) if (ids.Count == 0)
{ {
@@ -960,11 +963,7 @@ namespace IRDKit
string sha1String = HashTool.GetFileHash(isoPath, HashType.SHA1); string sha1String = HashTool.GetFileHash(isoPath, HashType.SHA1);
// Search redump.org for SHA1 hash // Search redump.org for SHA1 hash
#if !NETFRAMEWORK
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1String).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/" + sha1String);
#endif
if (ids2.Count == 0) if (ids2.Count == 0)
{ {
Console.Error.WriteLine("ISO not found in redump and no valid key provided, cannot create IRD"); Console.Error.WriteLine("ISO not found in redump and no valid key provided, cannot create IRD");
@@ -984,12 +983,8 @@ namespace IRDKit
} }
// Download key file from redump.org // Download key file from redump.org
#if !NETFRAMEWORK byte[] key = redump.DownloadData($"http://redump.org/disc/{id}/key").ConfigureAwait(false).GetAwaiter().GetResult();
byte[] key = redump.GetByteArrayAsync($"http://redump.org/disc/{id}/key").ConfigureAwait(false).GetAwaiter().GetResult(); if (key == null || key.Length != 16)
#else
byte[] key = redump.DownloadData($"http://redump.org/disc/{id}/key");
#endif
if (key.Length != 16)
{ {
Console.Error.WriteLine("Invalid key obtained from redump and no valid key provided, cannot create IRD"); Console.Error.WriteLine("Invalid key obtained from redump and no valid key provided, cannot create IRD");
return null; return null;
@@ -1034,7 +1029,7 @@ namespace IRDKit
return node.Attribute("name").Value; return node.Attribute("name").Value;
} }
public static void RenameIRD(string irdPath, XDocument datfile, bool serial = false, bool crc = false, bool verbose = false) public static void RenameIRD(string irdPath, XDocument datfile, bool serial = false, bool ver = false, bool crc = false, bool verbose = false)
{ {
IRD ird = IRD.Read(irdPath); IRD ird = IRD.Read(irdPath);
@@ -1043,7 +1038,9 @@ namespace IRDKit
string filename = GetDatFilename(ird, datfile) ?? 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) if (serial)
filename += $" [{ird.TitleID.Substring(0, 4)}-{ird.TitleID.Substring(5, 5)}]"; filename += $" [{ird.TitleID.Substring(0, 4).Replace('\0', ' ')}-{ird.TitleID.Substring(4, 5).Replace('\0', ' ')}]";
if (ver)
filename += $" [{ird.DiscVersion.Replace('\0', ' ')}]";
if (crc) if (crc)
filename += $" [{ird.UID:X8}]"; filename += $" [{ird.UID:X8}]";
+7
View File
@@ -32,6 +32,7 @@ For all options, run `irdkit help info`
To print info about an ISO or IRD file, run `irdkit info game.iso` or `irdkit info game.ird` To print info about an ISO or IRD file, run `irdkit info game.iso` or `irdkit info game.ird`
The info can be printed to a file, e.g. `-o out.txt` or `--output=` The info can be printed to a file, e.g. `-o out.txt` or `--output=`
The info can be formatted as a JSON with `-j` or `--json` The info can be formatted as a JSON with `-j` or `--json`
To print all info in the IRD use `-a` or `--all`
## Comparing IRDs ## Comparing IRDs
@@ -39,3 +40,9 @@ For all options, run `irdkit help diff`
To compare two IRDs, run `irdkit diff game1.ird game2.ird` To compare two IRDs, run `irdkit diff game1.ird game2.ird`
The comparison can be printed to a file, e.g. `-o out.txt` or `--output=` The comparison can be printed to a file, e.g. `-o out.txt` or `--output=`
## Renaming IRDs
For all options, run `irdkit help rename`
To rename an IRD (or folder of IRDs) according to a redump DAT, run `irdkit rename -d redump.dat game.ird`
+192 -30
View File
@@ -280,11 +280,6 @@ namespace LibIRD
/// <remarks>Last byte to read when reading the header</remarks> /// <remarks>Last byte to read when reading the header</remarks>
private long FirstDataSector { get; set; } private long FirstDataSector { get; set; }
/// <summary>
/// First byte of the PS3UPDAT.PUP file
/// </summary>
private long UpdateOffset { get; set; }
/// <summary> /// <summary>
/// Last byte of the PS3UPDAT.PUP file /// Last byte of the PS3UPDAT.PUP file
/// </summary> /// </summary>
@@ -413,7 +408,11 @@ namespace LibIRD
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(key)); throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(key));
// Setup AES decryption // Setup AES decryption
#if NET35_OR_GREATER || NETCOREAPP
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
#else
using Rijndael aes = Rijndael.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); ;
#endif
// Set AES settings // Set AES settings
aes.Key = D1AesKey; aes.Key = D1AesKey;
@@ -446,7 +445,11 @@ namespace LibIRD
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(d1)); throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(d1));
// Setup AES decryption // Setup AES decryption
#if NET35_OR_GREATER || NETCOREAPP
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
#else
using Rijndael aes = Rijndael.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); ;
#endif
// Set AES settings // Set AES settings
aes.Key = D1AesKey; aes.Key = D1AesKey;
@@ -478,7 +481,11 @@ namespace LibIRD
if (d2.Length != 16) throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(d2)); if (d2.Length != 16) throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(d2));
// Setup AES encryption // Setup AES encryption
#if NET35_OR_GREATER || NETCOREAPP
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
#else
using Rijndael aes = Rijndael.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); ;
#endif
// Set AES settings // Set AES settings
aes.Key = D2AesKey; aes.Key = D2AesKey;
@@ -511,7 +518,11 @@ namespace LibIRD
throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(d2)); throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(d2));
// Setup AES encryption // Setup AES encryption
#if NET35_OR_GREATER || NETCOREAPP
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
#else
using Rijndael aes = Rijndael.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); ;
#endif
// Set AES settings // Set AES settings
aes.Key = D2AesKey; aes.Key = D2AesKey;
@@ -636,6 +647,9 @@ namespace LibIRD
// Redump-style IRDs set the lowest bit of ExtraConfig to 1 // Redump-style IRDs set the lowest bit of ExtraConfig to 1
ExtraConfig |= 0x01; ExtraConfig |= 0x01;
// Try to get Title ID and Disc Version from PS3_DISC.SFB
try
{
// Redump-style IRDs use fields from PS3_DISC.SFB // Redump-style IRDs use fields from PS3_DISC.SFB
using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read); using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read);
@@ -653,10 +667,15 @@ namespace LibIRD
if (discVersionFound) if (discVersionFound)
DiscVersion = discVersion; DiscVersion = discVersion;
} }
catch { }
}
// Read PS3 Metadata from PARAM.SFO // Try to get Title ID, Title, Disc Version, and App Version from PARAM.SFO
using (SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read)) try
{ {
// Read PS3 Metadata from PARAM.SFO
using SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read);
// Parse PARAM.SFO file // Parse PARAM.SFO file
ParamSFO paramSFO = new(s); ParamSFO paramSFO = new(s);
@@ -691,18 +710,33 @@ namespace LibIRD
else else
AppVersion = "\0\0\0\0\0"; AppVersion = "\0\0\0\0\0";
} }
catch { }
// Determine system update version // Ensure Title ID is set and valid
if (string.IsNullOrEmpty(TitleID) || TitleID.Length != 9)
TitleID = "\0\0\0\0\0\0\0\0\0";
// Ensure Title is set
Title ??= string.Empty;
// Ensure Disc Version is set and valid
if (string.IsNullOrEmpty(DiscVersion) || DiscVersion.Length != 5)
DiscVersion = "\0\0\0\0\0";
// Ensure App Version is set and valid
if (string.IsNullOrEmpty(AppVersion) || AppVersion.Length != 5)
AppVersion = "\0\0\0\0\0";
// Try determine system update version
try
{
GetSystemVersion(fs, reader); GetSystemVersion(fs, reader);
}
catch { }
// Read and compress the ISO header // Ensure System Version was set and valid
GetHeader(fs, reader); if (string.IsNullOrEmpty(SystemVersion) || SystemVersion.Length != 4)
SystemVersion = "\0\0\0\0";
// Read and compress the ISO footer
GetFooter(fs);
// Get info region info from ISO
GetRegions(fs);
// Recursively count all files in ISO to allocate file arrays // Recursively count all files in ISO to allocate file arrays
DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\"); DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\");
@@ -731,13 +765,30 @@ namespace LibIRD
// Sort files by offset // Sort files by offset
Array.Sort(FileKeys, FileExtents); Array.Sort(FileKeys, FileExtents);
// Determine start of footer if no update file present
if (UpdateEnd == 0)
{
int lastFile = FileExtents.Length - 1;
int lastExtent = FileExtents[lastFile].Length - 1;
UpdateEnd = SectorSize * FileExtents[lastFile][lastExtent].Offset + FileExtents[lastFile][lastExtent].Count;
}
// Read and compress the ISO header
GetHeader(fs, reader);
// Read and compress the ISO footer
GetFooter(fs);
// Get info region info from ISO
GetRegions(fs);
// Calculate CRC32 hash of ISO only if generating a redump IRD and the UID is not already set // Calculate CRC32 hash of ISO only if generating a redump IRD and the UID is not already set
RegionHashes = new byte[RegionCount][]; RegionHashes = new byte[RegionCount][];
FileHashes = new byte[FileCount][]; FileHashes = new byte[FileCount][];
HashISO(fs, redump && UID == 0x00000000); HashISO(fs, redump && UID == 0x00000000);
} }
#endregion #endregion
#region Reading ISO #region Reading ISO
@@ -756,13 +807,13 @@ namespace LibIRD
throw new IOException("Invalid file extents for PS3UPDAT.PUP"); throw new IOException("Invalid file extents for PS3UPDAT.PUP");
// PS3UPDAT.PUP file begins at first byte of dedicated cluster // PS3UPDAT.PUP file begins at first byte of dedicated cluster
UpdateOffset = SectorSize * updateClusters[0].Offset; long updateOffset = SectorSize * updateClusters[0].Offset;
// Update file ends at the last byte of the last cluster // Update file ends at the last byte of the last cluster
int lastExtent = updateClusters.Length - 1; int lastExtent = updateClusters.Length - 1;
UpdateEnd = SectorSize * updateClusters[lastExtent].Offset + updateClusters[lastExtent].Count; UpdateEnd = SectorSize * updateClusters[lastExtent].Offset + updateClusters[lastExtent].Count;
// Check PUP file Magic // Check PUP file Magic
fs.Seek(UpdateOffset, SeekOrigin.Begin); fs.Seek(updateOffset, SeekOrigin.Begin);
byte[] pupMagic = new byte[5]; byte[] pupMagic = new byte[5];
fs.Read(pupMagic, 0, pupMagic.Length); fs.Read(pupMagic, 0, pupMagic.Length);
// If magic is incorrect, set version to all nulls, "\0\0\0\0" (unknown) // If magic is incorrect, set version to all nulls, "\0\0\0\0" (unknown)
@@ -771,13 +822,13 @@ namespace LibIRD
else else
{ {
// Determine location of version string // Determine location of version string
fs.Seek(UpdateOffset + 0x3E, SeekOrigin.Begin); fs.Seek(updateOffset + 0x3E, SeekOrigin.Begin);
byte[] offset = new byte[2]; byte[] offset = new byte[2];
fs.Read(offset, 0, 2); fs.Read(offset, 0, 2);
// Move stream to PUP version string // Move stream to PUP version string
Array.Reverse(offset); Array.Reverse(offset);
ushort versionOffset = BitConverter.ToUInt16(offset, 0); ushort versionOffset = BitConverter.ToUInt16(offset, 0);
fs.Seek(UpdateOffset + versionOffset, SeekOrigin.Begin); fs.Seek(updateOffset + versionOffset, SeekOrigin.Begin);
// Read version string // Read version string
byte[] version = new byte[4]; byte[] version = new byte[4];
fs.Read(version, 0, version.Length); fs.Read(version, 0, version.Length);
@@ -989,7 +1040,12 @@ namespace LibIRD
throw new ArgumentException("Number of sectors must be within buffer"); throw new ArgumentException("Number of sectors must be within buffer");
// Setup AES decryption // Setup AES decryption
#if NET35_OR_GREATER || NETCOREAPP
using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); using Aes aes = Aes.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings");
#else
using Rijndael aes = Rijndael.Create() ?? throw new InvalidOperationException("AES not available. Change your system settings"); ;
#endif
// Set AES settings // Set AES settings
aes.Key = DiscKey; aes.Key = DiscKey;
aes.Padding = PaddingMode.None; aes.Padding = PaddingMode.None;
@@ -1035,6 +1091,10 @@ namespace LibIRD
CountFiles(dirInfo); CountFiles(dirInfo);
} }
#endregion
#region Hashing
/// <summary> /// <summary>
/// Calculate hashes for all region and file extents /// Calculate hashes for all region and file extents
/// </summary> /// </summary>
@@ -1080,6 +1140,22 @@ namespace LibIRD
// If end of ISO reached, stop reading // If end of ISO reached, stop reading
if (numBytes == 0) if (numBytes == 0)
{ {
// Ensure all hashes have been saved
foreach (int i in regions)
{
// Close region hash
regionMD5[i].Terminate();
RegionHashes[i] = regionMD5[i].CurrentHashBytes;
regionMD5[i].Dispose();
}
foreach (int i in files)
{
// Close file hash
fileMD5[i].Terminate();
FileHashes[i] = fileMD5[i].CurrentHashBytes;
fileMD5[i].Dispose();
}
// If making redump-style IRD, save CRC32 hash to UID field // If making redump-style IRD, save CRC32 hash to UID field
if (redump) if (redump)
{ {
@@ -1087,6 +1163,7 @@ namespace LibIRD
Array.Reverse(crc32); Array.Reverse(crc32);
UID = BitConverter.ToUInt32(crc32, 0); UID = BitConverter.ToUInt32(crc32, 0);
} }
return; return;
} }
@@ -1180,7 +1257,7 @@ namespace LibIRD
// Don't decrypt last sectors if the encrypted region ends within this buffer // Don't decrypt last sectors if the encrypted region ends within this buffer
if (RegionEnd[i] < currentSector + bufSectors) if (RegionEnd[i] < currentSector + bufSectors)
encCount -= (int)(currentSector + bufSectors - RegionEnd[i] + 1); encCount -= (int)(currentSector + bufSectors - RegionEnd[i] - 1);
// Decrypt encrypted sectors // Decrypt encrypted sectors
DecryptSectors(ref buf, (int)currentSector + encOffset, encOffset, encCount); DecryptSectors(ref buf, (int)currentSector + encOffset, encOffset, encCount);
@@ -1215,7 +1292,7 @@ namespace LibIRD
// Check if current file has ended in this buffer (assumes last extent contains last byte) // Check if current file has ended in this buffer (assumes last extent contains last byte)
int lastExtent = FileExtents[i].Length - 1; int lastExtent = FileExtents[i].Length - 1;
long lastByte = SectorSize * FileExtents[i][lastExtent].Offset + FileExtents[i][lastExtent].Count; long lastByte = SectorSize * FileExtents[i][lastExtent].Offset + FileExtents[i][lastExtent].Count;
if (lastByte < SectorSize * (currentSector + bufSectors) if (lastByte <= SectorSize * (currentSector + bufSectors)
&& lastByte > SectorSize * currentSector) && lastByte > SectorSize * currentSector)
{ {
// Close file hash // Close file hash
@@ -1359,7 +1436,14 @@ namespace LibIRD
#endif #endif
// Write entire gzipped IRD stream to file // Write entire gzipped IRD stream to file
stream.Position = 0; stream.Position = 0;
#if NET40_OR_GREATER || NETCOREAPP
stream.CopyTo(gzStream); stream.CopyTo(gzStream);
#else
byte[] buffer = new byte[1024];
int numBytes;
while ((numBytes = stream.Read(buffer, 0, buffer.Length)) > 0)
gzStream.Write(buffer, 0, numBytes);
#endif
} }
/// <summary> /// <summary>
@@ -1477,7 +1561,9 @@ namespace LibIRD
/// Prints IRD fields to console /// Prints IRD fields to console
/// </summary> /// </summary>
/// <param name="printPath">Optional path to save file to</param> /// <param name="printPath">Optional path to save file to</param>
public void Print(string printPath = null, string irdName = null) /// <param name="printAll">Optionally print IRD name in output header</param>
/// <param name="printAll">Optionally print all IRD data</param>
public void Print(string printPath = null, string irdName = null, bool printAll = false)
{ {
// Build string from parameters // Build string from parameters
StringBuilder printText = new(); StringBuilder printText = new();
@@ -1495,11 +1581,38 @@ namespace LibIRD
printText.AppendLine($"PUP Version: {SystemVersion}"); printText.AppendLine($"PUP Version: {SystemVersion}");
printText.AppendLine($"Disc Version: {DiscVersion}"); printText.AppendLine($"Disc Version: {DiscVersion}");
printText.AppendLine($"App Version: {AppVersion}"); printText.AppendLine($"App Version: {AppVersion}");
if (printAll)
{
printText.AppendLine($"Header: {ByteArrayToHexString(Header)}");
printText.AppendLine($"Footer: {ByteArrayToHexString(Footer)}");
}
printText.AppendLine($"Regions: {RegionCount}"); printText.AppendLine($"Regions: {RegionCount}");
if (printAll)
{
for (int i = 0; i < RegionCount; i++)
{
printText.Append($" Region {i} : ");
if (RegionHashes[i] == null)
printText.AppendLine($"{ByteArrayToHexString(NullMD5)}");
else
printText.AppendLine($"{ByteArrayToHexString(RegionHashes[i])}");
}
}
printText.AppendLine($"Files: {FileCount}"); printText.AppendLine($"Files: {FileCount}");
if (ExtraConfig != 0x0000) if (printAll)
{
for (int i = 0; i < FileCount; i++)
{
printText.Append($" {FileKeys[i]:X7} : ");
if (FileHashes[i] == null)
printText.AppendLine($"{ByteArrayToHexString(NullMD5)}");
else
printText.AppendLine($"{ByteArrayToHexString(FileHashes[i])}");
}
}
if (printAll || ExtraConfig != 0x0000)
printText.AppendLine($"Extra Config: {ExtraConfig:X4}"); printText.AppendLine($"Extra Config: {ExtraConfig:X4}");
if (Attachments != 0x0000) if (printAll || Attachments != 0x0000)
printText.AppendLine($"Attachments: {Attachments:X4}"); printText.AppendLine($"Attachments: {Attachments:X4}");
printText.AppendLine($"Unique ID: {UID:X8}"); printText.AppendLine($"Unique ID: {UID:X8}");
printText.AppendLine($"Data 1 Key: {ByteArrayToHexString(Data1Key)}"); printText.AppendLine($"Data 1 Key: {ByteArrayToHexString(Data1Key)}");
@@ -1526,7 +1639,9 @@ namespace LibIRD
/// Prints IRD fields to a json object /// Prints IRD fields to a json object
/// </summary> /// </summary>
/// <param name="jsonPath">Optionally print to json file</param> /// <param name="jsonPath">Optionally print to json file</param>
public void PrintJson(string jsonPath = null, bool single = true) /// <param name="single">Optionally print single object (no trailing comma)</param>
/// <param name="printAll">Optionally print all IRD data</param>
public void PrintJson(string jsonPath = null, bool single = true, bool printAll = false)
{ {
// Build string from parameters // Build string from parameters
StringBuilder json = new(); StringBuilder json = new();
@@ -1540,11 +1655,58 @@ namespace LibIRD
json.AppendLine($" \"PUP Version\": \"{SystemVersion}\","); json.AppendLine($" \"PUP Version\": \"{SystemVersion}\",");
json.AppendLine($" \"Disc Version\": \"{DiscVersion}\","); json.AppendLine($" \"Disc Version\": \"{DiscVersion}\",");
json.AppendLine($" \"App Version\": \"{AppVersion}\","); json.AppendLine($" \"App Version\": \"{AppVersion}\",");
if (printAll)
{
json.AppendLine($" \"Header\": \"{ByteArrayToHexString(Header)}\",");
json.AppendLine($" \"Footer\": \"{ByteArrayToHexString(Footer)}\",");
}
if (!printAll)
json.AppendLine($" \"Regions\": \"{RegionCount}\","); json.AppendLine($" \"Regions\": \"{RegionCount}\",");
else
{
json.Append($" \"Regions\": [ ");
for (int i = 0; i < RegionCount - 1; i++)
{
if (RegionHashes[i] == null)
json.Append($"\"{ByteArrayToHexString(NullMD5)}\", ");
else
json.Append($"\"{ByteArrayToHexString(RegionHashes[i])}\", ");
}
if (RegionCount > 0)
{
if (RegionHashes[RegionCount - 1] == null)
json.Append($"\"{ByteArrayToHexString(NullMD5)}\"");
else
json.Append($"\"{ByteArrayToHexString(RegionHashes[RegionCount - 1])}\"");
}
json.AppendLine(" ],");
}
if(!printAll)
json.AppendLine($" \"Files\": \"{FileCount}\","); json.AppendLine($" \"Files\": \"{FileCount}\",");
if (ExtraConfig != 0x0000) else
{
json.Append($" \"Files\": [ ");
for (int i = 0; i < RegionCount - 1; i++)
{
json.Append($" \"{FileKeys[i]}\" : ");
if (RegionHashes[i] == null)
json.Append($"\"{ByteArrayToHexString(NullMD5)}\", ");
else
json.Append($"\"{ByteArrayToHexString(FileHashes[i])}\", ");
}
if (FileCount > 0)
{
json.Append($" \"{FileKeys[FileCount - 1]}\" : ");
if (FileHashes[FileCount - 1] == null)
json.Append($"\"{ByteArrayToHexString(NullMD5)}\"");
else
json.Append($"\"{ByteArrayToHexString(FileHashes[FileCount - 1])}\"");
}
json.AppendLine(" ],");
}
if (printAll || ExtraConfig != 0x0000)
json.AppendLine($" \"Extra Config\": \"{ExtraConfig:X4}\","); json.AppendLine($" \"Extra Config\": \"{ExtraConfig:X4}\",");
if (Attachments != 0x0000) if (printAll || Attachments != 0x0000)
json.AppendLine($" \"Attachments\": \"{Attachments:X4}\","); json.AppendLine($" \"Attachments\": \"{Attachments:X4}\",");
json.AppendLine($" \"Unique ID\": \"{UID:X8}\","); json.AppendLine($" \"Unique ID\": \"{UID:X8}\",");
json.AppendLine($" \"Data 1 Key\": \"{ByteArrayToHexString(Data1Key)}\","); json.AppendLine($" \"Data 1 Key\": \"{ByteArrayToHexString(Data1Key)}\",");
@@ -1571,7 +1733,7 @@ namespace LibIRD
} }
} }
#endregion #endregion
#region Helper Functions #region Helper Functions
+20 -5
View File
@@ -1,20 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<!-- Assembly Properties --> <!-- Assembly Properties -->
<TargetFrameworks>net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<CheckEolTargetFramework>false</CheckEolTargetFramework> <CheckEolTargetFramework>false</CheckEolTargetFramework>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings> <SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.7.0</Version> <Version>0.9.4</Version>
<PackageOutputPath>../nupkg</PackageOutputPath> <PackageOutputPath>../nupkg</PackageOutputPath>
<!-- Avoid inexact read with 'System.IO.Stream.Read' -->
<NoWarn>CA2022</NoWarn>
<!-- Package Properties --> <!-- Package Properties -->
<Authors>Deterous</Authors> <Authors>Deterous</Authors>
<Description>Library for ISO Rebuild Data</Description> <Description>Library for ISO Rebuild Data</Description>
<Copyright>Copyright (c) Deterous 2023-2024</Copyright> <Copyright>Copyright (c) Deterous 2023-2025</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/Deterous/LibIRD/</RepositoryUrl> <RepositoryUrl>https://github.com/Deterous/LibIRD/</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
@@ -23,13 +25,26 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="!$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<None Include="./README.md" Pack="true" PackagePath="" /> <None Include="./README.md" Pack="true" PackagePath="" />
</ItemGroup> </ItemGroup>
<!-- Support for old .NET versions -->
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`))">
<PackageReference Include="Net30.LinqBridge" Version="1.3.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.Hashing" Version="1.1.3" /> <PackageReference Include="SabreTools.Hashing" Version="1.4.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+1 -1
View File
@@ -13,7 +13,7 @@ IRDKit is a tool that allows direct use of LibIRD functionality from a command l
- Printing info about all ISOs and IRDs in a folder: `irdkit info .` - Printing info about all ISOs and IRDs in a folder: `irdkit info .`
- Creating an IRD from an ISO: `irdkit create game.iso` - Creating an IRD from an ISO: `irdkit create game.iso`
- Finding differences between two IRDs: `irdkit diff game1.ird game2.ird` - Finding differences between two IRDs: `irdkit diff game1.ird game2.ird`
- Renaming a folder of IRDs using a redump DAT: `irdkit rename -d redump.dat IRDs\` - Renaming an IRD or folder of IRDs using a redump DAT: `irdkit rename -d redump.dat game.ird`
For detailed usage, read more [here](IRDKit). For detailed usage, read more [here](IRDKit).
+14 -14
View File
@@ -1,15 +1,15 @@
dotnet publish -c Release -f net8.0 -r win-x86 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r win-x86 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
dotnet publish -c Release -f net8.0 -r win-x64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r win-x64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
dotnet publish -c Release -f net8.0 -r win-arm64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r win-arm64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
dotnet publish -c Release -f net8.0 -r linux-x64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r linux-x64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
dotnet publish -c Release -f net8.0 -r linux-arm64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r linux-arm64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
dotnet publish -c Release -f net8.0 -r osx-x64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r osx-x64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
dotnet publish -c Release -f net8.0 -r osx-arm64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj dotnet publish -c Release -f net9.0 -r osx-arm64 --self-contained=false -p:PublishSingleFile=true -p:DebugType=None IRDKit\IRDKit.csproj
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/win-x86/publish/irdkit.exe" -Destination "./irdkit-win-x86.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/win-x86/publish/irdkit.exe" -Destination "./irdkit-win-x86.zip" -CompressionLevel "Optimal"
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/win-x64/publish/irdkit.exe" -Destination "./irdkit-win-x64.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/win-x64/publish/irdkit.exe" -Destination "./irdkit-win-x64.zip" -CompressionLevel "Optimal"
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/win-arm64/publish/irdkit.exe" -Destination "./irdkit-win-arm64.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/win-arm64/publish/irdkit.exe" -Destination "./irdkit-win-arm64.zip" -CompressionLevel "Optimal"
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/linux-x64/publish/irdkit" -Destination "./irdkit-linux-x64.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/linux-x64/publish/irdkit" -Destination "./irdkit-linux-x64.zip" -CompressionLevel "Optimal"
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/linux-arm64/publish/irdkit" -Destination "./irdkit-linux-arm64.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/linux-arm64/publish/irdkit" -Destination "./irdkit-linux-arm64.zip" -CompressionLevel "Optimal"
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/osx-x64/publish/irdkit" -Destination "./irdkit-osx-x64.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/osx-x64/publish/irdkit" -Destination "./irdkit-osx-x64.zip" -CompressionLevel "Optimal"
Compress-Archive -Path "./IRDKit/bin/Release/net8.0/osx-arm64/publish/irdkit" -Destination "./irdkit-osx-arm64.zip" -CompressionLevel "Optimal" Compress-Archive -Path "./IRDKit/bin/Release/net9.0/osx-arm64/publish/irdkit" -Destination "./irdkit-osx-arm64.zip" -CompressionLevel "Optimal"