Skip to content

Commit

Permalink
Use RCorePJ if possible instead of PJ ##json
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jun 19, 2024
1 parent a5f9a18 commit 8f4630d
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 68 deletions.
8 changes: 4 additions & 4 deletions libr/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ static int cmd_kuery(void *data, const char *input) {
r_cons_println ("No Output from sdb");
break;
}
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
if (!pj) {
free (out);
break;
Expand Down Expand Up @@ -2683,7 +2683,7 @@ static int cmd_bsize(void *data, const char *input) {
}
break;
case 'j': { // "bj"
PJ * pj = pj_new ();
PJ *pj = r_core_pj_new (core);
if (!pj) {
break;
}
Expand Down Expand Up @@ -2847,7 +2847,7 @@ static int cmd_resize(void *data, const char *input) {
}
return true;
case 'j': { // "rj"
PJ * pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
if (oldsize != -1) {
pj_kn (pj, "size", oldsize);
Expand Down Expand Up @@ -3352,7 +3352,7 @@ static int cmd_json(void *data, const char *input) {
if (j) {
j_cmd = r_json_get (j, "cmd");
}
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
if (j_cmd) {
const RJson *j_json = r_json_get (j, "json");
Expand Down
16 changes: 8 additions & 8 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2959,7 +2959,7 @@ static void anal_bb_list(RCore *core, const char *input) {
return;
}
if (mode == 'j') {
pj = pj_new ();
pj = r_core_pj_new (core);
pj_o (pj);
pj_ka (pj, "blocks");
} else if (mode == ',' || mode == 't') {
Expand Down Expand Up @@ -3752,7 +3752,7 @@ static void cmd_anal_fcn_sig(RCore *core, const char *input) {
}

if (json) {
PJ *j = pj_new ();
PJ *j = r_core_pj_new (core);
if (!j) {
return;
}
Expand Down Expand Up @@ -6278,7 +6278,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
if (rs) {
RRegItem *r;
RListIter *iter;
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_a (pj);
r_list_foreach (rs->regs, iter, r) {
if (use_json) {
Expand Down Expand Up @@ -6306,7 +6306,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
break;
case 'A': // "arA"
if (str[1] == 'j') { // "arAj"
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
int nargs = 4;
RReg *reg = core->anal->reg;
Expand Down Expand Up @@ -7092,7 +7092,7 @@ static void cmd_anal_info(RCore *core, const char *input) {
break;
case 'a': // "aia"
if (input[1] == 'j') { // "aiaj"
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
int v = r_anal_archinfo (core->anal, R_ARCH_INFO_MINOP_SIZE);
pj_ki (pj, "minopsz", v);
Expand Down Expand Up @@ -7624,7 +7624,7 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length, const char *es
} else if ((mode >> 3) & 1) {
showregs (regnow);
} else if ((mode >> 4) & 1) {
pj = pj_new ();
pj = r_core_pj_new (core);
if (!pj) {
return false;
}
Expand Down Expand Up @@ -9898,7 +9898,7 @@ static void cmd_anal_syscall(RCore *core, const char *input) {
}
break;
case 'j': // "asj"
pj = pj_new ();
pj = r_core_pj_new (core);
pj_a (pj);
list = r_syscall_list (core->anal->syscall);
r_list_foreach (list, iter, si) {
Expand Down Expand Up @@ -10281,7 +10281,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
if (input[1] == '*') {
anal_axg (core, input + 2, 0, db, R_CORE_ANAL_GRAPHBODY, NULL); // r2 commands
} else if (input[1] == 'j') {
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
anal_axg (core, input + 2, 0, db, R_CORE_ANAL_JSON, pj);
const char *pjs = pj_string (pj);
r_cons_printf ("%s\n", *pjs? pjs: "{}");
Expand Down
2 changes: 1 addition & 1 deletion libr/core/cmd_cmp.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int radare_compare(RCore *core, const ut8 *f, const ut8 *d, int len, int
return 0;
}
if (mode == 'j') {
pj = pj_new ();
pj = r_core_pj_new (core);
if (!pj) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion libr/core/cmd_eval.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ static int cmd_eval(void *data, const char *input) {
break;
} else if (!strcmp (input + 1, "vj")) {
char **e = r_sys_get_environ ();
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
if (e != NULL) {
while (*e) {
Expand Down
37 changes: 19 additions & 18 deletions libr/core/cmd_flag.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ static void __flag_graph(RCore *core, const char *input, int mode) {
r_list_free (flags);
}

static void spaces_list(RSpaces *sp, int mode) {
static void spaces_list(RCore *core, RSpaces *sp, int mode) {
RSpaceIter *it;
RSpace *s;
const RSpace *cur = r_spaces_current (sp);
PJ *pj = NULL;
if (mode == 'j') {
pj = pj_new ();
pj = r_core_pj_new (core);
pj_a (pj);
}
r_spaces_foreach (sp, it, s) {
Expand Down Expand Up @@ -570,7 +570,7 @@ static void cmd_flag_tags(RCore *core, const char *input) {
if (mode == 'j') { // "ftj"
RListIter *iter, *iter2;
const char *tag, *flg;
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
RList *list = r_flag_tags_list (core->flags, NULL);
r_list_foreach (list, iter, tag) {
Expand Down Expand Up @@ -715,13 +715,13 @@ static void print_space_stack(RFlag *f, int ordinal, const char *name, bool sele
}
}

static int flag_space_stack_list(RFlag *f, int mode) {
static int flag_space_stack_list(RCore *core, RFlag *f, int mode) {
RListIter *iter;
char *space;
int i = 0;
PJ *pj = NULL;
if (mode == 'j') {
pj = pj_new ();
pj = r_core_pj_new (core);
pj_a (pj);
}
r_list_foreach (f->spaces.spacestack, iter, space) {
Expand Down Expand Up @@ -776,12 +776,13 @@ static void print_function_labels_for(RAnalFunction *fcn, int rad, PJ *pj) {
}
}

static void print_function_labels(RAnal *anal, RAnalFunction *fcn, int rad) {
r_return_if_fail (anal || fcn);
static void print_function_labels(RCore *core, RAnalFunction *fcn, int rad) {
r_return_if_fail (core || fcn);
RAnal *anal = core->anal;
PJ *pj = NULL;
bool json = rad == 'j';
if (json) {
pj = pj_new ();
pj = r_core_pj_new (core);
}
if (fcn) {
print_function_labels_for (fcn, rad, pj);
Expand Down Expand Up @@ -1119,11 +1120,11 @@ static int cmd_flag(void *data, const char *input) {
r_core_cmd_help_contains (core, help_msg_f, "f.");
} else if (input[1] == '*' || input[1] == 'j') {
if (input[2] == '*') {
print_function_labels (core->anal, NULL, input[1]);
print_function_labels (core, NULL, input[1]);
} else {
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
if (fcn) {
print_function_labels (core->anal, fcn, input[1]);
print_function_labels (core, fcn, input[1]);
} else {
R_LOG_ERROR ("Cannot find function at 0x%08"PFMT64x, off);
}
Expand Down Expand Up @@ -1153,7 +1154,7 @@ static int cmd_flag(void *data, const char *input) {
} else {
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
if (fcn) {
print_function_labels (core->anal, fcn, 0);
print_function_labels (core, fcn, 0);
} else {
R_LOG_ERROR ("Local flags require a function to work");
}
Expand Down Expand Up @@ -1261,7 +1262,7 @@ static int cmd_flag(void *data, const char *input) {
}
break;
case 's': // "fss"
flag_space_stack_list (core->flags, input[2]);
flag_space_stack_list (core, core->flags, input[2]);
break;
case '-': // "fs-"
switch (input[2]) {
Expand Down Expand Up @@ -1309,10 +1310,10 @@ static int cmd_flag(void *data, const char *input) {
case '\0':
case '*':
case 'q':
spaces_list (&core->flags->spaces, input[1]);
spaces_list (core, &core->flags->spaces, input[1]);
break;
default:
spaces_list (&core->flags->spaces, 0);
spaces_list (core, &core->flags->spaces, 0);
break;
}
break;
Expand Down Expand Up @@ -1532,7 +1533,7 @@ static int cmd_flag(void *data, const char *input) {
const RList *list = r_flag_get_list (core->flags, core->offset);
PJ *pj = NULL;
if (mode == 'j') {
pj = pj_new ();
pj = r_core_pj_new (core);
pj_a (pj);
}
RListIter *iter;
Expand Down Expand Up @@ -1683,7 +1684,7 @@ static int cmd_flag(void *data, const char *input) {
}
flaglist = r_flag_get_list (core->flags, addr);
isJson = strchr (input, 'j');
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
if (isJson) {
pj_a (pj);
}
Expand Down Expand Up @@ -1776,7 +1777,7 @@ static int cmd_flag(void *data, const char *input) {
if (f->offset != addr) {
// if input contains 'j' print json
if (strchr (input, 'j')) {
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
pj_kn (pj, "offset", f->offset);
pj_ks (pj, "name", f->name);
Expand All @@ -1801,7 +1802,7 @@ static int cmd_flag(void *data, const char *input) {
}
} else {
if (strchr (input, 'j')) {
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
pj_ks (pj, "name", f->name);
// Print flag's real name if defined
Expand Down
2 changes: 1 addition & 1 deletion libr/core/cmd_help.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ static int cmd_help(void *data, const char *input) {
break;
case 'j': // "?Vj"
{
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_o (pj);
pj_ks (pj, "arch", R_SYS_ARCH);
pj_ks (pj, "os", R_SYS_OS);
Expand Down
4 changes: 2 additions & 2 deletions libr/core/cmd_meta.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,13 +1466,13 @@ static int cmd_meta(void *data, const char *input) {
case 'j': // "CSj"
case '\0': // "CS"
case '*': // "CS*"
spaces_list (ms, input[1]);
spaces_list (core, ms, input[1]);
break;
case ' ': // "CS "
r_spaces_set (ms, input + 2);
break;
default:
spaces_list (ms, 0);
spaces_list (core, ms, 0);
break;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion libr/core/cmd_mount.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static void cmd_mount_ls(RCore *core, const char *input) {
RList *list = r_fs_dir (core->fs, input);
PJ *pj = NULL;
if (isJSON) {
pj = pj_new ();
pj = r_core_pj_new (core);
pj_a (pj);
}
if (list) {
Expand Down
6 changes: 3 additions & 3 deletions libr/core/cmd_open.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static void map_list(RCore *core, int mode, RPrint *print, int fd) {
r_return_if_fail (io && print && print->cb_printf);
PJ *pj = NULL;
if (mode == 'j') {
pj = pj_new ();
pj = r_core_pj_new (core);
if (!pj) {
return;
}
Expand Down Expand Up @@ -951,7 +951,7 @@ static void cmd_open_map(RCore *core, const char *input) {
map = r_io_map_get_at (core->io, core->offset);
if (map) {
if (input[2] == 'j') { // "om.j"
pj = pj_new ();
pj = r_core_pj_new (core);
if (!pj) {
return;
}
Expand Down Expand Up @@ -2159,7 +2159,7 @@ static int cmd_open(void *data, const char *input) {
r_core_cmd_help_match (core, help_msg_o, "oj");
break;
}
PJ *pj = pj_new ();
PJ *pj = r_core_pj_new (core);
pj_a (pj);
r_id_storage_foreach (core->io->files, desc_list_json_cb, pj);
pj_end (pj);
Expand Down
Loading

0 comments on commit 8f4630d

Please sign in to comment.