Editing PKG files

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 28: Line 28:
PS Vita: PSP securities + more Metadata (0xD-0x12) that embed digests of files embedded into the .pkg.
PS Vita: PSP securities + more Metadata (0xD-0x12) that embed digests of files embedded into the .pkg.


=== PKG Digest ===
=== 0x40 digest ===


See [[Keys#NPDRM_PKG.2FSELF_ECDSA_Public_Key]].
See [[Keys#GPKG.2FSELF_ECDSA_signature]].


{| class="wikitable"
{| class="wikitable"
Line 36: Line 36:
! Name !! Offset !! Size !! Remark
! Name !! Offset !! Size !! Remark
|-
|-
| cmac_hash || 0x0 || 0x10 || AES-CMAC hash. Using always npdrm_pkg_ps3_aes_key / npdrm_pkg_ps3_idu_aes_key, whatever the platform is.
| cmac_hash || 0x0 || 0x10 || CMAC OMAC hash. PS3 gpkg_key used as key.
|-
|-
| npdrm_signature || 0x10 || 0x28 || PKG header NPDRM ECDSA signature (R_sig, S_sig).
| npdrm_signature || 0x10 || 0x28 || PKG header NPDRM ECDSA (R_sig, S_sig)
|-
|-
| sha1_hash || 0x38 || 0x8 || Last 8 bytes of sha1 hash.
| sha1_hash || 0x38 || 0x8 || last 8 bytes of sha1 hash
|}
|}


<source lang="C">
<source lang="C">
   typedef struct pkg_digest { // size is 0x40
   typedef struct { // size is 0x40
     u8 cmac_hash[0x10];
     u8 cmac_hash[0x10];
     u8 npdrm_signature[0x28];
     u8 npdrm_signature[0x28];
     u8 sha1_hash[0x8];
     u8 sha1_hash[0x8];
   } pkg_digest;
   } digest;
</source>
</source>


Line 97: Line 97:
===== PS3 / PSP Finalized Packages =====
===== PS3 / PSP Finalized Packages =====


For PS3 / PSP NPDRM packages, the file table and the data are AES128CTR encrypted/decrypted using pkg_data_riv as the IV along with the PS3/PSP constant AES Key.
For PS3 / PSP NPDRM packages, the file table and the data is AES128CTR encrypted/decrypted using pkg_data_riv as the IV along with the PS3/PSP constant AES Key.


<source lang="C">
<source lang="C">
Line 117: Line 117:
===== PS Vita / PSM Finalized Packages =====
===== PS Vita / PSM Finalized Packages =====


For PS Vita / PSM NPDRM packages type 2, 3 and 4, pkg_data_riv is AES128ECB encrypted with the constant per-platform AES128 key to create an AES session key. Then it does the normal AES128CTR with pkg_data_riv as the IV and the session key as the AES128CTR key.
For PS Vita / PSM NPDRM packages type 2, 3 and 4, pkg_data_riv is AES128CTR encrypted to create an AES session key. Then it does the normal AES128CTR with pkg_data_riv as the IV and the session key as the AES128CTR key.


<source lang="C">
<source lang="C">
Line 136: Line 136:


memset(key, 0, sizeof key);
memset(key, 0, sizeof key);
memcpy(key, pkg->pkg_header_digest, 8);
memcpy(key, pkg->digest, 8);
memcpy(key + 0x08, pkg->pkg_header_digest, 8);
memcpy(key + 0x08, pkg->digest, 8);
if (isArcade)
if (isArcade)
memcpy(key + 0x10, pkg->pkg_header_digest, 8);
memcpy(key + 0x10, pkg->digest, 8);
else
else
memcpy(key + 0x10, pkg->pkg_header_digest + 0x08, 8);
memcpy(key + 0x10, pkg->digest + 0x08, 8);
memcpy(key + 0x18, pkg->pkg_header_digest + 0x08, 8);
memcpy(key + 0x18, pkg->digest + 0x08, 8);
if (isArcade)
if (isArcade)
memset(key + 0x20, 0xA0, 0x18);
memset(key + 0x20, 0xA0, 0x18);
Line 215: Line 215:
| <span style="background-color:#000000; color:#ffffff;">digest || 0x60 || 0x10 || 09 8B A2 CA 2D 30 30 1F 8B 5B 82 79 C6 70 35 F3 || sha1 from debug files and attributes together merged in one block
| <span style="background-color:#000000; color:#ffffff;">digest || 0x60 || 0x10 || 09 8B A2 CA 2D 30 30 1F 8B 5B 82 79 C6 70 35 F3 || sha1 from debug files and attributes together merged in one block
|-
|-
| <span style="background-color:#ed1c24;">pkg_data_riv          || 0x70 || 0x10 || D5 FA 15 9E 7F AC 82 70 BB 3E 0C EB 97 3D 30 11 || AES-128-CTR IV. Used with npdrm_pkg_PLATFORM_aes_key to decrypt data.
| <span style="background-color:#ed1c24;">pkg_data_riv          || 0x70 || 0x10 || D5 FA 15 9E 7F AC 82 70 BB 3E 0C EB 97 3D 30 11 || aes-128-ctr IV. Used with gpkg_aes_key to decrypt data.
|-
|-
| <span style="background-color:#808000;">pkg_header_digest     || 0x80 || 0x40 || || PKG Digest structure signing data at 0x00-0x7F.
| <span style="background-color:#808000;">header_cmac_hash     || 0x80 || 0x10 || 48 0D 86 60 9F 26 8E 7F 4F B4 DA A4 33 1E 9A A1 || CMAC OMAC hash from 0x00-0x7F. PS3 gpkg_key used as key.
|-
| <span style="background-color:#3f48cc; color:#FFFFFF;">header_npdrm_signature || 0x90 || 0x28 || || PKG header NPDRM ECDSA (R_sig, S_sig)
|-
| <span style="background-color:#a349a4; color:#FFFFFF;">header_sha1_hash      || 0xB8 || 0x08 || EC 61 40 39 A6 5B DC BD || last 8 bytes of sha1 hash of 0x00-0x7F
|}
|}


Line 235: Line 239:
     u8 digest[0x10];
     u8 digest[0x10];
     u8 pkg_data_riv[0x10];
     u8 pkg_data_riv[0x10];
     pkg_digest pkg_header_digest;
     u8 header_cmac_hash[0x10];
    u8 header_npdrm_signature[0x28];
    u8 header_sha1_hash[0x8];
   } PKG_HEADER;
   } PKG_HEADER;
