Skip to content

Commit

Permalink
V2
Browse files Browse the repository at this point in the history
In addition to the Windows interface version,
Windows Console
Linux Console
has now been added.
  • Loading branch information
DanielSvoboda committed Jul 11, 2024
1 parent 5a29b7b commit 48292b7
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 13 deletions.
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
# Download PS4 Game Update

It is possible to check the PS4 game update pkg directly from the PlayStation servers,<br>
It is possible to check the PS4 game update pkg directly from the PlayStation servers,
Providing the **"Title ID"** and **"PS4 HMAC-SHA256 Patch Pkg URL Key"**

Download: https://github.com/DanielSvoboda/download_ps4_game_update/releases
Download: [Download PS4 Game Update](https://github.com/DanielSvoboda/download_ps4_game_update/releases)
- Windows Executable
- Windows Console Executable
- Linux Console Executable

<img width="900" alt="portfolio_view" src="https://raw.githubusercontent.com/DanielSvoboda/download_ps4_game_update/main/Print1.png">
<img width="900" alt="portfolio_view" src="https://raw.githubusercontent.com/DanielSvoboda/download_ps4_game_update/main/Print2.png">
![Screenshot 1](https://raw.githubusercontent.com/DanielSvoboda/download_ps4_game_update/main/Print1.png)
![Screenshot 2](https://raw.githubusercontent.com/DanielSvoboda/download_ps4_game_update/main/Print2.png)

# Usage

## Windows

Enter the **"Title ID"** and **"HMAC-SHA256 Patch Pkg URL Key"** into their respective fields.
Click **"Check Updates"** to retrieve information about the game update.

## Windows Console

1. Open Command Prompt and navigate to the directory where `download_ps4_game_update_console.exe` is located:
```bash
cd path/to/download_ps4_game_update_console
```

2. Run the program with the required arguments:
```bash
download_ps4_game_update_console.exe -key <HMAC_SHA256_Patch_Pkg_URL_Key> -title <Title_ID>
```

## Linux Console

1. Download the `linux-x64.rar` file and extract it to a directory on your Linux machine.
2. Open a terminal and navigate to the directory where `download_ps4_game_update_console` is located:
```bash
cd path/to/linux-x64/download_ps4_game_update
```

3. Make the executable file `download_ps4_game_update_console` executable, if necessary:
```bash
chmod +x download_ps4_game_update_console
```
4. Execute the program with the following command, providing the necessary arguments:
```bash
./download_ps4_game_update_console -key <HMAC_SHA256_Patch_Pkg_URL_Key> -title <Title_ID>
```
<br><br><br>
Replace `<HMAC_SHA256_Patch_Pkg_URL_Key>` and `<Title_ID>` with actual values.

Make sure to replace `path/to/download_ps4_game_update_console` and `path/to/linux-x64/download_ps4_game_update` with the actual paths where `download_ps4_game_update_console` executable is located on your Windows and Linux systems respectively.
120 changes: 120 additions & 0 deletions download ps4 game update console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Xml;

namespace DownloadPS4GameUpdateConsole
{
class Program
{
static string urlKey = "";
static string titleId = "";

static void Main(string[] args)
{
if (args.Length < 4 || args[0] != "-key" || args[2] != "-title")
{
ShowHelp();
return;
}

urlKey = args[1];
titleId = args[3];

try
{
string xmlUrl = $"http://gs-sec.ww.np.dl.playstation.net/plo/np/{titleId}/{GetHash(titleId)}/{titleId}-ver.xml";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlUrl);

XmlNode titleNode = xmlDoc.SelectSingleNode("/titlepatch/tag/package[@version]");
string title = titleNode.SelectSingleNode("paramsfo/title").InnerText;
string version = titleNode.Attributes["version"].Value;

double sizeBytes = Convert.ToDouble(titleNode.Attributes["size"].Value);
double sizeMB = sizeBytes / (1024 * 1024);

XmlNode system_ver = xmlDoc.SelectSingleNode("/titlepatch/tag/package/@system_ver");
string hexadecimal = int.Parse(system_ver.Value).ToString("X8");
string system_ver_formatted = $"{hexadecimal.Substring(0, 2)}.{hexadecimal.Substring(2, 2)}";

Console.WriteLine($"Title: {title}");
Console.WriteLine($"Version: {version}");
Console.WriteLine($"Required Firmware: {system_ver_formatted}");
Console.WriteLine($"PKG Size: {(sizeMB > 1024 ? $"{sizeMB / 1024:0.##} GB" : $"{sizeMB:0.##} MB")}");

XmlNode manifestNode = xmlDoc.SelectSingleNode("/titlepatch/tag/package/@manifest_url");
if (manifestNode == null)
{
throw new Exception("Manifest URL not found in XML.");
}

using (var client = new WebClient())
{
string json = client.DownloadString(manifestNode.Value);

int index = json.IndexOf("\"pieces\":");
if (index < 0)
{
throw new Exception("Expected JSON format not found.");
}
json = json.Substring(index + "\"pieces\":".Length);

int urlStartIndex = json.IndexOf("\"url\":\"");
while (urlStartIndex >= 0)
{
urlStartIndex += "\"url\":\"".Length;
int urlEndIndex = json.IndexOf("\"", urlStartIndex);
string packageUrl = json.Substring(urlStartIndex, urlEndIndex - urlStartIndex);

Console.WriteLine(packageUrl);

urlStartIndex = json.IndexOf("\"url\":\"", urlEndIndex);
}
}

//Console.WriteLine($"\r\nxmlUrl: {xmlUrl}");
//Console.WriteLine($"manifestUrl: {manifestNode.Value}");
}
catch (Exception ex)
{
Console.WriteLine($"Error loading and parsing XML: {ex.Message}");
}
}

private static void ShowHelp()
{
#if WINDOWS
Console.WriteLine("Usage: download_ps4_game_update_console.exe -key <HMAC_SHA256_Patch_Pkg_URL_Key> -title <TitleId>");
#else
Console.WriteLine("Usage: ./download_ps4_game_update_console -key <HMAC_SHA256_Patch_Pkg_URL_Key> -title <TitleId>");
#endif
}


private static string GetHash(string gameID)
{
byte[] byteKey = StringToByteArray(urlKey);
byte[] dataBytes = Encoding.UTF8.GetBytes($"np_{gameID}");

using (var hmacsha256 = new HMACSHA256(byteKey))
{
byte[] hashBytes = hmacsha256.ComputeHash(dataBytes);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
}
}

public static byte[] StringToByteArray(string hex)
{
int numberChars = hex.Length;
byte[] bytes = new byte[numberChars / 2];
for (int i = 0; i < numberChars; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>download_ps4_game_update_console</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>download_ps4_game_update_console</AssemblyName>
</PropertyGroup>

<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>WINDOWS</DefineConstants>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions download ps4 game update.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "download ps4 game update", "download ps4 game update\download ps4 game update.csproj", "{ECB0A47A-287B-4178-8088-013420B478B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "download ps4 game update console", "download ps4 game update console\download ps4 game update console.csproj", "{FA5F8024-94E7-4040-BD6A-14B31E348ABF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{ECB0A47A-287B-4178-8088-013420B478B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECB0A47A-287B-4178-8088-013420B478B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECB0A47A-287B-4178-8088-013420B478B3}.Release|Any CPU.Build.0 = Release|Any CPU
{FA5F8024-94E7-4040-BD6A-14B31E348ABF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA5F8024-94E7-4040-BD6A-14B31E348ABF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA5F8024-94E7-4040-BD6A-14B31E348ABF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA5F8024-94E7-4040-BD6A-14B31E348ABF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion download ps4 game update/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions download ps4 game update/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ private void button2_Check_Updates(object sender, EventArgs e)
return;
}

string xmlUrl = $"https://gs-sec.ww.np.dl.playstation.net/plo/np/{TitleId}/{GetHash(TitleId)}/{TitleId}-ver.xml";
string xmlUrl = $"http://gs-sec.ww.np.dl.playstation.net/plo/np/{TitleId}/{GetHash(TitleId)}/{TitleId}-ver.xml";

try
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlUrl);

Expand Down Expand Up @@ -88,16 +86,12 @@ private void button2_Check_Updates(object sender, EventArgs e)
}
}
//textBox1_Result.Text += $"\r\nxmlUrl: {xmlUrl}\r\n";
//textBox1_Result.Text += $"manifestUrl: {manifestUrl}\r\n";
//textBox1_Result.Text += $"manifestUrl: {manifestNode.Value}\r\n";
}
catch (Exception ex)
{
MessageBox.Show($"Error loading and parsing XML: {ex.Message}");
}
finally
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = null;
}
}

private string GetHash(string gameID)
Expand Down

0 comments on commit 48292b7

Please sign in to comment.