Skip to content

Commit

Permalink
Implement , and ; in pf to rewind and be able to support unions ##print
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 22, 2018
1 parent a18fe42 commit a4618a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions libr/core/cmd_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ static const char *help_detail_pf[] = {
" ", "+", "toggle show flags for each offset",
" ", ":", "skip 4 bytes",
" ", ".", "skip 1 byte",
" ", ";", "rewind 4 bytes",
" ", ",", "rewind 1 byte",
NULL
};

Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_anal.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ typedef struct r_anal_fcn_meta_t {
/* Store various function information,
* variables, arguments, refs and even
* description */
typedef struct r_anal_type_function_t {
typedef struct r_anal_function_t {
char* name;
char* dsc; // For producing nice listings
ut32 _size;
Expand Down
29 changes: 17 additions & 12 deletions libr/util/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
p->cb_printf ("\",\"offset\":%d,\"value\":",
isptr? (seek + nexti - (p->bits / 8)) : seek + i);
}
bool noline = false;

if (isptr == NULLPTR) {
if (MUSTSEEJSON) {
Expand All @@ -2143,10 +2144,6 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
/* format chars */
// before to enter in the switch statement check buf boundaries due to updateAddr
// might go beyond its len and it's usually called in each of the following functions
#if 0
// those boundaries are wrong. the fix was not correct, we need a reproducer
if (((i+3)<len) || (i+7)<len) {
#endif
switch (tmp) {
case 'u':
i += r_print_format_uleb (p, endian, mode, setval, seeki, buf, i, size);
Expand Down Expand Up @@ -2210,7 +2207,21 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
break;
case 'o':
r_print_format_octal (p, endian, mode, setval, seeki, buf, i, size);
i += (size==-1) ? 4 : 4*size;
i += (size==-1) ? 4 : 4 * size;
break;
case ';':
noline = true;
i -= (size==-1) ? 4 : 4 * size;
if (i < 0) {
i = 0;
}
break;
case ',':
noline = true;
i -= (size==-1) ? 1 : size;
if (i < 0) {
i = 0;
}
break;
case 'x':
r_print_format_hexflag (p, endian, mode, setval, seeki, buf, i, size);
Expand Down Expand Up @@ -2401,12 +2412,6 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
break;
} //switch
}
#if 0
} else {
eprintf ("r_print_format: Likely a heap buffer overflow (%s)\n", buf);
goto beach;
}
#endif
if (mode & R_PRINT_DOT) {
p->cb_printf ("}");
}
Expand All @@ -2420,7 +2425,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
p->cb_printf ("*(%s)", s);
}
}
if (tmp != 'D' && !invalid && !fmtname && MUSTSEE) {
if (!noline && tmp != 'D' && !invalid && !fmtname && MUSTSEE) {
p->cb_printf ("\n");
}
last = tmp;
Expand Down

0 comments on commit a4618a7

Please sign in to comment.