</source>
</source>
Line 253: Line 259:
     u32 main_and_ext_headers_hmac_offset;  // ex: 0x100
     u32 main_and_ext_headers_hmac_offset;  // ex: 0x100
     u32 metadata_header_hmac_offset;      // ex: 0x360, 0x390, 0x490  
     u32 metadata_header_hmac_offset;      // ex: 0x360, 0x390, 0x490  
     u64 tail_offset;                      // Tail size seems to be always 0x1A0
     u64 tail_offset;                      // tail size seems to be always 0x1A0
     u32 padding1;
     u32 padding1;
     u32 pkg_key_id;                        // Id of the AES key used for decryption. PSP = 0x1, PS Vita = 0xC0000002, PSM = 0xC0000004
     u32 pkg_key_id;                        // Id of the AES key used for decryption. PSP = 0x1, PS Vita = 0xC0000002, PSM = 0xC0000004
Line 273: Line 279:
   } ...
   } ...
   // u8 padding[variable];
   // u8 padding[variable];
   pkg_digest pkg_metadata_digest; // [[PKG_files#PKG_digest]]
   u8 digest[0x40]; // [[PKG_files#0x40_digest]]
   } PKG_METADATA;
   } PKG_METADATA;
</source>
</source>
Line 1,024: Line 1,030:
PS Vita .pkg
PS Vita .pkg


[https://github.com/st4rk/PkgDecrypt Source code]
==== PSN_get_pkg_info.py by windsurfer1122 (2018) ====
 
[[PSN_get_pkg_info.py]] Extracts information from package file as text or JSON for further analysis.<br />
==== PKGrip by qwikrazor87 (2018) ====
 
Fast linux alternative for decrypting PS3/PSP NPDRM PKG files.
 
[https://github.com/qwikrazor87/pkgrip Source code]
 
==== PSN_get_pkg_info.py by windsurfer1122 (2018-2020) ====
 
Extracts information from package file as text or JSON for further analysis.<br />
Provides Linux shell scripts for mass creation of analysis data and to quickly grep through them.<br />
Provides Linux shell scripts for mass creation of analysis data and to quickly grep through them.<br />
Analysis data of 10.000+ packages already directly downloadable [https://mega.nz/#F!cyxSVACA!Lp8VFpFz4K-DQLb221d83A here].<br />
Analysis data of 10.000+ packages already directly downloadable [https://mega.nz/#F!cyxSVACA!Lp8VFpFz4K-DQLb221d83A here].<br />
Decrypts package to an unencrypted raw package.<br />
Decrypts package to an unencrypted raw package.<br />
Planned feature is package extraction like PkgDecrypt and pkg2zip.
Planned feature is package extraction like PkgDecrypt and pkg2zip.<br />
 
PS3/PS1/PSP/PSV/PSM .pkg
 
[https://github.com/windsurfer1122/PSN_get_pkg_info Source code]
 
==== LibOrbisPkg by Maxton ====
 
PS4 Tool but could help to understand PFS.
 
[https://github.com/maxton/LibOrbisPkg Source code]
 
==== PS4 PFS Tool by flatz (2020) ====
 
PS4 Tool but could help to understand PFS.


[https://github.com/flatz/pkg_pfs_tool Source code]
PS3/PSX/PSP/PSV/PSM .pkg


== Package links ==
== Package links ==
Please note that all contributions to PS3 Developer wiki are considered to be released under the GNU Free Documentation License 1.2 (see PS3 Developer wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)