SELF File Format: Difference between revisions
Jump to navigation
Jump to search
CelesteBlue (talk | contribs) |
CelesteBlue (talk | contribs) |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Software]]<noinclude>[[Category:Main]]</noinclude> | [[Category:Software]]<noinclude>[[Category:Main]]</noinclude> | ||
= File Format = | |||
== ELF Header == | |||
= | |||
=== Struct === | === Struct === | ||
<source lang="C"> | <source lang="C"> | ||
typedef struct { | typedef struct { | ||
uint8_t e_ident[16]; /* ELF identification */ | uint8_t e_ident[16]; /* ELF identification */ | ||
Line 132: | Line 24: | ||
uint16_t e_shstrndx; /* section name string table index */ | uint16_t e_shstrndx; /* section name string table index */ | ||
} __attribute__((packed)) ELF; | } __attribute__((packed)) ELF; | ||
</source> | |||
=== Table === | |||
{| class="wikitable sortable" | {| class="wikitable sortable" | ||
! Name of the variable !! Offset !! Size !! Notes | ! Name of the variable !! Offset !! Size !! Notes | ||
Line 172: | Line 66: | ||
|- | |- | ||
| e_shstrndx || elf_offset+0x32 || 2 || unused | | e_shstrndx || elf_offset+0x32 || 2 || unused | ||
| | |} | ||
== ELF Program Headers == | |||
=== | === Struct === | ||
<source lang="C"> | <source lang="C"> | ||
typedef struct { | typedef struct { | ||
uint32_t p_type; /* type of segment */ | uint32_t p_type; /* type of segment */ | ||
Line 207: | Line 83: | ||
uint64_t p_align; /* alignment of segment */ | uint64_t p_align; /* alignment of segment */ | ||
} __attribute__((packed)) ELF_PHDR; | } __attribute__((packed)) ELF_PHDR; | ||
</source> | |||
===Table=== | === Table === | ||
===Comments=== | === Comments === | ||
See Spec here: [http://www.sco.com/developers/gabi/latest/ch5.pheader.html ELF Program Headers] | See Spec here: [http://www.sco.com/developers/gabi/latest/ch5.pheader.html ELF Program Headers] | ||
== ELF Section Headers == | == ELF Section Headers == | ||
===Struct=== | === Struct === | ||
<source lang="C"> | |||
typedef struct { | typedef struct { | ||
uint32_t sh_name; /* section name */ | uint32_t sh_name; /* section name */ | ||
Line 228: | Line 107: | ||
uint64_t sh_entsize; /* size of entries, if section has table */ | uint64_t sh_entsize; /* size of entries, if section has table */ | ||
} __attribute__((packed)) ELF_SHDR; | } __attribute__((packed)) ELF_SHDR; | ||
</source> | </source> | ||
=== Table === | === Table === | ||
=== Comments === | === Comments === | ||
Revision as of 23: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;