-
-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor output modes to use enum (#489) #929
Changes from all commits
bf46c86
8b34737
b94a7c3
4adaad2
8689e99
3df56db
baa3c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would remove 0 and 1. |
||
case '*': | ||
case RZ_OUTPUT_MODE_RIZIN: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to define this if it goes into the default switch case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so I will remove all the three cases. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @XVilka Do you mean I should change it to something more specific like |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here and below. |
||
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,22 +470,22 @@ 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; | ||
} | ||
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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the commentary or just remove it.