From a2e5c2c09ed78e532bc240db04738c8732f1ba23 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 25 Nov 2024 19:59:25 +0100 Subject: [PATCH] Move RLang.list into RCore and use RCoreTableNew from debug/anal ##refactor --- libr/anal/meta.c | 25 +++++++++--------- libr/anal/xrefs.c | 14 +++++----- libr/bin/bin.c | 4 +-- libr/core/Makefile | 2 +- libr/core/clist.c | 54 +++++++++++++++++++++++++++++++++++++++ libr/core/cmd_anal.inc.c | 10 +++++--- libr/core/cmd_debug.inc.c | 16 ++++++------ libr/core/cmd_eval.inc.c | 8 +++--- libr/core/cmd_hash.inc.c | 13 ++++++---- libr/core/cmd_info.inc.c | 6 +++-- libr/core/cmd_log.inc.c | 8 +++--- libr/core/cmd_meta.inc.c | 50 ++++++++++++++++++++---------------- libr/core/meson.build | 1 + libr/core/project.c | 2 +- libr/debug/trace.c | 41 ++++++++++++++--------------- libr/include/r_anal.h | 10 ++++---- libr/include/r_bin.h | 2 +- libr/include/r_core.h | 1 + libr/include/r_debug.h | 2 +- libr/include/r_lang.h | 3 ++- libr/lang/lang.c | 51 +----------------------------------- libr/main/rabin2.c | 4 +-- 22 files changed, 177 insertions(+), 150 deletions(-) create mode 100644 libr/core/clist.c diff --git a/libr/anal/meta.c b/libr/anal/meta.c index f158a0e361146..4cc9928be45ac 100644 --- a/libr/anal/meta.c +++ b/libr/anal/meta.c @@ -236,7 +236,7 @@ R_API const char *r_meta_type_tostring(int type) { return "# unknown meta # "; } -R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { +R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, RTable *t, bool show_full) { R_RETURN_IF_FAIL (!(rad == 'j' && !pj)); // rad == 'j' => pj char *pstr, *base64_str; RCore *core = a->coreb.core; @@ -483,7 +483,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r } } -R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad, const char *tq) { +R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad, const char *tq, RTable *t) { RPVector *nodes = collect_nodes_at (a, R_META_TYPE_ANY, r_spaces_current (&a->meta_spaces), addr); if (!nodes) { return; @@ -491,16 +491,17 @@ R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad, const char *tq) { void **it; r_pvector_foreach (nodes, it) { RIntervalNode *node = *it; - r_meta_print (a, node->data, node->start, r_meta_node_size (node), rad, NULL, true); + r_meta_print (a, node->data, node->start, r_meta_node_size (node), rad, NULL, t, true); } r_pvector_free (nodes); } -static void print_meta_list(RAnal *a, int type, int rad, ut64 addr, const char *tq) { +static void print_meta_list(RAnal *a, int type, int rad, ut64 addr, const char *tq, RTable *t) { PJ *pj = NULL; - RTable *t = NULL; if (rad == ',') { - t = r_table_new ("meta"); + if (!t) { + t = r_table_new ("meta"); + } RTableColumnType *s = r_table_type ("string"); RTableColumnType *n = r_table_type ("number"); r_table_add_column (t, n, "addr", 0); @@ -541,7 +542,7 @@ static void print_meta_list(RAnal *a, int type, int rad, ut64 addr, const char * r_meta_node_size (node), type, name); } else { - r_meta_print (a, item, node->start, r_meta_node_size (node), rad, pj, true); + r_meta_print (a, item, node->start, r_meta_node_size (node), rad, pj, t, true); } } @@ -556,7 +557,7 @@ static void print_meta_list(RAnal *a, int type, int rad, ut64 addr, const char * if (!tq || !strstr (tq, "?")) { if (t) { char *s = r_table_tostring (t); - r_cons_printf ("%s\n", s); + r_cons_print (s); free (s); } else if (pj) { pj_end (pj); @@ -566,12 +567,12 @@ static void print_meta_list(RAnal *a, int type, int rad, ut64 addr, const char * pj_free (pj); } -R_API void r_meta_print_list_all(RAnal *a, int type, int rad, const char *tq) { - print_meta_list (a, type, rad, UT64_MAX, tq); +R_API void r_meta_print_list_all(RAnal *a, int type, int rad, const char *tq, RTable *t) { + print_meta_list (a, type, rad, UT64_MAX, tq, t); } -R_API void r_meta_print_list_in_function(RAnal *a, int type, int rad, ut64 addr, const char *tq) { - print_meta_list (a, type, rad, addr, tq); +R_API void r_meta_print_list_in_function(RAnal *a, int type, int rad, ut64 addr, const char *tq, RTable *t) { + print_meta_list (a, type, rad, addr, tq, t); } R_API void r_meta_rebase(RAnal *anal, ut64 diff) { diff --git a/libr/anal/xrefs.c b/libr/anal/xrefs.c index 16eb5bd8dba9b..9061c8706e131 100644 --- a/libr/anal/xrefs.c +++ b/libr/anal/xrefs.c @@ -333,8 +333,10 @@ R_API bool r_anal_xrefs_has_xrefs_at(RAnal *anal, ut64 at) { return !!entry; } -static void r_anal_xrefs_list_table(RAnal *anal, RVecAnalRef *anal_refs, const char *arg) { - RTable *table = r_table_new ("xrefs"); +static void r_anal_xrefs_list_table(RAnal *anal, RVecAnalRef *anal_refs, const char *arg, RTable *table) { + if (!table) { + table = r_table_new ("xrefs"); + } r_table_set_columnsf (table, "dddssss", "from", "to", "size", "type", "perm", "fromname", "toname"); RAnalRef *ref; @@ -358,8 +360,8 @@ static void r_anal_xrefs_list_table(RAnal *anal, RVecAnalRef *anal_refs, const c show_table = r_table_query (table, arg); } if (show_table) { - char *s = r_table_tofancystring (table); - r_cons_println (s); + char *s = r_table_tostring (table); + r_cons_print (s); free (s); } r_table_free (table); @@ -459,7 +461,7 @@ static void r_anal_xrefs_list_plaintext(RAnal *anal, RVecAnalRef *anal_refs) { } } -R_API void r_anal_xrefs_list(RAnal *anal, int rad, const char *arg) { +R_API void r_anal_xrefs_list(RAnal *anal, int rad, const char *arg, RTable *t) { R_RETURN_IF_FAIL (anal && anal->rm); RVecAnalRef *anal_refs = ref_manager_get_refs (anal->rm, UT64_MAX); @@ -472,7 +474,7 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad, const char *arg) { switch (rad) { case ',': - r_anal_xrefs_list_table (anal, anal_refs, arg); + r_anal_xrefs_list_table (anal, anal_refs, arg, t); break; case 'j': r_anal_xrefs_list_json (anal, anal_refs); diff --git a/libr/bin/bin.c b/libr/bin/bin.c index ab57ddaeb2c29..c9eeb7c73d4d6 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -1044,7 +1044,7 @@ static char *get_arch_string(const char *arch, int bits, RBinInfo *info) { return r_strbuf_drain (sb); } -R_API void r_bin_list_archs(RBin *bin, PJ *pj, int mode) { +R_API void r_bin_list_archs(RBin *bin, PJ *pj, RTable *t, int mode) { R_RETURN_IF_FAIL (bin); char unk[128]; @@ -1072,7 +1072,7 @@ R_API void r_bin_list_archs(RBin *bin, PJ *pj, int mode) { if (!nbinfile) { return; } - RTable *table = r_table_new ("bins"); + RTable *table = t? t: r_table_new ("bins"); const char *fmt = "dXnss"; if (mode == 'j') { pj_ka (pj, "bins"); diff --git a/libr/core/Makefile b/libr/core/Makefile index 3b5b34cd42a24..4f79efdf1b8cb 100644 --- a/libr/core/Makefile +++ b/libr/core/Makefile @@ -11,7 +11,7 @@ OBJS+=fortune.o hack.o vasm.o patch.o cbin.o corelog.o rtr.o cmd_api.o OBJS+=carg.o canal.o project.o gdiff.o casm.o disasm.o cplugin.o cmd_print_list.o OBJS+=vmenus.o vmenus_graph.o vmenus_zigns.o zdiff.o citem.o vslides.o OBJS+=task.o panels.o pseudo.o vmarks.o anal_tp.o anal_objc.o blaze.o cundo.o -OBJS+=cproject.o +OBJS+=cproject.o clist.o CFLAGS+=-DR2_PLUGIN_INCORE -I../../shlr LDFLAGS+=${DL_LIBS} diff --git a/libr/core/clist.c b/libr/core/clist.c new file mode 100644 index 0000000000000..7860f886527ce --- /dev/null +++ b/libr/core/clist.c @@ -0,0 +1,54 @@ +/* radare - LGPL - Copyright 2024 - pancake */ + +#include + +R_API void r_core_list_lang(RCore *core, int mode) { + RLang *lang = core->lang; + RListIter *iter; + RLangPlugin *h; + if (!lang) { + return; + } + PJ *pj = NULL; + RTable *table = NULL; + if (mode == 'j') { + pj = pj_new (); + pj_a (pj); + } else if (mode == ',') { + table = r_core_table_new (core, "langs"); + RTableColumnType *typeString = r_table_type ("string"); + r_table_add_column (table, typeString, "name", 0); + r_table_add_column (table, typeString, "desc", 0); + // r_table_add_column (table, typeString, "license", 0); + } + r_list_foreach (lang->langs, iter, h) { + const char *license = h->meta.license + ? h->meta.license : "???"; + if (mode == 'j') { + pj_o (pj); + r_lib_meta_pj (pj, &h->meta); + pj_end (pj); + } else if (mode == 'q') { + lang->cb_printf ("%s\n", h->meta.name); + } else if (mode == ',') { + r_table_add_row (table, + r_str_get (h->meta.name), + r_str_get (h->meta.license), + r_str_get (h->meta.desc), 0); + } else { + lang->cb_printf ("%-8s %6s %s\n", + h->meta.name, license, h->meta.desc); + } + } + if (pj) { + pj_end (pj); + char *s = pj_drain (pj); + lang->cb_printf ("%s\n", s); + free (s); + } else if (table) { + char *s = r_table_tostring (table); + lang->cb_printf ("%s", s); + free (s); + r_table_free (table); + } +} diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index 219e20df1f75d..dc71088057c72 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -1099,7 +1099,7 @@ static RCoreHelpMessage help_msg_ax = { // "axg*", " [addr]", "show xrefs graph to given address, use .axg*;aggv", // "axgj", " [addr]", "show xrefs graph to reach current function in json format", "axi", " addr [at]", "add indirect code reference (see ax?)", - "axj", "", "add jmp reference", // list refs in json format", + "axj", "", "add jmp reference", // list refs in json format", // R2_600 XXX this is wrong. axj must be listing xrefs with json "axl", "[jcq]", "list xrefs (axlc = count, axlq = quiet, axlj = json)", "axm", " addr [at]", "copy data/code references pointing to addr to also point to curseek (or at)", "axq", "", "list refs in quiet/human-readable format", @@ -10424,7 +10424,10 @@ static bool cmd_anal_refs(RCore *core, const char *input) { case 'q': // "axq" case '*': // "ax*" case ',': // "ax," - r_anal_xrefs_list (core->anal, input[0], *input? r_str_trim_head_ro (input + 1): ""); + { + RTable *table = (*input == ',')? r_core_table_new (core, "xrefs"): NULL; + r_anal_xrefs_list (core->anal, input[0], *input? r_str_trim_head_ro (input + 1): "", table); + } break; case '.': if (input[1] == 'j') { // "ax.j" @@ -10487,7 +10490,8 @@ static bool cmd_anal_refs(RCore *core, const char *input) { r_core_cmd_help (core, help_msg_axl); break; case 'j': // "axlj" - r_anal_xrefs_list (core->anal, 'j', ""); + // XXX axj != axlj r_core_cmd_call (core, "axj"); + r_anal_xrefs_list (core->anal, 'j', 0, NULL); break; case 'c': // "axlc" { diff --git a/libr/core/cmd_debug.inc.c b/libr/core/cmd_debug.inc.c index 795e3fd9a6dc4..7bfa67195fa3a 100644 --- a/libr/core/cmd_debug.inc.c +++ b/libr/core/cmd_debug.inc.c @@ -5444,19 +5444,19 @@ static int cmd_debug(void *data, const char *input) { // TODO: define ranges? to display only some traces, allow to scroll on this disasm? ~.. ? switch (input[1]) { case '\0': // "dt" - r_debug_trace_list (core->dbg, 0, core->offset); - break; case '=': // "dt=" - r_debug_trace_list (core->dbg, '=', core->offset); - break; case 'q': // "dtq" - r_debug_trace_list (core->dbg, 'q', core->offset); - break; case 'j': // "dtj" - r_debug_trace_list (core->dbg, 'j', core->offset); + r_debug_trace_list (core->dbg, input[1], core->offset, NULL); break; case '*': // "dt*" - r_debug_trace_list (core->dbg, 1, core->offset); + r_debug_trace_list (core->dbg, 1, core->offset, NULL); + break; + case ',': // "dt," + { + RTable *t = r_core_table_new (core, "traces"); + r_debug_trace_list (core->dbg, ',', core->offset, t); + } break; case ' ': // "dt [addr]" if ((t = r_debug_trace_get (core->dbg, diff --git a/libr/core/cmd_eval.inc.c b/libr/core/cmd_eval.inc.c index b0324c3f04d47..72cf1ced27509 100644 --- a/libr/core/cmd_eval.inc.c +++ b/libr/core/cmd_eval.inc.c @@ -530,19 +530,19 @@ static bool cmd_ec(RCore *core, const char *input) { r_str_argv_free (argv); return false; case '.': - r_meta_print_list_in_function (core->anal, R_META_TYPE_HIGHLIGHT, 0, core->offset, NULL); + r_meta_print_list_in_function (core->anal, R_META_TYPE_HIGHLIGHT, 0, core->offset, NULL, NULL); r_str_argv_free (argv); return false; case '\0': - r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 0, NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 0, NULL, NULL); r_str_argv_free (argv); return false; case 'j': - r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 'j', NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 'j', NULL, NULL); r_str_argv_free (argv); return false; case '*': - r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, '*', NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, '*', NULL, NULL); r_str_argv_free (argv); return false; case ' ': diff --git a/libr/core/cmd_hash.inc.c b/libr/core/cmd_hash.inc.c index 71fac58a76c42..cbed7e6761ebb 100644 --- a/libr/core/cmd_hash.inc.c +++ b/libr/core/cmd_hash.inc.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2023 - pancake, nibble */ +/* radare - LGPL - Copyright 2009-2024 - pancake, nibble */ #if R_INCLUDE_BEGIN @@ -99,18 +99,21 @@ static int cmd_hash_bang(RCore *core, const char *input) { switch (mod) { case 'j': case 'q': - r_lang_list (core->lang, mod); + r_core_list_lang (core, mod); break; case '*': - r_lang_list (core->lang, 0); + r_core_list_lang (core, 0); break; - default: + case '?': R_LOG_INFO ("Missing halp"); break; + default: + r_core_return_invalid_command (core, "#!", av[0][0]); + break; } } } else { - r_lang_list (core->lang, 0); + r_core_list_lang (core, 0); } r_str_argv_free (av); return true; diff --git a/libr/core/cmd_info.inc.c b/libr/core/cmd_info.inc.c index 8a1dcf52703d1..4fb26137fc0bc 100644 --- a/libr/core/cmd_info.inc.c +++ b/libr/core/cmd_info.inc.c @@ -2168,11 +2168,13 @@ static int cmd_info(void *data, const char *input) { if (r_str_startswith (input, "iaito")) { R_LOG_ERROR ("Missing plugin. Run: r2pm -ci r2iaito"); } else if (input[1] == 'j') { + RTable *t = r_core_table_new (core, "archs"); pj_o (pj); // weird - r_bin_list_archs (core->bin, pj, 'j'); + r_bin_list_archs (core->bin, pj, t, 'j'); pj_end (pj); } else { - r_bin_list_archs (core->bin, NULL, 1); + RTable *t = r_core_table_new (core, "archs"); + r_bin_list_archs (core->bin, NULL, t, 1); } break; case 'e': // "ie" diff --git a/libr/core/cmd_log.inc.c b/libr/core/cmd_log.inc.c index e16a673f1a61d..954e33c6e6f8d 100644 --- a/libr/core/cmd_log.inc.c +++ b/libr/core/cmd_log.inc.c @@ -581,15 +581,15 @@ static int cmd_plugins(void *data, const char *input) { break; case 'l': // "Ll" if (input[1] == 'j') { // "Llj" "#!?j" - r_lang_list (core->lang, 'j'); + r_core_list_lang (core, 'j'); } else if (input[1] == 'q') { // "Llq" "#!?q" - r_lang_list (core->lang, 'q'); + r_core_list_lang (core, 'q'); } else if (input[1] == ',') { // "Ll," - r_lang_list (core->lang, ','); // TODO: take table query as argument + r_core_list_lang (core, ','); } else if (input[1] == '?') { // "Ll?" r_cons_printf ("Usage: Ll[,jq] - list r_lang plugins\n"); } else { - r_lang_list (core->lang, 0); + r_core_list_lang (core, 0); } break; case 'L': // "LL" diff --git a/libr/core/cmd_meta.inc.c b/libr/core/cmd_meta.inc.c index fbc73e8ed87c8..41d2a4b836c3f 100644 --- a/libr/core/cmd_meta.inc.c +++ b/libr/core/cmd_meta.inc.c @@ -498,7 +498,10 @@ static int cmd_meta_comment(RCore *core, const char *input) { r_core_cmd_help (core, help_msg_CC); break; case ',': // "CC," - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, ',', input + 2); + { + RTable *t = r_core_table_new (core, "meta"); + r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, ',', input + 2, t); + } break; case 'F': // "CC," if (input[2] == '?') { @@ -519,9 +522,9 @@ static int cmd_meta_comment(RCore *core, const char *input) { } } else { const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); - if (comment && *comment) { + if (R_STR_ISNOTEMPTY (comment)) { char *cmtfile = r_str_between (comment, ",(", ")"); - if (cmtfile && *cmtfile) { + if (R_STR_ISNOTEMPTY (cmtfile)) { char *cwd = getcommapath (core); r_cons_printf ("%s"R_SYS_DIR"%s\n", cwd, cmtfile); free (cwd); @@ -540,7 +543,7 @@ static int cmd_meta_comment(RCore *core, const char *input) { } break; case 0: // "CC" - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 0, NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 0, NULL, NULL); break; case 'f': // "CCf" switch (input[2]) { @@ -565,21 +568,24 @@ static int cmd_meta_comment(RCore *core, const char *input) { } break; case ',': // "CCf," - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, ',', core->offset, input + 3); + { + RTable *t = r_core_table_new (core, "comments"); + r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, ',', core->offset, input + 3, t); + } break; case 'j': // "CCfj" - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 'j', core->offset, NULL); + r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 'j', core->offset, NULL, NULL); break; case '*': // "CCf*" - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 1, core->offset, NULL); + r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 1, core->offset, NULL, NULL); break; default: - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 0, core->offset, NULL); + r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 0, core->offset, NULL, NULL); break; } break; case 'j': // "CCj" - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 'j', input + 2); + r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 'j', input + 2, NULL); break; case '!': // "CC!" { @@ -632,7 +638,7 @@ static int cmd_meta_comment(RCore *core, const char *input) { } break; case '*': // "CC*" - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 1, NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 1, NULL, NULL); break; case '-': // "CC-" if (input[2] == '*') { // "CC-*" @@ -719,7 +725,7 @@ static int cmd_meta_vartype_comment(RCore *core, const char *input) { r_core_cmd_help (core, help_msg_Ct); break; case 0: // "Ct" - r_meta_print_list_all (core->anal, R_META_TYPE_VARTYPE, 0, NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_VARTYPE, 0, NULL, NULL); break; case ' ': // "Ct @ addr" { @@ -844,10 +850,10 @@ static int cmd_meta_others(RCore *core, const char *input) { } break; case '*': // "Cf*", "Cd*", ... - r_meta_print_list_all (core->anal, input[0], 1, NULL); + r_meta_print_list_all (core->anal, input[0], 1, NULL, NULL); break; case 'j': // "Cfj", "Cdj", ... - r_meta_print_list_all (core->anal, input[0], 'j', NULL); + r_meta_print_list_all (core->anal, input[0], 'j', NULL, NULL); break; case '!': // "Cf!", "Cd!", ... { @@ -868,14 +874,14 @@ static int cmd_meta_others(RCore *core, const char *input) { ut64 size; RAnalMetaItem *mi = r_meta_get_at (core->anal, addr, type, &size); if (mi) { - r_meta_print (core->anal, mi, addr, size, input[3], NULL, false); + r_meta_print (core->anal, mi, addr, size, input[3], NULL, NULL, false); } break; } else if (input[2] == 'j') { // "Cs.j" ut64 size; RAnalMetaItem *mi = r_meta_get_at (core->anal, addr, type, &size); if (mi) { - r_meta_print (core->anal, mi, addr, size, input[2], NULL, false); + r_meta_print (core->anal, mi, addr, size, input[2], NULL, NULL, false); r_cons_newline (); } break; @@ -994,7 +1000,7 @@ static int cmd_meta_others(RCore *core, const char *input) { type = 's'; } else { if (!input[1] && !core->tmpseek) { - r_meta_print_list_all (core->anal, type, 0, NULL); + r_meta_print_list_all (core->anal, type, 0, NULL, NULL); break; } } @@ -1345,24 +1351,24 @@ static int cmd_meta(void *data, const char *input) { cmd_Cv (core, input + 1); break; case '\0': // "C" - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 0, NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 0, NULL, NULL); break; case ',': // "C," - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input, input + 1); + r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input, input + 1, NULL); break; case 'j': // "Cj" case '*': { // "C*" if (input[1] == '.') { - r_meta_print_list_at (core->anal, core->offset, *input, input + 2); + r_meta_print_list_at (core->anal, core->offset, *input, input + 2, NULL); } else if (input[1]) { - r_meta_print_list_at (core->anal, core->offset, *input, input + 2); + r_meta_print_list_at (core->anal, core->offset, *input, input + 2, NULL); } else { - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input, input + 1); + r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input, input + 1, NULL); } break; } case '.': { // "C." - r_meta_print_list_at (core->anal, core->offset, 0, NULL); + r_meta_print_list_at (core->anal, core->offset, 0, NULL, NULL); break; } case 'L': // "CL" diff --git a/libr/core/meson.build b/libr/core/meson.build index 6ce0fb82a10e1..8dcc8a05625aa 100644 --- a/libr/core/meson.build +++ b/libr/core/meson.build @@ -4,6 +4,7 @@ r_core_sources = [ 'casm.c', 'cproject.c', 'blaze.c', + 'clist.c', 'citem.c', 'canal.c', 'carg.c', diff --git a/libr/core/project.c b/libr/core/project.c index ba07c294153d8..4c7f51b78de39 100644 --- a/libr/core/project.c +++ b/libr/core/project.c @@ -572,7 +572,7 @@ R_API bool r_core_project_save_script(RCore *core, const char *file, int opts) { } if (opts & R_CORE_PRJ_META) { r_cons_printf ("# meta\n"); - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 1, NULL); + r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 1, NULL, NULL); flush (sb); r_core_cmd (core, "fV*", 0); flush (sb); diff --git a/libr/debug/trace.c b/libr/debug/trace.c index 3062bbeff714b..0976fed475196 100644 --- a/libr/debug/trace.c +++ b/libr/debug/trace.c @@ -256,13 +256,14 @@ static void r_debug_trace_list_quiet(RDebug *dbg) { } static inline void listinfo_fini(RListInfo *info) { + R_RETURN_IF_FAIL (info); free (info->name); free (info->extra); } R_VEC_TYPE_WITH_FINI (RVecListInfo, RListInfo, listinfo_fini); -static void r_debug_trace_list_table(RDebug *dbg, ut64 offset) { +static void r_debug_trace_list_table(RDebug *dbg, ut64 offset, RTable *t) { RVecListInfo info_vec; RVecListInfo_init (&info_vec); @@ -288,12 +289,12 @@ static void r_debug_trace_list_table(RDebug *dbg, ut64 offset) { if (flag) { RVecListInfo_sort (&info_vec, cmpaddr); - RTable *table = r_table_new ("traces"); + RTable *table = t? t: r_table_new ("traces"); table->cons = r_cons_singleton (); RIO *io = dbg->iob.io; r_table_visual_vec (table, &info_vec, offset, 1, r_cons_get_size (NULL), io->va); char *s = r_table_tostring (table); - io->cb_printf ("\n%s\n", s); + io->cb_printf ("%s", s); free (s); r_table_free (table); } @@ -322,25 +323,25 @@ static void r_debug_trace_list_default(RDebug *dbg) { } } -R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset) { +R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset, RTable *t) { R_RETURN_IF_FAIL (dbg && dbg->trace); switch (mode) { - case 'j': - r_debug_trace_list_json (dbg); - break; - case 'q': - r_debug_trace_list_quiet (dbg); - break; - case '=': - r_debug_trace_list_table (dbg, offset); - break; - case 1: - case '*': - r_debug_trace_list_make (dbg); - break; - default: - r_debug_trace_list_default (dbg); - break; + case 'j': + r_debug_trace_list_json (dbg); + break; + case 'q': + r_debug_trace_list_quiet (dbg); + break; + case '=': + r_debug_trace_list_table (dbg, offset, t); + break; + case 1: + case '*': + r_debug_trace_list_make (dbg); + break; + default: + r_debug_trace_list_default (dbg); + break; } } diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 554df2af14f8a..e06925ac3dd19 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -1129,7 +1129,7 @@ R_API RVecAnalRef *r_anal_xrefs_get(RAnal *anal, ut64 to); R_API RVecAnalRef *r_anal_refs_get(RAnal *anal, ut64 from); R_API bool r_anal_xrefs_has_xrefs_at(RAnal *anal, ut64 at); R_API RVecAnalRef *r_anal_xrefs_get_from(RAnal *anal, ut64 to); -R_API void r_anal_xrefs_list(RAnal *anal, int rad, const char *arg); +R_API void r_anal_xrefs_list(RAnal *anal, int rad, const char *arg, RTable *t); R_API ut64 r_anal_xrefs_count(RAnal *anal); R_API ut64 r_anal_xrefs_count_at(RAnal *anal, ut64 to); R_API RVecAnalRef *r_anal_function_get_refs(RAnalFunction *fcn); @@ -1349,10 +1349,10 @@ R_API void r_meta_rebase(RAnal *anal, ut64 diff); R_API ut64 r_meta_get_size(RAnal *a, RAnalMetaType type); R_API const char *r_meta_type_tostring(int type); -R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full); -R_API void r_meta_print_list_all(RAnal *a, int type, int rad, const char *tq); -R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad, const char *tq); -R_API void r_meta_print_list_in_function(RAnal *a, int type, int rad, ut64 addr, const char *tq); +R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, RTable *t, bool show_full); +R_API void r_meta_print_list_all(RAnal *a, int type, int rad, const char *tq, RTable *t); +R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad, const char *tq, RTable *t); +R_API void r_meta_print_list_in_function(RAnal *a, int type, int rad, ut64 addr, const char *tq, RTable *t); /* hints */ diff --git a/libr/include/r_bin.h b/libr/include/r_bin.h index ff5c23a792001..e06351154d135 100644 --- a/libr/include/r_bin.h +++ b/libr/include/r_bin.h @@ -814,7 +814,7 @@ R_API RBinObject *r_bin_cur_object(RBin *bin); R_API bool r_bin_select(RBin *bin, const char *arch, int bits, const char *name); R_API bool r_bin_select_bfid(RBin *bin, ut32 bf_id); R_API bool r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name); -R_API void r_bin_list_archs(RBin *bin, PJ *pj, int mode); +R_API void r_bin_list_archs(RBin *bin, PJ *pj, RTable *t, int mode); R_API RBuffer *r_bin_create(RBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt); R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files); diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 87b2a227fb8dd..421060b034cb8 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -579,6 +579,7 @@ R_API void r_core_anal_cc_init(RCore *core); R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, int followDepth, bool is_json); R_API void r_core_list_io(RCore *core); +R_API void r_core_list_lang(RCore *core, int mode); R_API void r_core_visual_slides(RCore *core, const char *file); /* visual marks */ diff --git a/libr/include/r_debug.h b/libr/include/r_debug.h index b95cf9e8be67b..fe937ba1cad67 100644 --- a/libr/include/r_debug.h +++ b/libr/include/r_debug.h @@ -589,7 +589,7 @@ R_API bool r_debug_trace_pc(RDebug *dbg, ut64 pc); R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op); R_API void r_debug_trace_at(RDebug *dbg, const char *str); R_API RDebugTracepoint *r_debug_trace_get(RDebug *dbg, ut64 addr); -R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset); +R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset, RTable *t); R_API RDebugTracepoint *r_debug_trace_add(RDebug *dbg, ut64 addr, int size); R_API RDebugTrace *r_debug_trace_new(void); R_API void r_debug_trace_free(RDebugTrace *dbg); diff --git a/libr/include/r_lang.h b/libr/include/r_lang.h index 2378523160c56..e73f58620eec3 100644 --- a/libr/include/r_lang.h +++ b/libr/include/r_lang.h @@ -3,6 +3,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -73,7 +74,7 @@ R_API void r_lang_free(RLang *lang); R_API bool r_lang_setup(RLang *lang); R_API bool r_lang_plugin_add(RLang *lang, RLangPlugin *plugin); R_API bool r_lang_plugin_remove(RLang *lang, RLangPlugin *plugin); -R_API void r_lang_list(RLang *lang, int mode); +R_DEPRECATE R_API void r_lang_list(RLang *lang, int mode, RTable *t); // R2_600 - move into rcore R_API bool r_lang_use(RLang *lang, const char *name); R_API bool r_lang_use_plugin(RLang *lang, RLangPlugin *h); R_API bool r_lang_run(RLang *lang, const char *code, int len); diff --git a/libr/lang/lang.c b/libr/lang/lang.c index 76c25a5add9b5..a087024b9cf0c 100644 --- a/libr/lang/lang.c +++ b/libr/lang/lang.c @@ -181,56 +181,7 @@ R_API bool r_lang_plugin_remove(RLang *lang, RLangPlugin *plugin) { } /* TODO: deprecate all list methods */ -R_API void r_lang_list(RLang *lang, int mode) { - RListIter *iter; - RLangPlugin *h; - if (!lang) { - return; - } - PJ *pj = NULL; - RTable *table = NULL; - if (mode == 'j') { - pj = pj_new (); - pj_a (pj); - } else if (mode == ',') { - table = r_table_new ("langs"); - RTableColumnType *typeString = r_table_type ("string"); - r_table_add_column (table, typeString, "name", 0); - r_table_add_column (table, typeString, "license", 0); - r_table_add_column (table, typeString, "desc", 0); - } - r_list_foreach (lang->langs, iter, h) { - const char *license = h->meta.license - ? h->meta.license : "???"; - if (mode == 'j') { - pj_o (pj); - pj_ks (pj, "name", r_str_get (h->meta.name)); - pj_ks (pj, "license", license); - pj_ks (pj, "description", r_str_get (h->meta.desc)); - pj_end (pj); - } else if (mode == 'q') { - lang->cb_printf ("%s\n", h->meta.name); - } else if (mode == ',') { - r_table_add_row (table, - r_str_get (h->meta.name), - r_str_get (h->meta.license), - r_str_get (h->meta.desc), 0); - } else { - lang->cb_printf ("%-8s %6s %s\n", - h->meta.name, license, h->meta.desc); - } - } - if (pj) { - pj_end (pj); - char *s = pj_drain (pj); - lang->cb_printf ("%s\n", s); - free (s); - } else if (table) { - char *s = r_table_tostring (table); - lang->cb_printf ("%s\n", s); - free (s); - r_table_free (table); - } +R_API void r_lang_list(RLang *lang, int mode, RTable *t) { } R_API RLangPlugin *r_lang_get_by_extension(RLang *lang, const char *ext) { diff --git a/libr/main/rabin2.c b/libr/main/rabin2.c index 89ed7b2312f9a..7f94119ac54b0 100644 --- a/libr/main/rabin2.c +++ b/libr/main/rabin2.c @@ -1170,9 +1170,9 @@ R_API int r_main_rabin2(int argc, const char **argv) { if (action & R_BIN_REQ_LISTARCHS || ((arch || bits || arch_name) && !r_bin_select (bin, arch, bits, arch_name))) { if (rad == R_MODE_SIMPLEST || rad == R_MODE_SIMPLE) { - r_bin_list_archs (bin, pj, 'q'); + r_bin_list_archs (bin, pj, NULL, 'q'); } else { - r_bin_list_archs (bin, pj, (rad == R_MODE_JSON)? 'j': 1); + r_bin_list_archs (bin, pj, NULL, (rad == R_MODE_JSON)? 'j': 1); } free (arch_name); }