Skip to content

Commit

Permalink
Improve JSON output for the afsvj command ##analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Oct 26, 2023
1 parent 4f16499 commit 621ae3f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 30 deletions.
90 changes: 62 additions & 28 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4601,42 +4601,60 @@ static void cmd_afsv(RCore *core, ut64 pcv, int mode) {
RList *list = r_core_get_func_args (core, fcn_name);
if (!r_list_empty (list)) {
bool on_stack = false;
if (pj) {
pj_kn (pj, "argc", nargs);
pj_ka (pj, "argv");
}
r_list_foreach (list, iter, arg) {
if (arg->cc_source && r_str_startswith (arg->cc_source, "stack")) {
on_stack = true;
}
#if 0
if (arg->size) {
r_strbuf_appendf (sb, "int: ");
} else {
r_strbuf_appendf (sb, "%s: ", arg->c_type);
}
#endif
nextele = r_list_iter_get_next (iter);
if (!arg->fmt) {
if (asmtypes > 1) {
if (pj) {
pj_o (pj);
ut64 v = arg->src;
pj_kn (pj, "num", v);
const RList *list = r_flag_get_list (core->flags, v);
RFlagItem *item = r_list_last (list);
if (item) {
pj_ks (pj, "name", item->name);
}
char *s = print_fcn_arg (core, arg->orig_c_type, arg->name, arg->fmt, arg->src, on_stack, asmtypes);
// char *s = r_core_cmd_strf (core, "ps0 @ 0x%08"PFMT64x, v); r_str_trim (s);
if (R_STR_ISNOTEMPTY (s)) {
pj_ks (pj, "str", s);
}
free (s);
pj_end (pj);
} else {
if (!arg->fmt) {
if (asmtypes > 1) {
#if 0
if (warning) {
r_strbuf_append (sb, "_format");
if (warning) {
r_strbuf_append (sb, "_format");
} else {
r_strbuf_appendf (sb, "%s : unk_format", arg->c_type);
}
#endif
r_strbuf_append (sb, "NULL"); // arg->c_type);
} else {
r_strbuf_appendf (sb, "%s : unk_format", arg->c_type);
r_strbuf_append (sb, "?");
}
#endif
r_strbuf_append (sb, "NULL"); // arg->c_type);
} else {
r_strbuf_append (sb, "?");
}
} else {
// TODO: may need ds_comment_esil
char *argstr = print_fcn_arg (core, arg->orig_c_type, arg->name, arg->fmt, arg->src, on_stack, asmtypes);
if (R_STR_ISNOTEMPTY (argstr)) {
r_strbuf_append (sb, argstr);
} else {
r_strbuf_appendf (sb, "(%s)", arg->fmt);
// TODO: may need ds_comment_esil
char *argstr = print_fcn_arg (core, arg->orig_c_type, arg->name, arg->fmt, arg->src, on_stack, asmtypes);
if (R_STR_ISNOTEMPTY (argstr)) {
r_strbuf_append (sb, argstr);
} else {
r_strbuf_appendf (sb, "(%s)", arg->fmt);
}
free (argstr);
}
free (argstr);
r_strbuf_append (sb, nextele?", ":")");
}
r_strbuf_append (sb, nextele?", ":")");
}
if (pj) {
pj_end (pj);
}
r_list_free (list);
free (key);
Expand All @@ -4662,15 +4680,31 @@ static void cmd_afsv(RCore *core, ut64 pcv, int mode) {
for (i = 0; i < nargs; i++) {
ut64 v = r_debug_arg_get (core->dbg, cc, i);
if (pj) {
pj_n (pj, v);
// TODO: show value (string, flag if any in that address)
pj_o (pj);
pj_kn (pj, "num", v);
const RList *list = r_flag_get_list (core->flags, v);
if (list) {
RFlagItem *item = r_list_last (list);
if (item) {
pj_ks (pj, "name", item->name);
}
}
char *s = r_core_cmd_strf (core, "ps0 @ 0x%08"PFMT64x, v);
r_str_trim (s);
if (R_STR_ISNOTEMPTY (s) && !strstr (s, "\\xff")) {
pj_ks (pj, "str", s);
}
free (s);
pj_end (pj);
} else {
if (i > 0) {
r_strbuf_append (sb, ", ");
}
if (v == UT64_MAX || v == UT32_MAX) {
r_strbuf_appendf (sb, "-1");
r_strbuf_append (sb, "-1");
} else if (v == 0) {
r_strbuf_appendf (sb, "NULL");
r_strbuf_append (sb, "NULL");
} else {
r_strbuf_appendf (sb, "0x%"PFMT64x, v);
}
Expand Down
2 changes: 1 addition & 1 deletion libr/flag/flag.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2022 - pancake, ret2libc */
/* radare - LGPL - Copyright 2007-2023 - pancake, ret2libc */

#include <r_flag.h>
#include <r_util.h>
Expand Down
3 changes: 2 additions & 1 deletion libr/util/utype.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ R_API char *r_type_func_name(Sdb *types, const char *fname) {
return strdup (fname);
}
while ((str = strchr (str, '.'))) {
name = ++str;
str++;
name = str;
}
if (r_type_func_exist (types, name)) {
return strdup (name);
Expand Down

0 comments on commit 621ae3f

Please sign in to comment.