diff --git a/librz/analysis/class.c b/librz/analysis/class.c index 348c67a2673..8dcb2b73e4a 100644 --- a/librz/analysis/class.c +++ b/librz/analysis/class.c @@ -1257,16 +1257,16 @@ static void rz_analysis_class_list_json(RzAnalysis *analysis) { pj_free(j); } -RZ_API void rz_analysis_class_list(RzAnalysis *analysis, int mode) { - if (mode == 'j') { +RZ_API void rz_analysis_class_list(RzAnalysis *analysis, RzOutputMode mode) { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_analysis_class_list_json(analysis); return; } - SdbList *classes = rz_analysis_class_get_all(analysis, mode != '*'); + SdbList *classes = rz_analysis_class_get_all(analysis, mode != RZ_OUTPUT_MODE_RIZIN); SdbListIter *iter; SdbKv *kv; - if (mode == '*') { + if (mode == RZ_OUTPUT_MODE_RIZIN) { ls_foreach (classes, iter, kv) { // need to create all classes first, so they can be referenced rz_cons_printf("ac %s\n", sdbkv_key(kv)); @@ -1276,7 +1276,7 @@ RZ_API void rz_analysis_class_list(RzAnalysis *analysis, int mode) { } } else { ls_foreach (classes, iter, kv) { - rz_analysis_class_print(analysis, sdbkv_key(kv), mode == 'l'); + rz_analysis_class_print(analysis, sdbkv_key(kv), mode == RZ_OUTPUT_MODE_LONG); } } ls_free(classes); diff --git a/librz/analysis/meta.c b/librz/analysis/meta.c index bba04d0c045..2fc15f60e8a 100644 --- a/librz/analysis/meta.c +++ b/librz/analysis/meta.c @@ -237,8 +237,8 @@ RZ_API const char *rz_meta_type_to_string(int type) { return "# unknown meta # "; } -RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { - rz_return_if_fail(!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL +RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, RzOutputMode mode, PJ *pj, bool show_full) { + rz_return_if_fail(!(mode == RZ_OUTPUT_MODE_JSON && !pj)); // mode == 'j' => pj != NULL char *pstr, *base64_str; RzCore *core = a->coreb.core; bool esc_bslash = core ? core->print->esc_bslash : false; @@ -285,8 +285,8 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 pstr = d->str; } // rz_str_sanitize (str); - switch (rad) { - case 'j': + switch (mode) { + case RZ_OUTPUT_MODE_JSON: pj_o(pj); pj_kn(pj, "offset", start); pj_ks(pj, "type", rz_meta_type_to_string(d->type)); @@ -339,7 +339,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 break; case 0: case 1: - case '*': + case RZ_OUTPUT_MODE_RIZIN: default: switch (d->type) { case RZ_META_TYPE_COMMENT: { @@ -348,7 +348,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 if (!s) { s = strdup(pstr); } - if (rad) { + if (mode) { if (!strcmp(type, "CCu")) { a->cb_printf("%s base64:%s @ 0x%08" PFMT64x "\n", type, s, start); @@ -370,7 +370,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 free(s); } break; case RZ_META_TYPE_STRING: - if (rad) { + if (mode) { char cmd[] = "Cs#"; switch (d->subtype) { case 'a': @@ -402,7 +402,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 break; case RZ_META_TYPE_HIDE: case RZ_META_TYPE_DATA: - if (rad) { + if (mode) { a->cb_printf("%s %" PFMT64u " @ 0x%08" PFMT64x "\n", rz_meta_type_to_string(d->type), size, start); @@ -419,7 +419,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 break; case RZ_META_TYPE_MAGIC: case RZ_META_TYPE_FORMAT: - if (rad) { + if (mode) { a->cb_printf("%s %" PFMT64u " %s @ 0x%08" PFMT64x "\n", rz_meta_type_to_string(d->type), size, pstr, start); @@ -434,7 +434,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 } break; case RZ_META_TYPE_VARTYPE: - if (rad) { + if (mode) { a->cb_printf("%s %s @ 0x%08" PFMT64x "\n", rz_meta_type_to_string(d->type), pstr, start); } else { @@ -450,7 +450,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 // TODO: d->size } break; default: - if (rad) { + if (mode) { a->cb_printf("%s %" PFMT64u " 0x%08" PFMT64x " # %s\n", rz_meta_type_to_string(d->type), size, start, pstr); @@ -470,7 +470,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 } } -RZ_API void rz_meta_print_list_at(RzAnalysis *a, ut64 addr, int rad) { +RZ_API void rz_meta_print_list_at(RzAnalysis *a, ut64 addr, RzOutputMode mode) { RzPVector *nodes = collect_nodes_at(a, RZ_META_TYPE_ANY, rz_spaces_current(&a->meta_spaces), addr); if (!nodes) { return; @@ -478,14 +478,14 @@ RZ_API void rz_meta_print_list_at(RzAnalysis *a, ut64 addr, int rad) { void **it; rz_pvector_foreach (nodes, it) { RzIntervalNode *node = *it; - rz_meta_print(a, node->data, node->start, rz_meta_node_size(node), rad, NULL, true); + rz_meta_print(a, node->data, node->start, rz_meta_node_size(node), mode, NULL, true); } rz_pvector_free(nodes); } -static void print_meta_list(RzAnalysis *a, int type, int rad, ut64 addr) { +static void print_meta_list(RzAnalysis *a, int type, RzOutputMode mode, ut64 addr) { PJ *pj = NULL; - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { return; @@ -511,7 +511,7 @@ static void print_meta_list(RzAnalysis *a, int type, int rad, ut64 addr) { if (fcn && !rz_analysis_function_contains(fcn, node->start)) { continue; } - rz_meta_print(a, item, node->start, rz_meta_node_size(node), rad, pj, true); + rz_meta_print(a, item, node->start, rz_meta_node_size(node), mode, pj, true); } beach: @@ -522,12 +522,12 @@ static void print_meta_list(RzAnalysis *a, int type, int rad, ut64 addr) { } } -RZ_API void rz_meta_print_list_all(RzAnalysis *a, int type, int rad) { - print_meta_list(a, type, rad, UT64_MAX); +RZ_API void rz_meta_print_list_all(RzAnalysis *a, int type, RzOutputMode mode) { + print_meta_list(a, type, mode, UT64_MAX); } -RZ_API void rz_meta_print_list_in_function(RzAnalysis *a, int type, int rad, ut64 addr) { - print_meta_list(a, type, rad, addr); +RZ_API void rz_meta_print_list_in_function(RzAnalysis *a, int type, RzOutputMode mode, ut64 addr) { + print_meta_list(a, type, mode, addr); } RZ_API void rz_meta_rebase(RzAnalysis *analysis, ut64 diff) { diff --git a/librz/analysis/rtti.c b/librz/analysis/rtti.c index af48301e221..838cf83586c 100644 --- a/librz/analysis/rtti.c +++ b/librz/analysis/rtti.c @@ -14,8 +14,8 @@ RZ_API char *rz_analysis_rtti_demangle_class_name(RzAnalysis *analysis, const ch return rz_analysis_rtti_itanium_demangle_class_name(&context, name); } -RZ_API void rz_analysis_rtti_print_at_vtable(RzAnalysis *analysis, ut64 addr, int mode) { - bool use_json = mode == 'j'; +RZ_API void rz_analysis_rtti_print_at_vtable(RzAnalysis *analysis, ut64 addr, RzOutputMode mode) { + bool use_json = mode == RZ_OUTPUT_MODE_JSON; if (use_json) { rz_cons_print("["); } @@ -33,11 +33,11 @@ RZ_API void rz_analysis_rtti_print_at_vtable(RzAnalysis *analysis, ut64 addr, in } } -RZ_API void rz_analysis_rtti_print_all(RzAnalysis *analysis, int mode) { +RZ_API void rz_analysis_rtti_print_all(RzAnalysis *analysis, RzOutputMode mode) { RVTableContext context; rz_analysis_vtable_begin(analysis, &context); - bool use_json = mode == 'j'; + bool use_json = mode == RZ_OUTPUT_MODE_JSON; if (use_json) { rz_cons_print("["); } diff --git a/librz/analysis/rtti_itanium.c b/librz/analysis/rtti_itanium.c index e4297cd07c7..2cd2e638fe8 100644 --- a/librz/analysis/rtti_itanium.c +++ b/librz/analysis/rtti_itanium.c @@ -696,8 +696,8 @@ static void rtti_itanium_type_info_free(void *info) { } } -RZ_API bool rz_analysis_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, int mode) { - bool use_json = mode == 'j'; +RZ_API bool rz_analysis_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, RzOutputMode mode) { + bool use_json = mode == RZ_OUTPUT_MODE_JSON; class_type_info *cti = rtti_itanium_type_info_new(context, addr); if (!cti) { return false; diff --git a/librz/analysis/rtti_msvc.c b/librz/analysis/rtti_msvc.c index 7feba6721f8..019823bcfcf 100644 --- a/librz/analysis/rtti_msvc.c +++ b/librz/analysis/rtti_msvc.c @@ -416,14 +416,14 @@ RZ_API char *rz_analysis_rtti_msvc_demangle_class_name(RVTableContext *context, return ret; } -RZ_API void rz_analysis_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_analysis_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, RzOutputMode mode) { rtti_complete_object_locator col; if (!rtti_msvc_read_complete_object_locator(context, addr, &col)) { eprintf("Failed to parse Complete Object Locator at 0x%08" PFMT64x "\n", addr); return; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { PJ *pj = pj_new(); if (!pj) { return; @@ -436,14 +436,14 @@ RZ_API void rz_analysis_rtti_msvc_print_complete_object_locator(RVTableContext * } } -RZ_API void rz_analysis_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_analysis_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, RzOutputMode mode) { rtti_type_descriptor td = { 0 }; if (!rtti_msvc_read_type_descriptor(context, addr, &td)) { eprintf("Failed to parse Type Descriptor at 0x%08" PFMT64x "\n", addr); return; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { PJ *pj = pj_new(); if (!pj) { return; @@ -458,14 +458,14 @@ RZ_API void rz_analysis_rtti_msvc_print_type_descriptor(RVTableContext *context, rtti_type_descriptor_fini(&td); } -RZ_API void rz_analysis_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_analysis_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, RzOutputMode mode) { rtti_class_hierarchy_descriptor chd; if (!rtti_msvc_read_class_hierarchy_descriptor(context, addr, &chd)) { eprintf("Failed to parse Class Hierarchy Descriptor at 0x%08" PFMT64x "\n", addr); return; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { PJ *pj = pj_new(); if (!pj) { return; @@ -478,14 +478,14 @@ RZ_API void rz_analysis_rtti_msvc_print_class_hierarchy_descriptor(RVTableContex } } -RZ_API void rz_analysis_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_analysis_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, RzOutputMode mode) { rtti_base_class_descriptor bcd; if (!rtti_msvc_read_base_class_descriptor(context, addr, &bcd)) { eprintf("Failed to parse Base Class Descriptor at 0x%08" PFMT64x "\n", addr); return; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { PJ *pj = pj_new(); if (!pj) { return; @@ -498,7 +498,7 @@ RZ_API void rz_analysis_rtti_msvc_print_base_class_descriptor(RVTableContext *co } } -static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *context, ut64 atAddress, int mode, bool strict) { +static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *context, ut64 atAddress, RzOutputMode mode, bool strict) { ut64 colRefAddr = atAddress - context->word_size; ut64 colAddr; if (!context->read_addr(context->analysis, colRefAddr, &colAddr)) { @@ -552,7 +552,7 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont } // print - bool use_json = mode == 'j'; + bool use_json = mode == RZ_OUTPUT_MODE_JSON; PJ *pj = NULL; if (use_json) { pj = pj_new(); @@ -616,7 +616,7 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont return true; } -RZ_API bool rz_analysis_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, int mode, bool strict) { +RZ_API bool rz_analysis_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, RzOutputMode mode, bool strict) { return rtti_msvc_print_complete_object_locator_recurse(context, addr, mode, strict); } diff --git a/librz/analysis/var.c b/librz/analysis/var.c index dd61f5511d3..d2a48ca5add 100644 --- a/librz/analysis/var.c +++ b/librz/analysis/var.c @@ -1175,18 +1175,18 @@ static int regvar_comparator(const RzAnalysisVar *a, const RzAnalysisVar *b) { return (a && b) ? (a->argnum > b->argnum) - (a->argnum < b->argnum) : 0; } -RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction *fcn, int kind, int mode, PJ *pj) { +RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction *fcn, int kind, RzOutputMode mode, PJ *pj) { RzList *list = rz_analysis_var_list(analysis, fcn, kind); RzAnalysisVar *var; RzListIter *iter; - if (!pj && mode == 'j') { + if (!pj && mode == RZ_OUTPUT_MODE_JSON) { return; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_a(pj); } if (!list) { - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } return; @@ -1197,7 +1197,7 @@ RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction * continue; } switch (mode) { - case '*': + case RZ_OUTPUT_MODE_RIZIN: // we can't express all type info here :( if (kind == RZ_ANALYSIS_VAR_KIND_REG) { // registers RzRegItem *i = rz_reg_index_get(analysis->reg, var->delta); @@ -1216,7 +1216,7 @@ RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction * fcn->addr); } break; - case 'j': + case RZ_OUTPUT_MODE_JSON: switch (var->kind) { case RZ_ANALYSIS_VAR_KIND_BPV: { st64 delta = (st64)var->delta + fcn->bp_off; @@ -1311,7 +1311,7 @@ RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction * } } } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } rz_list_free(list); diff --git a/librz/analysis/vtable.c b/librz/analysis/vtable.c index c1675b91e9c..39f6fdf411f 100644 --- a/librz/analysis/vtable.c +++ b/librz/analysis/vtable.c @@ -285,7 +285,7 @@ RZ_API RzList *rz_analysis_vtable_search(RVTableContext *context) { return vtables; } -RZ_API void rz_analysis_list_vtables(RzAnalysis *analysis, int rad) { +RZ_API void rz_analysis_list_vtables(RzAnalysis *analysis, RzOutputMode mode) { RVTableContext context; rz_analysis_vtable_begin(analysis, &context); @@ -296,7 +296,7 @@ RZ_API void rz_analysis_list_vtables(RzAnalysis *analysis, int rad) { RzList *vtables = rz_analysis_vtable_search(&context); - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { PJ *pj = pj_new(); if (!pj) { return; @@ -320,7 +320,7 @@ RZ_API void rz_analysis_list_vtables(RzAnalysis *analysis, int rad) { pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); - } else if (rad == '*') { + } else if (mode == RZ_OUTPUT_MODE_RIZIN) { rz_list_foreach (vtables, vtableIter, table) { rz_cons_printf("f vtable.0x%08" PFMT64x " %" PFMT64d " @ 0x%08" PFMT64x "\n", table->saddr, diff --git a/librz/analysis/xrefs.c b/librz/analysis/xrefs.c index 6192e337ab1..22d141d2e6b 100644 --- a/librz/analysis/xrefs.c +++ b/librz/analysis/xrefs.c @@ -199,14 +199,14 @@ RZ_API RzList *rz_analysis_xrefs_get_from(RzAnalysis *analysis, ut64 to) { return list; } -RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, int rad) { +RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, RzOutputMode mode) { RzListIter *iter; RzAnalysisRef *ref; PJ *pj = NULL; RzList *list = rz_analysis_ref_list_new(); listxrefs(analysis->dict_refs, UT64_MAX, list); sortxrefs(list); - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = analysis->coreb.pjWithEncoding(analysis->coreb.core); if (!pj) { return; @@ -215,8 +215,8 @@ RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, int rad) { } rz_list_foreach (list, iter, ref) { int t = ref->type ? ref->type : ' '; - switch (rad) { - case '*': + switch (mode) { + case RZ_OUTPUT_MODE_RIZIN: analysis->cb_printf("ax%c 0x%" PFMT64x " 0x%" PFMT64x "\n", t, ref->addr, ref->at); break; case '\0': { @@ -238,10 +238,10 @@ RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, int rad) { analysis->cb_printf("\n"); } } break; - case 'q': + case RZ_OUTPUT_MODE_QUIET: analysis->cb_printf("0x%08" PFMT64x " -> 0x%08" PFMT64x " %s\n", ref->at, ref->addr, rz_analysis_xrefs_type_tostring(t)); break; - case 'j': { + case RZ_OUTPUT_MODE_JSON: { pj_o(pj); char *name = analysis->coreb.getNameDelta(analysis->coreb.core, ref->at); if (name) { @@ -264,7 +264,7 @@ RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, int rad) { break; } } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); analysis->cb_printf("%s\n", pj_string(pj)); pj_free(pj); diff --git a/librz/bin/bin.c b/librz/bin/bin.c index aff3cc592f8..7108ace4df3 100644 --- a/librz/bin/bin.c +++ b/librz/bin/bin.c @@ -956,7 +956,7 @@ RZ_API bool rz_bin_select_bfid(RzBin *bin, ut32 bf_id) { return bf ? rz_bin_file_set_obj(bin, bf, NULL) : false; } -static void list_xtr_archs(RzBin *bin, PJ *pj, int mode) { +static void list_xtr_archs(RzBin *bin, PJ *pj, RzOutputMode mode) { RzBinFile *binfile = rz_bin_cur(bin); if (binfile->xtr_data) { RzListIter *iter_xtr; @@ -964,7 +964,7 @@ static void list_xtr_archs(RzBin *bin, PJ *pj, int mode) { int bits, i = 0; char *arch, *machine; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_ka(pj, "bins"); } @@ -977,10 +977,10 @@ static void list_xtr_archs(RzBin *bin, PJ *pj, int mode) { machine = xtr_data->metadata->machine; bits = xtr_data->metadata->bits; switch (mode) { - case 'q': // "iAq" + case RZ_OUTPUT_MODE_QUIET: // "iAq" bin->cb_printf("%s\n", arch); break; - case 'j': { // "iAj" + case RZ_OUTPUT_MODE_JSON: { // "iAj" pj_o(pj); pj_ks(pj, "arch", arch); pj_ki(pj, "bits", bits); @@ -1000,13 +1000,13 @@ static void list_xtr_archs(RzBin *bin, PJ *pj, int mode) { } } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } } } -RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode) { +RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, RzOutputMode mode) { rz_return_if_fail(bin); char unk[128]; @@ -1036,7 +1036,7 @@ RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode) { } RzTable *table = rz_table_new(); const char *fmt = "dXnss"; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_ka(pj, "bins"); } RzBinObject *obj = nbinfile->o; @@ -1057,10 +1057,10 @@ RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode) { if (info && narch > 1) { switch (mode) { - case 'q': + case RZ_OUTPUT_MODE_QUIET: bin->cb_printf("%s\n", arch); break; - case 'j': + case RZ_OUTPUT_MODE_JSON: pj_o(pj); pj_ks(pj, "arch", arch); pj_ki(pj, "bits", bits); @@ -1089,10 +1089,10 @@ RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode) { } else { if (info) { switch (mode) { - case 'q': + case RZ_OUTPUT_MODE_QUIET: bin->cb_printf("%s\n", arch); break; - case 'j': + case RZ_OUTPUT_MODE_JSON: pj_o(pj); pj_ks(pj, "arch", arch); pj_ki(pj, "bits", bits); @@ -1118,10 +1118,10 @@ RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode) { boffset, obj_size, arch, bits); } else if (nbinfile && mode) { switch (mode) { - case 'q': + case RZ_OUTPUT_MODE_QUIET: bin->cb_printf("%s\n", arch); break; - case 'j': + case RZ_OUTPUT_MODE_JSON: pj_o(pj); pj_ks(pj, "arch", arch); pj_ki(pj, "bits", bits); @@ -1144,7 +1144,7 @@ RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode) { } //sdb_array_push (binfile_sdb, ARCHS_KEY, archline, 0); } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } rz_table_free(table); diff --git a/librz/bin/pdb/pdb.c b/librz/bin/pdb/pdb.c index 81a36325dcb..9d0108a4218 100644 --- a/librz/bin/pdb/pdb.c +++ b/librz/bin/pdb/pdb.c @@ -1307,7 +1307,7 @@ static void print_types_format(const RzPdb *pdb, const RzList *types) { * @param pdb PDB information * @param mode printing mode */ -static void print_types(const RzPdb *pdb, PJ *pj, const int mode) { +static void print_types(const RzPdb *pdb, PJ *pj, const RzOutputMode mode) { RzList *plist = pdb->pdb_streams; STpiStream *tpi_stream = rz_list_get_n(plist, ePDB_STREAM_TPI); @@ -1317,8 +1317,8 @@ static void print_types(const RzPdb *pdb, PJ *pj, const int mode) { } switch (mode) { case 'd': print_types_regular(pdb, tpi_stream->types); return; - case 'j': print_types_json(pdb, pj, tpi_stream->types); return; - case 'r': print_types_format(pdb, tpi_stream->types); return; + case RZ_OUTPUT_MODE_JSON: print_types_json(pdb, pj, tpi_stream->types); return; + case RZ_OUTPUT_MODE_RIZIN: print_types_format(pdb, tpi_stream->types); return; } } diff --git a/librz/bp/bp.c b/librz/bp/bp.c index d9b3df69188..300024d5bd0 100644 --- a/librz/bp/bp.c +++ b/librz/bp/bp.c @@ -280,12 +280,12 @@ RZ_API int rz_bp_set_trace_all(RzBreakpoint *bp, int set) { } // TODO: deprecate -RZ_API int rz_bp_list(RzBreakpoint *bp, int rad) { +RZ_API int rz_bp_list(RzBreakpoint *bp, RzOutputMode mode) { int n = 0; RzBreakpointItem *b; RzListIter *iter; PJ *pj = NULL; - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { return 0; @@ -306,7 +306,7 @@ RZ_API int rz_bp_list(RzBreakpoint *bp, int rad) { pj_ks(pj, "data", rz_str_get(b->data)); pj_ks(pj, "cond", rz_str_get(b->cond)); pj_end(pj); - } else if (rad) { + } else if (mode) { if (b->module_name) { bp->cb_printf("dbm %s %" PFMT64d "\n", b->module_name, b->module_delta); } else { diff --git a/librz/config/config.c b/librz/config/config.c index f7df7fd9084..2feff23b053 100644 --- a/librz/config/config.c +++ b/librz/config/config.c @@ -136,7 +136,7 @@ static void config_print_node(RzConfig *cfg, RzConfigNode *node, const char *pfx } } -RZ_API void rz_config_list(RzConfig *cfg, const char *str, int rad) { +RZ_API void rz_config_list(RzConfig *cfg, const char *str, RzOutputMode mode) { rz_return_if_fail(cfg); RzConfigNode *node; RzListIter *iter; @@ -154,7 +154,7 @@ RZ_API void rz_config_list(RzConfig *cfg, const char *str, int rad) { str++; len--; json = true; - rad = 'J'; + mode = RZ_OUTPUT_MODE_LONG_JSON; } if (len > 0 && str[0] == ' ') { str++; @@ -166,7 +166,7 @@ RZ_API void rz_config_list(RzConfig *cfg, const char *str, int rad) { } } - switch (rad) { + switch (mode) { case 1: pfx = "\"e "; sfx = "\""; @@ -232,17 +232,17 @@ RZ_API void rz_config_list(RzConfig *cfg, const char *str, int rad) { } } break; - case 'q': + case RZ_OUTPUT_MODE_QUIET: rz_list_foreach (cfg->nodes, iter, node) { if (!str || (str && (!strncmp(str, node->name, len)))) { cfg->cb_printf("%s\n", node->name); } } break; - case 'J': + case RZ_OUTPUT_MODE_LONG_JSON: verbose = true; /* fallthrou */ - case 'j': + case RZ_OUTPUT_MODE_JSON: isFirst = true; if (verbose) { cfg->cb_printf("["); @@ -688,7 +688,7 @@ static void __evalString(RzConfig *cfg, char *name) { } } else { if (rz_str_endswith(name, ".")) { - rz_config_list(cfg, name, 0); + rz_config_list(cfg, name, RZ_OUTPUT_MODE_QUIET); } else { const char *v = rz_config_get(cfg, name); if (v) { @@ -706,7 +706,7 @@ RZ_API bool rz_config_eval(RzConfig *cfg, const char *str, bool many) { char *s = rz_str_trim_dup(str); if (!*s || !strcmp(s, "help")) { - rz_config_list(cfg, NULL, 0); + rz_config_list(cfg, NULL, RZ_OUTPUT_MODE_QUIET); free(s); return false; } diff --git a/librz/cons/pal.c b/librz/cons/pal.c index 247210e1681..8c8eb1669d1 100644 --- a/librz/cons/pal.c +++ b/librz/cons/pal.c @@ -524,18 +524,18 @@ typedef struct { const char *str; } RAttrStr; -RZ_API void rz_cons_pal_list(int rad, const char *arg) { +RZ_API void rz_cons_pal_list(RzOutputMode mode, const char *arg) { char *name, **color; const char *hasnext; int i; - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_cons_print("{"); } for (i = 0; keys[i].name; i++) { RzColor *rcolor = RZCOLOR_AT(i); color = COLOR_AT(i); - switch (rad) { - case 'j': + switch (mode) { + case RZ_OUTPUT_MODE_JSON: hasnext = (keys[i + 1].name) ? "," : ""; rz_cons_printf("\"%s\":[%d,%d,%d]%s", keys[i].name, rcolor->r, rcolor->g, rcolor->b, hasnext); @@ -566,7 +566,7 @@ RZ_API void rz_cons_pal_list(int rad, const char *arg) { free(name); break; case '*': - case 'r': + case RZ_OUTPUT_MODE_RIZIN: case 1: rz_cons_printf("ec %s rgb:%02x%02x%02x", keys[i].name, rcolor->r, rcolor->g, rcolor->b); @@ -599,7 +599,7 @@ RZ_API void rz_cons_pal_list(int rad, const char *arg) { keys[i].name); } } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_cons_print("}\n"); } } diff --git a/librz/core/canalysis.c b/librz/core/canalysis.c index 88fe2e57e33..d0fbdac5a4a 100644 --- a/librz/core/canalysis.c +++ b/librz/core/canalysis.c @@ -989,7 +989,7 @@ static bool blacklisted_word(char *name) { return false; } -static char *analysis_fcn_autoname(RzCore *core, RzAnalysisFunction *fcn, int dump, int mode) { +static char *analysis_fcn_autoname(RzCore *core, RzAnalysisFunction *fcn, int dump, RzOutputMode mode) { int use_getopt = 0; int use_isatty = 0; PJ *pj = NULL; @@ -997,7 +997,7 @@ static char *analysis_fcn_autoname(RzCore *core, RzAnalysisFunction *fcn, int du RzAnalysisRef *ref; RzListIter *iter; RzList *refs = rz_analysis_function_get_refs(fcn); - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { // start a new JSON object pj = rz_core_pj_new(core); pj_a(pj); @@ -1010,7 +1010,7 @@ static char *analysis_fcn_autoname(RzCore *core, RzAnalysisFunction *fcn, int du if (dump) { // take only strings flags if (!strncmp(f->name, "str.", 4)) { - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { // add new json item pj_o(pj); pj_kn(pj, "addr", ref->at); @@ -1060,7 +1060,7 @@ static char *analysis_fcn_autoname(RzCore *core, RzAnalysisFunction *fcn, int du } rz_list_free(refs); } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } if (pj) { @@ -1099,7 +1099,7 @@ RZ_API void rz_core_analysis_autoname_all_fcns(RzCore *core) { if (!strncmp(fcn->name, "fcn.", 4) || !strncmp(fcn->name, "sym.func.", 9)) { RzFlagItem *item = rz_flag_get(core->flags, fcn->name); if (item) { - char *name = analysis_fcn_autoname(core, fcn, 0, 0); + char *name = analysis_fcn_autoname(core, fcn, 0, RZ_OUTPUT_MODE_QUIET); if (name) { rz_flag_rename(core->flags, item, name); free(fcn->name); @@ -1181,7 +1181,7 @@ RZ_API void rz_core_analysis_autoname_all_golang_fcns(RzCore *core) { /* suggest a name for the function at the address 'addr'. * If dump is true, every strings associated with the function is printed */ -RZ_API char *rz_core_analysis_fcn_autoname(RzCore *core, ut64 addr, int dump, int mode) { +RZ_API char *rz_core_analysis_fcn_autoname(RzCore *core, ut64 addr, int dump, RzOutputMode mode) { RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, addr, 0); if (fcn) { return analysis_fcn_autoname(core, fcn, dump, mode); @@ -1728,9 +1728,9 @@ static void print_hint_h_format(HintNode *node) { } // if mode == 'j', pj must be an existing PJ! -static void hint_node_print(HintNode *node, int mode, PJ *pj) { +static void hint_node_print(HintNode *node, RzOutputMode mode, PJ *pj) { switch (mode) { - case '*': + case RZ_OUTPUT_MODE_RIZIN: #define HINTCMD_ADDR(hint, fmt, x) rz_cons_printf(fmt " @ 0x%" PFMT64x "\n", x, (hint)->addr) switch (node->type) { case HINT_NODE_ADDR: { @@ -1802,7 +1802,7 @@ static void hint_node_print(HintNode *node, int mode, PJ *pj) { } #undef HINTCMD_ADDR break; - case 'j': + case RZ_OUTPUT_MODE_JSON: switch (node->type) { case HINT_NODE_ADDR: { const RzAnalysisAddrHintRecord *record; @@ -1933,16 +1933,16 @@ bool print_bits_hint_cb(ut64 addr, int bits, void *user) { return true; } -static void print_hint_tree(RBTree tree, int mode) { +static void print_hint_tree(RBTree tree, RzOutputMode mode) { PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); pj_a(pj); } #define END_ADDR \ if (pj) { \ pj_end(pj); \ - } else if (mode != '*') { \ + } else if (mode != RZ_OUTPUT_MODE_RIZIN) { \ rz_cons_newline(); \ } RBIter it; @@ -1959,7 +1959,7 @@ static void print_hint_tree(RBTree tree, int mode) { if (pj) { pj_o(pj); pj_kn(pj, "addr", node->addr); - } else if (mode != '*') { + } else if (mode != RZ_OUTPUT_MODE_RIZIN) { rz_cons_printf(" 0x%08" PFMT64x " =>", node->addr); } } @@ -1977,7 +1977,7 @@ static void print_hint_tree(RBTree tree, int mode) { } } -RZ_API void rz_core_analysis_hint_list(RzAnalysis *a, int mode) { +RZ_API void rz_core_analysis_hint_list(RzAnalysis *a, RzOutputMode mode) { RBTree tree = NULL; // Collect all hints in the tree to sort them rz_analysis_arch_hints_foreach(a, print_arch_hint_cb, &tree); @@ -1987,7 +1987,7 @@ RZ_API void rz_core_analysis_hint_list(RzAnalysis *a, int mode) { rz_rbtree_free(tree, hint_node_free, NULL); } -RZ_API void rz_core_analysis_hint_print(RzAnalysis *a, ut64 addr, int mode) { +RZ_API void rz_core_analysis_hint_print(RzAnalysis *a, ut64 addr, RzOutputMode mode) { RBTree tree = NULL; ut64 hint_addr = UT64_MAX; const char *arch = rz_analysis_hint_arch_at(a, addr, &hint_addr); @@ -3413,7 +3413,7 @@ RZ_API RzList *rz_core_analysis_fcn_get_calls(RzCore *core, RzAnalysisFunction * } // Lists function names and their calls (uniqified) -static int fcn_print_makestyle(RzCore *core, RzList *fcns, char mode) { +static int fcn_print_makestyle(RzCore *core, RzList *fcns, RzOutputMode mode) { RzListIter *refiter; RzListIter *fcniter; RzAnalysisFunction *fcn; @@ -3421,7 +3421,7 @@ static int fcn_print_makestyle(RzCore *core, RzList *fcns, char mode) { RzList *refs = NULL; PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); pj_a(pj); } @@ -3447,7 +3447,7 @@ static int fcn_print_makestyle(RzCore *core, RzList *fcns, char mode) { if (mode == 'm') { rz_cons_printf(":\n"); - } else if (mode == 'q') { + } else if (mode == RZ_OUTPUT_MODE_QUIET) { rz_cons_printf(" -> "); } // Iterate over all refs from a function @@ -3459,7 +3459,7 @@ static int fcn_print_makestyle(RzCore *core, RzList *fcns, char mode) { pj_ks(pj, "name", dst); pj_kn(pj, "addr", refi->addr); pj_end(pj); // close referenced item - } else if (mode == 'q') { + } else if (mode == RZ_OUTPUT_MODE_QUIET) { rz_cons_printf("%s ", dst); } else { rz_cons_printf(" %s\n", dst); @@ -3474,7 +3474,7 @@ static int fcn_print_makestyle(RzCore *core, RzList *fcns, char mode) { } } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); // close json output rz_cons_printf("%s\n", pj_string(pj)); } @@ -3593,11 +3593,11 @@ static int fcn_print_json(RzCore *core, RzAnalysisFunction *fcn, PJ *pj) { pj_ki(pj, "nargs", rz_analysis_var_count(core->analysis, fcn, 'b', 1) + rz_analysis_var_count(core->analysis, fcn, 'r', 1) + rz_analysis_var_count(core->analysis, fcn, 's', 1)); pj_k(pj, "bpvars"); - rz_analysis_var_list_show(core->analysis, fcn, 'b', 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, 'b', RZ_OUTPUT_MODE_JSON, pj); pj_k(pj, "spvars"); - rz_analysis_var_list_show(core->analysis, fcn, 's', 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, 's', RZ_OUTPUT_MODE_JSON, pj); pj_k(pj, "regvars"); - rz_analysis_var_list_show(core->analysis, fcn, 'r', 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, 'r', RZ_OUTPUT_MODE_JSON, pj); pj_ks(pj, "difftype", fcn->diff->type == RZ_ANALYSIS_DIFF_TYPE_MATCH ? "match" : fcn->diff->type == RZ_ANALYSIS_DIFF_TYPE_UNMATCH ? "unmatch" : "new"); @@ -3660,9 +3660,9 @@ static int fcn_print_detail(RzCore *core, RzAnalysisFunction *fcn) { } if (fcn) { /* show variables and arguments */ - rz_analysis_var_list_show(core->analysis, fcn, 'b', '*', NULL); - rz_analysis_var_list_show(core->analysis, fcn, 'r', '*', NULL); - rz_analysis_var_list_show(core->analysis, fcn, 's', '*', NULL); + rz_analysis_var_list_show(core->analysis, fcn, 'b', RZ_OUTPUT_MODE_RIZIN, NULL); + rz_analysis_var_list_show(core->analysis, fcn, 'r', RZ_OUTPUT_MODE_RIZIN, NULL); + rz_analysis_var_list_show(core->analysis, fcn, 's', RZ_OUTPUT_MODE_RIZIN, NULL); } /* Show references */ RzListIter *refiter; @@ -3789,9 +3789,9 @@ static int fcn_print_legacy(RzCore *core, RzAnalysisFunction *fcn) { var_count += rz_analysis_var_count(core->analysis, fcn, 'r', 0); rz_cons_printf("\nlocals: %d\nargs: %d\n", var_count, args_count); - rz_analysis_var_list_show(core->analysis, fcn, 'b', 0, NULL); - rz_analysis_var_list_show(core->analysis, fcn, 's', 0, NULL); - rz_analysis_var_list_show(core->analysis, fcn, 'r', 0, NULL); + rz_analysis_var_list_show(core->analysis, fcn, 'b', RZ_OUTPUT_MODE_QUIET, NULL); + rz_analysis_var_list_show(core->analysis, fcn, 's', RZ_OUTPUT_MODE_QUIET, NULL); + rz_analysis_var_list_show(core->analysis, fcn, 'r', RZ_OUTPUT_MODE_QUIET, NULL); rz_cons_printf("diff: type: %s", fcn->diff->type == RZ_ANALYSIS_DIFF_TYPE_MATCH ? "match" : fcn->diff->type == RZ_ANALYSIS_DIFF_TYPE_UNMATCH ? "unmatch" : "new"); @@ -3988,12 +3988,12 @@ RZ_API int rz_core_analysis_fcn_list(RzCore *core, const char *input, const char break; case 'm': // "aflm" { - char mode = 'm'; + RzOutputMode mode = 'm'; if (rad[1] != 0) { if (rad[1] == 'j') { // "aflmj" - mode = 'j'; + mode = RZ_OUTPUT_MODE_JSON; } else if (rad[1] == 'q') { // "aflmq" - mode = 'q'; + mode = RZ_OUTPUT_MODE_QUIET; } } fcn_print_makestyle(core, fcns, mode); @@ -4398,7 +4398,7 @@ static bool opiscall(RzCore *core, RzAnalysisOp *aop, ut64 addr, const ut8 *buf, } #define OPSZ 8 -RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, int mode) { +RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, RzOutputMode mode) { ut8 *buf = (ut8 *)malloc(core->blocksize); if (!buf) { return -1; @@ -4464,11 +4464,11 @@ RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, i op.size = 1; } break; - case 'r': + case RZ_OUTPUT_MODE_RIZIN: case 'w': case 'x': { rz_analysis_op(core->analysis, &op, at + i, buf + i, core->blocksize - i, RZ_ANALYSIS_OP_MASK_BASIC); - int mask = mode == 'r' ? 1 : mode == 'w' ? 2 + int mask = mode == RZ_OUTPUT_MODE_RIZIN ? 1 : mode == 'w' ? 2 : mode == 'x' ? 4 : 0; if (op.direction == mask) { @@ -4555,7 +4555,7 @@ RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, i return count; } -static bool found_xref(RzCore *core, ut64 at, ut64 xref_to, RzAnalysisRefType type, PJ *pj, int rad, int cfg_debug, bool cfg_analysis_strings) { +static bool found_xref(RzCore *core, ut64 at, ut64 xref_to, RzAnalysisRefType type, PJ *pj, RzOutputMode mode, int cfg_debug, bool cfg_analysis_strings) { // Validate the reference. If virtual addressing is enabled, we // allow only references to virtual addresses in order to reduce // the number of false positives. In debugger mode, the reference @@ -4572,7 +4572,7 @@ static bool found_xref(RzCore *core, ut64 at, ut64 xref_to, RzAnalysisRefType ty return false; } } - if (!rad) { + if (!mode) { if (cfg_analysis_strings && type == RZ_ANALYSIS_REF_TYPE_DATA) { int len = 0; char *str_string = is_string_at(core, xref_to, &len); @@ -4594,7 +4594,7 @@ static bool found_xref(RzCore *core, ut64 at, ut64 xref_to, RzAnalysisRefType ty if (xref_to) { rz_analysis_xrefs_set(core->analysis, at, xref_to, type); } - } else if (rad == 'j') { + } else if (mode == RZ_OUTPUT_MODE_JSON) { char *key = sdb_fmt("0x%" PFMT64x, xref_to); char *value = sdb_fmt("0x%" PFMT64x, at); pj_ks(pj, key, value); @@ -4623,7 +4623,7 @@ static bool found_xref(RzCore *core, ut64 at, ut64 xref_to, RzAnalysisRefType ty return true; } -RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *pj, int rad) { +RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *pj, RzOutputMode mode) { bool cfg_debug = rz_config_get_b(core->config, "cfg.debug"); bool cfg_analysis_strings = rz_config_get_i(core->config, "analysis.strings"); ut64 at; @@ -4686,32 +4686,32 @@ RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *p } // find references if ((st64)op.val > asm_sub_varmin && op.val != UT64_MAX && op.val != UT32_MAX) { - if (found_xref(core, op.addr, op.val, RZ_ANALYSIS_REF_TYPE_DATA, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.val, RZ_ANALYSIS_REF_TYPE_DATA, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } } // find references if (op.ptr && op.ptr != UT64_MAX && op.ptr != UT32_MAX) { - if (found_xref(core, op.addr, op.ptr, RZ_ANALYSIS_REF_TYPE_DATA, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.ptr, RZ_ANALYSIS_REF_TYPE_DATA, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } } // find references if (op.addr > 512 && op.disp > 512 && op.disp && op.disp != UT64_MAX) { - if (found_xref(core, op.addr, op.disp, RZ_ANALYSIS_REF_TYPE_DATA, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.disp, RZ_ANALYSIS_REF_TYPE_DATA, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } } switch (op.type) { case RZ_ANALYSIS_OP_TYPE_JMP: case RZ_ANALYSIS_OP_TYPE_CJMP: - if (found_xref(core, op.addr, op.jump, RZ_ANALYSIS_REF_TYPE_CODE, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.jump, RZ_ANALYSIS_REF_TYPE_CODE, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } break; case RZ_ANALYSIS_OP_TYPE_CALL: case RZ_ANALYSIS_OP_TYPE_CCALL: - if (found_xref(core, op.addr, op.jump, RZ_ANALYSIS_REF_TYPE_CALL, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.jump, RZ_ANALYSIS_REF_TYPE_CALL, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } break; @@ -4722,7 +4722,7 @@ RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *p case RZ_ANALYSIS_OP_TYPE_MJMP: case RZ_ANALYSIS_OP_TYPE_UCJMP: count++; - if (found_xref(core, op.addr, op.ptr, RZ_ANALYSIS_REF_TYPE_CODE, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.ptr, RZ_ANALYSIS_REF_TYPE_CODE, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } break; @@ -4731,7 +4731,7 @@ RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *p case RZ_ANALYSIS_OP_TYPE_RCALL: case RZ_ANALYSIS_OP_TYPE_IRCALL: case RZ_ANALYSIS_OP_TYPE_UCCALL: - if (found_xref(core, op.addr, op.ptr, RZ_ANALYSIS_REF_TYPE_CALL, pj, rad, cfg_debug, cfg_analysis_strings)) { + if (found_xref(core, op.addr, op.ptr, RZ_ANALYSIS_REF_TYPE_CALL, pj, mode, cfg_debug, cfg_analysis_strings)) { count++; } break; diff --git a/librz/core/cbin.c b/librz/core/cbin.c index d1719b71968..7aedc143550 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -1267,7 +1267,7 @@ static bool bin_dwarf(RzCore *core, RzBinFile *binfile, PJ *pj, int mode) { return true; } -RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, PJ *pj, int mode) { +RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, PJ *pj, RzOutputMode mode) { rz_return_val_if_fail(core && file, false); ut64 baddr = rz_config_get_i(core->config, "bin.baddr"); @@ -1294,17 +1294,17 @@ RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, PJ *pj, int mode) { rz_core_cmd0(core, ".iP*"); return true; case RZ_MODE_JSON: - mode = 'j'; + mode = RZ_OUTPUT_MODE_JSON; break; case '*': case 1: - mode = 'r'; + mode = RZ_OUTPUT_MODE_RIZIN; break; default: mode = 'd'; // default break; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_o(pj); } @@ -1314,7 +1314,7 @@ RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, PJ *pj, int mode) { rz_parse_pdb_types(core->analysis, &pdb); pdb.finish_pdb_parse(&pdb); - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } return true; @@ -4232,7 +4232,7 @@ static int bin_header(RzCore *r, int mode) { return false; } -RZ_API int rz_core_bin_info(RzCore *core, int action, PJ *pj, int mode, int va, RzCoreBinFilter *filter, const char *chksum) { +RZ_API int rz_core_bin_info(RzCore *core, int action, PJ *pj, RzOutputMode mode, int va, RzCoreBinFilter *filter, const char *chksum) { RzBinFile *binfile = rz_bin_cur(core->bin); int ret = true; const char *name = NULL; @@ -4425,7 +4425,7 @@ RZ_API bool rz_core_bin_delete(RzCore *core, ut32 bf_id) { return bf && rz_core_bin_apply_all_info(core, bf) && rz_core_block_read(core); } -static bool rz_core_bin_file_print(RzCore *core, RzBinFile *bf, PJ *pj, int mode) { +static bool rz_core_bin_file_print(RzCore *core, RzBinFile *bf, PJ *pj, RzOutputMode mode) { rz_return_val_if_fail(core && bf && bf->o, NULL); const char *name = bf ? bf->file : NULL; (void)rz_bin_get_info(core->bin); // XXX is this necssary for proper iniitialization @@ -4433,16 +4433,16 @@ static bool rz_core_bin_file_print(RzCore *core, RzBinFile *bf, PJ *pj, int mode // TODO: handle mode to print in json and r2 commands switch (mode) { - case '*': { + case RZ_OUTPUT_MODE_RIZIN: { char *n = __filterShell(name); rz_cons_printf("oba 0x%08" PFMT64x " %s # %d\n", bf->o->boffset, n, bf->id); free(n); break; } - case 'q': + case RZ_OUTPUT_MODE_QUIET: rz_cons_printf("%d\n", bf->id); break; - case 'j': { + case RZ_OUTPUT_MODE_JSON: { pj_o(pj); pj_ks(pj, "name", name ? name : ""); pj_ki(pj, "iofd", bf->fd); @@ -4478,7 +4478,7 @@ static bool rz_core_bin_file_print(RzCore *core, RzBinFile *bf, PJ *pj, int mode return true; } -RZ_API int rz_core_bin_list(RzCore *core, int mode) { +RZ_API int rz_core_bin_list(RzCore *core, RzOutputMode mode) { // list all binfiles and there objects and there archs int count = 0; RzListIter *iter; @@ -4489,7 +4489,7 @@ RZ_API int rz_core_bin_list(RzCore *core, int mode) { return false; } PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); if (!pj) { return 0; @@ -4499,7 +4499,7 @@ RZ_API int rz_core_bin_list(RzCore *core, int mode) { rz_list_foreach (binfiles, iter, binfile) { rz_core_bin_file_print(core, binfile, pj, mode); } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); rz_cons_print(pj_string(pj)); pj_free(pj); diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index fe2655eaee8..8ebec21a85f 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -1531,7 +1531,7 @@ static bool cb_dbgbackend(void *user, void *data) { RzCore *core = (RzCore *)user; RzConfigNode *node = (RzConfigNode *)data; if (!strcmp(node->value, "?")) { - rz_debug_plugin_list(core->dbg, 'q'); + rz_debug_plugin_list(core->dbg, RZ_OUTPUT_MODE_QUIET); return false; } if (!strcmp(node->value, "bf")) { diff --git a/librz/core/cdebug.c b/librz/core/cdebug.c index abf14e67fa3..7fea930af00 100644 --- a/librz/core/cdebug.c +++ b/librz/core/cdebug.c @@ -244,7 +244,7 @@ RZ_IPI bool rz_core_debug_reg_set(RzCore *core, const char *regname, ut64 val, c return true; } -RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int rad, const char *use_color) { +RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, RzOutputMode mode, const char *use_color) { RzDebug *dbg = core->dbg; int delta, cols, n = 0; const char *fmt, *fmt2, *kwhites; @@ -255,7 +255,7 @@ RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int const RzList *head; ut64 diff; char strvalue[256]; - bool isJson = (rad == 'j' || rad == 'J'); + bool isJson = (mode == RZ_OUTPUT_MODE_JSON || mode == RZ_OUTPUT_MODE_LONG_JSON); if (!dbg || !dbg->reg) { return false; } @@ -296,7 +296,7 @@ RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int if (!head) { return false; } - if (rad == 1 || rad == '*') { + if (mode == 1 || mode == RZ_OUTPUT_MODE_RIZIN) { dbg->cb_printf("fs+%s\n", RZ_FLAGS_FS_REGISTERS); } rz_list_foreach (head, iter, item) { @@ -377,7 +377,7 @@ RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int if (isJson) { continue; } - switch (rad) { + switch (mode) { case '-': rz_cons_printf("f-%s\n", item->name); break; @@ -385,7 +385,7 @@ RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int rz_cons_printf("aer %s = %s\n", item->name, strvalue); break; case 1: - case '*': + case RZ_OUTPUT_MODE_RIZIN: rz_cons_printf("f %s %d %s\n", item->name, item->size / 8, strvalue); break; case '.': @@ -441,13 +441,13 @@ RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int } n++; } - if (rad == 1 || rad == '*') { + if (mode == 1 || mode == RZ_OUTPUT_MODE_RIZIN) { dbg->cb_printf("fs-\n"); } beach: if (isJson) { pj_end(pj); - } else if (n > 0 && (rad == 2 || rad == '=') && ((n % cols))) { + } else if (n > 0 && (mode == 2 || mode == '=') && ((n % cols))) { rz_cons_printf("\n"); } return n != 0; diff --git a/librz/core/cfile.c b/librz/core/cfile.c index 7dd4f4c053a..3e7e5add247 100644 --- a/librz/core/cfile.c +++ b/librz/core/cfile.c @@ -1326,7 +1326,7 @@ RZ_API RzCoreFile *rz_core_file_get_by_fd(RzCore *core, int fd) { return NULL; } -RZ_API int rz_core_file_list(RzCore *core, int mode) { +RZ_API int rz_core_file_list(RzCore *core, RzOutputMode mode) { int count = 0; RzCoreFile *f; RzIODesc *desc; @@ -1335,7 +1335,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) { RzBinFile *bf; RzListIter *iter; PJ *pj; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { return 0; @@ -1350,7 +1350,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) { } from = 0LL; switch (mode) { - case 'j': { // "oij" + case RZ_OUTPUT_MODE_JSON: { // "oij" pj_o(pj); pj_kb(pj, "raised", core->io->desc->fd == f->fd); pj_ki(pj, "fd", f->fd); @@ -1361,8 +1361,8 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) { pj_end(pj); break; } - case '*': - case 'r': + case RZ_OUTPUT_MODE_RIZIN: + case RZ_OUTPUT_MODE_RIZIN: // TODO: use a getter { bool fileHaveBin = false; @@ -1419,7 +1419,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) { } count++; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_RIZIN) { pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); diff --git a/librz/core/cmd_analysis.c b/librz/core/cmd_analysis.c index 7ae91e098fd..0662b28c1aa 100644 --- a/librz/core/cmd_analysis.c +++ b/librz/core/cmd_analysis.c @@ -1104,11 +1104,11 @@ static int var_cmd(RzCore *core, const char *str) { } pj_o(pj); pj_k(pj, "sp"); - rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_SPV, 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_SPV, RZ_OUTPUT_MODE_JSON, pj); pj_k(pj, "bp"); - rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_BPV, 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_BPV, RZ_OUTPUT_MODE_JSON, pj); pj_k(pj, "reg"); - rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_REG, 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_REG, RZ_OUTPUT_MODE_JSON, pj); pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); @@ -1250,19 +1250,19 @@ static int var_cmd(RzCore *core, const char *str) { switch (str[1]) { // afv[bsr] case '\0': // "afv" case '*': // "afv[bsr]*" - rz_analysis_var_list_show(core->analysis, fcn, type, str[1], NULL); + rz_analysis_var_list_show(core->analysis, fcn, type, RZ_OUTPUT_MODE_RIZIN, NULL); break; case 'j': // "afv[bsr]j" pj = rz_core_pj_new(core); if (!pj) { return false; } - rz_analysis_var_list_show(core->analysis, fcn, type, str[1], pj); + rz_analysis_var_list_show(core->analysis, fcn, type, RZ_OUTPUT_MODE_JSON, pj); rz_cons_println(pj_string(pj)); pj_free(pj); break; case '.': // "afv[bsr]." - rz_analysis_var_list_show(core->analysis, fcn, core->offset, 0, NULL); + rz_analysis_var_list_show(core->analysis, fcn, core->offset, RZ_OUTPUT_MODE_QUIET, NULL); break; case '-': // "afv[bsr]-" if (!fcn) { @@ -3336,14 +3336,14 @@ RZ_IPI int rz_cmd_analysis_fcn(void *data, const char *input) { switch (input[1]) { case 's': // "afns" if (input[2] == 'j') { // "afnsj" - free(rz_core_analysis_fcn_autoname(core, core->offset, 1, input[2])); + free(rz_core_analysis_fcn_autoname(core, core->offset, 1, RZ_OUTPUT_MODE_JSON)); } else { - free(rz_core_analysis_fcn_autoname(core, core->offset, 1, 0)); + free(rz_core_analysis_fcn_autoname(core, core->offset, 1, RZ_OUTPUT_MODE_QUIET)); } break; case 'a': // "afna" { - char *name = rz_core_analysis_fcn_autoname(core, core->offset, 0, 0); + char *name = rz_core_analysis_fcn_autoname(core, core->offset, 0, RZ_OUTPUT_MODE_QUIET); if (name) { rz_cons_printf("afn %s 0x%08" PFMT64x "\n", name, core->offset); free(name); @@ -3501,12 +3501,12 @@ RZ_IPI int rz_cmd_analysis_fcn(void *data, const char *input) { } // size: 0: bits; -1: any; >0: exact size -static void __analysis_reg_list(RzCore *core, int type, int bits, char mode) { +static void __analysis_reg_list(RzCore *core, int type, int bits, RzOutputMode mode) { PJ *pj = NULL; if (mode == 'i') { rz_core_debug_ri(core, core->analysis->reg, 0); return; - } else if (mode == 'j') { + } else if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); if (!pj) { return; @@ -3529,7 +3529,7 @@ static void __analysis_reg_list(RzCore *core, int type, int bits, char mode) { } else if (!bits) { bits = core->analysis->bits; } - int mode2 = mode; + RzOutputMode mode2 = mode; if (core->analysis) { core->dbg->reg = core->analysis->reg; if (core->analysis->cur && core->analysis->cur->arch) { @@ -3539,8 +3539,8 @@ static void __analysis_reg_list(RzCore *core, int type, int bits, char mode) { } /* workaround for 6502 and avr*/ if ((!strcmp(core->analysis->cur->arch, "6502") && bits == 8) || (!strcmp(core->analysis->cur->arch, "avr") && bits == 8)) { - if (mode == 'j') { - mode2 = 'J'; + if (mode == RZ_OUTPUT_MODE_JSON) { + mode2 = RZ_OUTPUT_MODE_LONG_JSON; pj_o(pj); } rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, 16, pj, mode2, use_color); // XXX detect which one is current usage @@ -3562,7 +3562,7 @@ static void __analysis_reg_list(RzCore *core, int type, int bits, char mode) { } } rz_core_debug_reg_list(core, type, bits, pj, mode2, use_color); - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { if (mode2 == 'J') { pj_end(pj); } @@ -3712,10 +3712,10 @@ void cmd_analysis_reg(RzCore *core, const char *str) { case 'r': // "arr" switch (str[1]) { case 'j': // "arrj" - rz_core_debug_rr(core, core->analysis->reg, 'j'); + rz_core_debug_rr(core, core->analysis->reg, RZ_OUTPUT_MODE_JSON); break; default: - rz_core_debug_rr(core, core->analysis->reg, 0); + rz_core_debug_rr(core, core->analysis->reg, RZ_OUTPUT_MODE_QUIET); break; } break; @@ -3842,7 +3842,7 @@ void cmd_analysis_reg(RzCore *core, const char *str) { break; case 'o': // "aro" rz_reg_arena_swap(core->dbg->reg, false); - rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, bits, NULL, 0, use_color); // XXX detect which one is current usage + rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, bits, NULL, RZ_OUTPUT_MODE_QUIET, use_color); // XXX detect which one is current usage rz_reg_arena_swap(core->dbg->reg, false); break; case '=': // "ar=" @@ -5622,7 +5622,7 @@ static void cmd_analysis_opcode(RzCore *core, const char *input) { } break; case '*': // "ao*" - rz_core_analysis_hint_list(core->analysis, input[0]); + rz_core_analysis_hint_list(core->analysis, RZ_OUTPUT_MODE_RIZIN); break; case 0: // "ao" case ' ': { // "ao " @@ -6339,7 +6339,7 @@ static bool cmd_analysis_refs(RzCore *core, const char *input) { case 'j': // "axj" case 'q': // "axq" case '*': // "ax*" - rz_analysis_xrefs_list(core->analysis, input[0]); + rz_analysis_xrefs_list(core->analysis, RZ_OUTPUT_MODE_RIZIN); break; case '.': { // "ax." char *tInput = strdup(input); @@ -6692,7 +6692,7 @@ static void cmd_analysis_hint(RzCore *core, const char *input) { case '?': // "ah?" if (input[1]) { ut64 addr = rz_num_math(core->num, input + 1); - rz_core_analysis_hint_print(core->analysis, addr, 0); + rz_core_analysis_hint_print(core->analysis, addr, RZ_OUTPUT_MODE_QUIET); } else { rz_core_cmd_help(core, help_msg_ah); } @@ -7718,7 +7718,7 @@ static void cmd_analysis_graph(RzCore *core, const char *input) { RZ_API int rz_core_analysis_refs(RzCore *core, const char *input) { int cfg_debug = rz_config_get_b(core->config, "cfg.debug"); ut64 from, to; - int rad; + RzOutputMode mode; PJ *pj = NULL; if (*input == '?') { rz_core_cmd_help(core, help_msg_aar); @@ -7726,16 +7726,16 @@ RZ_API int rz_core_analysis_refs(RzCore *core, const char *input) { } if (*input == 'j' || *input == '*') { - rad = *input; + mode = (*input == 'j' ? RZ_OUTPUT_MODE_JSON : RZ_OUTPUT_MODE_RIZIN); input++; - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); if (!pj) { return 0; } } } else { - rad = 0; + mode = 0; } from = to = 0; @@ -7756,7 +7756,7 @@ RZ_API int rz_core_analysis_refs(RzCore *core, const char *input) { if (!list) { return 0; } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_o(pj); } rz_list_foreach (list, iter, map) { @@ -7770,17 +7770,17 @@ RZ_API int rz_core_analysis_refs(RzCore *core, const char *input) { } else if (to - from > UT32_MAX) { eprintf("Skipping huge range\n"); } else { - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_ki(pj, "mapid", map->id); pj_ko(pj, "refs"); } - rz_core_analysis_search_xrefs(core, from, to, pj, rad); - if (rad == 'j') { + rz_core_analysis_search_xrefs(core, from, to, pj, mode); + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); } } } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); @@ -7806,11 +7806,11 @@ RZ_API int rz_core_analysis_refs(RzCore *core, const char *input) { if (to - from > rz_io_size(core->io)) { return false; } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_o(pj); } - bool res = rz_core_analysis_search_xrefs(core, from, to, pj, rad); - if (rad == 'j') { + bool res = rz_core_analysis_search_xrefs(core, from, to, pj, mode); + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); @@ -8296,10 +8296,38 @@ static void cmd_analysis_rtti(RzCore *core, const char *input) { switch (input[0]) { case '\0': // "avr" case 'j': // "avrj" - rz_analysis_rtti_print_at_vtable(core->analysis, core->offset, input[0]); + rz_analysis_rtti_print_at_vtable(core->analysis, core->offset, RZ_OUTPUT_MODE_JSON); break; case 'a': // "avra" - rz_analysis_rtti_print_all(core->analysis, input[1]); + RzOutputMode mode = RZ_OUTPUT_MODE_STANDARD; + switch(input[1]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[1]; + } + rz_analysis_rtti_print_all(core->analysis, mode); break; case 'r': // "avrr" rz_analysis_rtti_recover_all(core->analysis); @@ -8325,7 +8353,7 @@ static void cmd_analysis_virtual_functions(RzCore *core, const char *input) { case '\0': // "av" case '*': // "av*" case 'j': // "avj" - rz_analysis_list_vtables(core->analysis, input[0]); + rz_analysis_list_vtables(core->analysis, RZ_OUTPUT_MODE_JSON); break; case 'r': // "avr" cmd_analysis_rtti(core, input + 1); @@ -8627,7 +8655,33 @@ static void cmd_analysis_classes(RzCore *core, const char *input) { break; } } - rz_analysis_class_list(core->analysis, input[1]); + switch(input[1]){ + case 'j': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_JSON); + break; + case '*': + case 'r': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_RIZIN); + break; + case 'q': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_QUIET); + break; + case 'k': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_SDB); + break; + case 'l': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_LONG); + break; + case 'J': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_LONG_JSON); + break; + case 't': + rz_analysis_class_list(core->analysis, RZ_OUTPUT_MODE_TABLE); + break; + default: + rz_warn_if_reached(); + rz_analysis_class_list(core->analysis, input[1]); + } break; case ' ': // "ac" case '-': // "ac-" @@ -8999,8 +9053,8 @@ RZ_IPI int rz_cmd_analysis(void *data, const char *input) { break; case '*': // "a*" rz_core_analysis_fcn_list(core, NULL, "*"); - rz_core_analysis_hint_list(core->analysis, '*'); - rz_analysis_xrefs_list(core->analysis, '*'); + rz_core_analysis_hint_list(core->analysis, RZ_OUTPUT_MODE_RIZIN); + rz_analysis_xrefs_list(core->analysis, RZ_OUTPUT_MODE_RIZIN); break; case 'a': // "aa" if (!cmd_analysis_all(core, input + 1)) { @@ -9420,11 +9474,11 @@ RZ_IPI RzCmdStatus rz_analysis_function_vars_handler(RzCore *core, int argc, con } pj_o(pj); pj_k(pj, "sp"); - rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_SPV, 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_SPV, RZ_OUTPUT_MODE_JSON, pj); pj_k(pj, "bp"); - rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_BPV, 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_BPV, RZ_OUTPUT_MODE_JSON, pj); pj_k(pj, "reg"); - rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_REG, 'j', pj); + rz_analysis_var_list_show(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_REG, RZ_OUTPUT_MODE_JSON, pj); pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); diff --git a/librz/core/cmd_api.c b/librz/core/cmd_api.c index 0155670f9bd..5574a5fe7db 100644 --- a/librz/core/cmd_api.c +++ b/librz/core/cmd_api.c @@ -260,7 +260,7 @@ static RzOutputMode suffix2mode(const char *suffix) { return argv_modes[i].mode; } } - return 0; + return RZ_OUTPUT_MODE_QUIET; } static bool is_valid_argv_modes(RzCmdDesc *cd, char last_letter) { diff --git a/librz/core/cmd_cmp.c b/librz/core/cmd_cmp.c index cd886688656..d0ced450353 100644 --- a/librz/core/cmd_cmp.c +++ b/librz/core/cmd_cmp.c @@ -88,14 +88,14 @@ RZ_API int rz_core_cmpwatch_del(RzCore *core, ut64 addr) { return ret; } -RZ_API int rz_core_cmpwatch_show(RzCore *core, ut64 addr, int mode) { +RZ_API int rz_core_cmpwatch_show(RzCore *core, ut64 addr, RzOutputMode mode) { char cmd[128]; RzListIter *iter; RzCoreCmpWatcher *w; rz_list_foreach (core->watchers, iter, w) { int is_diff = w->odata ? memcmp(w->odata, w->ndata, w->size) : 0; switch (mode) { - case '*': + case RZ_OUTPUT_MODE_RIZIN: rz_cons_printf("cw 0x%08" PFMT64x " %d %s%s\n", w->addr, w->size, w->cmd, is_diff ? " # differs" : ""); break; @@ -236,13 +236,13 @@ static int rizin_compare_unified(RzCore *core, ut64 of, ut64 od, int len) { return true; } -static int rizin_compare(RzCore *core, const ut8 *f, const ut8 *d, int len, int mode) { +static int rizin_compare(RzCore *core, const ut8 *f, const ut8 *d, int len, RzOutputMode mode) { int i, eq = 0; PJ *pj = NULL; if (len < 1) { return 0; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { return -1; @@ -280,7 +280,7 @@ static int rizin_compare(RzCore *core, const ut8 *f, const ut8 *d, int len, int } if (mode == 0) { eprintf("Compare %d/%d equal bytes (%d%%)\n", eq, len, (eq / len) * 100); - } else if (mode == 'j') { + } else if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); pj_ki(pj, "equal_bytes", eq); pj_ki(pj, "total_bytes", len); @@ -323,10 +323,10 @@ static void cmd_cmp_watcher(RzCore *core, const char *input) { rz_core_cmpwatch_update(core, addr); break; case '*': - rz_core_cmpwatch_show(core, UT64_MAX, '*'); + rz_core_cmpwatch_show(core, UT64_MAX, RZ_OUTPUT_MODE_RIZIN); break; case '\0': - rz_core_cmpwatch_show(core, UT64_MAX, 0); + rz_core_cmpwatch_show(core, UT64_MAX, RZ_OUTPUT_MODE_QUIET); break; case '?': { const char *help_message[] = { @@ -521,7 +521,8 @@ static void __core_cmp_bits(RzCore *core, ut64 addr) { RZ_IPI int rz_cmd_cmp(void *data, const char *input) { static char *oldcwd = NULL; - int ret = 0, i, mode = 0; + int ret = 0, i; + RzOutputMode mode = RZ_OUTPUT_MODE_QUIET; RzCore *core = (RzCore *)data; ut64 val = UT64_MAX; char *filled; @@ -563,12 +564,12 @@ RZ_IPI int rz_cmd_cmp(void *data, const char *input) { } val = rizin_compare(core, block, (ut8 *)input + 2, - strlen(input + 2) + 1, '*'); + strlen(input + 2) + 1, RZ_OUTPUT_MODE_RIZIN); break; case ' ': { char *str = strdup(input + 1); int len = rz_str_unescape(str); - val = rizin_compare(core, block, (ut8 *)str, len, 0); + val = rizin_compare(core, block, (ut8 *)str, len, RZ_OUTPUT_MODE_QUIET); free(str); } break; case 'j': { @@ -577,14 +578,14 @@ RZ_IPI int rz_cmd_cmp(void *data, const char *input) { } else { char *str = strdup(input + 2); int len = rz_str_unescape(str); - val = rizin_compare(core, block, (ut8 *)str, len, 'j'); + val = rizin_compare(core, block, (ut8 *)str, len, RZ_OUTPUT_MODE_JSON); free(str); } } break; case 'x': switch (input[1]) { case ' ': - mode = 0; + mode = RZ_OUTPUT_MODE_QUIET; input += 2; break; case '*': @@ -592,7 +593,7 @@ RZ_IPI int rz_cmd_cmp(void *data, const char *input) { eprintf("Usage: cx* 00..22'\n"); return 0; } - mode = '*'; + mode = RZ_OUTPUT_MODE_RIZIN; input += 3; break; default: @@ -649,7 +650,7 @@ RZ_IPI int rz_cmd_cmp(void *data, const char *input) { if (fread(buf, 1, core->blocksize, fd) < 1) { eprintf("Cannot read file %s\n", input + 2); } else { - val = rizin_compare(core, block, buf, core->blocksize, 0); + val = rizin_compare(core, block, buf, core->blocksize, RZ_OUTPUT_MODE_QUIET); } fclose(fd); free(buf); @@ -710,15 +711,15 @@ RZ_IPI int rz_cmd_cmp(void *data, const char *input) { break; case '2': // "c2" v16 = (ut16)rz_num_math(core->num, input + 1); - val = rizin_compare(core, block, (ut8 *)&v16, sizeof(v16), 0); + val = rizin_compare(core, block, (ut8 *)&v16, sizeof(v16), RZ_OUTPUT_MODE_QUIET); break; case '4': // "c4" v32 = (ut32)rz_num_math(core->num, input + 1); - val = rizin_compare(core, block, (ut8 *)&v32, sizeof(v32), 0); + val = rizin_compare(core, block, (ut8 *)&v32, sizeof(v32), RZ_OUTPUT_MODE_QUIET); break; case '8': // "c8" v64 = (ut64)rz_num_math(core->num, input + 1); - val = rizin_compare(core, block, (ut8 *)&v64, sizeof(v64), 0); + val = rizin_compare(core, block, (ut8 *)&v64, sizeof(v64), RZ_OUTPUT_MODE_QUIET); break; case 'c': // "cc" if (input[1] == '?') { // "cc?" diff --git a/librz/core/cmd_debug.c b/librz/core/cmd_debug.c index b79f3669dd8..ccb55636acb 100644 --- a/librz/core/cmd_debug.c +++ b/librz/core/cmd_debug.c @@ -1257,7 +1257,7 @@ static int dump_maps(RzCore *core, int perm, const char *filename) { return ret; } -static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" +static void cmd_debug_modules(RzCore *core, RzOutputMode mode) { // "dmm" ut64 addr = core->offset; RzDebugMap *map; RzList *list; @@ -1270,7 +1270,7 @@ static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" return; } PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); if (!pj) { return; @@ -1290,7 +1290,7 @@ static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" goto beach; } break; - case 'j': { + case RZ_OUTPUT_MODE_JSON: { /* Escape backslashes (e.g. for Windows). */ pj_o(pj); pj_kn(pj, "addr", map->addr); @@ -1300,8 +1300,8 @@ static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" pj_end(pj); } break; case ':': - case '*': - if (mode == '*' || (mode == ':' && addr >= map->addr && addr < map->addr_end)) { + case 'RZ_OUTPUT_MODE_RIZIN': + if (mode == 'RZ_OUTPUT_MODE_RIZIN' || (mode == ':' && addr >= map->addr && addr < map->addr_end)) { /* Escape backslashes (e.g. for Windows). */ char *escaped_path = rz_str_escape(map->file); char *filtered_name = strdup(map->name); @@ -1322,7 +1322,7 @@ static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" } } beach: - if (mode == 'j') { + if (mode == 'RZ_OUTPUT_MODE_JSON') { pj_end(pj); rz_cons_println(pj_string(pj)); } @@ -1411,7 +1411,7 @@ static int rz_debug_heap(RzCore *core, const char *input) { return true; } -static bool get_bin_info(RzCore *core, const char *file, ut64 baseaddr, PJ *pj, int mode, bool symbols_only, RzCoreBinFilter *filter) { +static bool get_bin_info(RzCore *core, const char *file, ut64 baseaddr, PJ *pj, RzOutputMode mode, bool symbols_only, RzCoreBinFilter *filter) { int fd; if ((fd = rz_io_fd_open(core->io, file, RZ_PERM_R, 0)) == -1) { return false; @@ -1451,8 +1451,36 @@ static int cmd_debug_map(RzCore *core, const char *input) { case 'm': // "dmm" if (!strcmp(input + 1, ".*")) { cmd_debug_modules(core, ':'); - } else - cmd_debug_modules(core, input[1]); + } else{ + RzOutputMode mode; + switch(input[1]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[1]; + } + cmd_debug_modules(core, mode); break; case '?': // "dm?" rz_core_cmd_help(core, help_msg_dm); @@ -1551,7 +1579,7 @@ static int cmd_debug_map(RzCore *core, const char *input) { case 'a': // "dmia" { const char *libname = NULL, *symname = NULL, *a0; - int mode; + RzOutputMode mode; ut64 baddr = 0LL; char *ptr; int i = 1; @@ -1566,17 +1594,17 @@ static int cmd_debug_map(RzCore *core, const char *input) { mode = RZ_MODE_SET; break; case '*': - mode = RZ_MODE_RIZINCMD; + mode = RZ_OUTPUT_MODE_RIZIN; break; case 'j': - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; pj = rz_core_pj_new(core); if (!pj) { return false; } break; case 'q': - mode = input[2] == 'q' ? input++, RZ_MODE_SIMPLEST : RZ_MODE_SIMPLE; + mode = input[2] == 'q' ? input++, RZ_MODE_SIMPLEST : RZ_OUTPUT_MODE_QUIET; break; default: mode = RZ_MODE_PRINT; @@ -1640,7 +1668,7 @@ static int cmd_debug_map(RzCore *core, const char *input) { rz_bin_set_baddr(core->bin, baddr); } } - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_cons_println(pj_string(pj)); pj_free(pj); } @@ -1839,7 +1867,7 @@ RZ_API void rz_core_debug_clear_register_flags(RzCore *core) { foreach_reg_set_or_clear(core, false); } -RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, int mode) { +RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, RzOutputMode mode) { char *color = ""; char *colorend = ""; int had_colors = rz_config_get_i(core->config, "scr.color"); @@ -1853,7 +1881,7 @@ RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, int mode) { RzRegItem *r; RzTable *t = rz_core_table(core); - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_config_set_i(core->config, "scr.color", false); use_colors = 0; } @@ -1913,7 +1941,7 @@ RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, int mode) { free(rrstr); } - char *s = (mode == 'j') ? rz_table_tojson(t) : rz_table_tostring(t); + char *s = (mode == RZ_OUTPUT_MODE_JSON) ? rz_table_tojson(t) : rz_table_tostring(t); rz_cons_print(s); free(s); rz_table_free(t); @@ -2606,10 +2634,10 @@ static void cmd_debug_reg(RzCore *core, const char *str) { } else { // drm # no arg if (str[1] == 'y') { // drmy rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_YMM, false); - rz_core_debug_reg_list(core, RZ_REG_TYPE_YMM, 256, NULL, 0, 0); + rz_core_debug_reg_list(core, RZ_REG_TYPE_YMM, 256, NULL, RZ_OUTPUT_MODE_QUIET, 0); } else { // drm rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_XMM, false); - rz_core_debug_reg_list(core, RZ_REG_TYPE_XMM, 128, NULL, 0, 0); + rz_core_debug_reg_list(core, RZ_REG_TYPE_XMM, 128, NULL, RZ_OUTPUT_MODE_QUIET, 0); } } //rz_debug_drx_list (core->dbg); @@ -2662,7 +2690,7 @@ static void cmd_debug_reg(RzCore *core, const char *str) { cmd_reg_profile(core, 'd', str); break; case 't': { // "drt" - char rad = 0; + RzOutputMode mode = RZ_OUTPUT_MODE_QUIET; switch (str[1]) { case '\0': // "drt" for (i = 0; (name = rz_reg_get_type(i)); i++) { @@ -2671,9 +2699,35 @@ static void cmd_debug_reg(RzCore *core, const char *str) { break; case 'j': // "drtj" case '*': // "drt*" - rad = str[1]; + switch(str[1]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = str[1]; + } str++; - if (rad == 'j' && !str[1]) { + if (mode == RZ_OUTPUT_MODE_JSON && !str[1]) { PJ *pj = rz_core_pj_new(core); if (!pj) { break; @@ -2705,11 +2759,11 @@ static void cmd_debug_reg(RzCore *core, const char *str) { } type = rz_reg_type_by_name(str + 2); rz_debug_reg_sync(core->dbg, type, false); - rz_core_debug_reg_list(core, type, size, NULL, rad, use_color); + rz_core_debug_reg_list(core, type, size, NULL, mode, use_color); } else { if (type != RZ_REG_TYPE_LAST) { rz_debug_reg_sync(core->dbg, type, false); - rz_core_debug_reg_list(core, type, size, NULL, rad, use_color); + rz_core_debug_reg_list(core, type, size, NULL, mode, use_color); } else { eprintf("cmd_debug_reg: unknown type\n"); } @@ -2738,7 +2792,7 @@ static void cmd_debug_reg(RzCore *core, const char *str) { break; case 'o': // "dro" rz_reg_arena_swap(core->dbg->reg, false); - rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, bits, NULL, 0, use_color); // xxx detect which one is current usage + rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, bits, NULL, RZ_OUTPUT_MODE_QUIET, use_color); // xxx detect which one is current usage rz_reg_arena_swap(core->dbg->reg, false); break; case ',': // "dr," @@ -2782,9 +2836,9 @@ static void cmd_debug_reg(RzCore *core, const char *str) { case '*': // "dr*" if (rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false)) { int pcbits2, pcbits = grab_bits(core, str + 1, &pcbits2); - rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits, NULL, '*', use_color); + rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits, NULL, RZ_OUTPUT_MODE_RIZIN, use_color); if (pcbits2) { - rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits2, NULL, '*', use_color); + rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits2, NULL, RZ_OUTPUT_MODE_RIZIN, use_color); } rz_flag_space_pop(core->flags); } @@ -2795,10 +2849,10 @@ static void cmd_debug_reg(RzCore *core, const char *str) { case 'r': // "drr" switch (str[1]) { case 'j': // "drrj" - rz_core_debug_rr(core, core->dbg->reg, 'j'); + rz_core_debug_rr(core, core->dbg->reg, RZ_OUTPUT_MODE_JSON); break; default: - rz_core_debug_rr(core, core->dbg->reg, 0); + rz_core_debug_rr(core, core->dbg->reg, RZ_OUTPUT_MODE_QUIET); break; } break; @@ -2818,9 +2872,9 @@ static void cmd_debug_reg(RzCore *core, const char *str) { if (!pj) { return; } - rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits, pj, 'j', use_color); + rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits, pj, RZ_OUTPUT_MODE_JSON, use_color); } else { - rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits, NULL, 0, use_color); + rz_core_debug_reg_list(core, RZ_REG_TYPE_GPR, pcbits, NULL, RZ_OUTPUT_MODE_QUIET, use_color); } } else { eprintf("cannot retrieve registers from pid %d\n", core->dbg->pid); @@ -3458,9 +3512,9 @@ static void rz_core_cmd_bp(RzCore *core, const char *input) { free(string); } break; - case 'j': rz_bp_list(core->dbg->bp, 'j'); break; + case 'j': rz_bp_list(core->dbg->bp, RZ_OUTPUT_MODE_JSON); break; case '*': rz_bp_list(core->dbg->bp, 1); break; - case '\0': rz_bp_list(core->dbg->bp, 0); break; + case '\0': rz_bp_list(core->dbg->bp, RZ_OUTPUT_MODE_QUIET); break; case '-': // "db-" if (input[2] == '*') { rz_bp_del_all(core->dbg->bp); @@ -4490,7 +4544,7 @@ RZ_IPI int rz_cmd_debug(void *data, const char *input) { rz_debug_trace_list(core->dbg, '=', core->offset); break; case 'q': // "dtq" - rz_debug_trace_list(core->dbg, 'q', core->offset); + rz_debug_trace_list(core->dbg, RZ_OUTPUT_MODE_QUIET, core->offset); break; case '*': // "dt*" rz_debug_trace_list(core->dbg, 1, core->offset); @@ -4831,7 +4885,7 @@ RZ_IPI int rz_cmd_debug(void *data, const char *input) { switch (input[1]) { case 'q': case 'j': - rz_debug_plugin_list(core->dbg, input[1]); + rz_debug_plugin_list(core->dbg, RZ_OUTPUT_MODE_JSON); break; case '?': rz_core_cmd_help(core, help_msg_dL); diff --git a/librz/core/cmd_eval.c b/librz/core/cmd_eval.c index bb765cf26c6..d59dc4aea07 100644 --- a/librz/core/cmd_eval.c +++ b/librz/core/cmd_eval.c @@ -106,15 +106,15 @@ static bool load_theme(RzCore *core, const char *path) { return res; } -static bool nextpal_item(RzCore *core, int mode, const char *file, int ctr) { +static bool nextpal_item(RzCore *core, RzOutputMode mode, const char *file, int ctr) { const char *fn = rz_str_lchr(file, '/'); if (!fn) fn = file; switch (mode) { - case 'j': // json + case RZ_OUTPUT_MODE_JSON: // json rz_cons_printf("%s\"%s\"", ctr ? "," : "", fn); break; - case 'l': // list + case RZ_OUTPUT_MODE_LONG: // list rz_cons_println(fn); break; case 'p': // previous @@ -211,7 +211,7 @@ RZ_API RzList *rz_core_list_themes(RzCore *core) { return list; } -RZ_IPI void rz_core_theme_nextpal(RzCore *core, int mode) { +RZ_IPI void rz_core_theme_nextpal(RzCore *core, RzOutputMode mode) { // TODO: use rz_core_list_themes() here instead of rewalking all the time RzList *files = NULL; RzListIter *iter; @@ -221,7 +221,7 @@ RZ_IPI void rz_core_theme_nextpal(RzCore *core, int mode) { char *home = rz_str_home(RZ_HOME_THEMES RZ_SYS_DIR); getNext = false; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_cons_printf("["); } if (home) { @@ -292,7 +292,7 @@ RZ_IPI void rz_core_theme_nextpal(RzCore *core, int mode) { rz_core_theme_nextpal(core, mode); return; } - if (mode == 'l' && !curtheme && !rz_list_empty(files)) { + if (mode == RZ_OUTPUT_MODE_LONG && !curtheme && !rz_list_empty(files)) { //rz_core_theme_nextpal (core, mode); } else if (mode == 'n' || mode == 'p') { if (curtheme) { @@ -301,7 +301,7 @@ RZ_IPI void rz_core_theme_nextpal(RzCore *core, int mode) { } rz_list_free(files); files = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { rz_cons_printf("]\n"); } } @@ -334,7 +334,7 @@ RZ_IPI int rz_eval_color(void *data, const char *input) { break; case 'o': // "eco" if (input[1] == 'j') { - rz_core_theme_nextpal(core, 'j'); + rz_core_theme_nextpal(core, RZ_OUTPUT_MODE_JSON); } else if (input[1] == ' ') { rz_core_load_theme(core, input + 2); } else if (input[1] == 'o') { @@ -373,13 +373,13 @@ RZ_IPI int rz_eval_color(void *data, const char *input) { } break; case 'j': // "ecj" - rz_cons_pal_list('j', NULL); + rz_cons_pal_list(RZ_OUTPUT_MODE_JSON, NULL); break; case 'c': // "ecc" rz_cons_pal_list('c', input + 1); break; case '\0': // "ec" - rz_cons_pal_list(0, NULL); + rz_cons_pal_list(RZ_OUTPUT_MODE_QUIET, NULL); break; case 'r': // "ecr" rz_cons_pal_random(); @@ -422,19 +422,19 @@ RZ_IPI int rz_eval_color(void *data, const char *input) { rz_str_argv_free(argv); return false; case '.': - rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_HIGHLIGHT, 0, core->offset); + rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_HIGHLIGHT, RZ_OUTPUT_MODE_QUIET, core->offset); rz_str_argv_free(argv); return false; case '\0': - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_HIGHLIGHT, 0); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_HIGHLIGHT, RZ_OUTPUT_MODE_QUIET); rz_str_argv_free(argv); return false; case 'j': - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_HIGHLIGHT, 'j'); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_HIGHLIGHT, RZ_OUTPUT_MODE_JSON); rz_str_argv_free(argv); return false; case '*': - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_HIGHLIGHT, '*'); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_HIGHLIGHT, RZ_OUTPUT_MODE_RIZIN); rz_str_argv_free(argv); return false; case ' ': @@ -512,7 +512,7 @@ RZ_IPI int rz_cmd_eval(void *data, const char *input) { RzCore *core = (RzCore *)data; switch (input[0]) { case '\0': // "e" - rz_config_list(core->config, NULL, 0); + rz_config_list(core->config, NULL, RZ_OUTPUT_MODE_QUIET); break; case '?': // "e?" default: @@ -573,13 +573,13 @@ RZ_IPI int rz_cmd_eval(void *data, const char *input) { // XXX we need headers for the cmd_xxx files. return rz_cmd_quit(data, ""); case 'j': // json - rz_config_list(core->config, NULL, 'j'); + rz_config_list(core->config, NULL, RZ_OUTPUT_MODE_JSON); break; case 'v': // verbose rz_config_list(core->config, input + 1, 'v'); break; case 'q': // quiet list of eval keys - rz_config_list(core->config, NULL, 'q'); + rz_config_list(core->config, NULL, RZ_OUTPUT_MODE_QUIET); break; case 'c': // "ec" rz_eval_color(core, input + 1); @@ -631,7 +631,7 @@ RZ_IPI int rz_cmd_eval(void *data, const char *input) { case '.': // "e " case ' ': // "e " if (rz_str_endswith(input, ".")) { - rz_config_list(core->config, input + 1, 0); + rz_config_list(core->config, input + 1, RZ_OUTPUT_MODE_QUIET); } else { // XXX we cant do "e cmd.gprompt=dr=", because the '=' is a token, and quotes dont affect him rz_config_eval(core->config, input + 1, false); @@ -643,7 +643,7 @@ RZ_IPI int rz_cmd_eval(void *data, const char *input) { RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **argv) { if (argc == 1) { - rz_config_list(core->config, NULL, 0); + rz_config_list(core->config, NULL, RZ_OUTPUT_MODE_QUIET); return RZ_CMD_STATUS_OK; } @@ -665,7 +665,7 @@ RZ_IPI RzCmdStatus rz_eval_getset_handler(RzCore *core, int argc, const char **a if (llen == 1 && rz_str_endswith(key, ".")) { // no value was set, only key with ".". List possible sub-keys. - rz_config_list(core->config, key, false); + rz_config_list(core->config, key, RZ_OUTPUT_MODE_QUIET); } else if (llen == 1) { // no value was set, show the value of the key const char *v = rz_config_get(core->config, key); @@ -691,13 +691,13 @@ RZ_IPI RzCmdStatus rz_eval_list_handler(RzCore *core, int argc, const char **arg rz_config_list(core->config, arg, 2); break; case RZ_OUTPUT_MODE_JSON: - rz_config_list(core->config, arg, 'j'); + rz_config_list(core->config, arg, RZ_OUTPUT_MODE_JSON); break; case RZ_OUTPUT_MODE_RIZIN: rz_config_list(core->config, arg, 1); break; case RZ_OUTPUT_MODE_QUIET: - rz_config_list(core->config, arg, 'q'); + rz_config_list(core->config, arg, RZ_OUTPUT_MODE_QUIET); break; case RZ_OUTPUT_MODE_LONG: rz_config_list(core->config, arg, 'v'); diff --git a/librz/core/cmd_flag.c b/librz/core/cmd_flag.c index 1069a95e3fc..766f8fdc2db 100644 --- a/librz/core/cmd_flag.c +++ b/librz/core/cmd_flag.c @@ -238,14 +238,14 @@ static RzList *__childrenFlagsOf(RzCore *core, RzList *flags, const char *prefix return list; } -static void __printRecursive(RzCore *core, RzList *list, const char *prefix, int mode, int depth); +static void __printRecursive(RzCore *core, RzList *list, const char *prefix, RzOutputMode mode, int depth); -static void __printRecursive(RzCore *core, RzList *flags, const char *prefix, int mode, int depth) { +static void __printRecursive(RzCore *core, RzList *flags, const char *prefix, RzOutputMode mode, int depth) { char *fn; RzListIter *iter; const int prefix_len = strlen(prefix); // eprintf ("# fg %s\n", prefix); - if (mode == '*' && !*prefix) { + if (mode == RZ_OUTPUT_MODE_RIZIN && !*prefix) { rz_cons_printf("agn root\n"); } if (rz_flag_get(core->flags, prefix)) { @@ -256,7 +256,7 @@ static void __printRecursive(RzCore *core, RzList *flags, const char *prefix, in if (!strcmp(fn, prefix)) { continue; } - if (mode == '*') { + if (mode == RZ_OUTPUT_MODE_RIZIN) { rz_cons_printf("agn %s %s\n", fn, fn + prefix_len); rz_cons_printf("age %s %s\n", *prefix ? prefix : "root", fn); } else { @@ -268,7 +268,7 @@ static void __printRecursive(RzCore *core, RzList *flags, const char *prefix, in rz_list_free(children); } -static void __flag_graph(RzCore *core, const char *input, int mode) { +static void __flag_graph(RzCore *core, const char *input, RzOutputMode mode) { RzList *flags = rz_list_newf(NULL); rz_flag_foreach_space(core->flags, rz_flag_space_cur(core->flags), listFlag, flags); __printRecursive(core, flags, input, mode, 0); @@ -414,7 +414,7 @@ static void cmd_fz(RzCore *core, const char *input) { } break; case '*': - rz_flag_zone_list(core->flags, '*'); + rz_flag_zone_list(core->flags, RZ_OUTPUT_MODE_RIZIN); break; case 0: rz_flag_zone_list(core->flags, 0); @@ -680,10 +680,10 @@ static bool adjust_offset(RzFlagItem *flag, void *user) { return true; } -static void print_space_stack(RzFlag *f, int ordinal, const char *name, bool selected, PJ *pj, int mode) { +static void print_space_stack(RzFlag *f, int ordinal, const char *name, bool selected, PJ *pj, RzOutputMode mode) { bool first = ordinal == 0; switch (mode) { - case 'j': { + case RZ_OUTPUT_MODE_JSON: { char *ename = rz_str_escape(name); if (!ename) { return; @@ -697,7 +697,7 @@ static void print_space_stack(RzFlag *f, int ordinal, const char *name, bool sel free(ename); break; } - case '*': { + case RZ_OUTPUT_MODE_RIZIN: { const char *fmt = first ? "fs %s\n" : "fs+%s\n"; rz_cons_printf(fmt, name); break; @@ -708,12 +708,12 @@ static void print_space_stack(RzFlag *f, int ordinal, const char *name, bool sel } } -static int flag_space_stack_list(RzFlag *f, int mode) { +static int flag_space_stack_list(RzFlag *f, RzOutputMode mode) { RzListIter *iter; char *space; int i = 0; PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); pj_a(pj); } @@ -722,7 +722,7 @@ static int flag_space_stack_list(RzFlag *f, int mode) { } const char *cur_name = rz_flag_space_cur_name(f); print_space_stack(f, i++, cur_name, true, pj, mode); - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); rz_cons_printf("%s\n", pj_string(pj)); pj_free(pj); @@ -731,7 +731,7 @@ static int flag_space_stack_list(RzFlag *f, int mode) { } typedef struct { - int rad; + RzOutputMode mode; PJ *pj; RzAnalysisFunction *fcn; } PrintFcnLabelsCtx; @@ -739,12 +739,12 @@ typedef struct { static bool print_function_labels_cb(void *user, const ut64 addr, const void *v) { const PrintFcnLabelsCtx *ctx = user; const char *name = v; - switch (ctx->rad) { - case '*': + switch (ctx->mode) { + case RZ_OUTPUT_MODE_RIZIN: case 1: rz_cons_printf("f.%s@0x%08" PFMT64x "\n", name, addr); break; - case 'j': + case RZ_OUTPUT_MODE_JSON: pj_kn(ctx->pj, name, addr); break; default: @@ -756,28 +756,28 @@ static bool print_function_labels_cb(void *user, const ut64 addr, const void *v) return true; } -static void print_function_labels_for(RzAnalysisFunction *fcn, int rad, PJ *pj) { - rz_return_if_fail(fcn && (rad != 'j' || pj)); - bool json = rad == 'j'; +static void print_function_labels_for(RzAnalysisFunction *fcn, RzOutputMode mode, PJ *pj) { + rz_return_if_fail(fcn && (mode != RZ_OUTPUT_MODE_JSON || pj)); + bool json = mode == RZ_OUTPUT_MODE_JSON; if (json) { pj_o(pj); } - PrintFcnLabelsCtx ctx = { rad, pj, fcn }; + PrintFcnLabelsCtx ctx = { mode, pj, fcn }; ht_up_foreach(fcn->labels, print_function_labels_cb, &ctx); if (json) { pj_end(pj); } } -static void print_function_labels(RzAnalysis *analysis, RzAnalysisFunction *fcn, int rad) { +static void print_function_labels(RzAnalysis *analysis, RzAnalysisFunction *fcn, RzOutputMode mode) { rz_return_if_fail(analysis || fcn); PJ *pj = NULL; - bool json = rad == 'j'; + bool json = mode == RZ_OUTPUT_MODE_JSON; if (json) { pj = pj_new(); } if (fcn) { - print_function_labels_for(fcn, rad, pj); + print_function_labels_for(fcn, mode, pj); } else { if (json) { pj_o(pj); @@ -791,7 +791,7 @@ static void print_function_labels(RzAnalysis *analysis, RzAnalysisFunction *fcn, if (json) { pj_k(pj, f->name); } - print_function_labels_for(f, rad, pj); + print_function_labels_for(f, mode, pj); } if (json) { pj_end(pj); @@ -1078,11 +1078,11 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { if (input[1]) { if (input[1] == '*' || input[1] == 'j') { if (input[2] == '*') { - print_function_labels(core->analysis, NULL, input[1]); + print_function_labels(core->analysis, NULL, input[1] == '*' ? RZ_OUTPUT_MODE_RIZIN : RZ_OUTPUT_MODE_JSON); } else { RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, off, 0); if (fcn) { - print_function_labels(core->analysis, fcn, input[1]); + print_function_labels(core->analysis, fcn, input[1] == '*' ? RZ_OUTPUT_MODE_RIZIN : RZ_OUTPUT_MODE_JSON); } else { eprintf("Cannot find function at 0x%08" PFMT64x "\n", off); } @@ -1112,7 +1112,7 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { } else { RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, off, 0); if (fcn) { - print_function_labels(core->analysis, fcn, 0); + print_function_labels(core->analysis, fcn, RZ_OUTPUT_MODE_QUIET); } else { eprintf("Local flags require a function to work."); } @@ -1216,7 +1216,35 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { } break; case 's': - flag_space_stack_list(core->flags, input[2]); + RzOutputMode mode; + switch(input[2]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[2]; + } + flag_space_stack_list(core->flags, mode); break; case '-': switch (input[2]) { @@ -1276,13 +1304,13 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { case 'g': // "fg" switch (input[1]) { case '*': - __flag_graph(core, rz_str_trim_head_ro(input + 2), '*'); + __flag_graph(core, rz_str_trim_head_ro(input + 2), RZ_OUTPUT_MODE_RIZIN); break; case ' ': __flag_graph(core, rz_str_trim_head_ro(input + 2), ' '); break; case 0: - __flag_graph(core, rz_str_trim_head_ro(input + 1), 0); + __flag_graph(core, rz_str_trim_head_ro(input + 1), RZ_OUTPUT_MODE_QUIET); break; default: eprintf("Usage: fg[*] ([prefix])\n"); @@ -1456,7 +1484,35 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { free(s); } } else { - rz_flag_list(core->flags, *input, input[0] ? input + 1 : ""); + RzOutputMode mode; + switch(*input){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = *input; + } + rz_flag_list(core->flags, mode, input[0] ? input + 1 : ""); } break; case 'i': // "fi" diff --git a/librz/core/cmd_info.c b/librz/core/cmd_info.c index 523f7c72af2..c29e230d44f 100644 --- a/librz/core/cmd_info.c +++ b/librz/core/cmd_info.c @@ -140,7 +140,7 @@ static bool demangle(RzCore *core, const char *s) { } #define STR(x) (x) ? (x) : "" -static void rz_core_file_info(RzCore *core, PJ *pj, int mode) { +static void rz_core_file_info(RzCore *core, PJ *pj, RzOutputMode mode) { const char *fn = NULL; bool io_cache = rz_config_get_i(core->config, "io.cache"); RzBinInfo *info = rz_bin_get_info(core->bin); @@ -148,10 +148,10 @@ static void rz_core_file_info(RzCore *core, PJ *pj, int mode) { int fd = rz_io_fd_get_current(core->io); RzIODesc *desc = rz_io_desc_get(core->io, fd); RzBinPlugin *plugin = rz_bin_file_cur_plugin(binfile); - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_o(pj); } - if (mode == RZ_MODE_RIZINCMD) { + if (mode == RZ_OUTPUT_MODE_RIZIN) { return; } if (mode == RZ_MODE_SIMPLE) { @@ -159,13 +159,13 @@ static void rz_core_file_info(RzCore *core, PJ *pj, int mode) { } if (info) { fn = info->file; - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_ks(pj, "type", info->type ? info->type : ""); } } else { fn = desc ? desc->name : NULL; } - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { const char *uri = fn; if (!uri) { if (desc && desc->uri && *desc->uri) { @@ -260,27 +260,27 @@ static int bin_is_executable(RzBinObject *obj) { return false; } -static void cmd_info_bin(RzCore *core, int va, PJ *pj, int mode) { +static void cmd_info_bin(RzCore *core, int va, PJ *pj, RzOutputMode mode) { RzBinObject *obj = rz_bin_cur_object(core->bin); int array = 0; if (core->file) { - if (mode & RZ_MODE_JSON) { + if (mode & RZ_OUTPUT_MODE_JSON) { if (!(mode & RZ_MODE_ARRAY)) { pj_o(pj); } else { array = 1; } - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; pj_k(pj, "core"); } rz_core_file_info(core, pj, mode); if (bin_is_executable(obj)) { - if ((mode & RZ_MODE_JSON)) { + if ((mode & RZ_OUTPUT_MODE_JSON)) { pj_k(pj, "bin"); } rz_core_bin_info(core, RZ_CORE_BIN_ACC_INFO, pj, mode, va, NULL, NULL); } - if ((mode & RZ_MODE_JSON) && array == 0) { + if ((mode & RZ_OUTPUT_MODE_JSON) && array == 0) { pj_end(pj); } } else { @@ -353,7 +353,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { int fd = rz_io_fd_get_current(core->io); RzIODesc *desc = rz_io_desc_get(core->io, fd); int i, va = core->io->va || core->bin->is_debugger; - int mode = 0; //RZ_MODE_SIMPLE; + RzOutputMode mode = RZ_OUTPUT_MODE_QUIET; //RZ_MODE_SIMPLE; bool rdump = false; int is_array = 0; bool is_izzzj = false; @@ -365,9 +365,9 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { ; if (i > 0) { switch (input[i - 1]) { - case '*': mode = RZ_MODE_RIZINCMD; break; - case 'j': mode = RZ_MODE_JSON; break; - case 'q': mode = RZ_MODE_SIMPLE; break; + case '*': mode = RZ_OUTPUT_MODE_RIZIN; break; + case 'j': mode = RZ_OUTPUT_MODE_JSON; break; + case 'q': mode = RZ_OUTPUT_MODE_QUIET; break; } } #define INIT_PJ() \ @@ -377,7 +377,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { return 1; \ } \ } - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { INIT_PJ(); int suffix_shift = 0; if (!strncmp(input, "SS", 2) || !strncmp(input, "ee", 2) || !strncmp(input, "zz", 2)) { @@ -458,7 +458,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { } break; case '*': - rz_core_bin_export_info(core, RZ_MODE_RIZINCMD); + rz_core_bin_export_info(core, RZ_OUTPUT_MODE_RIZIN); break; case '.': case ' ': @@ -504,7 +504,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { case 'A': // "iA" if (input[1] == 'j') { pj_o(pj); - rz_bin_list_archs(core->bin, pj, 'j'); + rz_bin_list_archs(core->bin, pj, RZ_OUTPUT_MODE_JSON); pj_end(pj); } else { rz_bin_list_archs(core->bin, NULL, 1); @@ -514,7 +514,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { case 'E': // "iE" { if (input[1] == 'j' && input[2] == '.') { - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; INIT_PJ(); RZBININFO("exports", RZ_CORE_BIN_ACC_EXPORTS, input + 2); } else { @@ -622,14 +622,14 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { if (input[1] == '=') { mode = RZ_MODE_EQUAL; } else if (input[1] == '*') { - mode = RZ_MODE_RIZINCMD; + mode = RZ_OUTPUT_MODE_RIZIN; } else if (input[1] == 'q' && input[2] == '.') { - mode = RZ_MODE_SIMPLE; + mode = RZ_OUTPUT_MODE_QUIET; } else if (input[1] == 'j' && input[2] == '.') { - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; INIT_PJ(); } - if (mode == RZ_MODE_RIZINCMD || mode == RZ_MODE_JSON || mode == RZ_MODE_SIMPLE) { + if (mode == RZ_OUTPUT_MODE_RIZIN || mode == RZ_OUTPUT_MODE_JSON || mode == RZ_OUTPUT_MODE_QUIET) { if (input[param_shift + 1]) { param_shift++; } @@ -674,14 +674,14 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { case 's': { // "is" // Case for isj. if (input[1] == 'j' && input[2] == '.') { - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; INIT_PJ(); RZBININFO("symbols", RZ_CORE_BIN_ACC_SYMBOLS, input + 2); } else if (input[1] == 'q' && input[2] == 'q') { mode = RZ_MODE_SIMPLEST; RZBININFO("symbols", RZ_CORE_BIN_ACC_SYMBOLS, input + 1); } else if (input[1] == 'q' && input[2] == '.') { - mode = RZ_MODE_SIMPLE; + mode = RZ_OUTPUT_MODE_QUIET; RZBININFO("symbols", RZ_CORE_BIN_ACC_SYMBOLS, input + 2); } else { RZBININFO("symbols", RZ_CORE_BIN_ACC_SYMBOLS, input + 1); @@ -873,10 +873,10 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { rdump = true; break; case '*': - mode = RZ_MODE_RIZINCMD; + mode = RZ_OUTPUT_MODE_RIZIN; break; case 'j': - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; INIT_PJ(); break; case 'q': //izzq @@ -884,7 +884,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { mode = RZ_MODE_SIMPLEST; input++; } else { - mode = RZ_MODE_SIMPLE; + mode = RZ_OUTPUT_MODE_QUIET; } break; default: @@ -906,7 +906,7 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { if (input[1] == 'q') { mode = (input[2] == 'q') ? RZ_MODE_SIMPLEST - : RZ_MODE_SIMPLE; + : RZ_OUTPUT_MODE_QUIET; input++; } RZBININFO("strings", RZ_CORE_BIN_ACC_STRINGS, NULL); @@ -1077,9 +1077,9 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { return 0; case 'a': // "ia" switch (mode) { - case RZ_MODE_RIZINCMD: rz_cmd_info(core, "IieEcsSmz*"); break; - case RZ_MODE_JSON: rz_cmd_info(core, "IieEcsSmzj"); break; - case RZ_MODE_SIMPLE: rz_cmd_info(core, "IieEcsSmzq"); break; + case RZ_OUTPUT_MODE_RIZIN: rz_cmd_info(core, "IieEcsSmz*"); break; + case RZ_OUTPUT_MODE_JSON: rz_cmd_info(core, "IieEcsSmzj"); break; + case RZ_OUTPUT_MODE_QUIET: rz_cmd_info(core, "IieEcsSmzq"); break; default: rz_cmd_info(core, "IiEecsSmz"); break; } break; @@ -1087,15 +1087,15 @@ RZ_IPI int rz_cmd_info(void *data, const char *input) { rz_core_cmd_help(core, help_msg_i); goto redone; case '*': // "i*" - if (mode == RZ_MODE_RIZINCMD) { + if (mode == RZ_OUTPUT_MODE_RIZIN) { // TODO:handle ** submodes - mode = RZ_MODE_RIZINCMD; + mode = RZ_OUTPUT_MODE_RIZIN; } else { - mode = RZ_MODE_RIZINCMD; + mode = RZ_OUTPUT_MODE_RIZIN; } goto done; case 'q': // "iq" - mode = RZ_MODE_SIMPLE; + mode = RZ_OUTPUT_MODE_QUIET; cmd_info_bin(core, va, pj, mode); goto done; case 'j': // "ij" diff --git a/librz/core/cmd_meta.c b/librz/core/cmd_meta.c index 641caf91b65..bc9949747bd 100644 --- a/librz/core/cmd_meta.c +++ b/librz/core/cmd_meta.c @@ -382,7 +382,7 @@ static int cmd_meta_comment(RzCore *core, const char *input) { } } break; case 0: // "CC" - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_COMMENT, 0); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_COMMENT, RZ_OUTPUT_MODE_QUIET); break; case 'f': // "CCf" switch (input[2]) { @@ -406,18 +406,18 @@ static int cmd_meta_comment(RzCore *core, const char *input) { } } break; case 'j': // "CCfj" - rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_COMMENT, 'j', core->offset); + rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_COMMENT, RZ_OUTPUT_MODE_JSON, core->offset); break; case '*': // "CCf*" rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_COMMENT, 1, core->offset); break; default: - rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_COMMENT, 0, core->offset); + rz_meta_print_list_in_function(core->analysis, RZ_META_TYPE_COMMENT, RZ_OUTPUT_MODE_QUIET, core->offset); break; } break; case 'j': // "CCj" - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_COMMENT, 'j'); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_COMMENT, RZ_OUTPUT_MODE_JSON); break; case '!': { char *out; @@ -547,7 +547,7 @@ static int cmd_meta_vartype_comment(RzCore *core, const char *input) { rz_core_cmd_help(core, help_msg_Ct); break; case 0: // "Ct" - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_VARTYPE, 0); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_VARTYPE, RZ_OUTPUT_MODE_QUIET); break; case ' ': // "Ct @ addr" { @@ -650,7 +650,7 @@ static int cmd_meta_others(RzCore *core, const char *input) { rz_meta_print_list_all(core->analysis, input[0], 1); break; case 'j': // "Cfj", "Cdj", ... - rz_meta_print_list_all(core->analysis, input[0], 'j'); + rz_meta_print_list_all(core->analysis, input[0], RZ_OUTPUT_MODE_JSON); break; case '!': // "Cf!", "Cd!", ... { @@ -664,18 +664,73 @@ static int cmd_meta_others(RzCore *core, const char *input) { } } break; case '.': // "Cf.", "Cd.", ... + RzOutputMode mode = RZ_OUTPUT_MODE_STANDARD; if (input[2] == '.') { // "Cs.." ut64 size; RzAnalysisMetaItem *mi = rz_meta_get_at(core->analysis, addr, type, &size); if (mi) { - rz_meta_print(core->analysis, mi, addr, size, input[3], NULL, false); + switch(input[3]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[3]; + } + rz_meta_print(core->analysis, mi, addr, size, mode, NULL, false); } break; } else if (input[2] == 'j') { // "Cs.j" ut64 size; RzAnalysisMetaItem *mi = rz_meta_get_at(core->analysis, addr, type, &size); if (mi) { - rz_meta_print(core->analysis, mi, addr, size, input[2], NULL, false); + switch(input[2]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[2]; + } + rz_meta_print(core->analysis, mi, addr, size, mode, NULL, false); rz_cons_newline(); } break; @@ -715,7 +770,7 @@ static int cmd_meta_others(RzCore *core, const char *input) { case 'a': case '8': if (type != 'z' && !input[1] && !core->tmpseek) { - rz_meta_print_list_all(core->analysis, type, 0); + rz_meta_print_list_all(core->analysis, type, RZ_OUTPUT_MODE_QUIET); break; } if (type == 'z') { @@ -995,19 +1050,47 @@ RZ_IPI int rz_cmd_meta(void *data, const char *input) { rz_comment_vars(core, input + 1); break; case '\0': // "C" - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_ANY, 0); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_ANY, RZ_OUTPUT_MODE_QUIET); break; case 'j': // "Cj" case '*': { // "C*" + RzOutputMode mode = RZ_OUTPUT_MODE_STANDARD; + switch (*input){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = *input; + } if (!input[0] || input[1] == '.') { - rz_meta_print_list_at(core->analysis, core->offset, *input); + rz_meta_print_list_at(core->analysis, core->offset, mode); } else { - rz_meta_print_list_all(core->analysis, RZ_META_TYPE_ANY, *input); + rz_meta_print_list_all(core->analysis, RZ_META_TYPE_ANY, mode); } break; } case '.': { // "C." - rz_meta_print_list_at(core->analysis, core->offset, 0); + rz_meta_print_list_at(core->analysis, core->offset, RZ_OUTPUT_MODE_QUIET); break; } case 'L': // "CL" @@ -1079,13 +1162,13 @@ RZ_IPI int rz_cmd_meta(void *data, const char *input) { case 'j': // "CSj" case '\0': // "CS" case '*': // "CS*" - spaces_list(ms, input[1]); + spaces_list(ms, RZ_OUTPUT_MODE_RIZIN); break; case ' ': // "CS " rz_spaces_set(ms, input + 2); break; default: - spaces_list(ms, 0); + spaces_list(ms, RZ_OUTPUT_MODE_QUIET); break; } break; diff --git a/librz/core/cmd_open.c b/librz/core/cmd_open.c index 28ecf7e0028..db91b1b2a23 100644 --- a/librz/core/cmd_open.c +++ b/librz/core/cmd_open.c @@ -182,7 +182,7 @@ static void cmd_open_bin(RzCore *core, const char *input) { case 'q': // "obj" case 'j': // "obj" case '*': // "ob*" - rz_core_bin_list(core, input[1]); + rz_core_bin_list(core, RZ_OUTPUT_MODE_RIZIN); if (input[1] == 'j') { rz_cons_newline(); } @@ -384,12 +384,12 @@ static void cmd_open_bin(RzCore *core, const char *input) { } // TODO: discuss the output format -static void map_list(RzIO *io, int mode, RzPrint *print, int fd) { +static void map_list(RzIO *io, RzOutputMode mode, RzPrint *print, int fd) { if (!io || !print || !print->cb_printf) { return; } PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { return; @@ -405,14 +405,14 @@ static void map_list(RzIO *io, int mode, RzPrint *print, int fd) { continue; } switch (mode) { - case 'q': + case RZ_OUTPUT_MODE_QUIET: if (fd == -2) { print->cb_printf("0x%08" PFMT64x "\n", rz_io_map_get_from(map)); } else { print->cb_printf("%d %d\n", map->fd, map->id); } break; - case 'j': + case RZ_OUTPUT_MODE_JSON: pj_o(pj); pj_ki(pj, "map", map->id); pj_ki(pj, "fd", map->fd); @@ -425,7 +425,7 @@ static void map_list(RzIO *io, int mode, RzPrint *print, int fd) { break; case 1: case '*': - case 'r': { + case RZ_OUTPUT_MODE_RIZIN: { // Need FIFO order here char *om_cmd = rz_str_newf("om %d 0x%08" PFMT64x " 0x%08" PFMT64x " 0x%08" PFMT64x " %s%s%s\n", map->fd, rz_io_map_get_from(map), map->itv.size, map->delta, rz_str_rwx_i(map->perm), @@ -449,7 +449,7 @@ static void map_list(RzIO *io, int mode, RzPrint *print, int fd) { print->cb_printf("%s", om_cmds); free(om_cmds); } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); print->cb_printf("%s\n", pj_string(pj)); pj_free(pj); @@ -704,7 +704,7 @@ static void cmd_open_map(RzCore *core, const char *input) { } else { int fd = rz_io_fd_get_current(core->io); if (rz_io_desc_get(core->io, fd)) { - map_list(core->io, 0, core->print, fd); + map_list(core->io, RZ_OUTPUT_MODE_QUIET, core->print, fd); } else { eprintf("Invalid fd %d\n", (int)fd); } @@ -827,9 +827,9 @@ static void cmd_open_map(RzCore *core, const char *input) { } } else { if (input[1] && input[2] == 'q') { // "omqq" - map_list(core->io, input[1], core->print, -2); + map_list(core->io, RZ_OUTPUT_MODE_QUIET, core->print, -2); } else { - map_list(core->io, input[1], core->print, -1); + map_list(core->io, RZ_OUTPUT_MODE_QUIET, core->print, -1); } } break; @@ -994,7 +994,7 @@ static bool desc_list_json_cb(void *user, void *data, ut32 id) { return true; } -static bool cmd_op(RzCore *core, char mode, int fd) { +static bool cmd_op(RzCore *core, RzOutputMode mode, int fd) { int cur_fd = rz_io_fd_get_current(core->io); int next_fd = cur_fd; switch (mode) { @@ -1007,7 +1007,7 @@ static bool cmd_op(RzCore *core, char mode, int fd) { case 'p': next_fd = rz_io_fd_get_prev(core->io, cur_fd); break; - case 'r': + case 'RZ_OUTPUT_MODE_RIZIN': next_fd = rz_io_fd_get_next(core->io, cur_fd); if (next_fd == -1) { next_fd = rz_io_fd_get_lowest(core->io); @@ -1192,7 +1192,7 @@ RZ_IPI int rz_cmd_open(void *data, const char *input) { case ' ': { int fd = rz_num_math(core->num, input + 1); if (fd >= 0 || input[1] == '0') { - cmd_op(core, 0, fd); + cmd_op(core, RZ_OUTPUT_MODE_QUIET, fd); } else { eprintf("Invalid fd number\n"); } @@ -1287,7 +1287,7 @@ RZ_IPI int rz_cmd_open(void *data, const char *input) { rz_core_cmd_help(core, help_msg_o_star); break; } - rz_core_file_list(core, (int)(*input)); + rz_core_file_list(core, RZ_OUTPUT_MODE_RIZIN); break; case 'j': // "oj" if ('?' == input[1]) { @@ -1347,7 +1347,7 @@ RZ_IPI int rz_cmd_open(void *data, const char *input) { case 'j': // "oij" case '*': // "oi*" case 0: // "oi" - rz_core_file_list(core, input[1]); + rz_core_file_list(core, RZ_OUTPUT_MODE_QUIET); break; } break; diff --git a/librz/core/cmd_print.c b/librz/core/cmd_print.c index 22135307384..97435c9f777 100644 --- a/librz/core/cmd_print.c +++ b/librz/core/cmd_print.c @@ -4109,7 +4109,7 @@ static int bbcmp(RzAnalysisBlock *a, RzAnalysisBlock *b) { } /* TODO: integrate this into rz_analysis */ -static void _pointer_table(RzCore *core, ut64 origin, ut64 offset, const ut8 *buf, int len, int step, int mode) { +static void _pointer_table(RzCore *core, ut64 origin, ut64 offset, const ut8 *buf, int len, int step, RzOutputMode mode) { int i; ut64 addr; st32 *delta; // only for step == 4 @@ -4122,7 +4122,7 @@ static void _pointer_table(RzCore *core, ut64 origin, ut64 offset, const ut8 *bu } if (origin != offset) { switch (mode) { - case '*': + case RZ_OUTPUT_MODE_RIZIN: rz_cons_printf("CC-@ 0x%08" PFMT64x "\n", origin); rz_cons_printf("CC switch table @ 0x%08" PFMT64x "\n", origin); rz_cons_printf("axd 0x%" PFMT64x " 0x%08" PFMT64x "\n", origin, offset); @@ -4152,7 +4152,7 @@ static void _pointer_table(RzCore *core, ut64 origin, ut64 offset, const ut8 *bu } addr = *delta; } - if (mode == '*') { + if (mode == 'RZ_OUTPUT_MODE_RIZIN') { rz_cons_printf("af case.%d.0x%" PFMT64x " 0x%08" PFMT64x "\n", n, offset, addr); rz_cons_printf("ax 0x%" PFMT64x " 0x%08" PFMT64x "\n", offset, addr); rz_cons_printf("ax 0x%" PFMT64x " 0x%08" PFMT64x "\n", addr, offset); // wrong, but useful because forward xrefs dont work :? @@ -4691,7 +4691,7 @@ static void rz_core_disasm_table(RzCore *core, int l, const char *input) { rz_table_free(t); } -static void cmd_pxr(RzCore *core, int len, int mode, int wordsize, const char *arg) { +static void cmd_pxr(RzCore *core, int len, RzOutputMode mode, int wordsize, const char *arg) { PJ *pj = NULL; RzTable *t = NULL; if (mode == ',') { @@ -4702,13 +4702,13 @@ static void cmd_pxr(RzCore *core, int len, int mode, int wordsize, const char *a rz_table_add_column(t, n, "value", 0); rz_table_add_column(t, s, "refs", 0); } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { return; } } - if (mode == 'j' || mode == ',' || mode == '*' || mode == 'q') { + if (mode == RZ_OUTPUT_MODE_JSON || mode == ',' || mode == RZ_OUTPUT_MODE_RIZIN || mode == RZ_OUTPUT_MODE_QUIET) { size_t i; const int be = core->analysis->big_endian; if (pj) { @@ -4748,10 +4748,10 @@ static void cmd_pxr(RzCore *core, int len, int mode, int wordsize, const char *a } refs = rstr; } - if (mode == '*' && RZ_STR_ISNOTEMPTY(refs)) { + if (mode == RZ_OUTPUT_MODE_RIZIN && RZ_STR_ISNOTEMPTY(refs)) { // Show only the mapped ones? rz_cons_printf("f pxr.%" PFMT64x "=0x%" PFMT64x "\n", val, addr); - } else if (mode == 'q' && RZ_STR_ISNOTEMPTY(refs)) { + } else if (mode == RZ_OUTPUT_MODE_QUIET && RZ_STR_ISNOTEMPTY(refs)) { rz_cons_printf("%s\n", refs); } if (t) { @@ -5439,7 +5439,35 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) { rz_core_cmd_help(core, help_msg_pda); break; } - rz_core_print_disasm_all(core, core->offset, l, len, input[2]); + RzOutputMode mode; + switch(input[2]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[2]; + } + rz_core_print_disasm_all(core, core->offset, l, len, mode); pd_result = true; break; case 'e': // "pde" @@ -5447,14 +5475,14 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) { if (!core->fixedblock && !sp) { l /= 4; } - int mode = RZ_MODE_PRINT; + RzOutputMode mode = RZ_MODE_PRINT; if (input[2] == 'j') { - mode = RZ_MODE_JSON; + mode = RZ_OUTPUT_MODE_JSON; } else if (input[2] == 'q') { if (input[3] == 'q') { mode = RZ_MODE_SIMPLEST; // Like pi } else { - mode = RZ_MODE_SIMPLE; // Like pdi + mode = RZ_OUTPUT_MODE_QUIET; // Like pdi } } rz_core_disasm_pde(core, l, mode); @@ -6319,7 +6347,35 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) { ut8 *block = calloc(len, 1); if (block) { memcpy(block, core->block, len); - _pointer_table(core, origin, core->offset, block, len, 4, input[2]); + RzOutputMode mode; + switch(input[2]){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = input[2]; + } + _pointer_table(core, origin, core->offset, block, len, 4, mode); free(block); } } break; @@ -6448,7 +6504,33 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) { case 2: case 4: case 8: - cmd_pxr(core, len, mode, wordsize, mode ? strchr(input, mode) : NULL); + switch(mode){ + case 'j': + cmd_pxr(core, len, RZ_OUTPUT_MODE_JSON, wordsize, mode ? strchr(input, mode) : NULL); + break; + case '*': + case 'r': + cmd_pxr(core, len, RZ_OUTPUT_MODE_RIZIN, wordsize, mode ? strchr(input, mode) : NULL); + break; + case 'q': + cmd_pxr(core, len, RZ_OUTPUT_MODE_QUIET, wordsize, mode ? strchr(input, mode) : NULL); + break; + case 'k': + cmd_pxr(core, len, RZ_OUTPUT_MODE_SDB, wordsize, mode ? strchr(input, mode) : NULL); + break; + case 'l': + cmd_pxr(core, len, RZ_OUTPUT_MODE_LONG, wordsize, mode ? strchr(input, mode) : NULL); + break; + case 'J': + cmd_pxr(core, len, RZ_OUTPUT_MODE_LONG_JSON, wordsize, mode ? strchr(input, mode) : NULL); + break; + case 't': + cmd_pxr(core, len, RZ_OUTPUT_MODE_TABLE, wordsize, mode ? strchr(input, mode) : NULL); + break; + default: + rz_warn_if_reached(); + cmd_pxr(core, len, mode, wordsize, mode ? strchr(input, mode) : NULL); + } break; default: eprintf("Invalid word size. Use 1, 2, 4 or 8.\n"); diff --git a/librz/core/cmd_search.c b/librz/core/cmd_search.c index 0bd540ca0b3..5e71ffe62ba 100644 --- a/librz/core/cmd_search.c +++ b/librz/core/cmd_search.c @@ -1132,7 +1132,7 @@ static RzList *construct_rop_gadget(RzCore *core, ut64 addr, ut8 *buf, int bufle return hitlist; } -static void print_rop(RzCore *core, RzList *hitlist, PJ *pj, int mode) { +static void print_rop(RzCore *core, RzList *hitlist, PJ *pj, RzOutputMode mode) { const char *otype; RzCoreAsmHit *hit = NULL; RzListIter *iter; @@ -1158,7 +1158,7 @@ static void print_rop(RzCore *core, RzList *hitlist, PJ *pj, int mode) { } switch (mode) { - case 'j': + case RZ_OUTPUT_MODE_JSON: pj_o(pj); pj_ka(pj, "opcodes"); rz_list_foreach (hitlist, iter, hit) { @@ -1196,7 +1196,7 @@ static void print_rop(RzCore *core, RzList *hitlist, PJ *pj, int mode) { } pj_end(pj); break; - case 'q': + case RZ_OUTPUT_MODE_QUIET: // Print gadgets in a 'linear manner', each sequence // on one line. rz_cons_printf("0x%08" PFMT64x ":", @@ -1285,7 +1285,7 @@ static void print_rop(RzCore *core, RzList *hitlist, PJ *pj, int mode) { rop_classify(core, db, ropList, key, size); } } - if (mode != 'j') { + if (mode != RZ_OUTPUT_MODE_JSON) { rz_cons_newline(); } rz_list_free(ropList); @@ -1529,11 +1529,37 @@ static int rz_core_search_rop(RzCore *core, RzInterval search_itv, int opt, cons } if ((mode == 'q') && subchain) { do { - print_rop(core, hitlist, NULL, mode); + print_rop(core, hitlist, NULL, RZ_OUTPUT_MODE_QUIET); hitlist->head = hitlist->head->n; } while (hitlist->head->n); } else { - print_rop(core, hitlist, param->pj, mode); + switch(mode){ + case 'j': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_JSON); + break; + case '*': + case 'r': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_RIZIN); + break; + case 'q': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_QUIET); + break; + case 'k': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_SDB); + break; + case 'l': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_LONG); + break; + case 'J': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_LONG_JSON); + break; + case 't': + print_rop(core, hitlist, param->pj, RZ_OUTPUT_MODE_TABLE); + break; + default: + rz_warn_if_reached(); + print_rop(core, hitlist, param->pj, mode); + } } rz_list_free(hitlist); if (max_count > 0) { @@ -2208,7 +2234,7 @@ static void do_section_search(RzCore *core, struct search_parameters *param, con free(buf); } -static void do_asm_search(RzCore *core, struct search_parameters *param, const char *input, int mode, RzInterval search_itv) { +static void do_asm_search(RzCore *core, struct search_parameters *param, const char *input, RzOutputMode mode, RzInterval search_itv) { RzCoreAsmHit *hit; RzListIter *iter, *itermap; int count = 0, maxhits = 0, filter = 0; @@ -2219,10 +2245,10 @@ static void do_asm_search(RzCore *core, struct search_parameters *param, const c bool everyByte = regexp && input[2] == 'a'; char *end_cmd = strchr(input, ' '); switch ((end_cmd ? *(end_cmd - 1) : input[1])) { - case 'j': + case RZ_OUTPUT_MODE_JSON: param->outmode = RZ_MODE_JSON; break; - case '*': + case RZ_OUTPUT_MODE_RIZIN: param->outmode = RZ_MODE_RIZINCMD; break; default: @@ -3082,7 +3108,33 @@ RZ_IPI int rz_cmd_search(void *data, const char *input) { rz_list_append(hitlist, hit); } while (*(s = strchr(s, ')') + 1) != '\0'); - print_rop(core, hitlist, param.pj, mode); + switch(mode){ + case 'j': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_JSON); + break; + case '*': + case 'r': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_RIZIN); + break; + case 'q': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_QUIET); + break; + case 'k': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_SDB); + break; + case 'l': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_LONG); + break; + case 'J': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_LONG_JSON); + break; + case 't': + print_rop(core, hitlist, param.pj, RZ_OUTPUT_MODE_TABLE); + break; + default: + rz_warn_if_reached(); + print_rop(core, hitlist, param.pj, mode); + } rz_list_free(hitlist); } } @@ -3113,7 +3165,7 @@ RZ_IPI int rz_cmd_search(void *data, const char *input) { RzIOMap *map; rz_list_foreach (param.boundaries, iter, map) { eprintf("-- 0x%" PFMT64x " 0x%" PFMT64x "\n", map->itv.addr, rz_itv_end(map->itv)); - rz_core_analysis_search(core, map->itv.addr, rz_itv_end(map->itv), n, 0); + rz_core_analysis_search(core, map->itv.addr, rz_itv_end(map->itv), n, RZ_OUTPUT_MODE_QUIET); } } break; case 'e': // "/re" @@ -3142,7 +3194,7 @@ RZ_IPI int rz_cmd_search(void *data, const char *input) { RzIOMap *map; rz_list_foreach (param.boundaries, iter, map) { eprintf("-- 0x%" PFMT64x " 0x%" PFMT64x "\n", map->itv.addr, rz_itv_end(map->itv)); - rz_core_analysis_search(core, map->itv.addr, rz_itv_end(map->itv), n, 'r'); + rz_core_analysis_search(core, map->itv.addr, rz_itv_end(map->itv), n, RZ_OUTPUT_MODE_RIZIN); } } break; case 'w': // "/rw" - write refs @@ -3164,10 +3216,10 @@ RZ_IPI int rz_cmd_search(void *data, const char *input) { ut64 to = rz_itv_end(map->itv); if (input[param_offset - 1] == ' ') { rz_core_analysis_search(core, from, to, - rz_num_math(core->num, input + 2), 0); + rz_num_math(core->num, input + 2), RZ_OUTPUT_MODE_QUIET); do_ref_search(core, rz_num_math(core->num, input + 2), from, to, ¶m); } else { - rz_core_analysis_search(core, from, to, core->offset, 0); + rz_core_analysis_search(core, from, to, core->offset, RZ_OUTPUT_MODE_QUIET); do_ref_search(core, core->offset, from, to, ¶m); } if (rz_cons_is_breaked()) { @@ -3185,7 +3237,7 @@ RZ_IPI int rz_cmd_search(void *data, const char *input) { rz_core_cmd_help(core, help_msg_slash_a); } else if (input[1] == 'd') { // "ad" dosearch = 0; - do_asm_search(core, ¶m, input + 1, 0, search_itv); + do_asm_search(core, ¶m, input + 1, RZ_OUTPUT_MODE_QUIET, search_itv); } else if (input[1] == 'e') { // "ae" dosearch = 0; do_asm_search(core, ¶m, input + 2, 'e', search_itv); diff --git a/librz/core/cmd_tasks.c b/librz/core/cmd_tasks.c index 8d4d2844e10..06496b9a3e9 100644 --- a/librz/core/cmd_tasks.c +++ b/librz/core/cmd_tasks.c @@ -46,7 +46,7 @@ static int task_break(RzCore *core, int tid) { RZ_IPI RzCmdStatus rz_tasks_handler(RzCore *core, int argc, const char **argv, RzOutputMode mode) { if (argc == 1) { - rz_core_task_list(core, mode == RZ_OUTPUT_MODE_STANDARD ? '\0' : 'j'); + rz_core_task_list(core, mode == RZ_OUTPUT_MODE_STANDARD ? '\0' : RZ_OUTPUT_MODE_JSON); return RZ_CMD_STATUS_OK; } else if (argc == 2) { return rz_cmd_int2status(task_enqueue(core, argv[1], false)); diff --git a/librz/core/cmd_type.c b/librz/core/cmd_type.c index 3f3bb0727db..e62a72bf534 100644 --- a/librz/core/cmd_type.c +++ b/librz/core/cmd_type.c @@ -531,13 +531,13 @@ static void cmd_type_noreturn(RzCore *core, const char *input) { } } -static void types_list(RzCore *core, int mode) { +static void types_list(RzCore *core, RzOutputMode mode) { switch (mode) { case 1: - case '*': + case RZ_OUTPUT_MODE_RIZIN: rz_core_types_print_all(core, RZ_OUTPUT_MODE_RIZIN); break; - case 'j': + case RZ_OUTPUT_MODE_JSON: rz_core_types_print_all(core, RZ_OUTPUT_MODE_JSON); break; default: @@ -745,7 +745,7 @@ RZ_IPI int rz_cmd_type(void *data, const char *input) { case 'j': // "tj" case '*': // "t*" case 0: // "t" - types_list(core, input[0]); + types_list(core, RZ_OUTPUT_MODE_QUIET); break; case 'o': // "to" if (input[1] == '?') { diff --git a/librz/core/cmd_zign.c b/librz/core/cmd_zign.c index 2e1aba15db8..3687d188b5a 100644 --- a/librz/core/cmd_zign.c +++ b/librz/core/cmd_zign.c @@ -1236,7 +1236,35 @@ static int cmdInfo(void *data, const char *input) { } RzCore *core = (RzCore *)data; rz_flag_space_push(core->flags, RZ_FLAGS_FS_SIGNS); - rz_flag_list(core->flags, *input, input[0] ? input + 1 : ""); + RzOutputMode mode; + switch(*input){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = *input; + } + rz_flag_list(core->flags, mode, input[0] ? input + 1 : ""); rz_flag_space_pop(core->flags); return true; } @@ -1474,10 +1502,10 @@ RZ_IPI RzCmdStatus rz_zign_space_select_handler(RzCore *core, int argc, const ch spaces_list(&core->analysis->zign_spaces, '\0'); break; case RZ_OUTPUT_MODE_JSON: - spaces_list(&core->analysis->zign_spaces, 'j'); + spaces_list(&core->analysis->zign_spaces, RZ_OUTPUT_MODE_JSON); break; case RZ_OUTPUT_MODE_RIZIN: - spaces_list(&core->analysis->zign_spaces, '*'); + spaces_list(&core->analysis->zign_spaces, RZ_OUTPUT_MODE_RIZIN); break; default: return RZ_CMD_STATUS_ERROR; @@ -1511,7 +1539,7 @@ RZ_IPI RzCmdStatus rz_zign_space_rename_handler(RzCore *core, int argc, const ch return RZ_CMD_STATUS_OK; } -static RzCmdStatus zi_handler_common(RzCore *core, int mode, const char *pfx) { +static RzCmdStatus zi_handler_common(RzCore *core, RzOutputMode mode, const char *pfx) { rz_flag_space_push(core->flags, RZ_FLAGS_FS_SIGNS); rz_flag_list(core->flags, mode, pfx); rz_flag_space_pop(core->flags); @@ -1523,11 +1551,11 @@ RZ_IPI RzCmdStatus rz_zign_info_handler(RzCore *core, int argc, const char **arg case RZ_OUTPUT_MODE_STANDARD: return zi_handler_common(core, '\0', ""); case RZ_OUTPUT_MODE_JSON: - return zi_handler_common(core, 'j', ""); + return zi_handler_common(core, RZ_OUTPUT_MODE_JSON, ""); case RZ_OUTPUT_MODE_QUIET: - return zi_handler_common(core, 'q', ""); + return zi_handler_common(core, RZ_OUTPUT_MODE_QUIET, ""); case RZ_OUTPUT_MODE_RIZIN: - return zi_handler_common(core, '*', ""); + return zi_handler_common(core, RZ_OUTPUT_MODE_RIZIN, ""); default: return RZ_CMD_STATUS_ERROR; } diff --git a/librz/core/core.c b/librz/core/core.c index cd6118bfe0a..96b41efc1dc 100644 --- a/librz/core/core.c +++ b/librz/core/core.c @@ -1918,9 +1918,9 @@ static int is_string(const ut8 *buf, int size, int *len) { return 1; } -RZ_API char *rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode) { +RZ_API char *rz_core_analysis_hasrefs(RzCore *core, ut64 value, RzOutputMode mode) { if (mode) { - PJ *pj = (mode == 'j') ? pj_new() : NULL; + PJ *pj = (mode == RZ_OUTPUT_MODE_JSON) ? pj_new() : NULL; const int hex_depth = 1; // r_config_get_i (core->config, "hex.depth"); char *res = rz_core_analysis_hasrefs_to_depth(core, value, pj, hex_depth); if (pj) { @@ -2363,7 +2363,7 @@ static const char *colorfor_cb(void *user, ut64 addr, bool verbose) { return rz_core_analysis_optype_colorfor((RzCore *)user, addr, verbose); } -static char *hasrefs_cb(void *user, ut64 addr, int mode) { +static char *hasrefs_cb(void *user, ut64 addr, RzOutputMode mode) { return rz_core_analysis_hasrefs((RzCore *)user, addr, mode); } diff --git a/librz/core/core_private.h b/librz/core/core_private.h index faa75b2a7fb..049cb3e2ee1 100644 --- a/librz/core/core_private.h +++ b/librz/core/core_private.h @@ -106,7 +106,7 @@ RZ_IPI void rz_core_agraph_print_write(RzCore *core, const char *filename); /* cdebug.c */ RZ_IPI bool rz_core_debug_reg_set(RzCore *core, const char *regname, ut64 val, const char *strval); -RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, int rad, const char *use_color); +RZ_IPI bool rz_core_debug_reg_list(RzCore *core, int type, int size, PJ *pj, RzOutputMode mode, const char *use_color); RZ_IPI void rz_core_debug_regs2flags(RzCore *core, int bits); RZ_IPI void rz_core_regs2flags(RzCore *core); RZ_IPI void rz_core_debug_single_step_in(RzCore *core); diff --git a/librz/core/disasm.c b/librz/core/disasm.c index ee2e0e51a2e..960214cdc92 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -6160,7 +6160,7 @@ RZ_API int rz_core_print_disasm_json(RzCore *core, ut64 addr, ut8 *buf, int nb_b return result; } -RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int mode) { +RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, RzOutputMode mode) { const bool scr_color = rz_config_get_i(core->config, "scr.color"); int i, ret, count = 0; ut8 *buf = core->block; @@ -6175,7 +6175,7 @@ RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int rz_io_read_at(core->io, addr, buf, l); } PJ *pj = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); if (!pj) { return 0; @@ -6193,7 +6193,7 @@ RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int ret = rz_asm_disassemble(core->rasm, &asmop, buf + i, l - i); if (ret < 1) { switch (mode) { - case 'j': + case RZ_OUTPUT_MODE_JSON: case '=': break; case 'i': @@ -6245,7 +6245,7 @@ RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int free(str); } break; - case 'j': { + case RZ_OUTPUT_MODE_JSON: { char *op_hex = rz_asm_op_get_hex(&asmop); pj_o(pj); pj_kn(pj, "addr", addr + i); @@ -6269,7 +6269,7 @@ RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int if (buf != core->block) { free(buf); } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); rz_cons_println(pj_string(pj)); pj_free(pj); @@ -6540,7 +6540,7 @@ static bool read_ahead(RzIO *io, ut8 **buf, size_t *buf_sz, ut64 address, size_t return rz_io_read_at_mapped(io, address, *buf + offset_into_buf, bytes_to_read); } -RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode) { +RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, RzOutputMode mode) { if (nb_opcodes < 1) { return 0; } @@ -6550,7 +6550,7 @@ RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode) { return -1; } PJ *pj = NULL; - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = rz_core_pj_new(core); if (!pj) { return -1; @@ -6638,7 +6638,7 @@ RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode) { } if (block_instr) { switch (mode) { - case RZ_MODE_JSON: + case RZ_OUTPUT_MODE_JSON: rz_core_print_disasm_json(core, block_start, buf, block_sz, block_instr, pj); break; case RZ_MODE_SIMPLE: @@ -6671,7 +6671,7 @@ RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode) { rz_core_seek_arch_bits(core, block_start); } } - if (mode == RZ_MODE_JSON) { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); rz_cons_print(pj_string(pj)); pj_free(pj); diff --git a/librz/core/task.c b/librz/core/task.c index 4e53a992d9d..049ad92bbce 100644 --- a/librz/core/task.c +++ b/librz/core/task.c @@ -759,8 +759,8 @@ RZ_API const char *rz_core_task_status(RzCoreTask *task) { } } -RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, int mode, PJ *j) { - rz_return_if_fail(mode != 'j' || j); +RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, RzOutputMode mode, PJ *j) { + rz_return_if_fail(mode != RZ_OUTPUT_MODE_JSON || j); if (task != core->tasks.main_task && task->runner != cmd_task_runner) { // don't print tasks that are custom function-runners, which come from internal code. // only main and command ones, which should be user-visible. @@ -771,7 +771,7 @@ RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, int mode, PJ *j) cmd = ((CmdTaskCtx *)task->runner_user)->cmd; } switch (mode) { - case 'j': { + case RZ_OUTPUT_MODE_JSON: { pj_o(j); pj_ki(j, "id", task->id); const char *state; @@ -812,11 +812,11 @@ RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, int mode, PJ *j) } } -RZ_API void rz_core_task_list(RzCore *core, int mode) { +RZ_API void rz_core_task_list(RzCore *core, RzOutputMode mode) { RzListIter *iter; RzCoreTask *task; PJ *j = NULL; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { j = pj_new(); pj_a(j); } diff --git a/librz/debug/plugin.c b/librz/debug/plugin.c index 18ede0f3c1e..b967afddc06 100644 --- a/librz/debug/plugin.c +++ b/librz/debug/plugin.c @@ -51,22 +51,22 @@ RZ_API bool rz_debug_use(RzDebug *dbg, const char *str) { return (dbg && dbg->h); } -RZ_API int rz_debug_plugin_list(RzDebug *dbg, int mode) { +RZ_API int rz_debug_plugin_list(RzDebug *dbg, RzOutputMode mode) { char spaces[16]; int count = 0; memset(spaces, ' ', 15); spaces[15] = 0; RzDebugPlugin *h; RzListIter *iter; - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { dbg->cb_printf("["); } rz_list_foreach (dbg->plugins, iter, h) { int sp = 8 - strlen(h->name); spaces[sp] = 0; - if (mode == 'q') { + if (mode == RZ_OUTPUT_MODE_QUIET) { dbg->cb_printf("%s\n", h->name); - } else if (mode == 'j') { + } else if (mode == RZ_OUTPUT_MODE_JSON) { dbg->cb_printf("%s{\"name\":\"%s\",\"license\":\"%s\"}", (count ? "," : ""), h->name, @@ -79,7 +79,7 @@ RZ_API int rz_debug_plugin_list(RzDebug *dbg, int mode) { spaces[sp] = ' '; count++; } - if (mode == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { dbg->cb_printf("]"); } return false; diff --git a/librz/debug/trace.c b/librz/debug/trace.c index 35c76b5cd75..0b88d9da40a 100644 --- a/librz/debug/trace.c +++ b/librz/debug/trace.c @@ -210,7 +210,7 @@ static int cmpaddr(const void *_a, const void *_b) { : 0; } -RZ_API void rz_debug_trace_list(RzDebug *dbg, int mode, ut64 offset) { +RZ_API void rz_debug_trace_list(RzDebug *dbg, RzOutputMode mode, ut64 offset) { int tag = dbg->trace->tag; RzListIter *iter; bool flag = false; @@ -222,7 +222,7 @@ RZ_API void rz_debug_trace_list(RzDebug *dbg, int mode, ut64 offset) { rz_list_foreach (dbg->trace->traces, iter, trace) { if (!trace->tag || (tag & trace->tag)) { switch (mode) { - case 'q': + case RZ_OUTPUT_MODE_QUIET: dbg->cb_printf("0x%" PFMT64x "\n", trace->addr); break; case '=': { diff --git a/librz/flag/flag.c b/librz/flag/flag.c index 3794ad5666d..c6197d87767 100644 --- a/librz/flag/flag.c +++ b/librz/flag/flag.c @@ -371,12 +371,12 @@ static bool print_flag_orig_name(RzFlagItem *flag, void *user) { } /* print with rz_cons the flag items in the flag f, given as a parameter */ -RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx) { +RZ_API void rz_flag_list(RzFlag *f, RzOutputMode mode, const char *pfx) { rz_return_if_fail(f); bool in_range = false; ut64 range_from = UT64_MAX; ut64 range_to = UT64_MAX; - if (rad == 'i') { + if (mode == 'i') { char *sp, *arg = strdup(pfx + 1); sp = strchr(arg, ' '); if (sp) { @@ -390,7 +390,7 @@ RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx) { } in_range = true; free(arg); - rad = pfx[0]; + mode = pfx[0]; pfx = NULL; } @@ -398,11 +398,11 @@ RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx) { pfx = NULL; } - switch (rad) { - case 'q': + switch (mode) { + case RZ_OUTPUT_MODE_QUIET: rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_name, f); break; - case 'j': { + case RZ_OUTPUT_MODE_JSON: { PJ *pj = pj_new(); struct print_flag_t u = { .f = f, @@ -420,7 +420,7 @@ RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx) { break; } case 1: - case '*': { + case RZ_OUTPUT_MODE_RIZIN: { struct print_flag_t u = { .f = f, .in_range = in_range, @@ -439,7 +439,7 @@ RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx) { .in_range = in_range, .range_from = range_from, .range_to = range_to, - .real = (rad == 'n') + .real = (mode == 'n') }; rz_flag_foreach_space(f, rz_flag_space_cur(f), print_flag_orig_name, &u); } else { diff --git a/librz/flag/zones.c b/librz/flag/zones.c index f2c35e0bdbf..1b6c4d4002c 100644 --- a/librz/flag/zones.c +++ b/librz/flag/zones.c @@ -144,11 +144,11 @@ RZ_API RzList *rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows) return list; } -RZ_API bool rz_flag_zone_list(RzFlag *f, int mode) { +RZ_API bool rz_flag_zone_list(RzFlag *f, RzOutputMode mode) { RzListIter *iter; RzFlagZoneItem *zi; rz_list_foreach (DB, iter, zi) { - if (mode == '*') { + if (mode == RZ_OUTPUT_MODE_RIZIN) { f->cb_printf("fz %s @ 0x08%" PFMT64x "\n", zi->name, zi->from); f->cb_printf("f %s %" PFMT64d " 0x08%" PFMT64x "\n", zi->name, zi->to - zi->from, zi->from); diff --git a/librz/include/rz_analysis.h b/librz/include/rz_analysis.h index 78c287dc338..847cd09f013 100644 --- a/librz/include/rz_analysis.h +++ b/librz/include/rz_analysis.h @@ -1591,7 +1591,7 @@ RZ_API RzAnalysisRefType rz_analysis_xrefs_type(char ch); RZ_API RzList *rz_analysis_xrefs_get(RzAnalysis *analysis, ut64 to); RZ_API RzList *rz_analysis_refs_get(RzAnalysis *analysis, ut64 to); RZ_API RzList *rz_analysis_xrefs_get_from(RzAnalysis *analysis, ut64 from); -RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, int rad); +RZ_API void rz_analysis_xrefs_list(RzAnalysis *analysis, RzOutputMode mode); RZ_API RzList *rz_analysis_function_get_refs(RzAnalysisFunction *fcn); RZ_API RzList *rz_analysis_function_get_xrefs(RzAnalysisFunction *fcn); RZ_API int rz_analysis_xrefs_from(RzAnalysis *analysis, RzList *list, const char *kind, const RzAnalysisRefType type, ut64 addr); @@ -1711,7 +1711,7 @@ RZ_API int rz_analysis_reflines_middle(RzAnalysis *analysis, RzList *list, ut64 RZ_API RzAnalysisRefStr *rz_analysis_reflines_str(void *core, ut64 addr, int opts); RZ_API void rz_analysis_reflines_str_free(RzAnalysisRefStr *refstr); /* TODO move to rz_core */ -RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction *fcn, int kind, int mode, PJ *pj); +RZ_API void rz_analysis_var_list_show(RzAnalysis *analysis, RzAnalysisFunction *fcn, int kind, RzOutputMode mode, PJ *pj); RZ_API RzList *rz_analysis_var_list(RzAnalysis *analysis, RzAnalysisFunction *fcn, int kind); RZ_API RZ_DEPRECATE RzList /**/ *rz_analysis_var_all_list(RzAnalysis *analysis, RzAnalysisFunction *fcn); RZ_API RZ_DEPRECATE RzList /**/ *rz_analysis_function_get_var_fields(RzAnalysisFunction *fcn, int kind); @@ -1820,10 +1820,10 @@ RZ_API void rz_meta_rebase(RzAnalysis *analysis, ut64 diff); RZ_API ut64 rz_meta_get_size(RzAnalysis *a, RzAnalysisMetaType type); RZ_API const char *rz_meta_type_to_string(int type); -RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full); -RZ_API void rz_meta_print_list_all(RzAnalysis *a, int type, int rad); -RZ_API void rz_meta_print_list_at(RzAnalysis *a, ut64 addr, int rad); -RZ_API void rz_meta_print_list_in_function(RzAnalysis *a, int type, int rad, ut64 addr); +RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, RzOutputMode mode, PJ *pj, bool show_full); +RZ_API void rz_meta_print_list_all(RzAnalysis *a, int type, RzOutputMode mode); +RZ_API void rz_meta_print_list_at(RzAnalysis *a, ut64 addr, RzOutputMode mode); +RZ_API void rz_meta_print_list_in_function(RzAnalysis *a, int type, RzOutputMode mode, ut64 addr); /* hints */ @@ -1939,27 +1939,27 @@ RZ_API ut64 rz_analysis_vtable_info_get_size(RVTableContext *context, RVTableInf RZ_API bool rz_analysis_vtable_begin(RzAnalysis *analysis, RVTableContext *context); RZ_API RVTableInfo *rz_analysis_vtable_parse_at(RVTableContext *context, ut64 addr); RZ_API RzList *rz_analysis_vtable_search(RVTableContext *context); -RZ_API void rz_analysis_list_vtables(RzAnalysis *analysis, int rad); +RZ_API void rz_analysis_list_vtables(RzAnalysis *analysis, RzOutputMode mode); /* rtti */ RZ_API char *rz_analysis_rtti_msvc_demangle_class_name(RVTableContext *context, const char *name); -RZ_API void rz_analysis_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, int mode); -RZ_API void rz_analysis_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, int mode); -RZ_API void rz_analysis_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, int mode); -RZ_API void rz_analysis_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, int mode); -RZ_API bool rz_analysis_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, int mode, bool strict); +RZ_API void rz_analysis_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, RzOutputMode mode); +RZ_API void rz_analysis_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, RzOutputMode mode); +RZ_API void rz_analysis_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, RzOutputMode mode); +RZ_API void rz_analysis_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, RzOutputMode mode); +RZ_API bool rz_analysis_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, RzOutputMode mode, bool strict); RZ_API void rz_analysis_rtti_msvc_recover_all(RVTableContext *vt_context, RzList *vtables); RZ_API char *rz_analysis_rtti_itanium_demangle_class_name(RVTableContext *context, const char *name); RZ_API void rz_analysis_rtti_itanium_print_class_type_info(RVTableContext *context, ut64 addr, int mode); RZ_API void rz_analysis_rtti_itanium_print_si_class_type_info(RVTableContext *context, ut64 addr, int mode); RZ_API void rz_analysis_rtti_itanium_print_vmi_class_type_info(RVTableContext *context, ut64 addr, int mode); -RZ_API bool rz_analysis_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, int mode); +RZ_API bool rz_analysis_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, RzOutputMode mode); RZ_API void rz_analysis_rtti_itanium_recover_all(RVTableContext *vt_context, RzList *vtables); RZ_API char *rz_analysis_rtti_demangle_class_name(RzAnalysis *analysis, const char *name); -RZ_API void rz_analysis_rtti_print_at_vtable(RzAnalysis *analysis, ut64 addr, int mode); -RZ_API void rz_analysis_rtti_print_all(RzAnalysis *analysis, int mode); +RZ_API void rz_analysis_rtti_print_at_vtable(RzAnalysis *analysis, ut64 addr, RzOutputMode mode); +RZ_API void rz_analysis_rtti_print_all(RzAnalysis *analysis, RzOutputMode mode); RZ_API void rz_analysis_rtti_recover_all(RzAnalysis *analysis); RZ_API RzList *rz_analysis_preludes(RzAnalysis *analysis); @@ -2037,7 +2037,7 @@ RZ_API RzAnalysisClassErr rz_analysis_class_vtable_delete(RzAnalysis *analysis, RZ_API void rz_analysis_class_print(RzAnalysis *analysis, const char *class_name, bool detailed); RZ_API void rz_analysis_class_json(RzAnalysis *analysis, PJ *j, const char *class_name); -RZ_API void rz_analysis_class_list(RzAnalysis *analysis, int mode); +RZ_API void rz_analysis_class_list(RzAnalysis *analysis, RzOutputMode mode); RZ_API void rz_analysis_class_list_bases(RzAnalysis *analysis, const char *class_name); RZ_API void rz_analysis_class_list_vtables(RzAnalysis *analysis, const char *class_name); RZ_API void rz_analysis_class_list_vtable_offset_functions(RzAnalysis *analysis, const char *class_name, ut64 offset); diff --git a/librz/include/rz_bin.h b/librz/include/rz_bin.h index 73dd0b892eb..6ce5fd5eaf1 100644 --- a/librz/include/rz_bin.h +++ b/librz/include/rz_bin.h @@ -766,7 +766,7 @@ RZ_API RzBinObject *rz_bin_cur_object(RzBin *bin); RZ_API bool rz_bin_select(RzBin *bin, const char *arch, int bits, const char *name); RZ_API bool rz_bin_select_bfid(RzBin *bin, ut32 bf_id); RZ_API bool rz_bin_use_arch(RzBin *bin, const char *arch, int bits, const char *name); -RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, int mode); +RZ_API void rz_bin_list_archs(RzBin *bin, PJ *pj, RzOutputMode mode); RZ_API RzBuffer *rz_bin_create(RzBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt); RZ_API RzBuffer *rz_bin_package(RzBin *bin, const char *type, const char *file, RzList *files); diff --git a/librz/include/rz_bp.h b/librz/include/rz_bp.h index 8b6fb22b3db..cea56e702c8 100644 --- a/librz/include/rz_bp.h +++ b/librz/include/rz_bp.h @@ -120,7 +120,7 @@ RZ_API void rz_bp_plugin_list(RzBreakpoint *bp); RZ_API int rz_bp_in(RzBreakpoint *bp, ut64 addr, int perm); // deprecate? -RZ_API int rz_bp_list(RzBreakpoint *bp, int rad); +RZ_API int rz_bp_list(RzBreakpoint *bp, RzOutputMode mode); RZ_API int rz_bp_size(RzBreakpoint *bp); /* bp item attribs setters */ diff --git a/librz/include/rz_config.h b/librz/include/rz_config.h index b57f783d6f0..f1453db4dea 100644 --- a/librz/include/rz_config.h +++ b/librz/include/rz_config.h @@ -89,7 +89,7 @@ RZ_API bool rz_config_get_b(RzConfig *cfg, const char *name); RZ_API const char *rz_config_get(RzConfig *cfg, const char *name); RZ_API const char *rz_config_desc(RzConfig *cfg, const char *name, const char *desc); RZ_API const char *rz_config_node_desc(RzConfigNode *node, const char *desc); -RZ_API void rz_config_list(RzConfig *cfg, const char *str, int rad); +RZ_API void rz_config_list(RzConfig *cfg, const char *str, RzOutputMode mode); RZ_API RzConfigNode *rz_config_node_get(RzConfig *cfg, const char *name); RZ_API RzConfigNode *rz_config_node_new(const char *name, const char *value); RZ_API void rz_config_node_free(void *n); diff --git a/librz/include/rz_cons.h b/librz/include/rz_cons.h index 71e3ee2d550..ba5f638a435 100644 --- a/librz/include/rz_cons.h +++ b/librz/include/rz_cons.h @@ -952,7 +952,7 @@ RZ_API const char *rz_cons_pal_get_name(int index); RZ_API int rz_cons_pal_len(void); RZ_API int rz_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a); RZ_API char *rz_cons_rgb_tostring(ut8 r, ut8 g, ut8 b); -RZ_API void rz_cons_pal_list(int rad, const char *arg); +RZ_API void rz_cons_pal_list(RzOutputMode mode, const char *arg); RZ_API void rz_cons_pal_show(void); RZ_API int rz_cons_get_size(int *rows); RZ_API bool rz_cons_isatty(void); diff --git a/librz/include/rz_core.h b/librz/include/rz_core.h index aa991ee5230..5c5f5dcbb31 100644 --- a/librz/include/rz_core.h +++ b/librz/include/rz_core.h @@ -404,7 +404,7 @@ RZ_API bool rz_core_plugin_fini(RzCore *core); //#define rz_core_ncast(x) (RzCore*)(size_t)(x) RZ_API RzList *rz_core_list_themes(RzCore *core); RZ_API char *rz_core_get_theme(void); -RZ_API void rz_core_theme_nextpal(RzCore *core, int mode); +RZ_API void rz_core_theme_nextpal(RzCore *core, RzOutputMode mode); RZ_API const char *rz_core_get_section_name(RzCore *core, ut64 addr); RZ_API RzCons *rz_core_get_cons(RzCore *core); RZ_API RzBin *rz_core_get_bin(RzCore *core); @@ -548,7 +548,7 @@ RZ_API RzCoreFile *rz_core_file_get_by_fd(RzCore *core, int fd); RZ_API int rz_core_file_close(RzCore *core, RzCoreFile *fh); RZ_API bool rz_core_file_close_fd(RzCore *core, int fd); RZ_API bool rz_core_file_close_all_but(RzCore *core); -RZ_API int rz_core_file_list(RzCore *core, int mode); +RZ_API int rz_core_file_list(RzCore *core, RzOutputMode mode); RZ_API int rz_core_file_binlist(RzCore *core); RZ_API bool rz_core_file_bin_raise(RzCore *core, ut32 num); RZ_API bool rz_core_extend_at(RzCore *core, ut64 addr, int size); @@ -562,7 +562,7 @@ RZ_API bool rz_core_debug_step_one(RzCore *core, int times); RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to); RZ_API void rz_core_debug_ri(RzCore *core, RzReg *reg, int mode); -RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, int mode); +RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, RzOutputMode mode); RZ_API void rz_core_debug_set_register_flags(RzCore *core); RZ_API void rz_core_debug_clear_register_flags(RzCore *core); @@ -620,10 +620,10 @@ RZ_API void rz_core_analysis_fcn_merge(RzCore *core, ut64 addr, ut64 addr2); RZ_API const char *rz_core_analysis_optype_colorfor(RzCore *core, ut64 addr, bool verbose); RZ_API ut64 rz_core_analysis_address(RzCore *core, ut64 addr); RZ_API void rz_core_analysis_undefine(RzCore *core, ut64 off); -RZ_API void rz_core_analysis_hint_print(RzAnalysis *a, ut64 addr, int mode); -RZ_API void rz_core_analysis_hint_list(RzAnalysis *a, int mode); -RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, int mode); -RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *pj, int rad); +RZ_API void rz_core_analysis_hint_print(RzAnalysis *a, ut64 addr, RzOutputMode mode); +RZ_API void rz_core_analysis_hint_list(RzAnalysis *a, RzOutputMode mode); +RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, RzOutputMode mode); +RZ_API int rz_core_analysis_search_xrefs(RzCore *core, ut64 from, ut64 to, PJ *pj, RzOutputMode mode); RZ_API int rz_core_analysis_data(RzCore *core, ut64 addr, int count, int depth, int wordsize); RZ_API void rz_core_analysis_datarefs(RzCore *core, ut64 addr); RZ_API void rz_core_analysis_coderefs(RzCore *core, ut64 addr); @@ -639,7 +639,7 @@ RZ_API void rz_core_analysis_flag_every_function(RzCore *core); RZ_API bool rz_core_analysis_function_rename(RzCore *core, ut64 addr, const char *_name); RZ_API bool rz_core_analysis_function_add(RzCore *core, const char *name, ut64 addr, bool analyze_recursively); RZ_API int rz_core_analysis_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth); -RZ_API char *rz_core_analysis_fcn_autoname(RzCore *core, ut64 addr, int dump, int mode); +RZ_API char *rz_core_analysis_fcn_autoname(RzCore *core, ut64 addr, int dump, RzOutputMode mode); RZ_API void rz_core_analysis_autoname_all_fcns(RzCore *core); RZ_API void rz_core_analysis_autoname_all_golang_fcns(RzCore *core); RZ_API int rz_core_analysis_fcn_list(RzCore *core, const char *input, const char *rad); @@ -688,10 +688,10 @@ RZ_API int rz_core_print_disasm(RzPrint *p, RzCore *core, ut64 addr, ut8 *buf, i RZ_API int rz_core_print_disasm_json(RzCore *core, ut64 addr, ut8 *buf, int len, int lines, PJ *pj); RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address, ut8 *buf, int nb_bytes, int nb_opcodes); RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes); -RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int mode); +RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, RzOutputMode mode); RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut32 nb_opcodes, ut32 nb_bytes, int fmt); RZ_API int rz_core_disasm_pdi(RzCore *core, int nb_opcodes, int nb_bytes, int fmt); -RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode); +RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, RzOutputMode mode); RZ_API int rz_core_flag_in_middle(RzCore *core, ut64 at, int oplen, int *midflags); RZ_API int rz_core_bb_starts_in_middle(RzCore *core, ut64 at, int oplen); @@ -706,7 +706,7 @@ RZ_API int rz_core_bin_set_by_name(RzCore *core, const char *name); RZ_API bool rz_core_bin_load(RzCore *core, const char *file, ut64 baseaddr); RZ_API int rz_core_bin_rebase(RzCore *core, ut64 baddr); RZ_API void rz_core_bin_export_info(RzCore *core, int mode); -RZ_API int rz_core_bin_list(RzCore *core, int mode); +RZ_API int rz_core_bin_list(RzCore *core, RzOutputMode mode); RZ_API bool rz_core_bin_delete(RzCore *core, ut32 binfile_idx); RZ_API ut64 rz_core_bin_impaddr(RzBin *bin, int va, const char *name); @@ -781,11 +781,11 @@ typedef struct rz_core_bin_filter_t { const char *name; } RzCoreBinFilter; -RZ_API int rz_core_bin_info(RzCore *core, int action, PJ *pj, int mode, int va, RzCoreBinFilter *filter, const char *chksum); +RZ_API int rz_core_bin_info(RzCore *core, int action, PJ *pj, RzOutputMode mode, int va, RzCoreBinFilter *filter, const char *chksum); RZ_API int rz_core_bin_set_arch_bits(RzCore *r, const char *name, const char *arch, ut16 bits); RZ_API int rz_core_bin_update_arch_bits(RzCore *r); RZ_API char *rz_core_bin_method_flags_str(ut64 flags, int mode); -RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, PJ *pj, int mode); +RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, PJ *pj, RzOutputMode mode); /* rtr */ RZ_API int rz_core_rtr_cmds(RzCore *core, const char *port); @@ -828,7 +828,7 @@ RZ_API RzCoreCmpWatcher *rz_core_cmpwatch_get(RzCore *core, ut64 addr); RZ_API int rz_core_cmpwatch_add(RzCore *core, ut64 addr, int size, const char *cmd); RZ_API int rz_core_cmpwatch_del(RzCore *core, ut64 addr); RZ_API int rz_core_cmpwatch_update(RzCore *core, ut64 addr); -RZ_API int rz_core_cmpwatch_show(RzCore *core, ut64 addr, int mode); +RZ_API int rz_core_cmpwatch_show(RzCore *core, ut64 addr, RzOutputMode mode); RZ_API int rz_core_cmpwatch_revert(RzCore *core, ut64 addr); // TODO MOVE SOMEWHERE ELSE @@ -856,7 +856,7 @@ typedef struct { RzCoreAnalStatsItem *block; } RzCoreAnalStats; -RZ_API char *rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode); +RZ_API char *rz_core_analysis_hasrefs(RzCore *core, ut64 value, RzOutputMode mode); RZ_API char *rz_core_analysis_get_comments(RzCore *core, ut64 addr); RZ_API RzCoreAnalStats *rz_core_analysis_get_stats(RzCore *a, ut64 from, ut64 to, ut64 step); RZ_API void rz_core_analysis_stats_free(RzCoreAnalStats *s); @@ -943,8 +943,8 @@ typedef void *(*RzCoreTaskFunction)(RzCore *core, void *user); RZ_API RzCoreTask *rz_core_function_task_new(RzCore *core, RzCoreTaskFunction fcn, void *fcn_user); RZ_API void *rz_core_function_task_get_result(RzCoreTask *task); RZ_API const char *rz_core_task_status(RzCoreTask *task); -RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, int mode, PJ *j); -RZ_API void rz_core_task_list(RzCore *core, int mode); +RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, RzOutputMode mode, PJ *j); +RZ_API void rz_core_task_list(RzCore *core, RzOutputMode mode); RZ_API bool rz_core_task_is_cmd(RzCore *core, int id); RZ_API void rz_core_task_del_all_done(RzCore *core); diff --git a/librz/include/rz_debug.h b/librz/include/rz_debug.h index 94c244a3d95..c33a3c2b215 100644 --- a/librz/include/rz_debug.h +++ b/librz/include/rz_debug.h @@ -482,7 +482,7 @@ RZ_API int rz_debug_kill_setup(RzDebug *dbg, int sig, int action); /* handle.c */ RZ_API void rz_debug_plugin_init(RzDebug *dbg); RZ_API int rz_debug_plugin_set(RzDebug *dbg, const char *str); -RZ_API int rz_debug_plugin_list(RzDebug *dbg, int mode); +RZ_API int rz_debug_plugin_list(RzDebug *dbg, RzOutputMode mode); RZ_API bool rz_debug_plugin_add(RzDebug *dbg, RzDebugPlugin *foo); RZ_API bool rz_debug_plugin_set_reg_profile(RzDebug *dbg, const char *str); @@ -542,7 +542,7 @@ RZ_API int rz_debug_trace_pc(RzDebug *dbg, ut64 pc); RZ_API void rz_debug_trace_op(RzDebug *dbg, RzAnalysisOp *op); RZ_API void rz_debug_trace_at(RzDebug *dbg, const char *str); RZ_API RzDebugTracepoint *rz_debug_trace_get(RzDebug *dbg, ut64 addr); -RZ_API void rz_debug_trace_list(RzDebug *dbg, int mode, ut64 offset); +RZ_API void rz_debug_trace_list(RzDebug *dbg, RzOutputMode mode, ut64 offset); RZ_API RzDebugTracepoint *rz_debug_trace_add(RzDebug *dbg, ut64 addr, int size); RZ_API RzDebugTrace *rz_debug_trace_new(void); RZ_API void rz_debug_trace_free(RzDebugTrace *dbg); diff --git a/librz/include/rz_flag.h b/librz/include/rz_flag.h index f6ced50204b..28986bb3f75 100644 --- a/librz/include/rz_flag.h +++ b/librz/include/rz_flag.h @@ -94,7 +94,7 @@ RZ_API void rz_flag_bind(RzFlag *io, RzFlagBind *bnd); #ifdef RZ_API RZ_API RzFlag *rz_flag_new(void); RZ_API RzFlag *rz_flag_free(RzFlag *f); -RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx); +RZ_API void rz_flag_list(RzFlag *f, RzOutputMode mode, const char *pfx); RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off); RZ_API RzFlagItem *rz_flag_get(RzFlag *f, const char *name); RZ_API RzFlagItem *rz_flag_get_i(RzFlag *f, ut64 off); @@ -184,7 +184,7 @@ RZ_API void rz_flag_zone_item_free(void *a); RZ_API bool rz_flag_zone_add(RzFlag *fz, const char *name, ut64 addr); RZ_API bool rz_flag_zone_del(RzFlag *fz, const char *name); RZ_API bool rz_flag_zone_around(RzFlag *fz, ut64 addr, const char **prev, const char **next); -RZ_API bool rz_flag_zone_list(RzFlag *fz, int mode); +RZ_API bool rz_flag_zone_list(RzFlag *fz, RzOutputMode mode); RZ_API bool rz_flag_zone_reset(RzFlag *f); RZ_API RzList *rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows); diff --git a/librz/include/rz_pdb.h b/librz/include/rz_pdb.h index b5558449142..b5e112ab504 100644 --- a/librz/include/rz_pdb.h +++ b/librz/include/rz_pdb.h @@ -16,7 +16,7 @@ struct RZ_PDB7_ROOT_STREAM; typedef struct rz_pdb_t { bool (*pdb_parse)(struct rz_pdb_t *pdb); void (*finish_pdb_parse)(struct rz_pdb_t *pdb); - void (*print_types)(const struct rz_pdb_t *pdb, PJ *pj, int mode); + void (*print_types)(const struct rz_pdb_t *pdb, PJ *pj, RzOutputMode mode); // FILE *fp; PrintfCallback cb_printf; struct RZ_PDB7_ROOT_STREAM *root_stream; diff --git a/librz/main/rizin.c b/librz/main/rizin.c index dc9936c812e..ef83840f11c 100644 --- a/librz/main/rizin.c +++ b/librz/main/rizin.c @@ -496,7 +496,7 @@ RZ_API int rz_main_rizin(int argc, const char **argv) { free(debugbackend); debugbackend = strdup(opt.arg); if (!strcmp(opt.arg, "?")) { - rz_debug_plugin_list(r->dbg, 'q'); + rz_debug_plugin_list(r->dbg, RZ_OUTPUT_MODE_QUIET); rz_cons_flush(); LISTS_FREE(); return 0; diff --git a/librz/main/rz-ax.c b/librz/main/rz-ax.c index 3ce097baccf..4e58c2bbfe2 100644 --- a/librz/main/rz-ax.c +++ b/librz/main/rz-ax.c @@ -48,7 +48,7 @@ static int use_stdin(RNum *num, ut64 *flags, int *fm) { return 0; } -static int format_output(RNum *num, char mode, const char *s, int force_mode, ut64 flags) { +static int format_output(RNum *num, RzOutputMode mode, const char *s, int force_mode, ut64 flags) { ut64 n = rz_num_math(num, s); char strbits[65]; if (force_mode) { @@ -74,7 +74,7 @@ static int format_output(RNum *num, char mode, const char *s, int force_mode, ut printf("%ff\n", *f); } break; case 'f': printf("%.01lf\n", num->fvalue); break; - case 'l': + case RZ_OUTPUT_MODE_LONG: RZ_STATIC_ASSERT(sizeof(float) == 4); float f = (float)num->fvalue; ut32 *p = (ut32 *)&f; @@ -225,7 +225,35 @@ static int rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm) { } else if (rz_str_endswith(str, "f")) { out_mode = 'l'; } - return format_output(num, out_mode, str, *fm, flags); + RzOutputMode mode; + switch(out_mode){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = out_mode; + } + return format_output(num, mode, str, *fm, flags); } printf("Usage: rz-ax [options] [expr ...]\n"); return help(); @@ -620,13 +648,41 @@ static int rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm) { str[strlen(str) - 2] = 't'; str[strlen(str) - 1] = '\0'; } + RzOutputMode mode; + switch(out_mode){ + case 'j': + mode = RZ_OUTPUT_MODE_JSON; + break; + case '*': + case 'r': + mode = RZ_OUTPUT_MODE_RIZIN; + break; + case 'q': + mode = RZ_OUTPUT_MODE_QUIET; + break; + case 'k': + mode = RZ_OUTPUT_MODE_SDB; + break; + case 'l': + mode = RZ_OUTPUT_MODE_LONG; + break; + case 'J': + mode = RZ_OUTPUT_MODE_LONG_JSON; + break; + case 't': + mode = RZ_OUTPUT_MODE_TABLE; + break; + default: + rz_warn_if_reached(); + mode = out_mode; + } while ((p = strchr(str, ' '))) { *p = 0; - format_output(num, out_mode, str, *fm, flags); + format_output(num, mode, str, *fm, flags); str = p + 1; } if (*str) { - format_output(num, out_mode, str, *fm, flags); + format_output(num, mode, str, *fm, flags); } return true; } diff --git a/librz/main/rz-bin.c b/librz/main/rz-bin.c index e98f835bfc3..071853e74a5 100644 --- a/librz/main/rz-bin.c +++ b/librz/main/rz-bin.c @@ -328,7 +328,7 @@ static bool __dumpSections(RzBin *bin, const char *scnname, const char *output, return true; } -static int rabin_do_operation(RzBin *bin, const char *op, int rad, const char *output, const char *file) { +static int rabin_do_operation(RzBin *bin, const char *op, RzOutputMode mode, const char *output, const char *file) { char *arg = NULL, *ptr = NULL, *ptr2 = NULL; bool rc = true; @@ -420,7 +420,7 @@ static int rabin_do_operation(RzBin *bin, const char *op, int rad, const char *o } } if (plg && plg->signature) { - char *sign = plg->signature(cur, rad == RZ_MODE_JSON); + char *sign = plg->signature(cur, mode == RZ_OUTPUT_MODE_JSON); if (sign) { rz_cons_println(sign); rz_cons_flush(); @@ -1128,9 +1128,9 @@ RZ_API int rz_main_rz_bin(int argc, const char **argv) { // List fatmach0 sub-binaries, etc if (action & RZ_BIN_REQ_LISTARCHS || ((arch || bits || arch_name) && !rz_bin_select(bin, arch, bits, arch_name))) { if (rad == RZ_MODE_SIMPLEST || rad == RZ_MODE_SIMPLE) { - rz_bin_list_archs(bin, pj, 'q'); + rz_bin_list_archs(bin, pj, RZ_OUTPUT_MODE_QUIET); } else { - rz_bin_list_archs(bin, pj, (rad == RZ_MODE_JSON) ? 'j' : 1); + rz_bin_list_archs(bin, pj, (rad == RZ_MODE_JSON) ? RZ_OUTPUT_MODE_JSON : 1); } free(arch_name); } diff --git a/librz/main/rz-hash.c b/librz/main/rz-hash.c index fee15ef4dc7..a9ce57d09a1 100644 --- a/librz/main/rz-hash.c +++ b/librz/main/rz-hash.c @@ -73,7 +73,7 @@ static void do_hash_seed(const char *seed) { } } -static void do_hash_hexprint(const ut8 *c, int len, int ule, PJ *pj, int rad) { +static void do_hash_hexprint(const ut8 *c, int len, int ule, PJ *pj, RzOutputMode mode) { int i; char *buf = malloc(len * 2 + 1); if (!buf) { @@ -88,19 +88,19 @@ static void do_hash_hexprint(const ut8 *c, int len, int ule, PJ *pj, int rad) { snprintf(buf + i * 2, (len - i) * 2 + 1, "%02x", c[i]); } } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_ks(pj, "hash", buf); } else { - printf("%s%s", buf, rad == 'n' ? "" : "\n"); + printf("%s%s", buf, mode == 'n' ? RZ_OUTPUT_MODE_STANDARD : "\n"); } free(buf); } -static void do_hash_print(RzHash *ctx, ut64 hash, int dlen, PJ *pj, int rad, int ule) { +static void do_hash_print(RzHash *ctx, ut64 hash, int dlen, PJ *pj, RzOutputMode mode, int ule) { char *o; const ut8 *c = ctx->digest; const char *hname = rz_hash_name(hash); - switch (rad) { + switch (mode) { case 0: if (!quiet) { printf("0x%08" PFMT64x "-0x%08" PFMT64x " %s: ", @@ -109,16 +109,16 @@ static void do_hash_print(RzHash *ctx, ut64 hash, int dlen, PJ *pj, int rad, int if (dlen == RZ_HASH_SIZE_ENTROPY) { printf("%.8f\n", ctx->entropy); } else { - do_hash_hexprint(c, dlen, ule, pj, rad); + do_hash_hexprint(c, dlen, ule, pj, mode); } break; case 'n': - do_hash_hexprint(c, dlen, ule, pj, rad); + do_hash_hexprint(c, dlen, ule, pj, mode); break; - case 'j': + case RZ_MODE_JSON: pj_o(pj); pj_ks(pj, "name", hname); - do_hash_hexprint(c, dlen, ule, pj, rad); + do_hash_hexprint(c, dlen, ule, pj, mode); pj_end(pj); break; default: @@ -129,7 +129,7 @@ static void do_hash_print(RzHash *ctx, ut64 hash, int dlen, PJ *pj, int rad, int } } -static int do_hash_internal(RzHash *ctx, ut64 hash, const ut8 *buf, int len, PJ *pj, int rad, int print, int le) { +static int do_hash_internal(RzHash *ctx, ut64 hash, const ut8 *buf, int len, PJ *pj, RzOutputMode mode, int print, int le) { if (len < 0) { return 0; } @@ -140,11 +140,11 @@ static int do_hash_internal(RzHash *ctx, ut64 hash, const ut8 *buf, int len, PJ if (iterations > 0) { rz_hash_do_spice(ctx, hash, iterations, _s); } - do_hash_print(ctx, hash, dlen, pj, rad, le); + do_hash_print(ctx, hash, dlen, pj, mode, le); return 1; } -static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, int rad, int ule, const ut8 *compare) { +static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, RzOutputMode mode, int ule, const ut8 *compare) { ut64 j, fsize, algobit = rz_hash_name_to_bits(algo); RzHash *ctx; ut8 *buf; @@ -182,7 +182,7 @@ static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, int } PJ *pj = NULL; - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { free(buf); @@ -199,15 +199,15 @@ static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, int int dlen = rz_hash_size(hashbit); rz_hash_do_begin(ctx, i); if (s.buf && s.prefix) { - do_hash_internal(ctx, hashbit, s.buf, s.len, pj, rad, 0, ule); + do_hash_internal(ctx, hashbit, s.buf, s.len, pj, mode, 0, ule); } for (j = from; j < to; j += bsize) { int len = ((j + bsize) > to) ? (to - j) : bsize; rz_io_pread_at(io, j, buf, len); - do_hash_internal(ctx, hashbit, buf, len, pj, rad, 0, ule); + do_hash_internal(ctx, hashbit, buf, len, pj, mode, 0, ule); } if (s.buf && !s.prefix) { - do_hash_internal(ctx, hashbit, s.buf, s.len, pj, rad, 0, ule); + do_hash_internal(ctx, hashbit, s.buf, s.len, pj, mode, 0, ule); } rz_hash_do_end(ctx, i); if (iterations > 0) { @@ -216,14 +216,14 @@ static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, int if (!*rz_hash_name(i)) { continue; } - if (!quiet && rad != 'j') { + if (!quiet && mode != RZ_OUTPUT_MODE_JSON) { printf("%s: ", file); } - do_hash_print(ctx, i, dlen, pj, quiet ? 'n' : rad, ule); + do_hash_print(ctx, i, dlen, pj, quiet ? 'n' : mode, ule); if (quiet == 1) { printf(" %s\n", file); } else { - if (quiet && !rad) { + if (quiet && !mode) { printf("\n"); } } @@ -253,15 +253,15 @@ static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, int if (to > fsize) { to = fsize; } - do_hash_internal(ctx, hashbit, buf, nsize, pj, rad, 1, ule); + do_hash_internal(ctx, hashbit, buf, nsize, pj, mode, 1, ule); } - do_hash_internal(ctx, hashbit, NULL, 0, pj, rad, 1, ule); + do_hash_internal(ctx, hashbit, NULL, 0, pj, mode, 1, ule); from = ofrom; to = oto; } } } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); printf("%s\n", pj_string(pj)); pj_free(pj); @@ -433,7 +433,8 @@ static int encrypt_or_decrypt_file(const char *algo, int direction, const char * RZ_API int rz_main_rz_hash(int argc, const char **argv) { ut64 i; - int ret, c, rad = 0, bsize = 0, numblocks = 0, ule = 0; + int ret, c, bsize = 0, numblocks = 0, ule = 0; + RzOutputMode mode = RZ_OUTPUT_MODE_QUIET; const char *file = NULL; const char *algo = "sha256"; /* default hashing algorithm */ const char *seed = NULL; @@ -465,7 +466,7 @@ RZ_API int rz_main_rz_hash(int argc, const char **argv) { return 1; } break; - case 'j': rad = 'j'; break; + case 'j': mode = RZ_OUTPUT_MODE_JSON; break; case 'S': seed = opt.arg; break; case 'I': ivseed = opt.arg; break; case 'n': numblocks = 1; break; @@ -473,7 +474,7 @@ RZ_API int rz_main_rz_hash(int argc, const char **argv) { case 'E': encrypt = opt.arg; break; case 'L': algolist(); return 0; case 'e': ule = 1; break; - case 'k': rad = 2; break; + case 'k': mode = 2; break; case 'p': ptype = opt.arg; break; case 'a': algo = opt.arg; break; case 'B': incremental = false; break; @@ -649,7 +650,7 @@ RZ_API int rz_main_rz_hash(int argc, const char **argv) { return 1; } PJ *pj = NULL; - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj = pj_new(); if (!pj) { if (str != hashstr) { @@ -666,12 +667,12 @@ RZ_API int rz_main_rz_hash(int argc, const char **argv) { ctx = rz_hash_new(true, hashbit); from = 0; to = strsz; - do_hash_internal(ctx, hashbit, (const ut8 *)str, strsz, pj, rad, 1, ule); + do_hash_internal(ctx, hashbit, (const ut8 *)str, strsz, pj, mode, 1, ule); compare_hashes(ctx, compareBin, rz_hash_size(algobit), &ret); rz_hash_free(ctx); } } - if (rad == 'j') { + if (mode == RZ_OUTPUT_MODE_JSON) { pj_end(pj); printf("%s\n", pj_string(pj)); pj_free(pj); @@ -750,7 +751,7 @@ RZ_API int rz_main_rz_hash(int argc, const char **argv) { return 1; } } - ret |= do_hash(argv[i], algo, io, bsize, rad, ule, compareBin); + ret |= do_hash(argv[i], algo, io, bsize, mode, ule, compareBin); to = 0; rz_io_desc_close(desc); }