diff --git a/libr/arch/p/arm/pseudo.c b/libr/arch/p/arm/pseudo.c index a18a81734aad6..665d3a34d4215 100644 --- a/libr/arch/p/arm/pseudo.c +++ b/libr/arch/p/arm/pseudo.c @@ -40,8 +40,10 @@ static int replace(int argc, const char *argv[], char *newstr) { { 0, "cbz", "if !# goto #", { 1, 2 } }, { 0, "cbnz", "if # goto #", { 1, 2 } }, { 0, "b.w", "goto #", { 1 } }, - { 0, "b.gt", "goto ifgt #", { 1 } }, - { 0, "b.le", "goto ifle #", { 1 } }, + { 0, "b.gt", "if (a > b) #", { 1 } }, + { 0, "b.le", "if (a <= b) #", { 1 } }, + { 0, "b.lt", "if (a < b) #", { 1 } }, + { 0, "b.ge", "if (a >= b) #", { 1 } }, { 0, "beq lr", "ifeq ret", {0} }, { 0, "beq", "je #", { 1 } }, { 0, "call", "# ()", { 1 } }, @@ -56,9 +58,12 @@ static int replace(int argc, const char *argv[], char *newstr) { { 0, "b.lo", "goto iflt #", { 1 } }, { 0, "cmf", "if (# == #)", { 1, 2 } }, { 0, "cmn", "if (# != #)", { 1, 2 } }, - { 0, "cmp", "if (# == #)", { 1, 2 } }, - { 0, "fcmp", "if (# == #)", { 1, 2 } }, - { 0, "tst", "if ((# & #) == 0)", { 1, 2 } }, + { 0, "cmp", "(a, b) = compare (#, #)", { 1, 2 } }, + { 0, "fcmp", "(a, b) = compare (#, #)", { 1, 2 } }, + { 0, "tst", "(a, b) = compare (#, #)", { 1, 2 } }, + // { 0, "cmp", "if (# == #)", { 1, 2 } }, + // { 0, "fcmp", "if (# == #)", { 1, 2 } }, + //{ 0, "tst", "if ((# & #) == 0)", { 1, 2 } }, { 4, "csel", "# = (#)? # : #", { 1, 4, 2, 3 } }, { 2, "cset", "# = (#)? 1 : 0", { 1, 2 } }, { 0, "dvf", "# = # / #", { 1, 2, 3 } }, diff --git a/libr/core/pseudo.c b/libr/core/pseudo.c index 527893cd24291..387abde21b82e 100644 --- a/libr/core/pseudo.c +++ b/libr/core/pseudo.c @@ -410,7 +410,7 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { } } else { NEWLINE (bb->addr, indent); - PRINTF ("goto loc_0x%"PFMT64x, bb->fail); + PRINTF ("goto loc_0x%"PFMT64x";", bb->fail); } if (sdb_const_get (db, K_INDENT (bb->addr), 0)) { // already analyzed, go pop and continue @@ -549,10 +549,12 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { } } PRINTF ("goto loc_0x%"PFMT64x";", bb->fail); +#if 0 if (nindent != indent) { NEWLINE (bb->addr, indent); PRINTF ("} else {"); } +#endif indent = nindent; } PRINTGOTO (bb->addr, gotoaddr); @@ -577,7 +579,13 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { r_config_set_b (core->config, "scr.html", true); } s = r_str_replace (s, ";", "//", true); - s = r_str_replace (s, "goto ", "goto loc_", true); + char *lastgoto = strstr (s, "goto "); + if (lastgoto) { + if (!strchr (lastgoto, '\n')) { + *s = 0; + } + } + s = r_str_replace (s, "goto ", "// goto loc_", true); if (show_addr) { // indent with | or stgh char *os = r_str_prefix_all (s, " "); @@ -609,7 +617,20 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { } else { NEWLINE (bb->addr, 1); } - PRINTF ("loc_0x%08"PFMT64x": // orphan\n%s", bb->addr, s); + RFlagItem *fi = r_flag_get_i (core->flags, bb->addr); + if (fi && r_str_startswith (fi->name, "case.")) { + const char *val = r_str_lchr (fi->name, '.') + 1; + char *hex = r_str_newf ("0x%s", val); + int nval = r_num_get (NULL, hex); + free (hex); + if (IS_PRINTABLE (nval)) { + PRINTF ("loc_0x%08"PFMT64x": // case '%c'\n%s", bb->addr, nval, s); + } else { + PRINTF ("loc_0x%08"PFMT64x": // case %s\n%s", bb->addr, val, s); + } + } else { + PRINTF ("loc_0x%08"PFMT64x": // orphan\n%s", bb->addr, s); + } ut64 nbbaddr = UT64_MAX; if (iter->n) { RAnalBlock *nbb = (RAnalBlock*)iter->n; diff --git a/test/db/cmd/cmd_pdc b/test/db/cmd/cmd_pdc index 1fcbdcbea3fc2..63f4ee8bff2ce 100644 --- a/test/db/cmd/cmd_pdc +++ b/test/db/cmd/cmd_pdc @@ -121,9 +121,9 @@ int entry0 (int stack, int stack) { si- var = si - 0 if (var > 0) goto loc_0x402018 // unlikely - goto loc_0x402042 + goto loc_0x402042; // } while (?); - goto loc_0x402042 + goto loc_0x402042; } return eax; loc_0x402042: @@ -171,12 +171,12 @@ int sym.func.100003a54 (int x0, int x1) { x8 = [x8 + 0x60] x9 = [x1 + 0x60] // arg2 x9 = [x9 + 0x60] - if (x8 == x9) - goto ifle 0x100003a74 // likely - goto loc_0x100003a6c + (a, b) = compare (x8, x9) + if (a <= b) 0x100003a74 // likely + goto loc_0x100003a6c; loc_0x100003a74: - b.ge 0x100003a80 // likely - goto loc_0x100003a78 + if (a >= b) 0x100003a80 // likely + goto loc_0x100003a78; loc_0x100003a80: x8 = x1 + 0x68 // arg2 x1 = x0 + 0x68 // arg1