SELF File Format

SELF stands for Signed Executable and Linkable Format.

It is the format used by the executables on the PS3 (SCE Header Version 2), PS Vita (SCE Header Version 3).

It consists of an ELF + SELF header. ELF segments can be compressed using gzip.

System and NPDRM SELFs are encrypted and signed and are decrypted on PSVita to memory by F00D.

ELF sections might be encrypted using AES CTR and signed using ECDSA + HMAC-SHA1.

SELF file has a specific header called SCE header where it stores all the parameters for this program.

= File Format =

Notes:


 * Numbers are stored in little endian format (whilst PS3 used big endian).

Struct
typedef struct { uint32_t magic;                /* 53434500 = SCE\0 */ uint32_t version;              /* header version 3*/ uint16_t sdk_type;             /* */ uint16_t header_type;          /* 1 self, 2 unknown, 3 pkg */ uint32_t metadata_offset;      /* metadata offset */ uint64_t header_len;           /* self header length */ uint64_t elf_filesize;         /* ELF file length */ uint64_t self_filesize;        /* SELF file length */ uint64_t unknown;              /* UNKNOWN */ uint64_t self_offset;          /* SELF offset */ uint64_t appinfo_offset;       /* app info offset */ uint64_t elf_offset;           /* ELF #1 offset */ uint64_t phdr_offset;          /* program header offset */ uint64_t shdr_offset;          /* section header offset */ uint64_t section_info_offset;  /* section info offset */ uint64_t sceversion_offset;    /* version offset */ uint64_t controlinfo_offset;   /* control info offset */ uint64_t controlinfo_size;     /* control info size */ uint64_t padding; } __attribute__((packed)) SELF_header;

Struct
typedef struct { uint64_t authority_id;         /* authority id */ uint32_t vendorid;             /* vendor id */ uint32_t selftype;             /* SELF type */ uint64_t sceversion;           /* sdk version */ uint64_t padding;              /* UNKNOWN */ } __attribute__((packed)) APP_INFO;

Comments
Aligned to 0x10 bytes.

Struct
typedef struct { uint8_t e_ident[16];             /* ELF identification */ uint16_t e_type;                 /* object file type */ uint16_t e_machine;              /* machine type */ uint32_t e_version;              /* object file version */ uint64_t e_entry;                /* entry point address */ uint64_t e_phoff;                /* program header offset */ uint64_t e_shoff;                /* section header offset */ uint16_t e_flags;                /* processor-specific flags */ uint32_t e_ehsize;               /* ELF header size */ uint16_t e_phentsize;            /* size of program header entry */ uint16_t e_phnum;                /* number of program header entries */ uint16_t e_shentsize;            /* size of section header entry */ uint16_t e_shnum;                /* number of section header entries */ uint16_t e_shstrndx;             /* section name string table index */ } __attribute__((packed)) ELF;

SCE-specific e_type
See Specifications here: ELF Header ELF-64 Object File Format

Struct
typedef struct { uint32_t p_type;                 /* type of segment */ uint32_t p_flags;                /* segment attributes */ uint64_t p_offset;               /* offset in file */ uint64_t p_vaddr;                /* virtual address in memory */ uint64_t p_paddr;                /* reserved */ uint64_t p_filesz;               /* size of segment in file */ uint64_t p_memsz;                /* size of segment in memory */ uint64_t p_align;                /* alignment of segment */ } __attribute__((packed)) ELF_PHDR;

Comments
See Spec here: ELF Program Headers

Struct
typedef struct { uint32_t sh_name;                /* section name */ uint32_t sh_type;                /* section type */ uint64_t sh_flags;               /* section attributes */ uint64_t sh_addr;                /* virtual address in memory */ uint64_t sh_offset;              /* offset in file */ uint64_t sh_size;                /* size of section */ uint32_t sh_link;                /* link to other section */ uint32_t sh_info;                /* miscellaneous information */ uint64_t sh_addralign;           /* address alignment boundary */ uint64_t sh_entsize;             /* size of entries, if section has table */ } __attribute__((packed)) ELF_SHDR;

Struct
typedef struct { uint64_t offset; uint64_t size; uint32_t compressed; uint32_t unknown1; uint32_t encrypted; uint32_t unknown2; } __attribute__((packed)) SECTION_INFO;

Comments
There is one of these entries (Segment Information) for each phdr entry (Program Header) in the ELF file so that the console knows where to decrypt the data from (because it might also be compressed).

Struct
typedef struct { uint32_t unknown1; // 0x1 uint32_t unknown2; uint32_t unknown3; // 0x10 ?size? uint32_t unknown4; } __attribute__((packed)) SCEVERSION_INFO;

Struct
typedef struct { uint32_t type; // 4==PSVita control flags; 5==PSVita NPDRM; 6==PSVita unk6; 7==PSVita unk7 uint32_t size; uint64_t next; // 1 if another Control Info structure follows else 0

union { // type 4, 0x50 bytes struct { // 0x40 bytes of data uint8_t digest1[0x14]; // hash digest, same for every file uint8_t digest2[0x20]; // unknown hash (maybe elf) uint8_t padding[0xC]; } PSVita_file_digest_info;

// type 5, 0x110 bytes struct { // 0x80 bytes of data uint32_t magic;              // 7F 44 52 4D (".DRM") uint32_t finalized_flag;     // ex: 80 00 00 01 uint32_t drm_type;           // license_type ex: 2 local, 0XD free with license uint32_t padding; uint8_t content_id[0x30]; uint8_t digest[0x10];        // ?sha-1 hash of debug self/sprx created with make_fself_npdrm? uint8_t padding_78[0x78]; uint8_t hash_signature[0x38]; // unknown hash/signature } PSVita_npdrm_info;

// type 6, 0x110 bytes struct { // 0x100 bytes of data uint32_t unknown1; // 0x1 uint8_t unknown2[0x9C]; } PSVita_control_type_6;

// type 7, 0x50 bytes struct { // 0x40 bytes of data uint8_t unk[0x40]; } PSVita_control_type_7; }; } __attribute__((packed)) PSVita_CONTROL_INFO;

Relocations
Relocations can be of two types: 8 byte "short" entries or 12 byte "long" entries. The relocation code is the same as ARM ELF format.

Segment start = Buffer address of segment indexed at "Patch segment"

Symbol start = Buffer address of segment indexed at "Symbol segment"

Address to patch = segment start + offset

P = address to patch

S = "Symbol segment" == 15 ? 0 : symbol start

A = addend