From cc6e60486376383480d82bad01bd438e29ec2a35 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 1 Dec 2024 18:51:26 +0100 Subject: [PATCH] Implement `rasm2 -L [arch]` to show detailed info of 1 plugin ##arch --- libr/bin/bin.c | 6 +++--- libr/main/rasm2.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/libr/bin/bin.c b/libr/bin/bin.c index ab57d6b1148d3..53e077f52934f 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -570,6 +570,7 @@ static void __printXtrPluginDetails(RBin *bin, RBinXtrPlugin *bx, int json) { } } +// TODO: move to libr/core/clist R_API bool r_bin_list_plugin(RBin *bin, const char* name, PJ *pj, int json) { RListIter *it; RBinPlugin *bp; @@ -645,9 +646,8 @@ R_API void r_bin_list(RBin *bin, PJ *pj, int format) { pj_end (pj); } else { r_list_foreach (bin->plugins, it, bp) { - bin->cb_printf ("bin %-11s %s %s %s\n", - bp->meta.name, bp->meta.desc, r_str_get (bp->meta.version), - r_str_get (bp->meta.author)); + bin->cb_printf ("bin %-11s %s\n", bp->meta.name, bp->meta.desc); + // bin->cb_printf ("bin %-11s %s %s %s\n", bp->meta.name, bp->meta.desc, r_str_get (bp->meta.version), r_str_get (bp->meta.author)); } r_list_foreach (bin->binxtrs, it, bx) { const char *name = strncmp (bx->meta.name, "xtr.", 4)? bx->meta.name : bx->meta.name + 3; diff --git a/libr/main/rasm2.c b/libr/main/rasm2.c index 2974d71b745a1..b6ec81f7469d0 100644 --- a/libr/main/rasm2.c +++ b/libr/main/rasm2.c @@ -184,7 +184,11 @@ static void rarch2_list(RAsmState *as, const char *arch) { pj = pj_new (); pj_a (pj); } - r_list_foreach (as->anal->arch->plugins, iter, h) { + RList *plugins = R_UNWRAP4 (as, anal, arch, plugins); + r_list_foreach (plugins, iter, h) { + if (arch && strcmp (arch, h->meta.name)) { + continue; + } const char *feat = "___"; if (h->encode) { feat = h->decode? "ade": "a__"; @@ -195,11 +199,10 @@ static void rarch2_list(RAsmState *as, const char *arch) { RList *bitslist = r_list_newf (NULL); for (i = 0; i < 8; i++) { ut8 bit = (bits & 0xFF); // TODO: use the macros - if (bit) { - r_list_append (bitslist, (void*)(size_t)bit); - } else { + if (!bit) { break; } + r_list_append (bitslist, (void*)(size_t)bit); bits >>= 8; // TODO: use the macros } r_list_sort (bitslist, sizetsort); @@ -222,6 +225,20 @@ static void rarch2_list(RAsmState *as, const char *arch) { pj_ks (pj, "description", h->meta.desc); pj_ks (pj, "features", feat); pj_end (pj); + } else if (arch) { + printf ("name: %s\n", h->meta.name); + printf ("bits: %s\n", bitstr); + printf ("desc: %s\n", h->meta.desc); + printf ("feat: %s\n", feat); + if (h->meta.author) { + printf ("auth: %s\n", h->meta.author); + } + if (h->meta.license) { + printf ("lice: %s\n", h->meta.license); + } + if (h->meta.version) { + printf ("vers: %s\n", h->meta.version); + } } else { printf ("%s %-11s %-11s %s", feat, bitstr, h->meta.name, h->meta.desc); #if 0 @@ -236,6 +253,9 @@ static void rarch2_list(RAsmState *as, const char *arch) { } r_list_free (bitslist); free (bitstr); + if (arch) { + break; + } } if (as->json) { pj_end (pj); @@ -266,7 +286,7 @@ static int rasm_show_help(int v) { " -j output in json format\n" " -k [kernel] select operating system (linux, windows, darwin, android, ios, ..)\n" " -l [len] input/Output length\n" - " -L list RArch plugins: (a=asm, d=disasm, e=esil)\n" + " -L ([name]) list RArch plugins: (a=asm, d=disasm, e=esil)\n" " -N same as r2 -N (or R2_NOPLUGINS) (not load any plugin)\n" // -n ? " -o [file] output file name (rasm2 -Bf a.asm -o a)\n" " -p run SPP over input for assembly\n" @@ -1058,8 +1078,8 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { } if (rad) { as->oneliner = true; - printf ("e asm.arch=%s\n", arch? arch: R_SYS_ARCH); - printf ("e asm.bits=%d\n", bits); + printf ("'e asm.arch=%s\n", arch? arch: R_SYS_ARCH); + printf ("'e asm.bits=%d\n", bits); printf ("'wa "); } ret = rasm_disasm (as, offset, (char *)usrstr, len,