diff --git a/libr/bin/d/elf64 b/libr/bin/d/elf64 index c10eef6d9c..d17f3f8536 100644 --- a/libr/bin/d/elf64 +++ b/libr/bin/d/elf64 @@ -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 diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index 3fda91b02e..ebe3d19ca2 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -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 diff --git a/libr/util/format.c b/libr/util/format.c index db7eb5cee1..a2c2ca8408 100644 --- a/libr/util/format.c +++ b/libr/util/format.c @@ -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 { diff --git a/test/db/cmd/cmd_pf_elf b/test/db/cmd/cmd_pf_elf index 5fa227a499..b47df3d03e 100644 --- a/test/db/cmd/cmd_pf_elf +++ b/test/db/cmd/cmd_pf_elf @@ -194,12 +194,12 @@ EXPECT=< + 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 diff --git a/test/db/cmd/print b/test/db/cmd/print index ba4ccf66f9..09e6db139f 100644 --- a/test/db/cmd/print +++ b/test/db/cmd/print @@ -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