mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 18:43:28 +00:00
pfc: Support n# (#17011) ##print
This commit is contained in:
parent
97f2d9cf5c
commit
a934a39236
@ -1869,19 +1869,20 @@ static char *get_format_type(const char fmt, const char arg) {
|
||||
case 'Z':
|
||||
type = strdup ("char*");
|
||||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
switch (arg) {
|
||||
case '1':
|
||||
type = strdup ("uint8_t");
|
||||
type = strdup (fmt == 'n' ? "int8_t" : "uint8_t");
|
||||
break;
|
||||
case '2':
|
||||
type = strdup ("uint16_t");
|
||||
type = strdup (fmt == 'n' ? "int16_t" : "uint16_t");
|
||||
break;
|
||||
case '4':
|
||||
type = strdup ("uint32_t");
|
||||
type = strdup (fmt == 'n' ? "int32_t" : "uint32_t");
|
||||
break;
|
||||
case '8':
|
||||
type = strdup ("uint64_t");
|
||||
type = strdup (fmt == 'n' ? "int64_t" : "uint64_t");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -2326,7 +2327,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, tmp == 'N' ? arg[1] : 0); // TODO tmp == 'n'
|
||||
char *type = get_format_type (tmp, (tmp == 'n' || tmp == 'N') ? arg[1] : 0);
|
||||
if (type) {
|
||||
p->cb_printf ("%*c%s %s; // ", ident, ' ', type, fieldname);
|
||||
} else {
|
||||
|
@ -498,3 +498,32 @@ EXPECT=<<EOF
|
||||
EOF
|
||||
EXPECT_ERR=
|
||||
RUN
|
||||
|
||||
NAME=pfc N# and n#
|
||||
FILE=-
|
||||
ARGS=-a x86 -b 64
|
||||
CMDS=<<EOF
|
||||
(wneg num size; wv$1 -$0; s+ $1)
|
||||
.(wneg 1 1)
|
||||
.(wneg 2 2)
|
||||
.(wneg 3 4)
|
||||
.(wneg 4 8)
|
||||
s 0
|
||||
pfc N1N2N4N8 byte word dword qword
|
||||
pfc n1n2n4n8 byte word dword qword
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
struct {
|
||||
uint8_t byte; // 255
|
||||
uint16_t word; // 65534
|
||||
uint32_t dword; // 4294967293
|
||||
uint64_t qword; // 18446744073709551612
|
||||
}
|
||||
struct {
|
||||
int8_t byte; // -1
|
||||
int16_t word; // -2
|
||||
int32_t dword; // -3
|
||||
int64_t qword; // -4
|
||||
}
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
x
Reference in New Issue
Block a user