diff --git a/BuildIRD/BuildIRD.cs b/BuildIRD/BuildIRD.cs deleted file mode 100644 index a67f953..0000000 --- a/BuildIRD/BuildIRD.cs +++ /dev/null @@ -1,42 +0,0 @@ -using LibIRD; -using System; -using System.IO; -using System.Text; - -namespace BuildIRD -{ - internal class Program - { - static void Main() - { - Console.OutputEncoding = Encoding.UTF8; - - // Create new reproducible redump-style IRD with a key file - try - { - // Read key from .key file - byte[] discKey = File.ReadAllBytes("./game.key"); - - IRD ird1 = new ReIRD("./game.iso", discKey); - ird1.Write("./test1.ird"); - ird1.Print(); - } - catch (FileNotFoundException) - { - Console.WriteLine("ERROR: File not found"); - } - - // Create new reproducible redump-style IRD with a ManaGunZ log - try - { - IRD ird2 = new ReIRD("./game.iso", "./log.getkey.log"); - ird2.Write("./test2.ird"); - ird2.Print(); - } - catch (FileNotFoundException) - { - Console.WriteLine("ERROR: File not found"); - } - } - } -} diff --git a/BuildIRD/BuildIRD.csproj b/BuildIRD/BuildIRD.csproj deleted file mode 100644 index 0e2902a..0000000 --- a/BuildIRD/BuildIRD.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net6.0 - win-x86;win-x64;linux-x64;osx-x64 - 0.1 - - - - - - - diff --git a/IRDKit/IRDKit.csproj b/IRDKit/IRDKit.csproj new file mode 100644 index 0000000..3a792eb --- /dev/null +++ b/IRDKit/IRDKit.csproj @@ -0,0 +1,33 @@ + + + + + Exe + true + irdkit + ./nupkg + net6.0;net7.0 + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 + 0.1.0 + + + Deterous + Library for ISO Rebuild Data + Copyright (c) 2023 Deterous + + https://github.com/Deterous/LibIRD + git + ps3 iso ird redump + GPL-3.0-only + + + + + + + + + + + + diff --git a/IRDKit/Program.cs b/IRDKit/Program.cs new file mode 100644 index 0000000..764acf5 --- /dev/null +++ b/IRDKit/Program.cs @@ -0,0 +1,113 @@ +using LibIRD; +using System; +using System.Collections.Generic; +using CommandLine; +using System.Text; +using System.IO; + +namespace IRDKit +{ + internal class Program + { + // IRD Creation + [Verb("create")] + public class CreateOptions + { + [Value(0, Required = true, HelpText = "Path to an ISO file, or directory of ISO files")] + public string ISOPath { get; set; } + + [Value(1, HelpText = "Path to the IRD file to be created")] + public string IRDPath { get; set; } + + [Option('r', "recurse", HelpText = "Recurse through all subdirectories and generate IRDs for all ISOs")] + public bool Recurse { get; set; } + + [Option('k', "key", HelpText = "Hexadecimal representation of the disc key")] + public string Key { get; set; } + + [Option("key-file", HelpText = "Path to a redump .key file")] + public string KeyFile { get; set; } + + [Option('l', "getkey-log", HelpText = "Path to a .getkey.log file")] + public string GetKeyLog { get; set; } + } + + // IRD Info + public class InfoOptions + { + [Value(0, Required = true, HelpText = "Path to the IRD file to be printed")] + public string IRDPath { get; set; } + } + + public static void Main(string[] args) + { + // Parse command line arguments + var result = Parser.Default.ParseArguments(args) + .WithParsed(Run) + .WithNotParsed(HandleParseError); + } + + private static void HandleParseError(IEnumerable errs) + { + if (errs.IsVersion()) + { + // --version + } + else if (errs.IsHelp()) + { + // --help + } + else + { + // Parsing error + } + return; + } + + private static void Run(object obj) + { + switch (obj) + { + case CreateOptions c: + Console.OutputEncoding = Encoding.UTF8; + + // Create new reproducible redump-style IRD with a key file + if (c.KeyFile != null) + { + try + { + // Read key from .key file + byte[] discKey = File.ReadAllBytes(c.KeyFile); + + IRD ird1 = new ReIRD(c.ISOPath, discKey); + ird1.Write(c.IRDPath); + ird1.Print(); + } + catch (FileNotFoundException) + { + Console.WriteLine("ERROR: File not found"); + } + } + + // Create new reproducible redump-style IRD with a GetKey log + if (c.GetKeyLog != null) + { + try + { + IRD ird2 = new ReIRD(c.ISOPath, c.GetKeyLog); + ird2.Write(c.IRDPath); + ird2.Print(); + } + catch (FileNotFoundException) + { + Console.WriteLine("ERROR: File not found"); + } + } + break; + case InfoOptions info: + // + break; + } + } + } +} \ No newline at end of file diff --git a/IRDKit/README.md b/IRDKit/README.md new file mode 100644 index 0000000..e67cf66 --- /dev/null +++ b/IRDKit/README.md @@ -0,0 +1,7 @@ +## How to use IRDKit + +IRDKit is a tool that allows direct use of LibIRD functionality from the command line interface. The basic usage is: +``` +irdkit game.iso game.ird +``` +For detailed usage, run `irdkit --help` \ No newline at end of file diff --git a/LibIRD.sln b/LibIRD.sln index 9a91fb2..e654573 100644 --- a/LibIRD.sln +++ b/LibIRD.sln @@ -5,9 +5,9 @@ VisualStudioVersion = 17.7.34202.233 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibIRD", "LibIRD\LibIRD.csproj", "{4A80C34B-D4C5-4536-BEAE-46218BC09980}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildIRD", "BuildIRD\BuildIRD.csproj", "{A2FC2D93-1C3E-46E2-9D69-11F9DDA8CFC7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrintParams", "PrintParams\PrintParams.csproj", "{B5D9C0AD-EA8D-486E-A1D7-ED2C3C7163BC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintParams", "PrintParams\PrintParams.csproj", "{B5D9C0AD-EA8D-486E-A1D7-ED2C3C7163BC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IRDKit", "IRDKit\IRDKit.csproj", "{9060E3AF-E4FB-436F-93A1-5C47389CB88E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -19,14 +19,14 @@ Global {4A80C34B-D4C5-4536-BEAE-46218BC09980}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A80C34B-D4C5-4536-BEAE-46218BC09980}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A80C34B-D4C5-4536-BEAE-46218BC09980}.Release|Any CPU.Build.0 = Release|Any CPU - {A2FC2D93-1C3E-46E2-9D69-11F9DDA8CFC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A2FC2D93-1C3E-46E2-9D69-11F9DDA8CFC7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A2FC2D93-1C3E-46E2-9D69-11F9DDA8CFC7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A2FC2D93-1C3E-46E2-9D69-11F9DDA8CFC7}.Release|Any CPU.Build.0 = Release|Any CPU {B5D9C0AD-EA8D-486E-A1D7-ED2C3C7163BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B5D9C0AD-EA8D-486E-A1D7-ED2C3C7163BC}.Debug|Any CPU.Build.0 = Debug|Any CPU {B5D9C0AD-EA8D-486E-A1D7-ED2C3C7163BC}.Release|Any CPU.ActiveCfg = Release|Any CPU {B5D9C0AD-EA8D-486E-A1D7-ED2C3C7163BC}.Release|Any CPU.Build.0 = Release|Any CPU + {9060E3AF-E4FB-436F-93A1-5C47389CB88E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9060E3AF-E4FB-436F-93A1-5C47389CB88E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9060E3AF-E4FB-436F-93A1-5C47389CB88E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9060E3AF-E4FB-436F-93A1-5C47389CB88E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LibIRD/IRD.cs b/LibIRD/IRD.cs index f5d3092..ce42334 100644 --- a/LibIRD/IRD.cs +++ b/LibIRD/IRD.cs @@ -1285,7 +1285,7 @@ namespace LibIRD print.AppendLine("============="); // Append IRD fields to string builder - print.AppendLine($"Magic: 3IRD"); + print.AppendLine($"Magic: {Encoding.ASCII.GetString(Magic)}"); print.AppendLine($"IRD Version: {Version}"); print.AppendLine($"Title ID: {TitleID}"); print.AppendLine($"Title: {Title}"); diff --git a/LibIRD/LibIRD.csproj b/LibIRD/LibIRD.csproj index 48eb777..abd1290 100644 --- a/LibIRD/LibIRD.csproj +++ b/LibIRD/LibIRD.csproj @@ -9,16 +9,16 @@ Deterous Library for ISO Rebuild Data - Copyright (c) Deterous 2023 + Copyright (c) 2023 Deterous README.md https://github.com/Deterous/LibIRD git - ps3 iso ird + ps3 iso ird redump GPL-3.0-only - + diff --git a/LibIRD/ParamSFO.cs b/LibIRD/ParamSFO.cs index 25ea5c2..9d45d28 100644 --- a/LibIRD/ParamSFO.cs +++ b/LibIRD/ParamSFO.cs @@ -100,6 +100,10 @@ namespace LibIRD get { int index = Array.FindIndex(Params, param => param.Name == key); + if (index == -1) + return null; + if (Params[index].DataFormat == 0x0404) + return Params[index].IntValue.ToString(); return Params[index].StringValue; } } diff --git a/LibIRD/README.md b/LibIRD/README.md new file mode 100644 index 0000000..8d078ed --- /dev/null +++ b/LibIRD/README.md @@ -0,0 +1,40 @@ +## How to use the LibIRD library + +LibIRD was originally made for creating reproducible, redump-style IRDs when dumping PS3 discs with [MPF](https://github.com/SabreTools/MPF). If you wish to integrate LibIRD into your own application, the following are some examples. + +### Reproducible, redump-style IRDs + +The standard way of generating a reproducible, redump-style IRD is with a redump ISO file and a redump key file (e.g. http://redump.org/disc/28721/key/): +```cs +byte[] discKey = File.ReadAllBytes("./game.key"); +IRD ird = new ReIRD("./game.iso", discKey); +``` +Alternatively, the disc key can be extracted from a [GetKey](https://archive.org/download/GetKeyR2GameOS.7z/GetKey-r2-GameOS.7z) log file obtained from a PS3 (or when dumping using [ManaGunZ](https://github.com/Zarh/ManaGunZ/)) +```cs +IRD ird = new ReIRD("./game.iso", "./game.getkey.log"); +``` + +### Custom IRDs + +Functionality is also provided for creating IRDs with a custom disc key, disc ID, and PIC: +```cs +byte[] discKey = new byte[16]; +byte[] discID = new byte[16]; +byte[] PIC = new byte[115]; +// Set vars to desired values +IRD ird = new IRD("./game.iso", discKey, discID, discPIC); +``` +As before, a GetKey log file can also be used with an ISO to create a custom IRD, with the disc key, disc ID, and PIC all being extracted from the log file (rather than just the key for redump-style IRDs). +```cs +IRD ird = new IRD("./game.iso", "./game.getkey.log"); +``` +Finally, an existing IRD file can be read to create an IRD: + ```cs +IRD ird = IRD.Read("./game.ird") +``` +An IRD can be then be tweaked, its fields printed, and written to a new IRD: +```cs +ird.UID = 0x9F1A51D8; +ird.Print(); +ird.Write("game2.ird"); +``` diff --git a/README.md b/README.md index 44f57e3..fc0d47b 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,18 @@ .NET library for generating, writing, and reading IRD files. Functionality is provided for deterministically generating IRDs such that a redump ISO and key have a 1-to-1 correspondence with an IRD file. -## How to use LibIRD +## What is an IRD? -### Reproducible, redump-style IRDs +IRD files contain a summary of what data is on a PlayStation 3 disc. It can be used to rebuild ISOs from files (JB folders). IRD files are also useful for decrypting ISOs after they have been dumped on a PC blu-ray drive, such as for the purposes of legally emulating your PS3 games. -The standard way of generating a reproducible, redump-style IRD is with a redump ISO file and a redump key file (e.g. http://redump.org/disc/28721/key/): -```cs -byte[] discKey = File.ReadAllBytes("./game.key"); -IRD ird = new ReIRD("./game.iso", discKey); -``` -Alternatively, the disc key can be extracted from a [ManaGunZ](https://github.com/Zarh/ManaGunZ/) log file: -```cs -IRD ird = new ReIRD("./game.iso", "./game.getkey.log"); -``` +## How to use IRDKit -### Custom IRDs +IRDKit is a tool that allows direct use of LibIRD functionality from the command line interface. The basic usage is: +``` +irdkit create game.iso +``` +For detailed usage, read more [here](IRDKit/README.MD). -Functionality is also provided for creating IRDs with a custom disc key, disc ID, and PIC: -```cs -byte[] discKey = new byte[16]; -byte[] discID = new byte[16]; -byte[] PIC = new byte[115]; -// Set vars to desired values -IRD ird = new IRD("./game.iso", discKey, discID, discPIC); -``` -As before, a [ManaGunZ](https://github.com/Zarh/ManaGunZ/) log file can also be used with an ISO to create a custom IRD, with the disc key, disc ID, and PIC all being extracted from the log file (rather than just the key). -```cs -IRD ird = new IRD("./game.iso", "./game.getkey.log"); -``` -Finally, an existing IRD file can be read to create an IRD: - ```cs -IRD ird = IRD.Read("./game.ird") -``` +## Using the LibIRD library -An IRD can be then be tweaked, its fields printed, and written to a new IRD: -```cs -ird.UID = 0x9F1A51D8; -ird.Print(); -ird.Write("game2.ird"); -``` +LibIRD was originally made for creating reproducible, redump-style IRDs when dumping PS3 discs with [MPF](https://github.com/SabreTools/MPF). If you wish to integrate LibIRD into your own application, read the examples [here](LibIRD/README.MD).