From cb087b81308f261b7b3bc178402799ab7ef0f0a1 Mon Sep 17 00:00:00 2001 From: Martins Mozeiko Date: Thu, 26 Oct 2017 01:04:21 -0700 Subject: [PATCH] unpacking patch pkg files --- README.md | 6 ++-- pkg2zip.c | 83 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 70 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 831fed0..44e69d9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ DLC support available when VitaShell will include [this pull request](https://gi * **small**, has no external library dependencies and uses very minimal dynamic memory allocations. * **fast**, uses AESNI hardware accelerated AES decryption if supported by CPU (requires [AESNI](https://en.wikipedia.org/wiki/AES_instruction_set) and [SSSE3](https://en.wikipedia.org/wiki/SSSE3) instructions). * **simple**, creates zip package with same folder structure that Vita expects (just drag & drop all file from zip archive to ux0:). Zip file is created directly from pkg without any intermediate temporary files. -* **DLC** support. +* **DLC** and **PATCH** pkg support. Limitations: @@ -28,9 +28,9 @@ This will create `title [id] [region].zip` file. Title, ID and region is automat If you don't have zRIF fake license, but just want to unpack files, then omit last argument: - pkg2zip package.pkg zRIF_STRING + pkg2zip package.pkg -Resulting zip file will not include work.bin. +Resulting zip file will not include work.bin. This is useful for patch pkg files. # Generating zRIF string diff --git a/pkg2zip.c b/pkg2zip.c index 67f8d38..b7fe28f 100644 --- a/pkg2zip.c +++ b/pkg2zip.c @@ -20,7 +20,7 @@ static const uint8_t pkg_vita_4[] = { 0xaf, 0x07, 0xfd, 0x59, 0x65, 0x25, 0x27, // http://vitadevwiki.com/vita/System_File_Object_(SFO)_(PSF)#Internal_Structure // https://github.com/TheOfficialFloW/VitaShell/blob/1.74/sfo.h#L29 -static void parse_sfo(sys_file f, uint64_t sfo_offset, uint32_t sfo_size, char* title, char* content, char* min_version) +static void parse_sfo(sys_file f, uint64_t sfo_offset, uint32_t sfo_size, int* patch, char* title, char* content, char* min_version, char* pkg_version) { uint8_t sfo[16 * 1024]; if (sfo_size < 16) @@ -44,15 +44,17 @@ static void parse_sfo(sys_file f, uint64_t sfo_offset, uint32_t sfo_size, char* int title_index = -1; int content_index = -1; + int category_index = -1; int minver_index = -1; - for (uint32_t i=0; i sfo_size) + if (i * 16 + 20 + 2 > sfo_size) { fatal("ERROR: sfo information is too small\n"); } - char* key = (char*)sfo + keys + get16le(sfo + i*16 + 20); + char* key = (char*)sfo + keys + get16le(sfo + i * 16 + 20); if (strcmp(key, "TITLE") == 0) { if (title_index < 0) @@ -68,18 +70,26 @@ static void parse_sfo(sys_file f, uint64_t sfo_offset, uint32_t sfo_size, char* { content_index = (int)i; } + else if (strcmp(key, "CATEGORY") == 0) + { + category_index = (int)i; + } else if (strcmp(key, "PSP2_DISP_VER") == 0) { minver_index = (int)i; } + else if (strcmp(key, "APP_VER") == 0) + { + pkgver_index = (int)i; + } } - if (title_index < 0 || content_index < 0) + if (title_index < 0 || content_index < 0 || category_index < 0) { fatal("ERROR: sfo information doesn't have game title or content id, pkg is probably corrupted\n"); } - const char* value = (char*)sfo + values + get32le(sfo + title_index*16 + 20 + 12); + char* value = (char*)sfo + values + get32le(sfo + title_index*16 + 20 + 12); size_t i; size_t max = 255; for (i=0; i