From 8e8b26a50dd3820210daead2f8e7fa9e8a23afd4 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 10 Dec 2024 01:17:05 +0100 Subject: [PATCH] Unify the asm.parse apis workflow ##asm --- doc/fortunes.fun | 1 + libr/anal/jmptbl.c | 2 +- libr/arch/p/arm/pseudo.c | 12 +- libr/arch/p/mips/pseudo.c | 14 +- libr/arch/p/tricore/pseudo.c | 18 +- libr/arch/p/v850/pseudo.c | 13 +- libr/arch/p/wasm/pseudo.c | 13 +- libr/arch/p/x86_nz/pseudo.c | 17 +- libr/asm/asm.c | 1 + libr/asm/filter.c | 90 +++++---- libr/asm/parse.c | 13 +- libr/core/cmd_anal.inc.c | 110 +++++----- libr/core/cmd_search.inc.c | 33 ++- libr/core/core.c | 2 + libr/core/disasm.c | 378 ++++++++++++++++++++--------------- libr/include/r_anal/op.h | 2 +- libr/include/r_asm.h | 8 +- test/db/anal/arm-esil | 2 +- test/db/anal/jmptbl | 10 +- test/db/anal/sparc | 2 +- test/db/cmd/charset | 12 +- test/db/cmd/cmd_agf | 2 +- test/db/cmd/cmd_disassembly | 2 +- test/db/cmd/cmd_pd | 66 +++--- test/db/cmd/cmd_pdc | 2 +- test/db/cmd/cmd_pde | 2 +- test/db/cmd/cmd_pix | 2 +- test/db/cmd/dwarf | 20 +- test/db/cmd/lea_intel | 6 +- test/db/formats/coff | 2 +- test/db/formats/elf/reloc | 20 +- test/db/formats/mangling/bin | 16 +- 32 files changed, 461 insertions(+), 432 deletions(-) diff --git a/doc/fortunes.fun b/doc/fortunes.fun index 09f60f7d5ce11..bb36683932ac8 100644 --- a/doc/fortunes.fun +++ b/doc/fortunes.fun @@ -355,3 +355,4 @@ Press the button again. It's been a long time. Relic malfunction detected. You are offline. Some functionality may be unavailable. +Patching instructions should be illegal diff --git a/libr/anal/jmptbl.c b/libr/anal/jmptbl.c index 00eed36d00bfd..3f9c5794020b9 100644 --- a/libr/anal/jmptbl.c +++ b/libr/anal/jmptbl.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2010-2023 - nibble, alvaro, pancake, th3str4ng3r */ +/* radare - LGPL - Copyright 2010-2024 - nibble, alvaro, pancake, th3str4ng3r */ #include diff --git a/libr/arch/p/arm/pseudo.c b/libr/arch/p/arm/pseudo.c index 781e54f4b9632..594a47bdb0765 100644 --- a/libr/arch/p/arm/pseudo.c +++ b/libr/arch/p/arm/pseudo.c @@ -559,7 +559,7 @@ static char *patch(RAsmPluginSession *s, RAnalOp *aop, const char *op) { return r_core_hack_arm (s, aop, op); } -static bool subvar(RAsmPluginSession *s, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static char *subvar(RAsmPluginSession *s, RAnalFunction *f, ut64 addr, int oplen, const char *data) { R_RETURN_VAL_IF_FAIL (s, false); RAsm *a = s->rasm; RParse *p = a->parse; @@ -679,15 +679,7 @@ static bool subvar(RAsmPluginSession *s, RAnalFunction *f, ut64 addr, int oplen, r_list_free (bpargs); r_list_free (spargs); } - if (len > strlen (tstr)) { - strcpy (str, tstr); - } else { - // TOO BIG STRING CANNOT REPLACE HERE - free (tstr); - return false; - } - free (tstr); - return true; + return tstr; } RAsmPlugin r_asm_plugin_arm = { diff --git a/libr/arch/p/mips/pseudo.c b/libr/arch/p/mips/pseudo.c index 4be1788b2aefb..ad1ba02595d8c 100644 --- a/libr/arch/p/mips/pseudo.c +++ b/libr/arch/p/mips/pseudo.c @@ -245,7 +245,7 @@ static bool parse(RAsmPluginSession *aps, const char *data, char *str) { return true; } -static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static char *subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, const char *data) { RAsm *a = aps->rasm; RParse *p = a->parse; RListIter *iter; @@ -350,18 +350,10 @@ static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int ople r_list_free (bpargs); r_list_free (spargs); } - bool ret = true; - if (len > strlen (tstr)) { - strcpy (str, tstr); - } else { - // TOO BIG STRING CANNOT REPLACE HERE - ret = false; - } - free (tstr); - return ret; + return tstr; } -RAsmPlugin r_asm_plugin_mips= { +RAsmPlugin r_asm_plugin_mips = { .meta = { .name = "mips", .desc = "MIPS pseudo syntax", diff --git a/libr/arch/p/tricore/pseudo.c b/libr/arch/p/tricore/pseudo.c index fdc757e4e75dd..95c8ce3929414 100644 --- a/libr/arch/p/tricore/pseudo.c +++ b/libr/arch/p/tricore/pseudo.c @@ -255,7 +255,7 @@ static void mk_reg_str(const char *regname, int delta, bool sign, bool att, char r_strbuf_free (sb); } -static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static char *subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, const char *data) { RAsm *a = aps->rasm; RParse *p = a->parse; RAnal *anal = a->analb.anal; @@ -435,27 +435,19 @@ static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int ople r_list_free (spargs); r_list_free (bpargs); } - +#if 0 char bp[32]; if (anal->reg->name[R_REG_NAME_BP]) { strncpy (bp, anal->reg->name[R_REG_NAME_BP], sizeof (bp) - 1); - if (isupper ((ut8)*str)) { + if (isupper ((ut8)tstr[0])) { r_str_case (bp, true); } bp[sizeof (bp) - 1] = 0; } else { bp[0] = 0; } - - bool ret = true; - if (len > strlen (tstr)) { - strcpy (str, tstr); - } else { - // TOO BIG STRING CANNOT REPLACE HERE - ret = false; - } - free (tstr); - return ret; +#endif + return tstr; } static void fini(RAsmPluginSession *aps) { diff --git a/libr/arch/p/v850/pseudo.c b/libr/arch/p/v850/pseudo.c index 6891a76511be9..686d99054f390 100644 --- a/libr/arch/p/v850/pseudo.c +++ b/libr/arch/p/v850/pseudo.c @@ -120,6 +120,7 @@ static int replace(int argc, const char *argv[], char *newstr) { return false; } +// UNSAFE static char *reorder(char *buf) { char *arr = strstr (buf, "-0x"); if (!arr) { @@ -198,7 +199,7 @@ static bool parse(RAsmPluginSession *p, const char *data, char *str) { return true; } -static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static char *subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, const char *data) { char *r0 = strstr (data, "[r0]"); if (r0) { char *neg = strstr (data, " -"); @@ -208,16 +209,10 @@ static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int ople free (n); *neg = 0; ut64 addr = UT32_MAX + negdelta + 1; - char *res = r_str_newf ("%s 0x%"PFMT64x"%s", data, addr, r0 + 4); - strcpy (str, res); - free (res); - return true; + return r_str_newf ("%s 0x%"PFMT64x"%s", data, addr, r0 + 4); } } - if (str != data) { - r_str_cpy (str, data); - } - return false; + return NULL; } RAsmPlugin r_asm_plugin_v850 = { diff --git a/libr/arch/p/wasm/pseudo.c b/libr/arch/p/wasm/pseudo.c index 1a77511aea658..7a174a67afa65 100644 --- a/libr/arch/p/wasm/pseudo.c +++ b/libr/arch/p/wasm/pseudo.c @@ -1,8 +1,6 @@ /* radare - LGPL - Copyright 2019-2024 - deroad */ #include -#include -#include #include static char* get_fcn_name(RAnal *anal, ut32 fcn_id) { @@ -10,19 +8,18 @@ static char* get_fcn_name(RAnal *anal, ut32 fcn_id) { return s? strdup (s): NULL; } -static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static char *subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, const char *data) { char *fcn_name = NULL; - str[0] = 0; - if (!strncmp (data, "call ", 5)) { + if (r_str_startswith (data, "call ")) { ut32 fcn_id = (ut32) r_num_get (NULL, data + 5); if (!(fcn_name = get_fcn_name (aps->rasm->analb.anal, fcn_id))) { return false; } - snprintf (str, len, "call sym.%s", fcn_name); + char *res = r_str_newf ("call sym.%s", fcn_name); free (fcn_name); - return true; + return res; } - return false; + return NULL; } RAsmPlugin r_asm_plugin_wasm= { diff --git a/libr/arch/p/x86_nz/pseudo.c b/libr/arch/p/x86_nz/pseudo.c index 9a0df55614dc5..4dd0e409ebf5c 100644 --- a/libr/arch/p/x86_nz/pseudo.c +++ b/libr/arch/p/x86_nz/pseudo.c @@ -441,7 +441,7 @@ static char *patch(RAsmPluginSession *aps, RAnalOp *aop, const char *op) { return NULL; } -static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static char *subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int oplen, const char *data) { RAsm *a = aps->rasm; RParse *p = a->parse; RAnal *anal = a->analb.anal; @@ -449,7 +449,7 @@ static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int ople char oldstr[64], newstr[64]; char *tstr = strdup (data); if (!tstr) { - return false; + return NULL; } bool att = strchr (data, '%'); @@ -625,23 +625,14 @@ static bool subvar(RAsmPluginSession *aps, RAnalFunction *f, ut64 addr, int ople char bp[32]; if (anal->reg->name[R_REG_NAME_BP]) { strncpy (bp, anal->reg->name[R_REG_NAME_BP], sizeof (bp) - 1); - if (isupper ((ut8)*str)) { + if (isupper ((ut8)*tstr)) { r_str_case (bp, true); } bp[sizeof (bp) - 1] = 0; } else { bp[0] = 0; } - - bool ret = true; - if (len > strlen (tstr)) { - strcpy (str, tstr); - } else { - // TOO BIG STRING CANNOT REPLACE HERE - ret = false; - } - free (tstr); - return ret; + return tstr; } static void fini(RAsmPluginSession *aps) { diff --git a/libr/asm/asm.c b/libr/asm/asm.c index a4b246372ef1c..091d61dcd838b 100644 --- a/libr/asm/asm.c +++ b/libr/asm/asm.c @@ -488,6 +488,7 @@ R_API int r_asm_disassemble(RAsm *a, RAnalOp *op, const ut8 *buf, int len) { char *newtext = r_asm_parse_pseudo (a, op->mnemonic); if (newtext) { r_anal_op_set_mnemonic (op, op->addr, newtext); + free (newtext); } } int opsz = (op->size > 0)? R_MAX (0, R_MIN (len, op->size)): 1; diff --git a/libr/asm/filter.c b/libr/asm/filter.c index 0bba6bdbd8f41..825052f615ea0 100644 --- a/libr/asm/filter.c +++ b/libr/asm/filter.c @@ -142,17 +142,20 @@ static void __replaceRegisters(RReg *reg, char *s, bool x86) { } } -static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian) { +static char *filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, const char *data) { RAsm *a = aps->rasm; RParse *p = a->parse; - char *ptr = data, *ptr2, *ptr_backup; + char *hdata = strdup (data); // XXX + char *ptr = hdata; + const bool big_endian = R_ARCH_CONFIG_IS_BIG_ENDIAN (a->config); + char *ptr2, *ptr_backup; RAnalFunction *fcn; RFlagItem *flag; ut64 off; RArchConfig *ac = R_UNWRAP3 (a, analb.anal, config); if (!ac) { - eprintf ("%p\n", a->analb.anal); R_LOG_ERROR ("no anal bind?"); + free (hdata); return false; } const int bits = ac->bits; @@ -172,6 +175,7 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, } } if (!data || !p) { + free (hdata); return 0; } #if FILTER_DWORD @@ -226,14 +230,14 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, name = flag->realname; } } - snprintf (str, len, "%s%s%s", data, name, - (ptr != ptr2)? ptr2: ""); - return true; + char *res = r_str_newf ("%s%s%s", hdata, name, (ptr != ptr2)? ptr2: ""); + free (hdata); + return res; } if (f) { RFlagItem *flag2; - bool lea = x86 && r_str_startswith (data, "lea") - && (data[3] == ' ' || data[3] == 0x1b); + bool lea = x86 && r_str_startswith (hdata, "lea") + && (hdata[3] == ' ' || hdata[3] == 0x1b); bool remove_brackets = false; flag = p->flag_get (f, false, off); if ((!flag || arm) && p->subrel_addr) { @@ -265,21 +269,18 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, if (remove_brackets && ptr != ptr2 && *ptr) { if (*ptr2 == ']') { ptr2++; - for (ptr--; ptr > data && *ptr != '['; ptr--) { + for (ptr--; ptr > hdata && *ptr != '['; ptr--) { ; } - if (ptr == data) { + if (ptr == hdata) { ptr = ptr_backup; } } } *ptr = 0; - char *flagname; - if (label) { - flagname = r_str_newf (".%s", label); - } else { - flagname = strdup (f->realnames? flag->realname : flag->name); - } + char *flagname = label + ? r_str_newf (".%s", label) + : strdup (f->realnames? flag->realname : flag->name); int maxflagname = p->maxflagnamelen; if (maxflagname > 0 && strlen (flagname) > maxflagname) { char *doublelower = (char *)r_str_rstr (flagname, "__"); @@ -297,17 +298,14 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, flagname = newstr; } else { const char *lower = r_str_rstr (flagname, "_"); - char *newstr; - if (lower) { - newstr = r_str_newf ("..%s", lower + 1); - } else { - newstr = r_str_newf ("..%s", flagname + (strlen (flagname) - maxflagname)); - } + char *newstr = lower + ? r_str_newf ("..%s", lower + 1) + : r_str_newf ("..%s", flagname + (strlen (flagname) - maxflagname)); free (flagname); flagname = newstr; } } - snprintf (str, len, "%s%s%s", data, flagname, (ptr != ptr2) ? ptr2 : ""); + char *str = r_str_newf ("%s%s%s", hdata, flagname, (ptr != ptr2) ? ptr2 : ""); free (flagname); bool banned = false; { @@ -320,11 +318,12 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, } if (p->subrel_addr && !banned && lea) { // TODO: use remove_brackets int flag_len = strlen (flag->name); - char *ptr_end = str + strlen (data) + flag_len - 1; + char *ptr_end = str + strlen (hdata) + flag_len - 1; char *ptr_right = ptr_end + 1, *ptr_left, *ptr_esc; bool ansi_found = false; if (!*ptr_end) { - return true; + free (hdata); + return str; } while (*ptr_right) { if (*ptr_right == 0x1b) { @@ -375,7 +374,8 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, break; } } - return true; + free (hdata); + return str; } if (p->subtail) { // && off > UT32_MAX && addr > UT32_MAX) if (off != UT64_MAX) { @@ -405,8 +405,9 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, int tmp_count; if (hint->offset) { *ptr = 0; - snprintf (str, len, "%s%s%s", data, hint->offset, (ptr != ptr2)? ptr2: ""); - return true; + char *res = r_str_newf ("%s%s%s", hdata, hint->offset, (ptr != ptr2)? ptr2: ""); + free (hdata); + return res; } strncpy (num, ptr, sizeof (num)-2); pnum = num; @@ -441,7 +442,7 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, break; case 1: // hack for ascii tmp_count = 0; - for (tmp = data; tmp < ptr; tmp++) { + for (tmp = hdata; tmp < ptr; tmp++) { if (*tmp == 0x1b) { while (tmp < ptr - 1 && *tmp != 'm') { tmp++; @@ -528,7 +529,7 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, RListIter *iter; bool imm32 = false; r_list_foreach (regs, iter, reg) { - if (reg->size == 32 && r_str_casestr (data, reg->name)) { + if (reg->size == 32 && r_str_casestr (hdata, reg->name)) { imm32 = true; break; } @@ -577,26 +578,29 @@ static bool filter(RAsmPluginSession *aps, ut64 addr, RFlag *f, RAnalHint *hint, break; } *ptr = 0; - snprintf (str, len, "%s%s%s", data, num, (ptr != ptr2)? ptr2: ""); - return true; + char *res = r_str_newf ("%s%s%s", hdata, num, (ptr != ptr2)? ptr2: ""); + free (hdata); + return res; } ptr = ptr2; } - if (data != str) { - strncpy (str, data, len); - } else { - R_LOG_ERROR ("Invalid str/data inputs"); - } - return false; + free (hdata); + return NULL; } -/// XXX very ugly arguments, redesign! -R_API bool r_asm_parse_filter(RAsm *a, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian) { +R_API char *r_asm_parse_filter(RAsm *a, ut64 addr, RFlag *f, RAnalHint *hint, const char *data) { RAsmPluginSession *aps = a->cur; - filter (aps, addr, f, hint, data, str, len, big_endian); + char *str = filter (aps, addr, f, hint, data); + if (!str) { + str = strdup (data); + } RAsmPlugin *ap = R_UNWRAP3 (a, cur, plugin); if (ap && ap->filter) { - return ap->filter (aps, addr, f, data, str, len, big_endian); + char *res = ap->filter (aps, addr, f, str); + if (res) { + free (str); + str = res; + } } - return false; + return str; } diff --git a/libr/asm/parse.c b/libr/asm/parse.c index a8174bd71e9c5..404e1f468b84d 100644 --- a/libr/asm/parse.c +++ b/libr/asm/parse.c @@ -14,9 +14,7 @@ R_API RParse *r_parse_new(void) { } R_API void r_parse_free(RParse *p) { - if (p) { - free (p); - } + free (p); } // TODO .make it internal @@ -25,6 +23,7 @@ R_API char *r_asm_parse_pseudo(RAsm *a, const char *data) { char *str = malloc (32 + (strlen (data) * 2)); if (str) { strcpy (str, data); + // XXX TODO return char * instead of passing both strings here RAsmParsePseudo parse = R_UNWRAP4 (a, cur, plugin, parse); bool bres = parse? parse (a->cur, data, str) : false; if (bres) { @@ -74,14 +73,14 @@ R_API char *r_asm_parse_immtrim(RAsm *a, const char *_opstr) { return opstr; } -// TODO : make it internal -R_API bool r_asm_parse_subvar(RAsm *a, R_NULLABLE RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +// TODO : make them internal? +R_API char *r_asm_parse_subvar(RAsm *a, R_NULLABLE RAnalFunction *f, ut64 addr, int oplen, const char *data) { R_RETURN_VAL_IF_FAIL (a, false); RAsmPlugin *pcur = R_UNWRAP3 (a, cur, plugin); if (pcur && pcur->subvar) { - return pcur->subvar (a->cur, f, addr, oplen, data, str, len); + return pcur->subvar (a->cur, f, addr, oplen, data); } - return false; + return NULL; } R_API char *r_asm_parse_patch(RAsm *a, RAnalOp *aop, const char *op) { diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index 411b57ef35597..3974f8cfcbebd 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -2477,33 +2477,34 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } else if (fmt == '*') { // TODO: ao* useful for wat? wx [bytes] ? } else if (fmt == 'j') { - char strsub[128] = {0}; // pc+33 - r_asm_parse_subvar (core->rasm, NULL, - core->offset + idx, - asmop.size, asmop.mnemonic, - strsub, sizeof (strsub)); - ut64 killme = UT64_MAX; - if (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { - core->rasm->parse->subrel_addr = killme; - } + char *strsub = r_asm_parse_subvar (core->rasm, NULL, + core->offset + idx, asmop.size, asmop.mnemonic); + ut64 killme = UT64_MAX; + if (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { + core->rasm->parse->subrel_addr = killme; + } // 0x33->sym.xx - char *p = strdup (strsub); - if (p) { - r_asm_parse_filter (core->rasm, addr, core->flags, hint, p, - strsub, sizeof (strsub), be); - free (p); + if (strsub) { + char *res2 = r_asm_parse_filter (core->rasm, addr, core->flags, hint, strsub); + if (res2) { + free (strsub); + strsub = res2; + } } pj_o (pj); pj_ks (pj, "opcode", asmop.mnemonic); - if (!*strsub) { - r_str_ncpy (strsub, asmop.mnemonic, sizeof (strsub) -1 ); + if (!strsub) { + strsub = strdup (asmop.mnemonic); } { RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { - r_asm_parse_subvar (core->rasm, fcn, addr, asmop.size, - strsub, strsub, sizeof (strsub)); + char *res2 = r_asm_parse_subvar (core->rasm, fcn, addr, asmop.size, strsub); + if (res2) { + free (strsub); + strsub = res2; + } } } pj_ks (pj, "disasm", strsub); @@ -2665,25 +2666,27 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int // ignored/skipped eprintf ("No esil for '%s'\n", op.mnemonic); } } else { - char disasm[128] = {0}; char *text = asmop.mnemonic; if (!text) { R_LOG_ERROR ("invalid"); break; } - r_asm_parse_subvar (core->rasm, NULL, + char *disasm = r_asm_parse_subvar (core->rasm, NULL, core->offset + idx, - asmop.size, text, - disasm, sizeof (disasm)); + asmop.size, text); + if (!disasm) { + disasm = strdup (text); + } ut64 killme = UT64_MAX; if (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { core->rasm->parse->subrel_addr = killme; } - char *p = strdup (disasm); - if (p) { - r_asm_parse_filter (core->rasm, addr, core->flags, hint, p, - disasm, sizeof (disasm), be); - free (p); + if (disasm) { + char *disasm2 = r_asm_parse_filter (core->rasm, addr, core->flags, hint, disasm); + if (disasm2) { + free (disasm); + disasm = disasm2; + } } #define printline(k, fmt, arg)\ { \ @@ -2696,14 +2699,17 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } printline ("address", "0x%" PFMT64x "\n", core->offset + idx); printline ("opcode", "%s\n", asmop.mnemonic); - if (!*disasm) { - r_str_ncpy (disasm, asmop.mnemonic, sizeof (disasm) - 1); + if (!disasm) { + disasm = strdup (asmop.mnemonic); } { RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { - r_asm_parse_subvar (core->rasm, fcn, addr, asmop.size, - disasm, disasm, sizeof (disasm)); + char *disasm2 = r_asm_parse_subvar (core->rasm, fcn, addr, asmop.size, disasm); + if (disasm2) { + free (disasm); + disasm = disasm2; + } } } if (esilstr) { @@ -2720,17 +2726,16 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } printline ("mnemonic", "%s\n", mnem); { - char *opname = strdup (disasm); - char *sp = strchr (opname, ' '); + char *sp = strchr (disasm, ' '); if (sp) { *sp = 0; } - char *d = r_asm_describe (core->rasm, opname); + char *d = r_asm_describe (core->rasm, disasm); if (R_STR_ISNOTEMPTY (d)) { printline ("description", "%s\n", d); } free (d); - free (opname); + R_FREE (disasm); } { const int left = len - idx; @@ -10231,12 +10236,10 @@ static char *get_op_ireg(void *user, ut64 addr) { static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn, bool color) { int has_color = core->print->flags & R_PRINT_FLAGS_COLOR; - char str[512]; const int size = 12; ut8 buf[12]; RAnalOp asmop = {0}; bool asm_subvar = r_config_get_b (core->config, "asm.sub.var"); - bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->rasm->config); core->rasm->parse->pseudo = r_config_get_b (core->config, "asm.pseudo"); core->rasm->parse->subrel = r_config_get_i (core->config, "asm.sub.rel"); core->rasm->parse->localvar_only = r_config_get_b (core->config, "asm.sub.varonly"); @@ -10247,27 +10250,34 @@ static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn, r_io_read_at (core->io, addr, buf, size); r_asm_set_pc (core->rasm, addr); r_asm_disassemble (core->rasm, &asmop, buf, size); - int ba_len = strlen (asmop.mnemonic) + 128; - char *ba = malloc (ba_len); - strcpy (ba, asmop.mnemonic); + char *ba = strdup (asmop.mnemonic); if (asm_subvar) { core->rasm->parse->get_ptr_at = r_anal_function_get_var_stackptr_at; core->rasm->parse->get_reg_at = r_anal_function_get_var_reg_at; core->rasm->parse->get_op_ireg = get_op_ireg; - r_asm_parse_subvar (core->rasm, fcn, addr, asmop.size, ba, ba, ba_len); + char *ba2 = r_asm_parse_subvar (core->rasm, fcn, addr, asmop.size, ba); + if (ba2) { + free (ba); + ba = ba2; + } } RAnalHint *hint = r_anal_hint_get (core->anal, addr); - r_asm_parse_filter (core->rasm, addr, core->flags, hint, ba, str, sizeof (str), be); + char *ba2 = r_asm_parse_filter (core->rasm, addr, core->flags, hint, ba); + if (ba2) { + free (ba); + ba = ba2; + } r_anal_hint_free (hint); r_anal_op_set_mnemonic (&asmop, asmop.addr, ba); free (ba); char *buf_asm = NULL; if (color && has_color) { - buf_asm = r_print_colorize_opcode (core->print, str, + buf_asm = r_print_colorize_opcode (core->print, asmop.mnemonic, core->cons->context->pal.reg, core->cons->context->pal.num, false, fcn ? fcn->addr : 0); } else { - buf_asm = strdup (str); + buf_asm = strdup (asmop.mnemonic); } + r_asm_op_fini (&asmop); return buf_asm; } @@ -10353,7 +10363,6 @@ static void axfm(RCore *core) { } static bool cmd_anal_refs(RCore *core, const char *input) { - bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->print->config); ut64 addr = core->offset; switch (input[0]) { case '-': { // "ax-" @@ -10824,7 +10833,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) { ref->at, ref->type); } } else { // "axf" - char str[512]; + char *str = asmop.mnemonic; int has_color = core->print->flags & R_PRINT_FLAGS_COLOR; RAnalRef *ref; R_VEC_FOREACH (list, ref) { @@ -10838,9 +10847,14 @@ static bool cmd_anal_refs(RCore *core, const char *input) { r_io_read_at (core->io, ref->addr, buf, sizeof (buf)); r_asm_set_pc (core->rasm, ref->addr); r_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)); + desc_to_free = str = strdup (asmop.mnemonic); RAnalHint *hint = r_anal_hint_get (core->anal, ref->addr); - r_asm_parse_filter (core->rasm, ref->addr, core->flags, - hint, asmop.mnemonic, str, sizeof (str), be); + char *res = r_asm_parse_filter (core->rasm, ref->addr, core->flags, + hint, asmop.mnemonic); + if (res) { + free (asmop.mnemonic); + asmop.mnemonic = res; + } r_anal_hint_free (hint); if (has_color) { desc = desc_to_free = r_print_colorize_opcode (core->print, str, diff --git a/libr/core/cmd_search.inc.c b/libr/core/cmd_search.inc.c index c63ab3408a33b..d571002fb6415 100644 --- a/libr/core/cmd_search.inc.c +++ b/libr/core/cmd_search.inc.c @@ -2264,8 +2264,6 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) { static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct search_parameters *param) { const int size = 12; - const bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->print->config); - char str[512]; ut8 buf[12]; RVecAnalRef *xrefs = r_anal_xrefs_get (core->anal, addr); if (!xrefs) { @@ -2280,7 +2278,7 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear r_asm_disassemble (core->rasm, &asmop, buf, size); RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0); RAnalHint *hint = r_anal_hint_get (core->anal, ref->addr); - r_asm_parse_filter (core->rasm, ref->addr, core->flags, hint, asmop.mnemonic, str, sizeof (str), be); + char *disasm = r_asm_parse_filter (core->rasm, ref->addr, core->flags, hint, asmop.mnemonic); r_anal_hint_free (hint); const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr); char *print_comment = NULL; @@ -2294,7 +2292,8 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear free (print_comment); if (from <= ref->addr && to >= ref->addr) { r_cons_printf ("%s 0x%" PFMT64x " [%s] %s\n", - buf_fcn, ref->addr, r_anal_ref_type_tostring (ref->type), str); + buf_fcn, ref->addr, r_anal_ref_type_tostring (ref->type), + disasm? disasm: asmop.mnemonic); if (*param->cmd_hit) { ut64 here = core->offset; r_core_seek (core, ref->addr, true); @@ -2411,21 +2410,21 @@ static void search_hit_at(RCore *core, struct search_parameters *param, RCoreAsm break; default: if (asm_sub_names) { - char tmp[128] = { 0 }; RAnalHint *hint = r_anal_hint_get (core->anal, hit->addr); - const bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->rasm->config); - r_asm_parse_filter (core->rasm, hit->addr, core->flags, hint, hit->code, tmp, sizeof (tmp), be); - r_anal_hint_free (hint); - if (param->outmode == R_MODE_SIMPLE) { - r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, tmp); - } else { - char *s = (hit->len > 0) - ? r_core_cmd_strf (core, "pDi %d @e:asm.flags=0@0x%08"PFMT64x, (int)hit->len, hit->addr) - : r_core_cmd_strf (core, "pdi 1 @e:asm.flags=0@0x%08"PFMT64x, hit->addr); - if (s) { - r_cons_printf ("%s", s); + char *tmp = r_asm_parse_filter (core->rasm, hit->addr, core->flags, hint, hit->code); + if (tmp) { + r_anal_hint_free (hint); + if (param->outmode == R_MODE_SIMPLE) { + r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, tmp); + } else { + char *s = (hit->len > 0) + ? r_core_cmd_strf (core, "pDi %d @e:asm.flags=0@0x%08"PFMT64x, (int)hit->len, hit->addr) + : r_core_cmd_strf (core, "pdi 1 @e:asm.flags=0@0x%08"PFMT64x, hit->addr); + if (s) { + r_cons_printf ("%s", s); + } + free (s); } - free (s); } } else { r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, r_str_get (hit->code)); diff --git a/libr/core/core.c b/libr/core/core.c index d5e4285a6ef19..b49c217deb6e6 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -2391,8 +2391,10 @@ R_API RFlagItem *r_core_flag_get_by_spaces(RFlag *f, bool prionospace, ut64 off) R_FLAGS_FS_STRINGS, R_FLAGS_FS_RESOURCES, R_FLAGS_FS_SYMBOLS_SECTIONS, +#if 1 R_FLAGS_FS_SECTIONS, R_FLAGS_FS_SEGMENTS, +#endif NULL); } diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 79a0ffa898ce1..390f31def9cbd 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -2,7 +2,7 @@ #define R_LOG_ORIGIN "disasm" -#include "r_core.h" +#include #include R_VEC_TYPE(RVecAnalRef, RAnalRef); @@ -80,7 +80,7 @@ static const char* r_vline_uc[] = { // imho this should be moved to RAsm typedef struct r_disasm_state_t { RCore *core; - char str[1024], strsub[1024]; + // char str[1024]; bool immtrim; bool immstr; bool use_esil; @@ -380,7 +380,7 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char * static void ds_print_ptr(RDisasmState *ds, int len, int idx); static void ds_print_demangled(RDisasmState *ds); static void ds_print_str(RDisasmState *ds, const char *str, int len, ut64 refaddr); -static char *ds_sub_jumps(RDisasmState *ds, char *str); +static char *ds_sub_jumps(RDisasmState *ds, const char *str); static void ds_start_line_highlight(RDisasmState *ds); static void ds_end_line_highlight(RDisasmState *ds); static bool line_highlighted(RDisasmState *ds); @@ -1156,11 +1156,10 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { core->rasm->parse->get_op_ireg = get_op_ireg; core->rasm->parse->get_ptr_at = get_ptr_at; core->rasm->parse->get_reg_at = get_reg_at; - r_asm_parse_subvar (core->rasm, f, at, ds->analop.size, - ds->opstr, ds->strsub, sizeof (ds->strsub)); - if (*ds->strsub) { + char *res = r_asm_parse_subvar (core->rasm, f, at, ds->analop.size, ds->opstr); + if (res) { free (ds->opstr); - ds->opstr = strdup (ds->strsub); + ds->opstr = res; } if (core->rasm->parse->subrel) { RVecAnalRef *refs = r_anal_refs_get (core->anal, at); @@ -1177,7 +1176,11 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { RVecAnalRef_free (refs); } } - ds->opstr = ds_sub_jumps (ds, ds->opstr); + char *res = ds_sub_jumps (ds, ds->opstr); + if (res) { + free (ds->opstr); + ds->opstr = res; + } if (ds->immtrim) { char *res = r_asm_parse_immtrim (core->rasm, ds->opstr); if (res) { @@ -1215,76 +1218,79 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { if (ds->pseudo) { char *res = r_asm_parse_pseudo (core->rasm, ds->opstr); if (res) { - r_str_ncpy (ds->str, res, sizeof (ds->str)); - R_LOG_DEBUG ("asm.parse.pseudo (%s) -> (%s)", ds->opstr, ds->str); - if (R_STR_ISNOTEMPTY (ds->str)) { - free (ds->opstr); - ds->opstr = strdup (ds->str); - } + free (ds->opstr); + ds->opstr = res; } } + bool isjmp = false; if (ds->subjmp) { - char *input = strdup (ds->opstr? ds->opstr: ds->str); - r_asm_parse_filter (core->rasm, ds->vat, core->flags, ds->hint, input, // asm_str, - ds->str, sizeof (ds->str), be); - free (input); - //ds->opstr = strdup (ds->str); - } else { - if (ds->opstr) { - r_str_ncpy (ds->str, ds->opstr, sizeof (ds->str)); + char *str = r_asm_parse_filter (core->rasm, ds->vat, core->flags, ds->hint, ds->opstr); + if (str) { + // isjmp = true; + free (ds->opstr); + ds->opstr = str; } } - // use 'str' from now on - // subvar depends on filter - if (ds->subvar) { - // HACK to do subvar outside rparse becacuse the whole rparse api must be rewritten - char *ox = strstr (ds->str, "0x"); + switch (ds->analop.type & R_ANAL_OP_TYPE_MASK) { + case R_ANAL_OP_TYPE_CJMP: + case R_ANAL_OP_TYPE_JMP: + isjmp = true; + break; + } + if (ds->subvar && !isjmp) { + // R2_600 - HACK to do subvar outside rparse becacuse the whole rparse api must be rewritten + char *ox = strstr (ds->opstr, "0x"); + if (ox && ox > ds->opstr) { + // if opcode contains "switch.0x" we wont replace it again "switch.switch.0x" + char *pox = ox - 1; + if (*pox == '.') { + ox = NULL; + } + } if (ox) { char *e = strchr (ox, ']'); if (!e) { e = strchr (ox, ','); if (!e) { e = strchr (ox, ')'); + if (!e) { + e = ""; + } } } - if (e) { - e = strdup (e); - ut64 addr = r_num_get (NULL, ox); - if (addr > ds->min_ref_addr) { - const RList *ls = r_flag_get_list (ds->core->flags, addr); - RFlagItem *fi; - RListIter *iter; - r_list_foreach (ls, iter, fi) { - if (fi->space && fi->space->name && (!strcmp (fi->space->name, "format") || !strcmp (fi->space->name, "segments") || !strcmp (fi->space->name, "sections"))) { - // ignore - } else { - const char *n = (fi->realname) ? fi->realname: fi->name; - if (strlen (n) > 3) { - r_str_cpy (ox, n); - r_str_cat (ox, e); - break; - } + e = strdup (e); + ut64 addr = r_num_get (NULL, ox); + if (addr > ds->min_ref_addr) { + const RList *ls = r_flag_get_list (ds->core->flags, addr); + RFlagItem *fi; + RListIter *iter; + r_list_foreach (ls, iter, fi) { + const char *fsname = R_UNWRAP3 (fi, space, name); + if (fsname && (!strcmp (fsname, "format") || !strcmp (fsname, "segments") || !strcmp (fsname, "sections"))) { + // ignore + } else { + const char *n = (core->flags->realnames) ? fi->realname? fi->realname: fi->name: fi->name; + if (strlen (n) > 3) { + char *opstrx = r_str_ndup (ds->opstr, ox - ds->opstr); + char *newox = r_str_newf ("%s%s%s", opstrx, n, e); + free (ds->opstr); + ds->opstr = newox; + free (opstrx); + break; } } } - free (e); } + free (e); } } core->rasm->parse->flagspace = ofs; - free (ds->opstr); - ds->opstr = strdup (ds->str); - __replaceImports (ds); - char *asm_str = colorize_asm_string (core, ds, print_color); - if (asm_str) { - free (ds->opstr); - ds->opstr = asm_str; - r_str_ncpy (ds->str, asm_str, sizeof (ds->str)); - } } else { r_str_trim (ds->opstr); // trim before coloring git - __replaceImports (ds); - char *asm_str = colorize_asm_string (core, ds, print_color); + } + __replaceImports (ds); + char *asm_str = colorize_asm_string (core, ds, print_color); + if (asm_str) { free (ds->opstr); ds->opstr = asm_str; } @@ -2927,9 +2933,9 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { } r_anal_op_fini (&ds->asmop); ret = r_asm_disassemble (core->rasm, &ds->asmop, buf, len); - if (len > ds->asmop.size) { - len = ds->asmop.size; - } + if (len > ds->asmop.size) { + len = ds->asmop.size; + } if (!ds->asmop.bytes) { // this happens only when the instruction is truncated r_anal_op_set_bytes (&ds->asmop, ds->at, buf, len); @@ -3068,15 +3074,11 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { } ds->oplen = ds->asmop.size; if (ds->pseudo) { - char *str = ds->opstr ? ds->opstr : ds->asmop.mnemonic; - if (!str) { - str = ds->str; - } + const char *str = ds->opstr ? ds->opstr : ds->asmop.mnemonic; char *res = r_asm_parse_pseudo (core->rasm, str); if (res) { - r_str_ncpy (ds->str, res, sizeof (ds->str)); free (ds->opstr); - ds->opstr = strdup (ds->str); + ds->opstr = strdup (res); } } if (ds->acase) { @@ -4772,7 +4774,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { bool aligned = false; int refptr = ds->analop.refptr; RFlagItem *f = NULL, *f2 = NULL; - bool f2_in_opstr = false; /* Also if true, f exists */ + bool f2_in_opstr = false; /* Also if true, f exists */ if (!ds->show_comments || !ds->show_slow) { return; } @@ -5122,7 +5124,7 @@ static void ds_print_relocs(RDisasmState *ds) { } RCore *core = ds->core; // const char *lang = r_config_get (core->config, "bin.lang"); - bool demangle = r_config_get_i (core->config, "asm.demangle"); + const bool demangle = r_config_get_i (core->config, "asm.demangle"); // bool keep_lib = r_config_get_i (core->config, "bin.demangle.pfxlib"); RBinReloc *rel = r_core_getreloc (core, ds->at, ds->analop.size); #if 0 @@ -5644,7 +5646,7 @@ static bool can_emulate_metadata(RCore *core, ut64 at) { static void mipsTweak(RDisasmState *ds) { RCore *core = ds->core; const char *asm_arch = r_config_get (core->config, "asm.arch"); - if (asm_arch && *asm_arch && strstr (asm_arch, "mips")) { + if (r_str_startswith (asm_arch, "mips")) { if (r_config_get_b (core->config, "anal.fixed.gp")) { ut64 gp = r_config_get_i (core->config, "anal.gp"); r_reg_setv (core->anal->reg, "gp", gp); @@ -6129,7 +6131,9 @@ static char *_find_next_number(char *op) { return NULL; } +#if 0 static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, const char **name) { +return true; RFlag *f = ds->core->flags; if (!f) { return false; @@ -6138,7 +6142,7 @@ static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, cons // nothing to do, neither demangled nor regular realnames should be shown return false; } - RFlagItem *flag_sym = r_flag_get_by_spaces (f, false, addr, R_FLAGS_FS_SYMBOLS, NULL); + RFlagItem *flag_sym = r_flag_get_by_spaces (f, true, addr, R_FLAGS_FS_SYMBOLS, NULL); if (!flag_sym || !flag_sym->realname) { // nothing to replace return false; @@ -6150,78 +6154,135 @@ static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, cons *name = flag_sym->realname; RFlagItem *flag_mthd = r_flag_get_by_spaces (f, false, addr, R_FLAGS_FS_CLASSES, NULL); if (!f->realnames) { +#if 1 // for asm.flags.real, we don't want these prefixes if (flag_mthd && flag_mthd->name && r_str_startswith (flag_mthd->name, "method.")) { - *kw = "method "; + *kw = "method,"; } else { - *kw = "sym "; + *kw = "sym,"; } +#endif } return true; } +#endif -// TODO: this should be moved into r_parse -static char *ds_sub_jumps(RDisasmState *ds, char *str) { +// R2_600 - TODO: this should be moved into r_parse +static char *ds_sub_jumps(RDisasmState *ds, const char *str) { RAnal *anal = ds->core->anal; RFlag *f = ds->core->flags; + const char* arch = r_config_get (ds->core->config, "asm.arch"); + const bool x86 = r_str_startswith (arch, "x86"); const char *name = NULL; const char *kw = ""; if (!ds->subjmp || !anal) { - return str; + return NULL; } - int optype = ds->analop.type & 0xFFFF; + ut64 addr = ds->analop.jump; +#if 1 + int optype = ds->analop.type & R_ANAL_OP_TYPE_MASK; switch (optype) { + case R_ANAL_OP_TYPE_LEA: + if (x86) { + // let the pseudo plugin trim the '[]' + return NULL; + } + // for ARM adrp, section is better than adrp, segment + break; case R_ANAL_OP_TYPE_JMP: - case R_ANAL_OP_TYPE_UJMP: + case R_ANAL_OP_TYPE_CJMP: + case R_ANAL_OP_TYPE_MOV: + case R_ANAL_OP_TYPE_MJMP: + break; + case R_ANAL_OP_TYPE_PUSH: + addr = ds->analop.val; + if (addr < 10) { + // ignore push 0 + return NULL; + } + break; case R_ANAL_OP_TYPE_CALL: + case R_ANAL_OP_TYPE_UJMP: + case R_ANAL_OP_TYPE_UCALL: break; + // return NULL; default: - return str; + return NULL; + } +#endif + RBinReloc *rel = NULL; + RBinObject *bo = r_bin_cur_object (ds->core->bin); + if (bo && !bo->is_reloc_patched) { + rel = r_core_getreloc (ds->core, ds->analop.addr, ds->analop.size); + } + if (!rel) { + rel = r_core_getreloc (ds->core, addr, ds->analop.size); + if (!rel) { + // some jmp 0 are actually relocs, so we can just ignore it + if (!addr || addr == UT64_MAX) { + rel = r_core_getreloc (ds->core, ds->analop.ptr, ds->analop.size); + if (rel) { + addr = ds->analop.ptr; + } + } + } + } + if (addr == UT64_MAX) { + if (rel) { + addr = 0; + } else { + addr = ds->analop.ptr; + } } - ut64 addr = ds->analop.jump; - RAnalFunction *fcn = r_anal_get_function_at (anal, addr); if (fcn) { - if (!set_jump_realname (ds, addr, &kw, &name)) { + // if (!set_jump_realname (ds, addr, &kw, &name)) { name = fcn->name; - } - } else if (f) { - RBinReloc *rel = NULL; - RBinObject *bo = r_bin_cur_object (ds->core->bin); - if (bo && !bo->is_reloc_patched) { - rel = r_core_getreloc (ds->core, ds->analop.addr, ds->analop.size); - } - if (!rel) { - rel = r_core_getreloc (ds->core, addr, ds->analop.size); - } + // } + } else { if (rel) { if (rel && rel->import && rel->import->name) { name = r_bin_name_tostring (rel->import->name); } else if (rel && rel->symbol && rel->symbol->name) { name = r_bin_name_tostring (rel->symbol->name); } - } else { - if (!set_jump_realname (ds, addr, &kw, &name)) { + if (addr) { // && *name == '.') { RFlagItem *flag = r_core_flag_get_by_spaces (f, false, addr); - if (flag && strchr (flag->name, '.')) { - name = flag->name; - if (f->realnames && flag->realname) { - name = flag->realname; + if (flag) { + if (!r_str_startswith (flag->name, "section")) { + name = flag->name; + if (f->realnames && flag->realname) { + name = flag->realname; + } } } } + } else { + + // if (!set_jump_realname (ds, addr, &kw, &name)) { + RFlagItem *flag = r_core_flag_get_by_spaces (f, false, addr); + if (flag) { + // R2R db/anal/jmptbl + // adrp x0, segment.DATA //instead-of// adrp x0, section.20.__DATA.__objc_const + if (!r_str_startswith (flag->name, "section")) { + name = flag->name; + if (f->realnames && flag->realname) { + name = flag->realname; + } + } + } + // } } } if (name) { - char *nptr, *ptr; + char *nptr; ut64 numval; - ptr = str; + char *hstr = strdup (str); + char *ptr = hstr; + const int bits = ds->core->rasm->config->bits; + const int seggrn = ds->core->rasm->config->seggrn; while ((nptr = _find_next_number (ptr))) { ptr = nptr; - const char* arch = r_config_get (ds->core->config, "asm.arch"); - const bool x86 = !strncmp (arch, "x86", 3); - const int bits = ds->core->rasm->config->bits; - const int seggrn = ds->core->rasm->config->seggrn; char* colon = strchr (ptr, ':'); if (x86 && bits == 16 && colon) { *colon = '\0'; @@ -6238,9 +6299,9 @@ static char *ds_sub_jumps(RDisasmState *ds, char *str) { } char *kwname = r_str_newf ("%s%s", kw, name); if (kwname) { - char* numstr = r_str_ndup (ptr, nptr-ptr); + char* numstr = r_str_ndup (ptr, nptr - ptr); if (numstr) { - str = r_str_replace (str, numstr, kwname, 0); + hstr = r_str_replace (hstr, numstr, kwname, 0); free (numstr); } free (kwname); @@ -6248,8 +6309,9 @@ static char *ds_sub_jumps(RDisasmState *ds, char *str) { break; } } + return hstr; } - return str; + return NULL; } static bool line_highlighted(RDisasmState *ds) { @@ -6285,7 +6347,6 @@ R_API int r_core_print_disasm(RCore *core, ut64 addr, ut8 *buf, int len, int cou bool pdu_condition_met = false; char *opstr_nocolor = NULL; int opcode_len = -1; - //const char *pdu_condition_esil = NULL; const char *pdu_condition_instruction = NULL; const char *pdu_condition_opcode = NULL; @@ -7121,9 +7182,6 @@ R_API int r_core_print_disasm_instructions_with_buf(RCore *core, ut64 address, u if (oret < 1) { free (ds->opstr); ds->opstr = strdup (ds->analop.mnemonic); - } else { - free (ds->opstr); - ds->opstr = strdup (ds->str); } asm_str = colorize_asm_string (core, ds, true); if (asm_str) { @@ -7253,7 +7311,6 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ ut64 at; int dis_opcodes = 0; int limit_by = 'b'; - char str[512]; const char *pdu_condition_opcode = pdu_condition ? (const char *)pdu_condition : ""; int opcode_len = strlen (pdu_condition_opcode); @@ -7377,8 +7434,7 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ continue; } - char opstr[256]; - r_str_ncpy (opstr, asmop.mnemonic, sizeof (opstr) - 1); + char *opstr = strdup (asmop.mnemonic); core->rasm->pseudo = opseudo; ds->has_description = false; @@ -7388,22 +7444,18 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ if (ds->pseudo) { char *res = r_asm_parse_pseudo (core->rasm, opstr); if (res) { - r_str_ncpy (opstr, res, sizeof (opstr)); - free (res); + free (opstr); + opstr = res; } } // f = r_anal_get_fcn_in (core->anal, at, f = fcnIn (ds, at, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM | R_ANAL_FCN_TYPE_LOC); if (ds->subvar && f) { - int ba_len = strlen (asmop.mnemonic) + 128; - char *ba = malloc (ba_len); - if (ba) { - strcpy (ba, asmop.mnemonic); - r_asm_parse_subvar (core->rasm, f, at, ds->analop.size, - ba, ba, ba_len); - r_asm_op_set_asm (&asmop, ba); - free (ba); + char *res = r_asm_parse_subvar (core->rasm, f, at, ds->analop.size, asmop.mnemonic); + if (res) { + r_asm_op_set_asm (&asmop, res); + free (res); } } ds->oplen = r_asm_op_get_size (&asmop); @@ -7424,17 +7476,18 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ core->rasm->parse->subrel_addr = killme; } } + char *disasm = strdup (asmop.mnemonic); { - const char *aop = asmop.mnemonic; - char *buf = malloc (strlen (aop) + 128); + char *buf = ds_sub_jumps (ds, disasm); if (buf) { - strcpy (buf, aop); - buf = ds_sub_jumps (ds, buf); - r_asm_parse_filter (core->rasm, ds->vat, core->flags, ds->hint, buf, - str, sizeof (str) - 1, be); - str[sizeof (str) - 1] = '\0'; - r_asm_op_set_asm (&asmop, buf); - free (buf); + free (disasm); + disasm = buf; + } + char *res = r_asm_parse_filter (core->rasm, ds->vat, core->flags, ds->hint, disasm); + if (res) { + r_asm_op_set_asm (&asmop, res); + free (disasm); + disasm = res; } } @@ -7453,7 +7506,8 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ pj_kn (pj, "fcn_last", f ? r_anal_function_max_addr (f) - ds->oplen : 0); pj_ki (pj, "size", ds->analop.size); pj_ks (pj, "opcode", opstr); - pj_ks (pj, "disasm", str); + pj_ks (pj, "disasm", disasm); + free (disasm); { char *hex = r_asm_op_get_hex (&asmop); pj_ks (pj, "bytes", hex); @@ -7582,6 +7636,7 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ if (end_nbopcodes || end_nbbytes || end_pdu_condition) { break; } + free (opstr); } r_cons_break_pop (); r_anal_op_fini (&ds->analop); @@ -7595,16 +7650,10 @@ R_IPI int r_core_print_disasm_json_ipi(RCore *core, ut64 addr, ut8 *buf, int nb_ return result; } -// XXX R2_600 this is just a stupid wrapper that must be eliminated -R_IPI int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_bytes, int nb_opcodes, PJ *pj) { - return r_core_print_disasm_json_ipi (core, addr, buf, nb_bytes, nb_opcodes, pj, NULL); -} - R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mode) { const bool scr_color = r_config_get_i (core->config, "scr.color") > 0; int i, ret, count = 0; ut8 *buf = core->block; - char str[128]; if (l < 1) { l = len; } @@ -7626,7 +7675,6 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo } pj_a (pj); } - const bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->rasm->config); int minopsz = r_anal_archinfo (core->anal, R_ARCH_INFO_MINOP_SIZE); int opalign = r_anal_archinfo (core->anal, R_ARCH_INFO_CODE_ALIGN); r_cons_break_push (NULL, NULL); @@ -7673,20 +7721,23 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo count ++; switch (mode) { case 'i': - r_asm_parse_filter (core->rasm, ds->vat, core->flags, ds->hint, asmop.mnemonic, - str, sizeof (str), be); - if (scr_color) { - RAnalOp aop; - RAnalFunction *f = fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL); - r_anal_op (core->anal, &aop, addr, buf + i, l - i, R_ARCH_OP_MASK_ALL); - char *buf_asm = r_print_colorize_opcode (core->print, str, - core->cons->context->pal.reg, core->cons->context->pal.num, false, f ? f->addr : 0); - if (buf_asm) { - r_cons_printf ("%s%s\n", r_print_color_op_type (core->print, aop.type), buf_asm); - free (buf_asm); + { + char *res = r_asm_parse_filter (core->rasm, ds->vat, core->flags, ds->hint, asmop.mnemonic); + + if (scr_color) { + RAnalOp aop; + RAnalFunction *f = fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL); + r_anal_op (core->anal, &aop, addr, buf + i, l - i, R_ARCH_OP_MASK_ALL); + char *buf_asm = r_print_colorize_opcode (core->print, res? res: asmop.mnemonic, + core->cons->context->pal.reg, core->cons->context->pal.num, false, f ? f->addr : 0); + if (buf_asm) { + r_cons_printf ("%s%s\n", r_print_color_op_type (core->print, aop.type), buf_asm); + free (buf_asm); + } + } else { + r_cons_println (asmop.mnemonic); } - } else { - r_cons_println (asmop.mnemonic); + free (res); } break; case '=': @@ -7862,8 +7913,7 @@ R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 n } } r_asm_set_pc (core->rasm, addr + i); - ret = r_asm_disassemble (core->rasm, &asmop, buf + addrbytes * i, - nb_bytes - addrbytes * i); + ret = r_asm_disassemble (core->rasm, &asmop, buf + addrbytes * i, nb_bytes - addrbytes * i); ret = asmop.size; if (midflags || midbb) { RDisasmState ds = { @@ -7945,10 +7995,7 @@ R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 n } free (tmpopstr); } else { - char opstr[128] = { - 0 - }; - char *asm_str = asmop.mnemonic; + char *asm_str = strdup (asmop.mnemonic); if (asm_ucase) { r_str_case (asm_str, 1); } @@ -7960,24 +8007,25 @@ R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 n } } if (subnames) { - const bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->rasm->config); RAnalHint *hint = r_anal_hint_get (core->anal, at); - r_asm_parse_filter (core->rasm, at, core->flags, hint, - asm_str, opstr, sizeof (opstr) - 1, be); + char *res = r_asm_parse_filter (core->rasm, at, core->flags, hint, asm_str); + if (res) { + free (asm_str); + asm_str = res; + } r_anal_hint_free (hint); - asm_str = (char *)&opstr; } if (show_color) { - RAnalOp aop = { - 0 - }; + RAnalOp aop = { 0 }; RAnalFunction *f = r_anal_get_fcn_in (core->anal, addr + i, R_ANAL_FCN_TYPE_NULL); + r_anal_op_init (&aop); r_anal_op (core->anal, &aop, addr + i, buf + addrbytes * i, nb_bytes - addrbytes * i, R_ARCH_OP_MASK_BASIC); asm_str = r_print_colorize_opcode (core->print, asm_str, color_reg, color_num, false, f ? f->addr : 0); r_cons_printf ("%s%s"Color_RESET "\n", r_print_color_op_type (core->print, aop.type), asm_str); + r_anal_op_fini (&aop); free (asm_str); } else { r_cons_println (asm_str); diff --git a/libr/include/r_anal/op.h b/libr/include/r_anal/op.h index b22cf4843b185..c51a8c09dbfba 100644 --- a/libr/include/r_anal/op.h +++ b/libr/include/r_anal/op.h @@ -78,7 +78,7 @@ On x86 according to Wikipedia #define R_ANAL_OP_HINT_MASK 0xf0000000 typedef enum { - // R2_590 - DEPRECATE + // R2_600 - DEPRECATE R_ANAL_OP_TYPE_COND = 0x80000000, // TODO must be moved to prefix? // should not be TYPE those are modifiers! R_ANAL_OP_TYPE_REP = 0x40000000, /* repeats next instruction N times */ R_ANAL_OP_TYPE_MEM = 0x20000000, // TODO must be moved to prefix? diff --git a/libr/include/r_asm.h b/libr/include/r_asm.h index c9dc3ec630662..14a0f2d9d4be9 100644 --- a/libr/include/r_asm.h +++ b/libr/include/r_asm.h @@ -88,8 +88,8 @@ typedef struct r_asm_plugin_session_t { typedef void (*RAsmParseInit)(RAsmPluginSession *s); typedef void (*RAsmParseFini)(RAsmPluginSession *s); typedef bool (*RAsmParsePseudo)(RAsmPluginSession *s, const char *data, char *str); -typedef int (*RAsmParseFilter)(RAsmPluginSession *s, ut64 addr, RFlag *f, char *data, char *str, int len, bool big_endian); -typedef bool (*RAsmParseSubvar)(RAsmPluginSession *s, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len); +typedef char *(*RAsmParseFilter)(RAsmPluginSession *s, ut64 addr, RFlag *f, const char *data); +typedef char *(*RAsmParseSubvar)(RAsmPluginSession *s, RAnalFunction *f, ut64 addr, int oplen, const char *data); typedef char *(*RAsmParsePatch)(RAsmPluginSession *s, RAnalOp *aop, const char *newop); typedef struct r_asm_plugin_t { @@ -109,8 +109,8 @@ R_API RParse *r_parse_new(void); R_API void r_parse_free(RParse *p); R_API char *r_asm_parse_pseudo(RAsm *a, const char *data); -R_API bool r_asm_parse_filter(RAsm *a, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian); -R_API bool r_asm_parse_subvar(RAsm *a, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len); +R_API char *r_asm_parse_filter(RAsm *a, ut64 addr, RFlag *f, RAnalHint *hint, const char *data); +R_API char *r_asm_parse_subvar(RAsm *a, RAnalFunction *f, ut64 addr, int oplen, const char *data); R_API char *r_asm_parse_immtrim(RAsm *a, const char *opstr); R_API char *r_asm_parse_patch(RAsm *a, RAnalOp *aop, const char *newop); diff --git a/test/db/anal/arm-esil b/test/db/anal/arm-esil index a6ded942c5954..5ac776473e598 100644 --- a/test/db/anal/arm-esil +++ b/test/db/anal/arm-esil @@ -48,7 +48,7 @@ s 0x00001373 axt EOF EXPECT=< ().Sgvg ; sym.imp.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______.Sgvg +0x1000042a8 bl sym.imp.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______.Sgvg ; Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer -> ().Sgvg 0x1000042ac cbz x0, 0x1000044a0 | // true: 0x1000044a0 false: 0x1000042b0 0x1000042b0 mov x19, x0 -0x1000042b4 bl sym getter Foundation.__DataStorage._offset.allocator__Swift.Int -> (): allocator_offsetallocatorS...vg ; sym.imp.getter_Foundation.__DataStorage._offset.allocator__Swift.Int______:_allocator_offsetallocatorS...vg +0x1000042b4 bl sym.imp.getter_Foundation.__DataStorage._offset.allocator__Swift.Int______:_allocator_offsetallocatorS...vg ; getter Foundation.__DataStorage._offset.allocator__Swift.Int -> (): allocator_offsetallocatorS...vg 0x1000042b8 subs x8, x23, x0 0x1000042bc b.vc 0x100004378 | // true: 0x100004378 false: 0x1000042c0 @@ -318,11 +318,11 @@ EXPECT=< ().Sgvg ; sym.imp.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______.Sgvg +0x100004360 bl sym.imp.Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer______.Sgvg ; Foundation.__DataStorage._bytes.allocator__UnsafeMutableRawPointer -> ().Sgvg 0x100004364 cbz x0, 0x1000044a4 | // true: 0x1000044a4 false: 0x100004368 0x100004368 mov x19, x0 -0x10000436c bl sym getter Foundation.__DataStorage._offset.allocator__Swift.Int -> (): allocator_offsetallocatorS...vg ; sym.imp.getter_Foundation.__DataStorage._offset.allocator__Swift.Int______:_allocator_offsetallocatorS...vg +0x10000436c bl sym.imp.getter_Foundation.__DataStorage._offset.allocator__Swift.Int______:_allocator_offsetallocatorS...vg ; getter Foundation.__DataStorage._offset.allocator__Swift.Int -> (): allocator_offsetallocatorS...vg 0x100004370 subs x8, x23, x0 0x100004374 b.vs 0x100004490 | // true: 0x100004490 false: 0x100004378 @@ -350,7 +350,7 @@ EXPECT=< /dev/null aac 2> /dev/null s 0x0000f190 -agfj~reloc.free +agfj~free EOF EXPECT=< \\u00a2\\u20ac\\U00010348 in yellow:.[33m ......... .[0m\n" - 0x00401693 mov edi, 0x4021ff ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:.[33m ... .[0m." + 0x00401693 mov edi, str.utf8__u00a2u20acU00010348_in_yellow:e_33m__e_0m_n ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:.[33m ......... .[0m\n" + 0x00401693 mov edi, str.utf8__u00a2u20acU00010348_in_yellow:e_33m__e_0m_n ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:.[33m ... .[0m." 0x004016ac mov edi, 0x40224a ; 'J\"@' ; u"utf16le> \\u00a2\\u20ac\\U00010348 in green:.[32m ... .[0m." - 0x004016ed mov edi, 0x40258c ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:.[36m ... .[0m." - 0x004016f7 mov edi, 0x40266c ; U"Mountain range with embedded quad zeros: .A.A.A." + 0x004016ed mov edi, str.utf32le__u00a2u20acU00010348_in_cyan:e_36m__e_0m_n ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:.[36m ... .[0m." + 0x004016f7 mov edi, str.Mountain_range_with_embedded_quad_zeros:_AAA_n ; U"Mountain range with embedded quad zeros: .A.A.A." EOF RUN @@ -903,9 +903,9 @@ e bin.str.enc=guess pd 1 @ 0x00401693 EOF EXPECT=< \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \u00a2\u20ac\U00010348 \x1b[0m\n" - 0x00401693 mov edi, 0x4021ff ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \xc2\xa2\xe2\x82\xac\xf0\x90\x8d\x88 \x1b[0m\n" - 0x00401693 mov edi, 0x4021ff ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \u00a2\u20ac\U00010348 \x1b[0m\n" + 0x00401693 mov edi, str.utf8__u00a2u20acU00010348_in_yellow:e_33m__e_0m_n ; 0x4021ff ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \u00a2\u20ac\U00010348 \x1b[0m\n" + 0x00401693 mov edi, str.utf8__u00a2u20acU00010348_in_yellow:e_33m__e_0m_n ; 0x4021ff ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \xc2\xa2\xe2\x82\xac\xf0\x90\x8d\x88 \x1b[0m\n" + 0x00401693 mov edi, str.utf8__u00a2u20acU00010348_in_yellow:e_33m__e_0m_n ; 0x4021ff ; "utf8> \\u00a2\\u20ac\\U00010348 in yellow:\x1b[33m \u00a2\u20ac\U00010348 \x1b[0m\n" EOF RUN @@ -980,8 +980,8 @@ EOF EXPECT=< \\u00a2\\u20ac\\U00010348 in cyan:\x1b[36m \xa2\u20ac\U00010348 \x1b[0m\n" - 0x004016f7 mov edi, 0x40266c ; U"Mountain range with embedded quad zeros: \U00010300A\U00010300A\U00010300A\n" + 0x004016ed mov edi, str.utf32le__u00a2u20acU00010348_in_cyan:e_36m__e_0m_n ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:\x1b[36m \xa2\u20ac\U00010348 \x1b[0m\n" + 0x004016f7 mov edi, str.Mountain_range_with_embedded_quad_zeros:_AAA_n ; U"Mountain range with embedded quad zeros: \U00010300A\U00010300A\U00010300A\n" 0x00401701 mov edi, 0x402730 ; '0\'@' ; "e%" 0x00401701 mov edi, 0x402730 ; '0\'@' ; U"\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u2565\u256b\u2565\u2565\u2565\u2565\u2565\u2565\u2565" EOF @@ -1042,9 +1042,9 @@ EXPECT=< \\u00a2\\u20ac\\U00010348 in cyan:\x1b[36m \xa2\u20ac\U00010348 \x1b[0m\n" + 0x004016ed mov edi, str.utf32le__u00a2u20acU00010348_in_cyan:e_36m__e_0m_n ; U"utf32le> \\u00a2\\u20ac\\U00010348 in cyan:\x1b[36m \xa2\u20ac\U00010348 \x1b[0m\n" utf32be utf16le @@ -1123,12 +1123,14 @@ RUN NAME=fcn name cmt alignment FILE=bins/pe/ConsoleApplication1.exe CMDS=< 0x00402018 6a00 push 0 | : 0x0040201a 680e104000 push "LABEL" ; 0x40100e | : 0x0040201f 6800104000 push "Hello, World!" ; section..data diff --git a/test/db/cmd/cmd_pde b/test/db/cmd/cmd_pde index 9dbf19fcea230..ed316eb7085ae 100644 --- a/test/db/cmd/cmd_pde +++ b/test/db/cmd/cmd_pde @@ -160,7 +160,7 @@ EXPECT=< +| 0x000057fb e8501b0000 call dbg.new<[i32; 10]> ; core::fmt::ArgumentV1::new::h4b3dd9450748c5fc | 0x00005800 4889442470 mov qword [var_70h], rax | 0x00005805 4889542468 mov qword [var_68h], rdx | 0x0000580a 488b442470 mov rax, qword [var_70h] @@ -332,13 +332,13 @@ EXPECT=< +| 0x00005875 e8f6f9ffff call dbg.bubble_sort ; rust::bubble_sort::h0777bc845caabc60 | 0x0000587a 488b05f72a.. mov rax, qword [0x00038378] ; [0x38378:8]=0x38358 | 0x00005881 488d8c2480.. lea rcx, [numbers] | 0x00005889 48898c2430.. mov qword [var_130h], rcx @@ -347,7 +347,7 @@ EXPECT=< +| 0x000058b0 e89b1a0000 call dbg.new<[i32; 10]> ; core::fmt::ArgumentV1::new::h4b3dd9450748c5fc | 0x000058b5 4889442450 mov qword [var_50h], rax | 0x000058ba 4889542448 mov qword [var_48h], rdx | 0x000058bf 488b442450 mov rax, qword [var_50h] @@ -362,7 +362,7 @@ EXPECT=<::len::hbaf7153778228b73 ; dbg.len +| 0x00005291 e8ea090000 call dbg.len ; core::slice::_::len::hbaf7153778228b73 | 0x00005296 4889442450 mov qword [n], rax | 0x0000529b c644245f01 mov byte [swapped], 1 | ; CODE XREF from rust::bubble_sort::h0777bc845caabc60 @ 0x5441(x) @@ -434,7 +434,7 @@ EXPECT=<::into_iter::h12f1e7995fb38cf5 ; dbg.into_iter> +| 0x000052d1 e83a140000 call dbg.into_iter> ; _::into_iter::h12f1e7995fb38cf5 | 0x000052d6 4889442438 mov qword [var_38h], rax | 0x000052db 4889542430 mov qword [var_30h], rdx | 0x000052e0 488b442438 mov rax, qword [var_38h] @@ -443,7 +443,7 @@ EXPECT=<>::next::h707e8283b20ce50a ; dbg.next +| 0x000052f9 e812130000 call dbg.next ; core::iter::range::_>::next::h707e8283b20ce50a | 0x000052fe 4889942488.. mov qword [var_88h], rdx | 0x00005306 4889842480.. mov qword [var_80h], rax | 0x0000530e 488b842480.. mov rax, qword [var_80h] @@ -621,7 +621,7 @@ EXPECT=<::QFlags(int QFlags::Private::*) ; method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_ - 0x08049278 call sym QLabel::QLabel(QString const&, QWidget*, QFlags) ; sym.imp.QLabel::QLabel_QString_const__QWidget__QFlags_Qt::WindowType__ + 0x08049249 call method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_ ; QFlags::QFlags(int QFlags::Private::*) + 0x08049278 call sym.imp.QLabel::QLabel_QString_const__QWidget__QFlags_Qt::WindowType__ ; QLabel::QLabel(QString const&, QWidget*, QFlags) 0x0804921a call sym.__x86.get_pc_thunk.si - ; method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_ - 0x08049249 call method QFlags::QFlags(int QFlags::Private::*) - ; sym.imp.QLabel::QLabel_QString_const__QWidget__QFlags_Qt::WindowType__ - 0x08049278 call sym QLabel::QLabel(QString const&, QWidget*, QFlags) + ; QFlags::QFlags(int QFlags::Private::*) + 0x08049249 call method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_ + ; QLabel::QLabel(QString const&, QWidget*, QFlags) + 0x08049278 call sym.imp.QLabel::QLabel_QString_const__QWidget__QFlags_Qt::WindowType__ | 0x0804921a call sym.__x86.get_pc_thunk.si -| 0x08049249 call method QFlags::QFlags(int QFlags::Private::*) ; method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_ -| 0x08049278 call sym QLabel::QLabel(QString const&, QWidget*, QFlags) ; sym.imp.QLabel::QLabel_QString_const__QWidget__QFlags_Qt::WindowType__ +| 0x08049249 call method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_ ; QFlags::QFlags(int QFlags::Private::*) +| 0x08049278 call sym.imp.QLabel::QLabel_QString_const__QWidget__QFlags_Qt::WindowType__ ; QLabel::QLabel(QString const&, QWidget*, QFlags) | 0x0804921a call sym.__x86.get_pc_thunk.si | 0x08049249 call method.QFlags_Qt::WindowType_.QFlags_int_QFlags_Qt::WindowType_::Private::_