Skip to content

Commit

Permalink
Print PS4/PS5 app.pkg info (#785)
Browse files Browse the repository at this point in the history
* Print PS4/PS5 app.pkg info

* namespace

* Use a filestream

* Use appPkgHeaderDeserializer obj

* null check
  • Loading branch information
Deterous authored Dec 19, 2024
1 parent 9207627 commit ca59d71
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
- (EXPERIMENTAL) Skip log line queue
- Fully remove processing queue code
- Introduce maximum log length
- Print PS4/PS5 app.pkg info

### 3.2.4 (2024-11-24)

Expand Down
111 changes: 111 additions & 0 deletions MPF.Frontend/Tools/PhysicalTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,61 @@ public static bool GetBusEncryptionEnabled(Drive? drive)
}
}

/// <summary>
/// Get the app.pkg info from a PlayStation 4 disc, if possible
/// </summary>
/// <param name="drive">Drive to extract information from</param>
/// <returns>PKG info if possible, null on error</returns>
public static string? GetPlayStation4PkgInfo(Drive? drive)
{
// If there's no drive path, we can't do this part
if (string.IsNullOrEmpty(drive?.Name))
return null;

// If the folder no longer exists, we can't do this part
if (!Directory.Exists(drive!.Name))
return null;

// Try parse the app.pkg (multiple if they exist)
try
{
string? pkgInfo = "";

string[] appDirs = Directory.GetDirectories(Path.Combine(drive.Name, "app"), "?????????", SearchOption.TopDirectoryOnly);

foreach (string dir in appDirs)
{
string appPkgPath = Path.Combine(dir, "app.pkg");
if (!File.Exists(appPkgPath))
continue;

// Read the app.pkg header
using var fileStream = new FileStream(appPkgPath, FileMode.Open, FileAccess.Read);
var appPkgHeaderDeserializer = new SabreTools.Serialization.Deserializers.AppPkgHeader();
var appPkgHeader = appPkgHeaderDeserializer.Deserialize(fileStream);

if (appPkgHeader != null)
{
byte[] date = BitConverter.GetBytes(appPkgHeader.VersionDate);
if (BitConverter.IsLittleEndian)
Array.Reverse(date);

pkgInfo = $"app.pkg ID: {appPkgHeader.ContentID}" + Environment.NewLine + $"app.pkg Date: {date[0]:X2}{date[1]:X2}-{date[2]:X2}-{date[3]:X2}";
}
}

if (pkgInfo == "")
return null;
else
return pkgInfo;
}
catch
{
// We don't care what the error was
return null;
}
}

/// <summary>
/// Get the internal serial from a PlayStation 5 disc, if possible
/// </summary>
Expand Down Expand Up @@ -550,6 +605,62 @@ public static bool GetBusEncryptionEnabled(Drive? drive)
}
}

/// <summary>
/// Get the app.pkg info from a PlayStation 5 disc, if possible
/// </summary>
/// <param name="drive">Drive to extract information from</param>
/// <returns>PKG info if possible, null on error</returns>
public static string? GetPlayStation5PkgInfo(Drive? drive)
{
// If there's no drive path, we can't do this part
if (string.IsNullOrEmpty(drive?.Name))
return null;

// If the folder no longer exists, we can't do this part
if (!Directory.Exists(drive!.Name))
return null;

// Try parse the app_sc.pkg (multiple if they exist)
try
{
string? pkgInfo = "";

string[] appDirs = Directory.GetDirectories(Path.Combine(drive.Name, "app"), "?????????", SearchOption.TopDirectoryOnly);

foreach (string dir in appDirs)
{
string appPkgPath = Path.Combine(dir, "app_sc.pkg");
if (!File.Exists(appPkgPath))
continue;

// Read the app_sc.pkg header
using var fileStream = new FileStream(appPkgPath, FileMode.Open, FileAccess.Read);
var appPkgHeaderDeserializer = new SabreTools.Serialization.Deserializers.AppPkgHeader();
var appPkgHeader = appPkgHeaderDeserializer.Deserialize(fileStream);

if (appPkgHeader != null)
{
byte[] date = BitConverter.GetBytes(appPkgHeader.VersionDate);
if (BitConverter.IsLittleEndian)
Array.Reverse(date);

string pkgDate = $"{date[0]:X2}{date[1]:X2}-{date[2]:X2}-{date[3]:X2}";
pkgInfo = $"app_sc.pkg ID: {appPkgHeader.ContentID}" + Environment.NewLine + $"app_sc.pkg Date: {pkgDate}";
}
}

if (pkgInfo == "")
return null;
else
return pkgInfo;
}
catch
{
// We don't care what the error was
return null;
}
}

#endregion

#region Xbox
Expand Down
2 changes: 2 additions & 0 deletions MPF.Frontend/Tools/SubmissionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,13 @@ private static bool ProcessSystem(SubmissionInfo info, RedumpSystem? system, Dri
case RedumpSystem.SonyPlayStation4:
SetCommentFieldIfNotExists(info, SiteCode.InternalSerialName, drive, PhysicalTool.GetPlayStation4Serial);
SetVersionIfNotExists(info, drive, PhysicalTool.GetPlayStation4Version);
SetContentFieldIfNotExists(info, SiteCode.Games, drive, PhysicalTool.GetPlayStation4PkgInfo);
break;

case RedumpSystem.SonyPlayStation5:
SetCommentFieldIfNotExists(info, SiteCode.InternalSerialName, drive, PhysicalTool.GetPlayStation5Serial);
SetVersionIfNotExists(info, drive, PhysicalTool.GetPlayStation5Version);
SetContentFieldIfNotExists(info, SiteCode.Games, drive, PhysicalTool.GetPlayStation5PkgInfo);
break;

case RedumpSystem.TomyKissSite:
Expand Down

0 comments on commit ca59d71

Please sign in to comment.