SELF File Format: Difference between revisions

From Vita Developer wiki
Jump to navigation Jump to search
Line 112: Line 112:


=== Comments ===
=== Comments ===
== Section Information ==
=== Struct ===
<source lang="C">
typedef struct {
  uint64_t offset;
  uint64_t size;
  uint32_t compression;
  uint32_t unk1;
  uint32_t encryption;
  uint32_t unk2;
} __attribute__((packed)) SECTION_INFO;
</source>
=== Table ===
{| class="wikitable"
! field !! offset !! type !! notes
|-
| Offset || 0x00 || u64 || Offset of data
|-
| Size || 0x08 || u64 || Size of data
|-
| Compression || 0x10 || u32 || 1 = uncompressed, 2 = compressed
|-
| unknown 1 || 0x14 || u32 ||
|-
| Encryption || 0x18 || u32 || 1 = encrypted, 2 = unencrypted
|-
| unknown 2 || 0x1C || u32 ||
|}
=== Comments ===
There is one of these entries (Section 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).

Revision as of 22:44, 23 December 2019


File Format

ELF Header

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 */
    uint32_t e_entry;                 /* entry point address */
    uint32_t e_phoff;                 /* program header offset */
    uint32_t e_shoff;                 /* section header offset */
    uint32_t e_flags;                 /* processor-specific flags */
    uint16_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;

Table

Name of the variable Offset Size Notes
e_ident[0..3] elf_offset+(0,1,2,3) 4 Magic
e_ident[4] elf_offset+4 1 Class Type must be [ELFCLASS32 = 0x01]
e_ident[5] elf_offset+5 1 Data Type must be [ELFDATA2LSB (i.e. le) = 0x01]
e_ident[6] elf_offset+6 1 File version (must be 0x1)
e_ident[7..15] elf_offset+(6->15) 1 unused
e_type elf_offset+0x10 2 SCE-specific e_type
e_machine elf_offset+0x12 2 Machine type must be [EM_ARM = 0x0028]
e_version elf_offset+0x14 4 elf version (must be 0x00000001)
e_entry elf_offset+0x18 4 Address to jump to in order to start program
e_phoff elf_offset+0x1c 4 boundary checked, but unused (already given by SELF header)
e_shoff elf_offset+0x20 4 unused
e_flags elf_offset+0x24 4 unused
e_ehsize elf_offset+0x28 2 Must be sizeof(Elf32_Ehdr) = 0x0034
e_phentsize elf_offset+0x2a 2 Must be sizeof(Elf32_Phdr) = 0x0020
e_phnum elf_offset+0x2c 2 Count of Program Header in this elf
e_shentsize elf_offset+0x2e 2 unused
e_shnum elf_offset+0x30 2 unused
e_shstrndx elf_offset+0x32 2  unused

ELF Program Headers

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;

Table

Comments

See Spec here: ELF Program Headers

ELF Section 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;

Table

Comments