mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 21:29:49 +00:00
elf64 pf.elf_header: w -> N2 for phnum, shnum, shstrndx, ehsize, phentsize and shentsize (#16992)
* elf64 pf.elf_header: w -> N2 for phnum, shnum, shstrndx, ehsize, phentsize and shentsize * Add support for 'N' to pfc
This commit is contained in:
parent
5817770e29
commit
f3c227ee88
@ -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]Eqqqxwwwwww (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]EqqqxN2N2N2N2N2N2 (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]E[4]Eqqqqqq (elf_p_type)type (elf_p_flags)flags offset vaddr paddr filesz memsz align
|
||||
pf.elf_shdr x[4]E[8]Eqqqxxqq name (elf_s_type)type (elf_s_flags_64)flags addr offset size link info addralign entsize
|
||||
|
@ -183,7 +183,7 @@ static bool init_ehdr(ELFOBJ *bin) {
|
||||
sdb_set (bin->kv, "elf_ident.format", "[4]z[1]E[1]E[1]E.::"
|
||||
" magic (elf_class)class (elf_data)data (elf_hdr_version)version", 0);
|
||||
#if R_BIN_ELF64
|
||||
sdb_set (bin->kv, "elf_header.format", "?[2]E[2]E[4]Eqqqxwwwwww"
|
||||
sdb_set (bin->kv, "elf_header.format", "?[2]E[2]E[4]EqqqxN2N2N2N2N2N2"
|
||||
" (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
|
||||
|
@ -1450,7 +1450,7 @@ static void r_print_format_num(const RPrint *p, int endian, int mode, const char
|
||||
if (MUSTSET) {
|
||||
p->cb_printf ("wv%d %s @ 0x%08"PFMT64x"\n", bytes, setval, seeki+((elem>=0)?elem*(bytes):0));
|
||||
} else if ((mode & R_PRINT_DOT) || MUSTSEESTRUCT) {
|
||||
p->cb_printf ("%"PFMT64u, addr);
|
||||
r_print_format_num_specifier (p, addr, bytes, sign);
|
||||
} else if (MUSTSEE) {
|
||||
if (!SEEVALUE && !ISQUIET) {
|
||||
p->cb_printf ("0x%08"PFMT64x" = ", seeki + ((elem >= 0)? elem * bytes: 0));
|
||||
@ -1824,7 +1824,7 @@ static char *get_args_offset(const char *arg) {
|
||||
return args;
|
||||
}
|
||||
|
||||
static char *get_format_type(const char fmt) {
|
||||
static char *get_format_type(const char fmt, const char arg) {
|
||||
char *type = NULL;
|
||||
switch (fmt) {
|
||||
case 'b':
|
||||
@ -1868,6 +1868,23 @@ static char *get_format_type(const char fmt) {
|
||||
case 'z':
|
||||
case 'Z':
|
||||
type = strdup ("char*");
|
||||
break;
|
||||
case 'N':
|
||||
switch (arg) {
|
||||
case '1':
|
||||
type = strdup ("uint8_t");
|
||||
break;
|
||||
case '2':
|
||||
type = strdup ("uint16_t");
|
||||
break;
|
||||
case '4':
|
||||
type = strdup ("uint32_t");
|
||||
break;
|
||||
case '8':
|
||||
type = strdup ("uint64_t");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
@ -2309,7 +2326,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
|
||||
|
||||
/* c struct */
|
||||
if (MUSTSEESTRUCT) {
|
||||
char *type = get_format_type (tmp);
|
||||
char *type = get_format_type (tmp, tmp == 'N' ? arg[1] : 0); // TODO tmp == 'n'
|
||||
if (type) {
|
||||
p->cb_printf ("%*c%s %s; // ", ident, ' ', type, fieldname);
|
||||
} else {
|
||||
|
@ -194,12 +194,12 @@ EXPECT=<<EOF
|
||||
phoff : 0x00400020 = (qword)0x0000000000000040
|
||||
shoff : 0x00400028 = (qword)0x00000000000000a8
|
||||
flags : 0x00400030 = 0x00000000
|
||||
ehsize : 0x00400034 = 0x0040
|
||||
phentsize : 0x00400036 = 0x0038
|
||||
phnum : 0x00400038 = 0x0001
|
||||
shentsize : 0x0040003a = 0x0040
|
||||
shnum : 0x0040003c = 0x0003
|
||||
shstrndx : 0x0040003e = 0x0002
|
||||
ehsize : 0x00400034 = 64
|
||||
phentsize : 0x00400036 = 56
|
||||
phnum : 0x00400038 = 1
|
||||
shentsize : 0x0040003a = 64
|
||||
shnum : 0x0040003c = 3
|
||||
shstrndx : 0x0040003e = 2
|
||||
EOF
|
||||
RUN
|
||||
|
||||
@ -380,12 +380,12 @@ EXPECT=<<EOF
|
||||
phoff : 0x00000020 = (qword)0x0000000000000040
|
||||
shoff : 0x00000028 = (qword)0x00000000000000a8
|
||||
flags : 0x00000030 = 0x00000000
|
||||
ehsize : 0x00000034 = 0x0040
|
||||
phentsize : 0x00000036 = 0x0038
|
||||
phnum : 0x00000038 = 0x0001
|
||||
shentsize : 0x0000003a = 0x0040
|
||||
shnum : 0x0000003c = 0x0003
|
||||
shstrndx : 0x0000003e = 0x0002
|
||||
ehsize : 0x00000034 = 64
|
||||
phentsize : 0x00000036 = 56
|
||||
phnum : 0x00000038 = 1
|
||||
shentsize : 0x0000003a = 64
|
||||
shnum : 0x0000003c = 3
|
||||
shstrndx : 0x0000003e = 2
|
||||
EOF
|
||||
RUN
|
||||
|
||||
@ -442,3 +442,32 @@ EXPECT=<<EOF
|
||||
shstrndx : 0x00000032 = 28
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=64: normal elf header
|
||||
FILE=bins/elf/hello_world
|
||||
CMDS=<<EOF
|
||||
pfo elf64
|
||||
pf.elf_header @ segment.ehdr
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
ident :
|
||||
struct<elf_ident>
|
||||
magic : 0x00000000 = "\x7fELF"
|
||||
class : 0x00000004 = class (enum elf_class) = 0x2 ; ELFCLASS64
|
||||
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) = 0x3e ; EM_X86_64
|
||||
version : 0x00000014 = version (enum elf_obj_version) = 0x1 ; EV_CURRENT
|
||||
entry : 0x00000018 = (qword)0x00000000000006a0
|
||||
phoff : 0x00000020 = (qword)0x0000000000000040
|
||||
shoff : 0x00000028 = (qword)0x0000000000001a08
|
||||
flags : 0x00000030 = 0x00000000
|
||||
ehsize : 0x00000034 = 64
|
||||
phentsize : 0x00000036 = 56
|
||||
phnum : 0x00000038 = 9
|
||||
shentsize : 0x0000003a = 64
|
||||
shnum : 0x0000003c = 29
|
||||
shstrndx : 0x0000003e = 28
|
||||
EOF
|
||||
RUN
|
||||
|
@ -217,12 +217,12 @@ struct elf_header {
|
||||
uint64_t phoff; // 64
|
||||
uint64_t shoff; // 136040
|
||||
int32_t flags; // 0x00000000
|
||||
uint16_t ehsize; // 0x0040
|
||||
uint16_t phentsize; // 0x0038
|
||||
uint16_t phnum; // 0x000b
|
||||
uint16_t shentsize; // 0x0040
|
||||
uint16_t shnum; // 0x0019
|
||||
uint16_t shstrndx; // 0x0018
|
||||
uint16_t ehsize; // 64
|
||||
uint16_t phentsize; // 56
|
||||
uint16_t phnum; // 11
|
||||
uint16_t shentsize; // 64
|
||||
uint16_t shnum; // 25
|
||||
uint16_t shstrndx; // 24
|
||||
}
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
Reference in New Issue
Block a user