From 9968329d49ee1a21f1c64865880b980a8ded83e4 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 30 Sep 2024 23:39:02 +0200 Subject: [PATCH] Use asm.var.summary=4 by default ##disasm --- doc/fortunes.tips | 1 + libr/arch/arch.c | 2 +- libr/core/cconfig.c | 2 +- libr/core/disasm.c | 24 ++++++++++++------- libr/lang/p/qjs/arch.c | 4 +++- test/db/anal/arm | 24 ++++++++++++++++++- test/db/anal/arm64-crypto | 2 +- test/db/anal/calls | 3 +++ test/db/anal/emu | 2 ++ test/db/anal/jmptbl | 43 ++--------------------------------- test/db/anal/mach0 | 1 + test/db/anal/mips | 27 ++++++++-------------- test/db/anal/sparc | 1 + test/db/anal/types | 1 + test/db/anal/vars | 11 +++++---- test/db/anal/x86_16 | 3 +-- test/db/anal/x86_32 | 8 ++++++- test/db/anal/x86_64 | 16 ++++++++++--- test/db/cmd/cmd_af | 9 +------- test/db/cmd/cmd_graph | 1 + test/db/cmd/cmd_meta | 2 +- test/db/cmd/cmd_pd | 12 +++++++--- test/db/cmd/cmd_pd2 | 2 ++ test/db/cmd/cmd_pd_bugs | 1 + test/db/cmd/cmd_px | 2 +- test/db/cmd/cmd_traces | 1 + test/db/cmd/dwarf | 8 ++++++- test/db/cmd/noreturn | 2 +- test/db/cmd/types | 5 ++++ test/db/formats/elf/elf-relro | 4 ++-- test/db/formats/elf/random | 2 ++ test/db/formats/elf/riscv | 3 +++ 32 files changed, 129 insertions(+), 100 deletions(-) diff --git a/doc/fortunes.tips b/doc/fortunes.tips index cc09a5e4a6..6dc1376430 100644 --- a/doc/fortunes.tips +++ b/doc/fortunes.tips @@ -86,3 +86,4 @@ You can use registers in math expressions. For example: 'wx 1234 @ esp - 2' For HTTP authentication 'e http.auth = 1', 'e http.authfile = ' Tip: do 'r2pm -i r2premium; echo "e cfg.fortunes.type = nsfw" >> ~/.radare2rc' for a premium r2 experience Use the `:` command To run the io plugin cmd callback, many io plugins provide useful features, find them out! +Change asm.var.summary variable to 0 to display all local variables and argument types and names diff --git a/libr/arch/arch.c b/libr/arch/arch.c index 16d89389f2..ff36761121 100644 --- a/libr/arch/arch.c +++ b/libr/arch/arch.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2022-2023 - pancake, condret */ +/* radare - LGPL - Copyright 2022-2024 - pancake, condret */ #include #include diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index f12db6462f..0dbaa7b403 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -3781,7 +3781,7 @@ R_API int r_core_config_init(RCore *core) { SETBPREF ("asm.var", "true", "show local function variables in disassembly"); SETBPREF ("asm.var.access", "false", "show accesses of local variables"); SETBPREF ("asm.sub.var", "true", "substitute variables in disassembly"); - SETICB ("asm.var.summary", 0, &cb_asm_var_summary, "show variables summary instead of full list in disasm (0, 1, 2)"); + SETICB ("asm.var.summary", 4, &cb_asm_var_summary, "show variables summary instead of full list in disasm (0, 1, 2, 3, 4)"); SETBPREF ("asm.sub.varonly", "true", "substitute the entire variable expression with the local variable name (e.g. [local10h] instead of [ebp+local10h])"); SETBPREF ("asm.sub.reg", "false", "substitute register names with their associated role name (drp~=)"); SETBPREF ("asm.sub.rel", "true", "substitute pc relative expressions in disasm"); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index ab000f9561..37d5b361b3 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -1931,11 +1931,14 @@ static void print_var_summary(RDisasmState *ds, RList *list) { if (sp_args) { sp_args_color = numColor; } if (rg_args) { rg_args_color = numColor; } if (ds->show_varsum == 4) { - ds_begin_line (ds); - ds_print_pre (ds, true); int total_args = bp_args + sp_args + rg_args; + int total_vars = bp_vars + sp_vars + rg_vars; + if (total_args > 0 || total_vars > 0) { + ds_begin_line (ds); + ds_print_pre (ds, true); + } if (total_args > 0) { - r_cons_printf ("afv: args("); + r_cons_printf ("`- args("); const char *comma = ""; int minsprange = ST32_MAX; int maxsprange = 0; @@ -1958,9 +1961,12 @@ static void print_var_summary(RDisasmState *ds, RList *list) { if (maxsprange > 0) { r_cons_printf ("%ssp[0x%x..0x%x]", comma, minsprange, maxsprange); } - r_cons_printf (") "); + if (total_vars > 0) { + r_cons_printf (") "); + } else { + r_cons_printf (")"); + } } - int total_vars = bp_vars + sp_vars + rg_vars; if (total_vars > 0) { if (total_args < 1) { r_cons_printf ("afv: "); @@ -1986,11 +1992,13 @@ static void print_var_summary(RDisasmState *ds, RList *list) { } } if (maxsprange > 0) { - r_cons_printf ("%ssp[0x%x..0x%x]", comma, minsprange, maxsprange); + r_cons_printf ("%s%d:sp[0x%x..0x%x]", comma, total_vars, minsprange, maxsprange); } r_cons_printf (")"); } - ds_newline (ds); + if (total_args > 0 || total_vars > 0) { + ds_newline (ds); + } return; } if (ds->show_varsum == 3) { @@ -3572,7 +3580,7 @@ static bool ds_print_data_type(RDisasmState *ds, const ut8 *obuf, int ib, int si if (size == 4 || size == 8) { if (r_str_startswith (r_config_get (core->config, "asm.arch"), "arm")) { ut64 bits = r_config_get_i (core->config, "asm.bits"); - //adjust address for arm/thumb address + // adjust address for arm/thumb address if ((bits < 64) && (n & 1)) { n--; } diff --git a/libr/lang/p/qjs/arch.c b/libr/lang/p/qjs/arch.c index 92f72c8d3c..ec3295ad66 100644 --- a/libr/lang/p/qjs/arch.c +++ b/libr/lang/p/qjs/arch.c @@ -90,7 +90,9 @@ static bool r2qjs_arch_init(RArchSession *s) { } static bool r2qjs_arch_fini(RArchSession *s) { - R_RETURN_VAL_IF_FAIL (s, false); + if (s == NULL) { + return false; + } RCore *core = s->user; QjsPluginManager *pm = R_UNWRAP4 (core, lang, session, plugin_data); diff --git a/test/db/anal/arm b/test/db/anal/arm index 4effcaa27b..8eb875bb72 100644 --- a/test/db/anal/arm +++ b/test/db/anal/arm @@ -320,7 +320,7 @@ EOF EXPECT=<dH\x8b\x04%(" \ 0x00005b08 ff150ac30100 call qword [reloc.__libc_start_main] ; [0x21e18:8]=0 +/ 46: entry0 (int64_t arg3); +| ; arg int64_t arg3 @ rdx +| 0x00005ae0 f30f1efa endbr64 +| 0x00005ae4 31ed xor ebp, ebp EOF RUN diff --git a/test/db/cmd/cmd_pd2 b/test/db/cmd/cmd_pd2 index ffa6d694ab..5b527045e3 100644 --- a/test/db/cmd/cmd_pd2 +++ b/test/db/cmd/cmd_pd2 @@ -156,6 +156,7 @@ NAME=realign after sparse (#11810) FILE=bins/pe/cmd_adf_sample0.exe CMDS=<