PKG files: Difference between revisions
m (→File Header) |
|||
Line 117: | Line 117: | ||
0x00000003 = ...Upgradeable, DRM Type? | 0x00000003 = ...Upgradeable, DRM Type? | ||
0x00000004 = Total Size | 0x00000004 = Total Size | ||
0x00000005 = make_package_npdrm version | 0x00000005 = make_package_npdrm reversion + Package version | ||
0x00000006 = Version + App Version | 0x00000006 = Version + App Version | ||
0x00000007 | 0x00000007 |
Revision as of 19:58, 27 February 2014
See also Discussion page
Firmware Packages
File Header
All values are in big endian format.
typedef struct { u32 0x00, 0x53434500// magic u32 0x04, 2 // version u16 0x08, 0 // sdk type? u16 0x0a, 3 // SCE header type; pkg u32 0x0c, 0 // meta offset u64 0x10, // size of sce_hdr + sizeof meta_hdr u64 0x18, 0x80 // + content_size_real }
Game Packages
All game packages are signed with the ECDSA signature. The public key for it can be found in download_plugin.prx or in nas_plugin.prx (this also applies to NPDRM SELFs). Usually game packages are signed with two signatures - one for the header and the other for the entry table.
File Header
Retail PS3 .pkg
- Example: Scott Pilgrim VS. The World Unlock .pkg file:
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 7F 50 4B 47 80 00 00 01 00 00 00 C0 00 00 00 08 .PKGЂ......А.... 00000010 00 00 00 C0 00 00 00 02 00 00 00 00 00 00 17 C0 ...А...........А 00000020 00 00 00 00 00 00 01 80 00 00 00 00 00 00 15 E0 .......Ђ.......а 00000030 55 50 30 30 30 31 2D 4E 50 55 42 33 30 31 36 32 UP0001-NPUB30162 00000040 5F 30 30 2D 53 43 4F 54 54 50 49 4C 47 52 49 4D _00-SCOTTPILGRIM 00000050 30 30 30 32 00 00 00 00 00 00 00 00 00 00 00 00 0002............ 00000060 09 8B A2 CA 2D 30 30 1F 8B 5B 82 79 C6 70 35 F3 .‹ўК-00.‹[‚yЖp5у 00000070 D5 FA 15 9E 7F AC 82 70 BB 3E 0C EB 97 3D 30 11 Хъ.ћ.¬‚p»>.л—=0. 00000080 48 0D 86 60 9F 26 8E 7F 4F B4 DA A4 33 1E 9A A1 H.†`џ&Ћ.OґЪ¤3.љЎ 00000090 0C 85 45 95 A8 D4 A3 9B 62 44 68 C1 38 CE D7 63 .…E•ЁФЈ›bDhБ8ОЧc 000000A0 0D FF 0C C5 3A 77 C6 E6 E4 62 AD 05 F3 93 D0 7A .я.Е:wЖждb..у“Рz 000000B0 CC 02 B4 35 2B 70 47 D6 EC 61 40 39 A6 5B DC BD М.ґ5+pGЦмa@9¦[ЬЅ
Name | Offset | Size | Example | Remark |
magic | 0x00 | 0x04 | 7F 50 4B 47 | '.PKG' |
pkg_revision | 0x04 | 0x02 | 80 00 | 80 00 for retail (finalized), 00 00 for debug (non finalized) |
pkg_type | 0x06 | 0x02 | 00 01 | 00 01 for ps3, 00 02 for psp |
pkg_info_offset | 0x08 | 0x04 | 00 00 00 C0 | 0xC0 |
pkg_info_count | 0x0C | 0x04 | 00 00 00 08 | Item count |
header_size | 0x10 | 0x04 | 00 00 00 C0 | 0xC0 |
item_count | 0x14 | 0x04 | 00 00 00 02 | files and folders into the encrypted data |
total_size | 0x18 | 0x08 | 00 00 00 00 00 00 17 C0 | 0x17C0 - total pkg file size |
data_offset | 0x20 | 0x08 | 00 00 00 00 00 00 01 80 | 0x0180 - encrypted data offset |
data_size | 0x28 | 0x08 | 00 00 00 00 00 00 15 E0 | 0x15E0 - encrypted data size |
contentid | 0x30 | 0x24 | 'UP0001-NPUB30162_00-SCOTTPILGRIM0002' pkg content id | |
padding | 0x54 | 0x0C | 00 00 00 00 00 00 00 00 00 00 00 00 | 0x0C bytes padding |
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 |
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. uses with gpkg_key for decrypt data |
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, gpkg_key used as key |
header_npdrm_signature | 0x90 | 0x28 | Header NPDRM ECDSA (R_sig, S_sig) | |
header_sha1_hash | 0xB8 | 0x08 | EC 61 40 39 A6 5B DC BD | last 8 bytes of sha1 hash from 0x00-0x7F |
All values are in big endian format.
typedef struct { u32 magic; u32 pkg_type; u32 pkg_info_offset; u32 pkg_info_count; u32 header_size; u32 item_count; u64 total_size; u64 data_offset; u64 data_size; char contentid[0x30]; u8 digest[0x10]; u8 k_licensee[0x10]; } PKG_HEADER;
typedef struct { union{ u32 packet_identifier; 0-0x12 u32 size of content; { content } } ... } PKG_INFO;
Identifier :
0x00000001 = DRM Type: Count = 0/5/6/7/8/9/0xA/0xB/0xC (unknown), 1 (network), 2 (local), 3/0xD (free), 4 (PSP) 0x00000002 = Category/Content Type 0x00000003 = ...Upgradeable, DRM Type? 0x00000004 = Total Size 0x00000005 = make_package_npdrm reversion + Package version 0x00000006 = Version + App Version 0x00000007 0x00000008 0x00000009 0x0000000A 0x0000000B 0x0000000C 0x0000000D 0x0000000E 0x0000000F 0x00000010 0x00000011 0x00000012
content type | type name | install path (on ps3) | notes |
---|---|---|---|
0x00000004 | GameData (also Patches) | /dev_hdd0/game/ | |
0x00000005 | Game_Exec | /dev_hdd0/game/ | |
0x00000006 | PS1emu | /dev_hdd0/game/ | |
0x00000007 | PSP & PCEngine | /dev_hdd0/game/ | |
0x00000008 | |||
0x00000009 | Theme | /dev_hdd0/theme | |
0x0000000A | Widget | /dev_hdd0/widget | |
0x0000000B | License | /dev_hdd0/home/<current user>/exdata | |
0x0000000C | VSH Module | /dev_hdd0/vsh/modules/ | |
0x0000000D | PSN Avatar | /dev_hdd0/home/<current user>/psn_avatar | |
0x0000000E | PSPgo | /dev_hdd0/game/ | Displayed as Unknown Album: Corrupted Data |
0x0000000F | Minis | /dev_hdd0/game/ | |
0x00000010 | NEOGEO | /dev_hdd0/game/ | |
0x00000011 | VMC | /dev_hdd0/tmp/vmc/ | |
0x00000012 | Seen on PS2 classic | /dev_hdd0/game/ | |
0x00000014 | Seen on PSP remastered | /dev_hdd0/game/ | |
0x00000015 | PSVita (PSP2GD) | ||
0x00000016 | PSVita (PSP2AC) | ||
0x00000017 | PSVita (PSP2LA) | ||
0x00000019 | WT (Web TV?) | /dev_hdd0/game/ |
File Entry
All values are in big endian format
typedef struct { u32 filename_offset; u32 filename_size; u64 data_offset; u64 data_size; u32 flags; u32 padding; } PKG_FILE_HEADER;
field | offset | type | notes |
---|---|---|---|
filename_offset | 0x0 | u32 | |
filename_size | 0x4 | u32 | |
data_offset | 0x8 | u64 | |
data_size | 0x10 | u64 | |
flags | 0x18 | u32 | The file type |
padding | 0x1C | u32 | zero |
Misc/Note
From FW 4.00, install PKG from root device (but not as "bubble") for PS1 classic if not containing .EDAT files license type Free will abort or install directly as bubble according to the cfw.
The last 0x20 bytes of the package contains a hash (sha1sum) of the package (sha1 of the whole file minus the last 0x20 bytes). Or in other words... to verify the integrity of a package is needed to crop the 0x20 bytes at the end, then calculate the sha1 of the resulting file, then compare with the sha1 that was cropped
Is also used as part of the package identification info inside the TITLE_ID-ver.xml files in PSN servers that lists the available game patches for each game. See: Game Updating Procedure page and the sha1sum in the .xml examples
- Notes
- This footer area is considered part of the package and is included when counting the total_size of the package (in the header at offset 0x18), and the header is hashed too by header_sha1_hash (at offset 0xB8), this is important in the sequence of actions needed when buiding the package and updating/adding the sha1 footer at the end
- Homebrew packages (at least some of them) doesnt includes this footer
|