Skip to content

Commit

Permalink
Sort plugins alphabetically when listed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Oct 24, 2024
1 parent 200035b commit 083b5e2
Show file tree
Hide file tree
Showing 21 changed files with 441 additions and 272 deletions.
9 changes: 6 additions & 3 deletions librz/bp/bp_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name) {
// TODO: deprecate
RZ_API void rz_bp_plugin_list(RzBreakpoint *bp) {
RzIterator *iter = ht_sp_as_iter(bp->plugins);
RzBreakpointPlugin **val;
rz_iterator_foreach(iter, val) {
RzBreakpointPlugin *b = *val;
RzList *plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_breakpoint_plugin_cmp, NULL);
RzListIter *it;
RzBreakpointPlugin *b;
rz_list_foreach (plugin_list, it, b) {
bp->cb_printf("bp %c %s\n",
(bp->cur && !strcmp(bp->cur->name, b->name)) ? '*' : '-',
b->name);
}
rz_list_free(plugin_list);
rz_iterator_free(iter);
}
13 changes: 8 additions & 5 deletions librz/core/casm.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ RZ_API RzCmdStatus rz_core_asm_plugins_print(RzCore *core, const char *arch, RzC
int i;
RzAsm *a = core->rasm;
RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
RzList *plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_asm_plugin_cmp, NULL);
RzListIter *it;
RzAsmPlugin *ap;
RzCmdStatus status;
if (arch) {
rz_iterator_foreach(iter, val) {
RzAsmPlugin *ap = *val;
rz_list_foreach (plugin_list, it, ap) {
if (ap->cpus && !strcmp(arch, ap->name)) {
char *c = rz_str_dup(ap->cpus);
int n = rz_str_split(c, ',');
Expand All @@ -186,19 +188,20 @@ RZ_API RzCmdStatus rz_core_asm_plugins_print(RzCore *core, const char *arch, RzC
}
} else {
rz_cmd_state_output_array_start(state);
rz_iterator_foreach(iter, val) {
RzAsmPlugin *ap = *val;
rz_list_foreach (plugin_list, it, ap) {
const char *license = ap->license
? ap->license
: "unknown";
status = rz_core_asm_plugin_print(core, ap, arch, state, license);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
rz_list_free(plugin_list);
return status;
}
}
rz_cmd_state_output_array_end(state);
}
rz_list_free(plugin_list);
rz_iterator_free(iter);
return RZ_CMD_STATUS_OK;
}
Expand Down
23 changes: 16 additions & 7 deletions librz/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4904,29 +4904,38 @@ RZ_API RzCmdStatus rz_core_bin_plugins_print(RzBin *bin, RzCmdStateOutput *state
rz_return_val_if_fail(bin && state, RZ_CMD_STATUS_ERROR);

RzCmdStatus status;
rz_cmd_state_output_array_start(state);

RzIterator *iter = ht_sp_as_iter(bin->plugins);
RzBinPlugin **bp_val;
RzBinXtrPlugin **bx_val;
RzList *plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_bin_plugin_cmp, NULL);
RzListIter *it;
RzBinPlugin *bp;
RzBinXtrPlugin *bx;

rz_cmd_state_output_array_start(state);
rz_iterator_foreach(iter, bp_val) {
RzBinPlugin *bp = *bp_val;
rz_list_foreach (plugin_list, it, bp) {
status = rz_core_bin_plugin_print(bp, state);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
rz_list_free(plugin_list);
return status;
}
}
rz_list_free(plugin_list);
rz_iterator_free(iter);

iter = ht_sp_as_iter(bin->binxtrs);
rz_iterator_foreach(iter, bx_val) {
RzBinXtrPlugin *bx = *bx_val;
plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_bin_xtr_plugin_cmp, NULL);
rz_list_foreach (plugin_list, it, bx) {
status = rz_core_binxtr_plugin_print(bx, state);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
rz_list_free(plugin_list);
return status;
}
}
rz_list_free(plugin_list);
rz_iterator_free(iter);
rz_cmd_state_output_array_end(state);
return RZ_CMD_STATUS_OK;
Expand Down
16 changes: 11 additions & 5 deletions librz/core/ccrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,26 @@ RZ_API RzCmdStatus rz_core_crypto_plugins_print(RzCrypto *cry, RzCmdStateOutput
rz_return_val_if_fail(cry, RZ_CMD_STATUS_ERROR);

RzCmdStatus status;
RzIterator *it = ht_sp_as_iter(cry->plugins);
RzCryptoPlugin **val;
rz_cmd_state_output_array_start(state);
if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
rz_cons_println("algorithm license author");
}
rz_iterator_foreach(it, val) {
const RzCryptoPlugin *plugin = *val;
RzIterator *iter = ht_sp_as_iter(cry->plugins);
RzList *plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_crypto_plugin_cmp, NULL);
RzListIter *it;
RzCryptoPlugin *plugin;
rz_list_foreach (plugin_list, it, plugin) {
status = core_crypto_plugin_print(state, plugin);
if (status != RZ_CMD_STATUS_OK) {
rz_list_free(plugin_list);
rz_iterator_free(iter);
return status;
}
}
rz_iterator_free(it);
rz_list_free(plugin_list);
rz_iterator_free(iter);

if (state->mode == RZ_OUTPUT_MODE_QUIET) {
rz_cons_newline();
}
Expand Down
13 changes: 9 additions & 4 deletions librz/core/cdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,25 +325,30 @@ RZ_API RzCmdStatus rz_core_debug_plugins_print(RzCore *core, RzCmdStateOutput *s
memset(spaces, ' ', 15);
spaces[15] = 0;
RzDebug *dbg = core->dbg;
RzIterator *iter = ht_sp_as_iter(dbg->plugins);
RzDebugPlugin **val;
RzCmdStatus status;
if (!dbg) {
return RZ_CMD_STATUS_ERROR;
}
rz_cmd_state_output_array_start(state);
rz_iterator_foreach(iter, val) {
RzDebugPlugin *plugin = *val;
RzIterator *iter = ht_sp_as_iter(dbg->plugins);
RzList *plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_debug_plugin_cmp, NULL);
RzListIter *it;
RzDebugPlugin *plugin;
rz_list_foreach (plugin_list, it, plugin) {
int sp = 8 - strlen(plugin->name);
spaces[sp] = 0;
status = rz_core_debug_plugin_print(dbg, plugin, state, count, spaces);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
rz_list_free(plugin_list);
return status;
}
spaces[sp] = ' ';
count++;
}
rz_iterator_free(iter);
rz_list_free(plugin_list);
rz_cmd_state_output_array_end(state);
return RZ_CMD_STATUS_OK;
}
Expand Down
12 changes: 8 additions & 4 deletions librz/core/cio.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,23 @@ RZ_API RzCmdStatus rz_core_io_plugin_print(RzIOPlugin *plugin, RzCmdStateOutput
*/
RZ_API RzCmdStatus rz_core_io_plugins_print(RzIO *io, RzCmdStateOutput *state) {
rz_return_val_if_fail(io && state, RZ_CMD_STATUS_ERROR);
RzIterator *iter = ht_sp_as_iter(io->plugins);
RzIOPlugin **val;

if (!io) {
return RZ_CMD_STATUS_ERROR;
}
rz_cmd_state_output_array_start(state);
rz_cmd_state_output_set_columnsf(state, "sssss", "perm", "license", "name", "uri", "description");
rz_iterator_foreach(iter, val) {
RzIOPlugin *plugin = *val;

RzIterator *iter = ht_sp_as_iter(io->plugins);
RzList *plugin_list = rz_list_new_from_iterator(iter);
rz_list_sort(plugin_list, (RzListComparator)rz_io_plugin_cmp, NULL);
RzListIter *it;
RzIOPlugin *plugin;
rz_list_foreach (plugin_list, it, plugin) {
rz_core_io_plugin_print(plugin, state);
}
rz_iterator_free(iter);
rz_list_free(plugin_list);
rz_cmd_state_output_array_end(state);
return RZ_CMD_STATUS_OK;
}
Expand Down
14 changes: 14 additions & 0 deletions librz/include/rz_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ typedef struct rz_asm_plugin_t {
const char *platforms;
} RzAsmPlugin;

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_asm_plugin_cmp(RZ_NULLABLE const RzAsmPlugin *a, RZ_NULLABLE const RzAsmPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

#ifdef RZ_API
/* asm.c */
RZ_API RzAsm *rz_asm_new(void);
Expand Down
28 changes: 28 additions & 0 deletions librz/include/rz_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,34 @@ typedef struct rz_bin_bind_t {
ut32 visibility;
} RzBinBind;

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_bin_plugin_cmp(RZ_NULLABLE const RzBinPlugin *a, RZ_NULLABLE const RzBinPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_bin_xtr_plugin_cmp(RZ_NULLABLE const RzBinXtrPlugin *a, RZ_NULLABLE const RzBinXtrPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

RZ_API RzBinField *rz_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named);
RZ_API void rz_bin_field_free(RZ_NULLABLE RzBinField *field);
RZ_API RzBinClassField *rz_bin_class_field_new(ut64 vaddr, ut64 paddr, const char *name, const char *classname, const char *libname, const char *type);
Expand Down
14 changes: 14 additions & 0 deletions librz/include/rz_bp.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ typedef struct rz_bp_trace_t {
int bitlen;
} RzBreakpointTrace;

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_breakpoint_plugin_cmp(RZ_NULLABLE const RzBreakpointPlugin *a, RZ_NULLABLE const RzBreakpointPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

#ifdef RZ_API
RZ_API RzBreakpoint *rz_bp_new(RZ_BORROW RZ_NONNULL RzBreakpointContext *ctx);
RZ_API RzBreakpoint *rz_bp_free(RzBreakpoint *bp);
Expand Down
15 changes: 15 additions & 0 deletions librz/include/rz_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <rz_types.h>
#include <rz_util/ht_sp.h>
#include <rz_crypto/rz_des.h>
#include <rz_util/rz_str.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -53,6 +54,20 @@ typedef struct rz_crypto_plugin_t {

typedef ut64 RzCryptoSelector;

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_crypto_plugin_cmp(RZ_NULLABLE const RzCryptoPlugin *a, RZ_NULLABLE const RzCryptoPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

#ifdef RZ_API
RZ_API bool rz_crypto_plugin_add(RZ_NONNULL RzCrypto *cry, RZ_NONNULL RzCryptoPlugin *h);
RZ_API bool rz_crypto_plugin_del(RZ_NONNULL RzCrypto *cry, RZ_NONNULL RzCryptoPlugin *h);
Expand Down
17 changes: 17 additions & 0 deletions librz/include/rz_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <rz_config.h>
#include "rz_bind.h"
#include "rz_util/rz_assert.h"
#include "rz_util/rz_str.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -430,6 +432,21 @@ typedef struct rz_debug_esil_watchpoint_t {
} RzDebugEsilWatchpoint;

#ifdef RZ_API

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_debug_plugin_cmp(RZ_NULLABLE const RzDebugPlugin *a, RZ_NULLABLE const RzDebugPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

RZ_API RZ_OWN RzDebug *rz_debug_new(RZ_BORROW RZ_NONNULL RzBreakpointContext *bp_ctx);
RZ_API RzDebug *rz_debug_free(RzDebug *dbg);

Expand Down
14 changes: 14 additions & 0 deletions librz/include/rz_egg.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ typedef struct rz_egg_emit_t {
void (*get_while_end)(RzEgg *egg, char *out, const char *ctxpush, const char *label);
} RzEggEmit;

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_egg_plugin_cmp(RZ_NULLABLE const RzEggPlugin *a, RZ_NULLABLE const RzEggPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

#ifdef RZ_API
RZ_API RzEgg *rz_egg_new(void);
RZ_API void rz_egg_lang_init(RzEgg *egg);
Expand Down
15 changes: 15 additions & 0 deletions librz/include/rz_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rz_list.h>
#include <rz_util/ht_sp.h>
#include <rz_util/rz_mem.h>
#include <rz_util/rz_str.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -49,6 +50,20 @@ typedef struct rz_hash_cfg_t {
RzHash *hash;
} RzHashCfg;

/**
* \brief Compare plugins by name (via strcmp).
*/
static inline int rz_hash_plugin_cmp(RZ_NULLABLE const RzHashPlugin *a, RZ_NULLABLE const RzHashPlugin *b) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
return rz_str_cmp(a->name, b->name, -1);
}

#ifdef RZ_API

RZ_API RzHash *rz_hash_new(void);
Expand Down
Loading

0 comments on commit 083b5e2

Please sign in to comment.