elf32 pf.elf_header: w -> N2 for phnum, shnum, shstrndx, ehsize, phentsize and shentsize (#16978)

* elf32 pf.elf_header: w -> N2 for phnum, shnum and shstrndx
* elf32 pf.elf_header: w -> N2 for ehsize, phentsize and shentsize
This commit is contained in:
Khairul Azhar Kasmiran 2020-06-01 12:33:42 +08:00 committed by GitHub
parent 3d4dd3a04c
commit fc4ea0f9a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 33 deletions

View File

@ -1,5 +1,5 @@
pfo elf_enums
pf.elf_ident [4]z[1]E[1]E[1]E.:: magic (elf_class)class (elf_data)data (elf_hdr_version)version
pf.elf_header ?[2]E[2]E[4]Exxxxwwwwww (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
pf.elf_header ?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
pf.elf_phdr [4]Exxxxx[4]Ex (elf_p_type)type offset vaddr paddr filesz memsz (elf_p_flags)flags align
pf.elf_shdr x[4]E[4]Exxxxxxx name (elf_s_type)type (elf_s_flags_32)flags addr offset size link info addralign entsize

View File

@ -187,7 +187,7 @@ static bool init_ehdr(ELFOBJ *bin) {
" (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version"
" entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx", 0);
#else
sdb_set (bin->kv, "elf_header.format", "?[2]E[2]E[4]Exxxxwwwwww"
sdb_set (bin->kv, "elf_header.format", "?[2]E[2]E[4]ExxxxN2N2N2N2N2N2"
" (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version"
" entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx", 0);
#endif

View File

@ -455,8 +455,8 @@ pf?elf_header
pf? elf_header
EOF
EXPECT=<<EOF
?[2]E[2]E[4]Exxxxwwwwww (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
?[2]E[2]E[4]Exxxxwwwwww (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
EOF
RUN
@ -489,13 +489,12 @@ EXPECT=<<EOF
phoff : 0x0000001c = 0x00000034
shoff : 0x00000020 = 0x00000000
flags : 0x00000024 = 0x00000000
ehsize : 0x00000028 = 0x0034
phentsize : 0x0000002a = 0x0020
phnum : 0x0000002c = 0x0001
shentsize : 0x0000002e = 0x0000
shnum : 0x00000030 = 0x0000
shstrndx : 0x00000032 = 0x0000
EOF
EXPECT_ERR=<<EOF
ehsize : 0x00000028 = 52
phentsize : 0x0000002a = 32
phnum : 0x0000002c = 1
shentsize : 0x0000002e = 0
shnum : 0x00000030 = 0
shstrndx : 0x00000032 = 0
EOF
EXPECT_ERR=
RUN

View File

@ -165,12 +165,12 @@ EXPECT=<<EOF
phoff : 0x0804801c = 0x00000034
shoff : 0x08048020 = 0x00000000
flags : 0x08048024 = 0x00000000
ehsize : 0x08048028 = 0x0034
phentsize : 0x0804802a = 0x0020
phnum : 0x0804802c = 0x0001
shentsize : 0x0804802e = 0x0000
shnum : 0x08048030 = 0x0000
shstrndx : 0x08048032 = 0x0000
ehsize : 0x08048028 = 52
phentsize : 0x0804802a = 32
phnum : 0x0804802c = 1
shentsize : 0x0804802e = 0
shnum : 0x08048030 = 0
shstrndx : 0x08048032 = 0
EOF
RUN
@ -226,12 +226,12 @@ EXPECT=<<EOF
phoff : 0x0000001c = 0x00000034
shoff : 0x00000020 = 0x00000000
flags : 0x00000024 = 0x00000000
ehsize : 0x00000028 = 0x0034
phentsize : 0x0000002a = 0x0020
phnum : 0x0000002c = 0x0001
shentsize : 0x0000002e = 0x0000
shnum : 0x00000030 = 0x0000
shstrndx : 0x00000032 = 0x0000
ehsize : 0x00000028 = 52
phentsize : 0x0000002a = 32
phnum : 0x0000002c = 1
shentsize : 0x0000002e = 0
shnum : 0x00000030 = 0
shstrndx : 0x00000032 = 0
[
{
@ -321,37 +321,37 @@ EXPECT=<<EOF
},
{
"name": "ehsize",
"type": "w",
"type": "N2",
"offset": 40,
"value": 52
},
{
"name": "phentsize",
"type": "w",
"type": "N2",
"offset": 42,
"value": 32
},
{
"name": "phnum",
"type": "w",
"type": "N2",
"offset": 44,
"value": 1
},
{
"name": "shentsize",
"type": "w",
"type": "N2",
"offset": 46,
"value": 0
},
{
"name": "shnum",
"type": "w",
"type": "N2",
"offset": 48,
"value": 0
},
{
"name": "shstrndx",
"type": "w",
"type": "N2",
"offset": 50,
"value": 0
}
@ -403,13 +403,42 @@ wz `pf? elf_header`
.(pfelf 2)
EOF
EXPECT=<<EOF
?[2]E[2]E[4]Exxxxwwwwww (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
52
{1}?[2]E[2]E[4]Exxxxwwwwww (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
{1}?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
52
{2}?[2]E[2]E[4]Exxxxwwwwww (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
{2}?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
104
EOF
RUN
NAME=32: normal elf header
FILE=bins/elf/hello_world32
CMDS=<<EOF
pfo elf32
pf.elf_header @ segment.ehdr
EOF
EXPECT=<<EOF
ident :
struct<elf_ident>
magic : 0x00000000 = "\x7fELF"
class : 0x00000004 = class (enum elf_class) = 0x1 ; ELFCLASS32
data : 0x00000005 = data (enum elf_data) = 0x1 ; ELFDATA2LSB
version : 0x00000006 = version (enum elf_hdr_version) = 0x1 ; EV_CURRENT
type : 0x00000010 = type (enum elf_type) = 0x3 ; ET_DYN
machine : 0x00000012 = machine (enum elf_machine) = 0x3 ; EM_386
version : 0x00000014 = version (enum elf_obj_version) = 0x1 ; EV_CURRENT
entry : 0x00000018 = 0x000004d0
phoff : 0x0000001c = 0x00000034
shoff : 0x00000020 = 0x0000182c
flags : 0x00000024 = 0x00000000
ehsize : 0x00000028 = 52
phentsize : 0x0000002a = 32
phnum : 0x0000002c = 9
shentsize : 0x0000002e = 40
shnum : 0x00000030 = 29
shstrndx : 0x00000032 = 28
EOF
RUN