Refactor, IRDKit can take directories
This commit is contained in:
+84
-28
@@ -6,6 +6,7 @@ using System.IO.Compression;
|
||||
using System.IO.Hashing;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace LibIRD
|
||||
{
|
||||
@@ -663,11 +664,11 @@ namespace LibIRD
|
||||
// Parse PARAM.SFO file
|
||||
ParamSFO paramSFO = new(s);
|
||||
// If PS3_DISC.SFB did not set TitleID, use PARAM.SFO TITLE_ID
|
||||
TitleID ??= paramSFO["TITLE_ID"];
|
||||
Title = paramSFO["TITLE"];
|
||||
TitleID ??= paramSFO.Field["TITLE_ID"];
|
||||
Title = paramSFO.Field["TITLE"];
|
||||
// If PS3_DISC.SFB did not set DiscVersion, use PARAM.SFO VERSION
|
||||
DiscVersion ??= paramSFO["VERSION"];
|
||||
AppVersion = paramSFO["APP_VER"];
|
||||
DiscVersion ??= paramSFO.Field["VERSION"];
|
||||
AppVersion = paramSFO.Field["APP_VER"];
|
||||
}
|
||||
|
||||
// Determine system update version
|
||||
@@ -1266,38 +1267,93 @@ namespace LibIRD
|
||||
/// <summary>
|
||||
/// Prints IRD fields to console
|
||||
/// </summary>
|
||||
public void Print()
|
||||
/// <param name="printPath">Optional path to save file to</param>
|
||||
public void Print(string printPath = null)
|
||||
{
|
||||
// Build string from parameters
|
||||
StringBuilder print = new();
|
||||
print.AppendLine("IRD Contents:");
|
||||
print.AppendLine("=============");
|
||||
StringBuilder printText = new();
|
||||
printText.AppendLine("IRD Contents:");
|
||||
printText.AppendLine("=============");
|
||||
|
||||
// Append IRD fields to string builder
|
||||
print.AppendLine($"Magic: {Encoding.ASCII.GetString(Magic)}");
|
||||
print.AppendLine($"IRD Version: {Version}");
|
||||
print.AppendLine($"Title ID: {TitleID}");
|
||||
print.AppendLine($"Title: {Title}");
|
||||
print.AppendLine($"PUP Version: {SystemVersion}");
|
||||
print.AppendLine($"Disc Version: {DiscVersion}");
|
||||
print.AppendLine($"App Version: {AppVersion}");
|
||||
print.AppendLine($"Regions: {RegionCount}");
|
||||
print.AppendLine($"Files: {FileCount}");
|
||||
printText.AppendLine($"Magic: {Encoding.ASCII.GetString(Magic)}");
|
||||
printText.AppendLine($"IRD Version: {Version}");
|
||||
printText.AppendLine($"Title ID: {TitleID}");
|
||||
printText.AppendLine($"Title: {Title}");
|
||||
printText.AppendLine($"PUP Version: {SystemVersion}");
|
||||
printText.AppendLine($"Disc Version: {DiscVersion}");
|
||||
printText.AppendLine($"App Version: {AppVersion}");
|
||||
printText.AppendLine($"Regions: {RegionCount}");
|
||||
printText.AppendLine($"Files: {FileCount}");
|
||||
if (ExtraConfig != 0x0000)
|
||||
print.AppendLine($"Extra Config: {ExtraConfig:X4}");
|
||||
printText.AppendLine($"Extra Config: {ExtraConfig:X4}");
|
||||
if (Attachments != 0x0000)
|
||||
print.AppendLine($"Attachments: {Attachments:X4}");
|
||||
print.AppendLine($"Unique ID: {UID:X8}");
|
||||
print.AppendLine($"Data 1 Key: {Convert.ToHexString(Data1Key)}");
|
||||
print.AppendLine($"Data 2 Key: {Convert.ToHexString(Data2Key)}");
|
||||
print.AppendLine($"PIC: {Convert.ToHexString(PIC)}");
|
||||
print.AppendLine();
|
||||
printText.AppendLine($"Attachments: {Attachments:X4}");
|
||||
printText.AppendLine($"Unique ID: {UID:X8}");
|
||||
printText.AppendLine($"Data 1 Key: {Convert.ToHexString(Data1Key)}");
|
||||
printText.AppendLine($"Data 2 Key: {Convert.ToHexString(Data2Key)}");
|
||||
printText.AppendLine($"PIC: {Convert.ToHexString(PIC)}");
|
||||
printText.AppendLine();
|
||||
|
||||
// Ensure UTF-8 will display properly
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
if (printPath == null)
|
||||
{
|
||||
// Ensure UTF-8 will display properly
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
// Print formatted string
|
||||
Console.Write(print);
|
||||
// Print formatted string
|
||||
Console.Write(printText);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.WriteAllText(printPath, printText.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Prints IRD fields to a json object
|
||||
/// </summary>
|
||||
/// <param name="jsonPath">Optionally print to json file</param>
|
||||
public void PrintJson(string jsonPath = null)
|
||||
{
|
||||
// Build string from parameters
|
||||
StringBuilder json = new();
|
||||
|
||||
// Append IRD fields to string builder
|
||||
json.AppendLine("{");
|
||||
json.AppendLine($" \"Magic\": \"{Encoding.ASCII.GetString(Magic)}\",");
|
||||
json.AppendLine($" \"IRD Version\": \"{Version}\",");
|
||||
json.AppendLine($" \"Title ID\": \"{TitleID}\",");
|
||||
json.AppendLine($" \"Title\": \"{Title}\",");
|
||||
json.AppendLine($" \"PUP Version\": \"{SystemVersion}\",");
|
||||
json.AppendLine($" \"Disc Version\": \"{DiscVersion}\",");
|
||||
json.AppendLine($" \"App Version\": \"{AppVersion}\",");
|
||||
json.AppendLine($" \"Regions\": \"{RegionCount}\",");
|
||||
json.AppendLine($" \"Files\": \"{FileCount}\",");
|
||||
if (ExtraConfig != 0x0000)
|
||||
json.AppendLine($" \"Extra Config\": \"{ExtraConfig:X4}\",");
|
||||
if (Attachments != 0x0000)
|
||||
json.AppendLine($" \"Attachments\": \"{Attachments:X4}\",");
|
||||
json.AppendLine($" \"Unique ID\": \"{UID:X8}");
|
||||
json.AppendLine($" \"Data 1 Key\": \"{Convert.ToHexString(Data1Key)}\",");
|
||||
json.AppendLine($" \"Data 2 Key\": \"{Convert.ToHexString(Data2Key)}\",");
|
||||
json.AppendLine($" \"PIC\": \"{Convert.ToHexString(PIC)}\"");
|
||||
json.AppendLine("}");
|
||||
|
||||
// If no path given, output to console
|
||||
if (jsonPath == null)
|
||||
{
|
||||
// Ensure UTF-8 will display properly in console
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
// Print formatted string to console
|
||||
Console.Write(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write to path
|
||||
File.AppendAllText(jsonPath, json.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -5,14 +5,15 @@
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Version>0.1.0</Version>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.2.0</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Deterous</Authors>
|
||||
<Description>Library for ISO Rebuild Data</Description>
|
||||
<Copyright>Copyright (c) Deterous 2023</Copyright>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/Deterous/LibIRD</RepositoryUrl>
|
||||
<RepositoryUrl>https://github.com/Deterous/LibIRD/</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>ps3 iso ird redump</PackageTags>
|
||||
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
|
||||
|
||||
+47
-15
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace LibIRD
|
||||
{
|
||||
@@ -25,6 +26,7 @@ namespace LibIRD
|
||||
/// <summary>
|
||||
/// A field within the PS3_DISC.SFB file
|
||||
/// </summary>
|
||||
/// <remarks>string Key, string Value</remarks>
|
||||
public Dictionary<string, string> Field { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -35,8 +37,7 @@ namespace LibIRD
|
||||
public PS3_DiscSFB(string sfbPath)
|
||||
{
|
||||
// Validate file path
|
||||
if (sfbPath == null || sfbPath.Length <= 0)
|
||||
throw new ArgumentNullException(nameof(sfbPath));
|
||||
ArgumentNullException.ThrowIfNull(sfbPath, nameof(sfbPath));
|
||||
|
||||
// Read file as a stream, and parse file
|
||||
using FileStream fs = new(sfbPath, FileMode.Open, FileAccess.Read);
|
||||
@@ -47,7 +48,6 @@ namespace LibIRD
|
||||
/// Parse PS3_DISC.SFB from stream
|
||||
/// </summary>
|
||||
/// <param name="sfbStream">SFB file stream</param>
|
||||
/// <exception cref="FileLoadException"></exception>
|
||||
public PS3_DiscSFB(Stream sfbStream)
|
||||
{
|
||||
// Parse file stream
|
||||
@@ -102,27 +102,59 @@ namespace LibIRD
|
||||
/// <summary>
|
||||
/// Prints formatted parameters extracted from PS3_DISC.SFB to console
|
||||
/// </summary>
|
||||
public void Print()
|
||||
/// <param name="printPath">Optionally print to text file</param>
|
||||
public void Print(string printPath = null)
|
||||
{
|
||||
// Build string from parameters
|
||||
StringBuilder print = new();
|
||||
print.AppendLine("PS3_DISC.SFB Contents:");
|
||||
print.AppendLine("======================");
|
||||
StringBuilder printText = new();
|
||||
printText.AppendLine("PS3_DISC.SFB Contents:");
|
||||
printText.AppendLine("======================");
|
||||
|
||||
// Loop through all parameters in PARAM.SFO
|
||||
foreach (KeyValuePair<string, string> field in Field)
|
||||
printText.AppendLine(field.Key + ": " + field.Value);
|
||||
// Blank line
|
||||
printText.Append(Environment.NewLine);
|
||||
|
||||
// If no path given, print to console
|
||||
if (printPath == null)
|
||||
{
|
||||
print.Append(field.Key);
|
||||
print.Append(": ");
|
||||
print.AppendLine(field.Value);
|
||||
// Ensure UTF-8 will display properly in console
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
// Print formatted string to console
|
||||
Console.Write(printText);
|
||||
}
|
||||
print.Append(Environment.NewLine);
|
||||
else
|
||||
{
|
||||
// Write data to file
|
||||
File.AppendAllText(printPath, printText.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure UTF-8 will display properly
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
/// <summary>
|
||||
/// Prints parameters extracted from PS3_DISC.SFB to a json object
|
||||
/// </summary>
|
||||
/// <param name="jsonPath">Optionally print to json file</param>
|
||||
public void PrintJson(string jsonPath = null)
|
||||
{
|
||||
// Serialise PS3_Disc.SFB data to a JSON object
|
||||
string json = JsonSerializer.Serialize(Field, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
// Print formatted string
|
||||
Console.Write(print);
|
||||
// If no path given, output to console
|
||||
if (jsonPath == null)
|
||||
{
|
||||
// Ensure UTF-8 will display properly in console
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
// Print formatted string to console
|
||||
Console.Write(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write to path
|
||||
File.AppendAllText(jsonPath, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+82
-142
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace LibIRD
|
||||
{
|
||||
@@ -22,91 +24,10 @@ namespace LibIRD
|
||||
public uint Version { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The location of the first byte of the Key Table
|
||||
/// A field within the PS3_DISC.SFB file
|
||||
/// </summary>
|
||||
public uint KeyTableStart { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The location of the first byte of the Data Table
|
||||
/// </summary>
|
||||
public uint DataTableStart { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of parameters in the table
|
||||
/// </summary>
|
||||
public uint ParamCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parameter, a single entry in parameter table
|
||||
/// </summary>
|
||||
public class Param
|
||||
{
|
||||
/// <summary>
|
||||
/// Offset of key, relative to KeyTableStart
|
||||
/// </summary>
|
||||
public ushort KeyOffset { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Format of parameter
|
||||
/// </summary>
|
||||
/// <remarks>0x0400 is string, 0x0404 is uint</remarks>
|
||||
public ushort DataFormat { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes used for parameter
|
||||
/// </summary>
|
||||
public uint DataLength { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total number of bytes for parameter
|
||||
/// </summary>
|
||||
/// <remarks>DataTotal - DataLength is padding of 0x00</remarks>
|
||||
public uint DataTotal { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// offset of parameter, relative to DataTableStart
|
||||
/// </summary>
|
||||
public uint DataOffset { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the parameter
|
||||
/// </summary>
|
||||
public string Name { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The value of the parameter, if it is a string
|
||||
/// </summary>
|
||||
public string StringValue { get; internal set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// The value of the parameter, if it is a UInt32
|
||||
/// </summary>
|
||||
public int IntValue { get; internal set; } = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The parameters in the table
|
||||
/// </summary>
|
||||
/// <remarks><see cref="ParamCount"/> Params in the table</remarks>
|
||||
public Param[] Params { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// String index overloading, gets string value of given key
|
||||
/// </summary>
|
||||
/// <param name="key">Parameter to be retreived</param>
|
||||
/// <returns>The string value of the given key</returns>
|
||||
public string this[string key]
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
/// <remarks>string Key, string Value</remarks>
|
||||
public Dictionary<string, string> Field { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor using a PARAM.SFO file stream
|
||||
@@ -151,95 +72,114 @@ namespace LibIRD
|
||||
|
||||
// Parse header
|
||||
Version = br.ReadUInt32();
|
||||
KeyTableStart = br.ReadUInt32();
|
||||
DataTableStart = br.ReadUInt32();
|
||||
ParamCount = br.ReadUInt32();
|
||||
uint keyTableStart = br.ReadUInt32();
|
||||
uint dataTableStart = br.ReadUInt32();
|
||||
uint paramCount = br.ReadUInt32();
|
||||
|
||||
// Parse parameter metadata
|
||||
Params = new Param[ParamCount];
|
||||
for (int i = 0; i < ParamCount; i++)
|
||||
ushort[] keyOffset = new ushort[paramCount];
|
||||
uint[] dataFormat = new uint[paramCount];
|
||||
uint[] dataLength = new uint[paramCount];
|
||||
uint[] dataTotal = new uint[paramCount];
|
||||
uint[] dataOffset = new uint[paramCount];
|
||||
for (int i = 0; i < paramCount; i++)
|
||||
{
|
||||
Params[i] = new Param
|
||||
{
|
||||
KeyOffset = br.ReadUInt16(),
|
||||
DataFormat = br.ReadUInt16(),
|
||||
DataLength = br.ReadUInt32(),
|
||||
DataTotal = br.ReadUInt32(),
|
||||
DataOffset = br.ReadUInt32()
|
||||
};
|
||||
keyOffset[i] = br.ReadUInt16();
|
||||
dataFormat[i] = br.ReadUInt16();
|
||||
dataLength[i] = br.ReadUInt32();
|
||||
dataTotal[i] = br.ReadUInt32();
|
||||
dataOffset[i] = br.ReadUInt32();
|
||||
}
|
||||
|
||||
// Parse parameters
|
||||
for (int i = 0; i < ParamCount; i++)
|
||||
Field = [];
|
||||
for (int i = 0; i < paramCount; i++)
|
||||
{
|
||||
// Move stream to ith key
|
||||
sfoStream.Position = KeyTableStart + Params[i].KeyOffset;
|
||||
sfoStream.Position = keyTableStart + keyOffset[i];
|
||||
|
||||
// Determine ith key length
|
||||
uint keyLen = ((i == ParamCount - 1) ? DataTableStart - KeyTableStart : Params[i + 1].KeyOffset)
|
||||
- Params[i].KeyOffset;
|
||||
uint keyLen = ((i == paramCount - 1) ? dataTableStart - keyTableStart : keyOffset[i + 1])
|
||||
- keyOffset[i];
|
||||
|
||||
// Read ith key name
|
||||
Params[i].Name = Encoding.ASCII.GetString(br.ReadBytes((int) keyLen)).TrimEnd('\0');
|
||||
string key = Encoding.ASCII.GetString(br.ReadBytes((int) keyLen)).TrimEnd('\0');
|
||||
|
||||
// Move stream to ith data
|
||||
sfoStream.Position = DataTableStart + Params[i].DataOffset;
|
||||
sfoStream.Position = dataTableStart + dataOffset[i];
|
||||
|
||||
// Read ith data, based on data format
|
||||
switch (Params[i].DataFormat)
|
||||
Field[key] = dataFormat[i] switch
|
||||
{
|
||||
case 0x0400: // Non-null-terminated UTF-8 String
|
||||
Params[i].StringValue = Encoding.UTF8.GetString(br.ReadBytes((int)Params[i].DataLength));
|
||||
break;
|
||||
case 0x0402: // Null-terminated UTF-8 String
|
||||
Params[i].StringValue = Encoding.UTF8.GetString(br.ReadBytes((int)Params[i].DataLength)).TrimEnd('\0');
|
||||
break;
|
||||
case 0x0404: // Integer
|
||||
//if (Params[i].DataLength != 4)
|
||||
//throw new ArgumentException("Integer parameter not 4 bytes?");
|
||||
Params[i].IntValue = br.ReadInt32();
|
||||
break;
|
||||
default: // Unknown data format, assume null-terminated string
|
||||
Params[i].StringValue = Encoding.UTF8.GetString(br.ReadBytes((int)Params[i].DataLength)).TrimEnd('\0');
|
||||
break;
|
||||
}
|
||||
// Non-null-terminated UTF-8 String
|
||||
0x0004 => Encoding.UTF8.GetString(br.ReadBytes((int) dataLength[i])),
|
||||
// Null-terminated UTF-8 String
|
||||
0x0204 => Encoding.UTF8.GetString(br.ReadBytes((int) dataLength[i])).TrimEnd('\0'),
|
||||
// Integer
|
||||
0x0404 => br.ReadInt32().ToString(),
|
||||
// Unknown data format, assume null-terminated string
|
||||
_ => Encoding.UTF8.GetString(br.ReadBytes((int) dataLength[i])).TrimEnd('\0'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints formatted parameters extracted from PARAM.SFO to console
|
||||
/// </summary>
|
||||
public void Print()
|
||||
/// <param name="printPath">Optionally print to text file</param>
|
||||
public void Print(string printPath = null)
|
||||
{
|
||||
// Build string from parameters
|
||||
StringBuilder print = new();
|
||||
print.AppendLine("PARAM.SFO Contents:");
|
||||
print.AppendLine("====================");
|
||||
StringBuilder printText = new();
|
||||
printText.AppendLine("PARAM.SFO Contents:");
|
||||
printText.AppendLine("====================");
|
||||
|
||||
// Loop through all parameters in PARAM.SFO
|
||||
for (int i = 0; i < ParamCount; i++)
|
||||
foreach (KeyValuePair<string, string> field in Field)
|
||||
printText.AppendLine(field.Key + ": " + field.Value);
|
||||
// Blank line
|
||||
printText.Append(Environment.NewLine);
|
||||
|
||||
// If no path given, print to console
|
||||
if (printPath == null)
|
||||
{
|
||||
print.Append(Params[i].Name);
|
||||
print.Append(' ');
|
||||
for (int j = Params[i].Name.Length; j < 20; j++)
|
||||
print.Append(' ');
|
||||
switch (Params[i].DataFormat)
|
||||
{
|
||||
case 0x0404:
|
||||
print.Append(Params[i].IntValue +Environment.NewLine);
|
||||
break;
|
||||
default:
|
||||
print.AppendLine(Params[i].StringValue);
|
||||
break;
|
||||
}
|
||||
// Ensure UTF-8 will display properly in console
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
// Print formatted string to console
|
||||
Console.Write(printText);
|
||||
}
|
||||
print.Append(Environment.NewLine);
|
||||
else
|
||||
{
|
||||
// Write data to file
|
||||
File.AppendAllText(printPath, printText.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure UTF-8 will display properly
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
/// <summary>
|
||||
/// Prints parameters extracted from PARAM.SFO to a json object
|
||||
/// </summary>
|
||||
/// <param name="jsonPath">Optionally print to json file</param>
|
||||
public void PrintJson(string jsonPath = null)
|
||||
{
|
||||
// Serialise PS3_Disc.SFB data to a JSON object
|
||||
string json = JsonSerializer.Serialize(Field, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
// If no path given, output to console
|
||||
if (jsonPath == null)
|
||||
{
|
||||
// Ensure UTF-8 will display properly in console
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
// Print formatted string to console
|
||||
Console.Write(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write to path
|
||||
File.AppendAllText(jsonPath, json);
|
||||
}
|
||||
|
||||
// Print formatted string
|
||||
Console.Write(print);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-24
@@ -67,10 +67,9 @@ namespace LibIRD
|
||||
/// </summary>
|
||||
/// <param name="isoPath">Path to the ISO</param>
|
||||
/// <param name="getKeyLog">Path to the GetKey log file</param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="FileNotFoundException"></exception>
|
||||
/// <param name="layerbreak">Layerbreak value, in sectors</param>
|
||||
/// <exception cref="InvalidDataException"></exception>
|
||||
public ReIRD(string isoPath, string getKeyLog) : base(isoPath, getKeyLog, true)
|
||||
public ReIRD(string isoPath, string getKeyLog, long? layerbreak = null) : base(isoPath, getKeyLog, true)
|
||||
{
|
||||
// Generate Unique Identifier using ISO CRC32
|
||||
UID = GenerateUID(isoPath);
|
||||
@@ -80,12 +79,10 @@ namespace LibIRD
|
||||
|
||||
// Generate Data 2 using Disc ID
|
||||
DiscID = GenerateID(Size);
|
||||
// Check that GetKey log matches expected Disc ID
|
||||
//if (!((ReadOnlySpan<byte>)Data2Key).SequenceEqual(d2))
|
||||
// throw new InvalidDataException("Unexpected Disc ID in .getkey.log");
|
||||
|
||||
// Generate Disc PIC
|
||||
byte[] pic = GeneratePIC(Size);
|
||||
byte[] pic = GeneratePIC(Size, layerbreak * SectorSize);
|
||||
|
||||
// Check that GetKey log matches expected PIC
|
||||
if (!((ReadOnlySpan<byte>)PIC).SequenceEqual(pic))
|
||||
throw new InvalidDataException("Unexpected PIC in .getkey.log");
|
||||
@@ -96,10 +93,9 @@ namespace LibIRD
|
||||
/// </summary>
|
||||
/// <param name="isoPath">Path to the ISO</param>
|
||||
/// <param name="key">Disc Key, redump-style (AES encrypted Data 1)</param>
|
||||
/// <param name="layerbreak">Layerbreak value, in sectors</param>
|
||||
/// <param name="region">Disc Region</param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="FileNotFoundException"></exception>
|
||||
public ReIRD(string isoPath, byte[] key, Region region = Region.NONE)
|
||||
public ReIRD(string isoPath, byte[] key, long? layerbreak = null, Region region = Region.NONE)
|
||||
{
|
||||
// Generate Unique Identifier using ISO CRC32
|
||||
UID = GenerateUID(isoPath);
|
||||
@@ -114,7 +110,7 @@ namespace LibIRD
|
||||
DiscID = GenerateID(Size, region);
|
||||
|
||||
// Generate Disc PIC
|
||||
PIC = GeneratePIC(Size);
|
||||
PIC = GeneratePIC(Size, layerbreak * SectorSize);
|
||||
|
||||
// Generate IRD fields
|
||||
GenerateIRD(isoPath, true);
|
||||
@@ -144,7 +140,7 @@ namespace LibIRD
|
||||
/// Generates the PIC data for a given ISO size in bytes
|
||||
/// </summary>
|
||||
/// <param name="size">Total ISO size in number of bytes</param>
|
||||
/// <param name="layer_break">Layer break value, byte at which disc layers are split across</param>
|
||||
/// <param name="layerbreak">Layer break value, byte at which disc layers are split across</param>
|
||||
/// <param name="exactIRD">True to generate a PIC in 3k3y style (0x03 at 115th byte for BD-50 discs)</param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static byte[] GeneratePIC(long size, long? layerbreak = null, bool exactIRD = false)
|
||||
@@ -171,20 +167,20 @@ namespace LibIRD
|
||||
long l0_start_sector = 1048576;
|
||||
|
||||
// Layer 0 end sector = start sector + layerbreak - 2
|
||||
long l0_end_sector = layer_break + l0_start_sector - 2;
|
||||
long l0_end_sector = (layer_break / SectorSize) + l0_start_sector - 2;
|
||||
// Convert end sector location to hex values for PIC
|
||||
byte[] l0es = [(byte)((l0_end_sector >> 24) & 0xFF),
|
||||
(byte)((l0_end_sector >> 16) & 0xFF),
|
||||
(byte)((l0_end_sector >> 8) & 0xFF),
|
||||
(byte)((l0_end_sector >> 0) & 0xFF)];
|
||||
(byte)((l0_end_sector >> 16) & 0xFF),
|
||||
(byte)((l0_end_sector >> 8) & 0xFF),
|
||||
(byte)((l0_end_sector >> 0) & 0xFF)];
|
||||
|
||||
// Layer 1 start sector = end of disc (0x01EFFFFE) - layerbreak + 2
|
||||
long l1_start_sector = 32505854 - layer_break + 2;
|
||||
long l1_start_sector = 32505854 - (layer_break / SectorSize) + 2;
|
||||
// Convert start of start sector location to hex values for PIC
|
||||
byte[] l1ss = [(byte)((l1_start_sector >> 24) & 0xFF),
|
||||
(byte)((l1_start_sector >> 16) & 0xFF),
|
||||
(byte)((l1_start_sector >> 8) & 0xFF),
|
||||
(byte)((l1_start_sector >> 0) & 0xFF)];
|
||||
(byte)((l1_start_sector >> 16) & 0xFF),
|
||||
(byte)((l1_start_sector >> 8) & 0xFF),
|
||||
(byte)((l1_start_sector >> 0) & 0xFF)];
|
||||
|
||||
// Total sectors used = num_sectors + Layer 0 start + sectors_between_layers (usually 0x01358C00 - 0x00CA73FE - 3)
|
||||
long total_sectors = (size / SectorSize) + l0_start_sector + (l1_start_sector - l0_end_sector - 3);
|
||||
@@ -262,8 +258,7 @@ namespace LibIRD
|
||||
private static uint GenerateUID(string isoPath)
|
||||
{
|
||||
// Validate ISO path
|
||||
if (isoPath == null || isoPath.Length <= 0)
|
||||
throw new ArgumentNullException(nameof(isoPath));
|
||||
ArgumentNullException.ThrowIfNull(isoPath, nameof(isoPath));
|
||||
|
||||
// Check file exists
|
||||
var iso = new FileInfo(isoPath);
|
||||
@@ -292,8 +287,7 @@ namespace LibIRD
|
||||
private static long CalculateSize(string isoPath)
|
||||
{
|
||||
// Validate ISO path
|
||||
if (isoPath == null || isoPath.Length <= 0)
|
||||
throw new ArgumentNullException(nameof(isoPath));
|
||||
ArgumentNullException.ThrowIfNull(isoPath, nameof(isoPath));
|
||||
|
||||
// Check file exists
|
||||
var iso = new FileInfo(isoPath);
|
||||
|
||||
Reference in New Issue
Block a user