Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82d53db68f | ||
|
|
f8a9c8515d | ||
|
|
0ef06c36e9 | ||
|
|
c1c25b5f5e | ||
|
|
c175fedbdb | ||
|
|
f7879bf9e8 |
@@ -5,13 +5,13 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetName>irdkit</TargetName>
|
||||
<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</TargetFrameworks>
|
||||
<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>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.7.0</Version>
|
||||
<Version>0.9.2</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Deterous</Authors>
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.1.3" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.1.4" />
|
||||
<PackageReference Include="SabreTools.RedumpLib" Version="1.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
+9
-4
@@ -97,6 +97,9 @@ namespace IRDKit
|
||||
[Option('s', "serial", HelpText = "Appends disc serial to new IRD filename")]
|
||||
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")]
|
||||
public bool CRC { get; set; }
|
||||
|
||||
@@ -414,7 +417,7 @@ namespace IRDKit
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -435,7 +438,7 @@ namespace IRDKit
|
||||
// Rename provided IRD path
|
||||
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)
|
||||
{
|
||||
@@ -1034,7 +1037,7 @@ namespace IRDKit
|
||||
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);
|
||||
|
||||
@@ -1043,7 +1046,9 @@ namespace IRDKit
|
||||
|
||||
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)}]";
|
||||
filename += $" [{ird.TitleID.Substring(0, 4).Replace('\0', ' ')}-{ird.TitleID.Substring(4, 5).Replace('\0', ' ')}]";
|
||||
if (ver)
|
||||
filename += $" [{ird.DiscVersion.Replace('\0', ' ')}]";
|
||||
if (crc)
|
||||
filename += $" [{ird.UID:X8}]";
|
||||
|
||||
|
||||
@@ -39,3 +39,9 @@ For all options, run `irdkit help diff`
|
||||
|
||||
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=`
|
||||
|
||||
## 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`
|
||||
|
||||
+120
-36
@@ -280,11 +280,6 @@ namespace LibIRD
|
||||
/// <remarks>Last byte to read when reading the header</remarks>
|
||||
private long FirstDataSector { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// First byte of the PS3UPDAT.PUP file
|
||||
/// </summary>
|
||||
private long UpdateOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last byte of the PS3UPDAT.PUP file
|
||||
/// </summary>
|
||||
@@ -413,7 +408,11 @@ namespace LibIRD
|
||||
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(key));
|
||||
|
||||
// Setup AES decryption
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
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
|
||||
aes.Key = D1AesKey;
|
||||
@@ -446,7 +445,11 @@ namespace LibIRD
|
||||
throw new ArgumentException("Disc Key must be a byte array of length 16", nameof(d1));
|
||||
|
||||
// Setup AES decryption
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
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
|
||||
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));
|
||||
|
||||
// Setup AES encryption
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
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
|
||||
aes.Key = D2AesKey;
|
||||
@@ -511,7 +518,11 @@ namespace LibIRD
|
||||
throw new ArgumentException("Disc ID must be a byte array of length 16", nameof(d2));
|
||||
|
||||
// Setup AES encryption
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
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
|
||||
aes.Key = D2AesKey;
|
||||
@@ -636,27 +647,35 @@ namespace LibIRD
|
||||
// Redump-style IRDs set the lowest bit of ExtraConfig to 1
|
||||
ExtraConfig |= 0x01;
|
||||
|
||||
// Redump-style IRDs use fields from PS3_DISC.SFB
|
||||
using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read);
|
||||
// Try to get Title ID and Disc Version from PS3_DISC.SFB
|
||||
try
|
||||
{
|
||||
// Redump-style IRDs use fields from PS3_DISC.SFB
|
||||
using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read);
|
||||
|
||||
// Parse PS3_DISC.SFB file
|
||||
PS3_DiscSFB ps3_DiscSFB = new(s);
|
||||
// Parse PS3_DISC.SFB file
|
||||
PS3_DiscSFB ps3_DiscSFB = new(s);
|
||||
|
||||
bool titleIDFound = ps3_DiscSFB.Field.TryGetValue("TITLE_ID", out string titleID);
|
||||
// If a valid TITLE_ID field is present, remove the hyphen to fit into standard IRD file
|
||||
if (titleIDFound && titleID.Length == 10 && titleID[4] == '-')
|
||||
TitleID = titleID.Substring(0, 4) + titleID.Substring(5, 5);
|
||||
bool titleIDFound = ps3_DiscSFB.Field.TryGetValue("TITLE_ID", out string titleID);
|
||||
// If a valid TITLE_ID field is present, remove the hyphen to fit into standard IRD file
|
||||
if (titleIDFound && titleID.Length == 10 && titleID[4] == '-')
|
||||
TitleID = titleID.Substring(0, 4) + titleID.Substring(5, 5);
|
||||
|
||||
// If the version field is present, this is a multi-game disc
|
||||
// Redump-style IRDs use the VERSION field from PS3_DISC.SFB instead of VERSION from PARAM.SFO
|
||||
bool discVersionFound = ps3_DiscSFB.Field.TryGetValue("VERSION", out string discVersion);
|
||||
if (discVersionFound)
|
||||
DiscVersion = discVersion;
|
||||
// If the version field is present, this is a multi-game disc
|
||||
// Redump-style IRDs use the VERSION field from PS3_DISC.SFB instead of VERSION from PARAM.SFO
|
||||
bool discVersionFound = ps3_DiscSFB.Field.TryGetValue("VERSION", out string discVersion);
|
||||
if (discVersionFound)
|
||||
DiscVersion = discVersion;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Read PS3 Metadata from PARAM.SFO
|
||||
using (SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
|
||||
// Try to get Title ID, Title, Disc Version, and App Version from PARAM.SFO
|
||||
try
|
||||
{
|
||||
// Read PS3 Metadata from PARAM.SFO
|
||||
using SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read);
|
||||
|
||||
// Parse PARAM.SFO file
|
||||
ParamSFO paramSFO = new(s);
|
||||
|
||||
@@ -691,18 +710,33 @@ namespace LibIRD
|
||||
else
|
||||
AppVersion = "\0\0\0\0\0";
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Determine system update version
|
||||
GetSystemVersion(fs, reader);
|
||||
// Ensure Title ID is set and valid
|
||||
if (string.IsNullOrEmpty(TitleID) || TitleID.Length != 9)
|
||||
TitleID = "\0\0\0\0\0\0\0\0\0";
|
||||
|
||||
// Read and compress the ISO header
|
||||
GetHeader(fs, reader);
|
||||
// Ensure Title is set
|
||||
Title ??= string.Empty;
|
||||
|
||||
// Read and compress the ISO footer
|
||||
GetFooter(fs);
|
||||
// Ensure Disc Version is set and valid
|
||||
if (string.IsNullOrEmpty(DiscVersion) || DiscVersion.Length != 5)
|
||||
DiscVersion = "\0\0\0\0\0";
|
||||
|
||||
// Get info region info from ISO
|
||||
GetRegions(fs);
|
||||
// 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);
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Ensure System Version was set and valid
|
||||
if (string.IsNullOrEmpty(SystemVersion) || SystemVersion.Length != 4)
|
||||
SystemVersion = "\0\0\0\0";
|
||||
|
||||
// Recursively count all files in ISO to allocate file arrays
|
||||
DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\");
|
||||
@@ -731,13 +765,30 @@ namespace LibIRD
|
||||
// Sort files by offset
|
||||
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
|
||||
RegionHashes = new byte[RegionCount][];
|
||||
FileHashes = new byte[FileCount][];
|
||||
HashISO(fs, redump && UID == 0x00000000);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Reading ISO
|
||||
|
||||
@@ -756,13 +807,13 @@ namespace LibIRD
|
||||
throw new IOException("Invalid file extents for PS3UPDAT.PUP");
|
||||
|
||||
// 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
|
||||
int lastExtent = updateClusters.Length - 1;
|
||||
UpdateEnd = SectorSize * updateClusters[lastExtent].Offset + updateClusters[lastExtent].Count;
|
||||
|
||||
// Check PUP file Magic
|
||||
fs.Seek(UpdateOffset, SeekOrigin.Begin);
|
||||
fs.Seek(updateOffset, SeekOrigin.Begin);
|
||||
byte[] pupMagic = new byte[5];
|
||||
fs.Read(pupMagic, 0, pupMagic.Length);
|
||||
// If magic is incorrect, set version to all nulls, "\0\0\0\0" (unknown)
|
||||
@@ -771,13 +822,13 @@ namespace LibIRD
|
||||
else
|
||||
{
|
||||
// Determine location of version string
|
||||
fs.Seek(UpdateOffset + 0x3E, SeekOrigin.Begin);
|
||||
fs.Seek(updateOffset + 0x3E, SeekOrigin.Begin);
|
||||
byte[] offset = new byte[2];
|
||||
fs.Read(offset, 0, 2);
|
||||
// Move stream to PUP version string
|
||||
Array.Reverse(offset);
|
||||
ushort versionOffset = BitConverter.ToUInt16(offset, 0);
|
||||
fs.Seek(UpdateOffset + versionOffset, SeekOrigin.Begin);
|
||||
fs.Seek(updateOffset + versionOffset, SeekOrigin.Begin);
|
||||
// Read version string
|
||||
byte[] version = new byte[4];
|
||||
fs.Read(version, 0, version.Length);
|
||||
@@ -989,7 +1040,12 @@ namespace LibIRD
|
||||
throw new ArgumentException("Number of sectors must be within buffer");
|
||||
|
||||
// Setup AES decryption
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
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
|
||||
aes.Key = DiscKey;
|
||||
aes.Padding = PaddingMode.None;
|
||||
@@ -1035,6 +1091,10 @@ namespace LibIRD
|
||||
CountFiles(dirInfo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hashing
|
||||
|
||||
/// <summary>
|
||||
/// Calculate hashes for all region and file extents
|
||||
/// </summary>
|
||||
@@ -1080,6 +1140,22 @@ namespace LibIRD
|
||||
// If end of ISO reached, stop reading
|
||||
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 (redump)
|
||||
{
|
||||
@@ -1087,6 +1163,7 @@ namespace LibIRD
|
||||
Array.Reverse(crc32);
|
||||
UID = BitConverter.ToUInt32(crc32, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1180,7 +1257,7 @@ namespace LibIRD
|
||||
|
||||
// Don't decrypt last sectors if the encrypted region ends within this buffer
|
||||
if (RegionEnd[i] < currentSector + bufSectors)
|
||||
encCount -= (int)(currentSector + bufSectors - RegionEnd[i] + 1);
|
||||
encCount -= (int)(currentSector + bufSectors - RegionEnd[i] - 1);
|
||||
|
||||
// Decrypt encrypted sectors
|
||||
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)
|
||||
int lastExtent = FileExtents[i].Length - 1;
|
||||
long lastByte = SectorSize * FileExtents[i][lastExtent].Offset + FileExtents[i][lastExtent].Count;
|
||||
if (lastByte < SectorSize * (currentSector + bufSectors)
|
||||
if (lastByte <= SectorSize * (currentSector + bufSectors)
|
||||
&& lastByte > SectorSize * currentSector)
|
||||
{
|
||||
// Close file hash
|
||||
@@ -1359,7 +1436,14 @@ namespace LibIRD
|
||||
#endif
|
||||
// Write entire gzipped IRD stream to file
|
||||
stream.Position = 0;
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
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>
|
||||
@@ -1571,7 +1655,7 @@ namespace LibIRD
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Helper Functions
|
||||
|
||||
|
||||
+12
-5
@@ -2,13 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- 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>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.7.0</Version>
|
||||
<Version>0.9.1</Version>
|
||||
<PackageOutputPath>../nupkg</PackageOutputPath>
|
||||
|
||||
<!-- Package Properties -->
|
||||
@@ -22,6 +21,14 @@
|
||||
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.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</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="./README.md" Pack="true" PackagePath="" />
|
||||
@@ -29,7 +36,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.1.3" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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 .`
|
||||
- Creating an IRD from an ISO: `irdkit create game.iso`
|
||||
- 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).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user