Skip to content

Commit

Permalink
apply suggestions and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astralia committed Jun 13, 2024
1 parent d962a4d commit 05f6fe4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
32 changes: 13 additions & 19 deletions libr/core/cmd_info.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static void cmd_info_bin(RCore *core, int va, PJ *pj, int mode) {
}
} else {
if (mode & R_MODE_JSON) {
r_cons_printf ("{}");
r_cons_print ("{}");
}
R_LOG_ERROR ("No file selected");
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ static void cmd_ic(RCore *core, const char *input, PJ *pj, bool is_array, bool v
}
bool first = true;
if (r_list_empty (objs) && mode == 'j') {
r_cons_printf ("[]");
r_cons_print ("[]");
return;
}
r_list_foreach (objs, objs_iter, bf) {
Expand Down Expand Up @@ -1136,12 +1136,6 @@ static void cmd_ic(RCore *core, const char *input, PJ *pj, bool is_array, bool v
}

static void cmd_iz(RCore *core, PJ *pj, int mode, int is_array, bool va, const char *input) {
RBinInfo *info = r_bin_get_info (core->bin);
if (!info && pj) {
r_cons_print ("[]");
r_core_return_value (core, 1);
return;
}
bool rdump = false;
if (input[1] == '-') { // "iz-"
char *strpurge = core->bin->strpurge;
Expand Down Expand Up @@ -1731,7 +1725,7 @@ static int cmd_info(void *data, const char *input) {
RBININFO ("imports", R_CORE_BIN_ACC_IMPORTS, NULL, amount);
}
} else if (mode & R_MODE_JSON) {
r_cons_printf ("[]");
r_cons_print ("[]");
}
core->bin->cur = cur;
r_list_free (objs);
Expand All @@ -1744,7 +1738,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("{}");
r_cons_print ("{}");
}
r_list_foreach (objs, iter, bf) {
core->bin->cur = bf;
Expand All @@ -1761,7 +1755,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("{}");
r_cons_print ("{}");
}
r_list_foreach (objs, iter, bf) {
core->bin->cur = bf;
Expand All @@ -1778,7 +1772,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("[]");
r_cons_print ("[]");
}
r_list_foreach (objs, iter, bf) {
core->bin->cur = bf;
Expand Down Expand Up @@ -1810,7 +1804,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("[]");
r_cons_print ("[]");
}
r_list_foreach (bfiles, iter, bf) {
core->bin->cur = bf;
Expand Down Expand Up @@ -1876,10 +1870,10 @@ static int cmd_info(void *data, const char *input) {
subcmds++;
}
if (mode == R_MODE_JSON) {
r_cons_printf ("}");
r_cons_print ("}");
}
} else {
r_cons_printf ("{}");
r_cons_print ("{}");
}
break;
case 'A': // "iA"
Expand Down Expand Up @@ -1922,7 +1916,7 @@ static int cmd_info(void *data, const char *input) {
}
if (r_list_empty (objs)) {
if (mode & R_MODE_JSON) {
r_cons_printf ("[]");
r_cons_print ("[]");
}
} else {
r_list_foreach (objs, iter, bf) {
Expand Down Expand Up @@ -2035,7 +2029,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("{}");
r_cons_print ("{}");
break;
}
RList *bfiles = r_core_bin_files (core);
Expand All @@ -2056,7 +2050,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("[]");
r_cons_print ("[]");
}
r_list_foreach (objs, iter, bf) {
RBinObject *obj = bf->bo;
Expand All @@ -2075,7 +2069,7 @@ static int cmd_info(void *data, const char *input) {
RBinFile *bf;
RBinFile *cur = core->bin->cur;
if (!cur && pj) {
r_cons_printf ("[]");
r_cons_print ("[]");
}
r_list_foreach (objs, iter, bf) {
core->bin->cur = bf;
Expand Down
24 changes: 14 additions & 10 deletions test/db/json/cmd_i
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
iSj
iaj
iAj
icj
iCj
idj
iEj
iej
ihj
iIj
iEj
# ihj
iij
iIj
ij
ilj
iLj
iMj
iLj io
imj
iRj
iMj
irj
iSj
is.j @ 0xffffffffffffffff
# iRj
isj
is.j @ 0xffffffffffffffff
iSj
iSj entropy
iSj sha1
iSSj
itj
iTj
iVj
izj
izzj
iZj
# izzj
# iZj
3 changes: 0 additions & 3 deletions test/db/json/json2
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@ fj
fdj
fd.j
fsj
iaj
iAj
iCj
tj
ttj

0 comments on commit 05f6fe4

Please sign in to comment.