PKG files

From PS3 Developer wiki
Revision as of 11:50, 13 August 2012 by Ada L0ve Lace (talk | contribs) (→‎File Header: cosmetic: size added for harmony with other tables)
Jump to navigation Jump to search

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

All values are in big endian format.

 typedef struct {
   u32 magic;
   u32 pkg_type;
   u32 pkg_info_offset;
   u32 pkg_info_size;
   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;


field offset size type notes
Unencrypted header
magic 0x0 4 u32 Magic value of 0x7f504b47 "\x7fPKG"
pkg_type 0x4 4 u32 The package type is 1 for PS3 pkg and 2 for PSP (minis also)/Vita packages. the flag 0x80000000 is used for retail.
pkg_info_offset 0x8 4 u32 offset of the pkg_info structure
pkg_info_size 0xC 4 u32 pkg_info_size*8 = size of the pkg_info structure
header_size 0x10 4 u32 Size of the header
item_count 0x14 4 u32
total_size 0x18 8 u64
data_offset 0x20 8 u64
data_size 0x28 8 u64
contentid 0x30 48 u8[48] see PARAM.SFO#CONTENT_ID
digest 0x60 16 u8[16]
k_licensee 0x70 16 u8[16]


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