Use pj in cmd_info.c ##refactor

This commit is contained in:
eagleoflqj 2021-01-02 17:48:49 -05:00 committed by pancake
parent 592ddf81eb
commit 2879c582af
9 changed files with 287 additions and 429 deletions

View File

@ -480,21 +480,15 @@ R_API void r_bin_free(RBin *bin) {
}
}
static bool r_bin_print_plugin_details(RBin *bin, RBinPlugin *bp, int json) {
static bool r_bin_print_plugin_details(RBin *bin, RBinPlugin *bp, PJ *pj, int json) {
if (json == 'q') {
bin->cb_printf ("%s\n", bp->name);
} else if (json) {
PJ *pj = pj_new ();
if (!pj) {
return false;
}
pj_o (pj);
pj_ks (pj, "name", bp->name);
pj_ks (pj, "description", bp->desc);
pj_ks (pj, "license", r_str_get_fail (bp->license, "???"));
pj_end (pj);
bin->cb_printf ("%s\n", pj_string (pj));
pj_free (pj);
} else {
bin->cb_printf ("Name: %s\n", bp->name);
bin->cb_printf ("Description: %s\n", bp->desc);
@ -535,7 +529,7 @@ static void __printXtrPluginDetails(RBin *bin, RBinXtrPlugin *bx, int json) {
}
}
R_API bool r_bin_list_plugin(RBin *bin, const char* name, int json) {
R_API bool r_bin_list_plugin(RBin *bin, const char* name, PJ *pj, int json) {
RListIter *it;
RBinPlugin *bp;
RBinXtrPlugin *bx;
@ -546,7 +540,7 @@ R_API bool r_bin_list_plugin(RBin *bin, const char* name, int json) {
if (!r_str_cmp (name, bp->name, strlen (name))) {
continue;
}
return r_bin_print_plugin_details (bin, bp, json);
return r_bin_print_plugin_details (bin, bp, pj, json);
}
r_list_foreach (bin->binxtrs, it, bx) {
if (!r_str_cmp (name, bx->name, strlen (name))) {
@ -560,7 +554,7 @@ R_API bool r_bin_list_plugin(RBin *bin, const char* name, int json) {
return false;
}
R_API void r_bin_list(RBin *bin, int format) {
R_API void r_bin_list(RBin *bin, PJ *pj, int format) {
RListIter *it;
RBinPlugin *bp;
RBinXtrPlugin *bx;
@ -574,10 +568,6 @@ R_API void r_bin_list(RBin *bin, int format) {
bin->cb_printf ("%s\n", bx->name);
}
} else if (format) {
PJ *pj = pj_new ();
if (!pj) {
return;
}
pj_o (pj);
pj_ka (pj, "bin");
r_list_foreach (bin->plugins, it, bp) {
@ -607,8 +597,6 @@ R_API void r_bin_list(RBin *bin, int format) {
}
pj_end (pj);
pj_end (pj);
bin->cb_printf ("%s\n", pj_string (pj));
pj_free (pj);
} else {
r_list_foreach (bin->plugins, it, bp) {
bin->cb_printf ("bin %-11s %s (%s) %s %s\n",
@ -959,20 +947,15 @@ R_API bool r_bin_select_bfid (RBin *bin, ut32 bf_id) {
return bf? r_bin_file_set_obj (bin, bf, NULL): false;
}
static void list_xtr_archs(RBin *bin, int mode) {
static void list_xtr_archs(RBin *bin, PJ *pj, int mode) {
RBinFile *binfile = r_bin_cur (bin);
if (binfile->xtr_data) {
RListIter *iter_xtr;
RBinXtrData *xtr_data;
int bits, i = 0;
char *arch, *machine;
PJ *pj;
if (mode == 'j') {
pj = pj_new ();
if (!pj) {
return;
}
pj_ka (pj, "bins");
}
@ -1010,13 +993,11 @@ static void list_xtr_archs(RBin *bin, int mode) {
if (mode == 'j') {
pj_end (pj);
bin->cb_printf ("%s", pj_string (pj));
pj_free (pj);
}
}
}
R_API void r_bin_list_archs(RBin *bin, int mode) {
R_API void r_bin_list_archs(RBin *bin, PJ *pj, int mode) {
r_return_if_fail (bin);
char unk[128];
@ -1027,7 +1008,7 @@ R_API void r_bin_list_archs(RBin *bin, int mode) {
//are we with xtr format?
if (binfile && binfile->curxtr) {
list_xtr_archs (bin, mode);
list_xtr_archs (bin, pj, mode);
return;
}
Sdb *binfile_sdb = binfile? binfile->sdb: NULL;
@ -1046,12 +1027,7 @@ R_API void r_bin_list_archs(RBin *bin, int mode) {
}
RTable *table = r_table_new ();
const char *fmt = "dXnss";
PJ *pj;
if (mode == 'j') {
pj = pj_new ();
if (!pj) {
return;
}
pj_ka (pj, "bins");
}
RBinObject *obj = nbinfile->o;
@ -1161,11 +1137,6 @@ R_API void r_bin_list_archs(RBin *bin, int mode) {
}
if (mode == 'j') {
pj_end (pj);
const char *s = pj_string (pj);
if (s) {
bin->cb_printf ("%s", s);
}
pj_free (pj);
}
r_table_free (table);
}

View File

@ -170,7 +170,7 @@ static bool is_valid_guid(const char *guid) {
return i >= 33; // len of GUID and age
}
int r_bin_pdb_download(RCore *core, int isradjson, int *actions_done, SPDBOptions *options) {
int r_bin_pdb_download(RCore *core, PJ *pj, int isradjson, SPDBOptions *options) {
int ret;
SPDBDownloaderOpt opt;
SPDBDownloader pdb_downloader;
@ -201,23 +201,14 @@ int r_bin_pdb_download(RCore *core, int isradjson, int *actions_done, SPDBOption
init_pdb_downloader (&opt, &pdb_downloader);
ret = pdb_downloader.download ? pdb_downloader.download (&pdb_downloader) : 0;
if (isradjson) {
PJ *pj = pj_new ();
if (!pj) {
return 1;
}
pj_ko (pj, "pdb");
pj_ks (pj, "file", opt.dbg_file);
pj_kb (pj, "download", (bool) ret);
pj_end (pj);
r_cons_printf ("%s%s", actions_done && *actions_done ? "," : "", pj_string (pj));
pj_free (pj);
} else {
r_cons_printf ("PDB \"%s\" download %s\n",
opt.dbg_file, ret ? "success" : "failed");
}
if (actions_done) {
(*actions_done)++;
}
deinit_pdb_downloader (&pdb_downloader);
return !ret;

View File

@ -45,7 +45,7 @@ void deinit_pdb_downloader(SPDBDownloader *pdb_downloader);
///
/// \brief download PDB file
R_API int r_bin_pdb_download(RCore *core, int isradjson, int *actions_done, SPDBOptions *options);
R_API int r_bin_pdb_download(RCore *core, PJ *pj, int isradjson, SPDBOptions *options);
#ifdef __cplusplus
}

File diff suppressed because it is too large Load Diff

View File

@ -1436,7 +1436,7 @@ static int r_debug_heap(RCore *core, const char *input) {
return true;
}
static bool get_bin_info(RCore *core, const char *file, ut64 baseaddr, int mode, bool symbols_only, RCoreBinFilter *filter) {
static bool get_bin_info(RCore *core, const char *file, ut64 baseaddr, PJ *pj, int mode, bool symbols_only, RCoreBinFilter *filter) {
int fd;
if ((fd = r_io_fd_open (core->io, file, R_PERM_R, 0)) == -1) {
return false;
@ -1456,7 +1456,7 @@ static bool get_bin_info(RCore *core, const char *file, ut64 baseaddr, int mode,
} else if (mode == R_MODE_SET || mode == R_MODE_RADARE) {
action &= ~R_CORE_BIN_ACC_ENTRIES & ~R_CORE_BIN_ACC_MAIN;
}
r_core_bin_info (core, action, mode, 1, filter, NULL);
r_core_bin_info (core, action, pj, mode, 1, filter, NULL);
RBinFile *bf = r_bin_cur (core->bin);
r_bin_file_delete (core->bin, bf->id);
r_bin_file_set_cur_binfile (core->bin, obf);
@ -1583,6 +1583,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
symbols_only = false;
input++;
}
PJ *pj = NULL;
switch (input[1]) {
case 's':
mode = R_MODE_SET;
@ -1592,6 +1593,10 @@ static int cmd_debug_map(RCore *core, const char *input) {
break;
case 'j':
mode = R_MODE_JSON;
pj = r_core_pj_new (core);
if (!pj) {
return false;
}
break;
case 'q':
mode = input[2] == 'q' ? input++, R_MODE_SIMPLEST : R_MODE_SIMPLE;
@ -1645,7 +1650,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
file, map->size, baddr, R_SYS_DEVNULL);
}
}
get_bin_info (core, file, baddr, mode, symbols_only, &filter);
get_bin_info (core, file, baddr, pj, mode, symbols_only, &filter);
if (newfile) {
if (!r_file_rm (newfile)) {
eprintf ("Error when removing %s\n", newfile);
@ -1654,10 +1659,14 @@ static int cmd_debug_map(RCore *core, const char *input) {
}
} else {
r_bin_set_baddr (core->bin, map->addr);
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, (input[1]=='*'), true, &filter, NULL);
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, pj, input[1] == '*', true, &filter, NULL);
r_bin_set_baddr (core->bin, baddr);
}
}
if (mode == R_MODE_JSON) {
r_cons_println (pj_string (pj));
pj_free (pj);
}
free (ptr);
}
break;
@ -1688,7 +1697,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
filter.name = (char *) closest_symbol->name;
r_bin_set_baddr (core->bin, map->addr);
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, false, true, &filter, NULL);
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, NULL, false, true, &filter, NULL);
}
}
}
@ -5071,10 +5080,8 @@ static int cmd_debug(void *data, const char *input) {
case 'L': // "dL"
switch (input[1]) {
case 'q':
r_debug_plugin_list (core->dbg, 'q');
break;
case 'j':
r_debug_plugin_list (core->dbg, 'j');
r_debug_plugin_list (core->dbg, input[1]);
break;
case '?':
r_core_cmd_help (core, help_msg_dL);

View File

@ -143,10 +143,10 @@ static bool demangle(RCore *core, const char *s) {
return true;
}
static void cmd_info_here(RCore *core, int mode) {
static void cmd_info_here(RCore *core, PJ *pj, int mode) {
RCoreItem *item = r_core_item_at (core, core->offset);
if (item) {
PJ *pj = pj_new ();
// fixme: other modes
if (item && mode == R_MODE_JSON) {
pj_o (pj);
pj_ks (pj, "type", item->type);
@ -198,15 +198,11 @@ static void cmd_info_here(RCore *core, int mode) {
}
}
pj_end (pj);
char *s = pj_drain (pj);
r_cons_printf ("%s\n", s);
free (s);
r_core_item_free (item);
}
}
//TODO PJ
static void r_core_file_info(RCore *core, int mode) {
static void r_core_file_info(RCore *core, PJ *pj, int mode) {
const char *fn = NULL;
int dbg = r_config_get_i (core->config, "cfg.debug");
bool io_cache = r_config_get_i (core->config, "io.cache");
@ -216,7 +212,7 @@ static void r_core_file_info(RCore *core, int mode) {
RIODesc *desc = r_io_desc_get (core->io, fd);
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
if (mode == R_MODE_JSON) {
r_cons_printf ("{");
pj_o (pj);
}
if (mode == R_MODE_RADARE) {
return;
@ -224,12 +220,10 @@ static void r_core_file_info(RCore *core, int mode) {
if (mode == R_MODE_SIMPLE) {
return;
}
const char *comma = "";
if (info) {
fn = info->file;
if (mode == R_MODE_JSON) {
comma = ",";
r_cons_printf ("\"type\":\"%s\"", r_str_get (info->type));
pj_ks (pj, "type", r_str_get (info->type));
}
} else {
fn = desc ? desc->name: NULL;
@ -243,43 +237,35 @@ static void r_core_file_info(RCore *core, int mode) {
uri = "";
}
}
{
char *escapedFile = r_str_escape_utf8_for_json (uri, -1);
r_cons_printf ("%s\"file\":\"%s\"", comma, escapedFile);
comma = ",";
free (escapedFile);
}
pj_ks (pj, "file", uri);
if (dbg) {
dbg = R_PERM_WX;
}
if (desc) {
ut64 fsz = r_io_desc_size (desc);
r_cons_printf ("%s\"fd\":%d", comma, desc->fd);
comma = ",";
pj_ki (pj, "fd", desc->fd);
if (fsz != UT64_MAX) {
char humansz[8];
r_cons_printf (",\"size\":%"PFMT64d, fsz);
pj_kN (pj, "size", fsz);
r_num_units (humansz, sizeof (humansz), fsz);
r_cons_printf (",\"humansz\":\"%s\"", humansz);
pj_ks (pj, "humansz", humansz);
}
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache || desc->perm & R_PERM_W));
r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (desc->perm & R_PERM_RWX));
pj_kb (pj, "iorw", io_cache || desc->perm & R_PERM_W);
pj_ks (pj, "mode", r_str_rwx_i (desc->perm & R_PERM_RWX));
if (desc->referer && *desc->referer) {
r_cons_printf (",\"referer\":\"%s\"", desc->referer);
pj_ks (pj, "referer", desc->referer);
}
}
r_cons_printf ("%s\"block\":%d", comma, core->blocksize);
pj_ki (pj, "block", core->blocksize);
if (binfile) {
if (binfile->curxtr) {
r_cons_printf (",\"packet\":\"%s\"",
binfile->curxtr->name);
pj_ks (pj, "packet", binfile->curxtr->name);
}
if (plugin) {
r_cons_printf (",\"format\":\"%s\"",
plugin->name);
pj_ks (pj, "format", plugin->name);
}
}
r_cons_printf ("}");
pj_end (pj);
} else if (desc && mode != R_MODE_SIMPLE) {
//r_cons_printf ("# Core file info\n");
if (dbg) {
@ -344,29 +330,28 @@ static int bin_is_executable(RBinObject *obj){
return false;
}
//TODO PJ
static void cmd_info_bin(RCore *core, int va, int mode) {
static void cmd_info_bin(RCore *core, int va, PJ *pj, int mode) {
RBinObject *obj = r_bin_cur_object (core->bin);
int array = 0;
if (core->file) {
if ((mode & R_MODE_JSON) && !(mode & R_MODE_ARRAY)) {
if (mode & R_MODE_JSON) {
if (!(mode & R_MODE_ARRAY)) {
pj_o (pj);
} else {
array = 1;
}
mode = R_MODE_JSON;
r_cons_strcat ("{\"core\":");
pj_k (pj, "core");
}
if ((mode & R_MODE_JSON) && (mode & R_MODE_ARRAY)) {
mode = R_MODE_JSON;
array = 1;
r_cons_strcat (",\"core\":");
}
r_core_file_info (core, mode);
r_core_file_info (core, pj, mode);
if (bin_is_executable (obj)) {
if ((mode & R_MODE_JSON)) {
r_cons_strcat (",\"bin\":");
pj_k (pj, "bin");
}
r_core_bin_info (core, R_CORE_BIN_ACC_INFO, mode, va, NULL, NULL);
r_core_bin_info (core, R_CORE_BIN_ACC_INFO, pj, mode, va, NULL, NULL);
}
if ((mode & R_MODE_JSON) && array == 0) {
r_cons_print ("}");
pj_end (pj);
}
} else {
eprintf ("No file selected\n");
@ -458,6 +443,7 @@ static int cmd_info(void *data, const char *input) {
bool is_izzzj = false;
bool is_idpij = false;
Sdb *db;
PJ *pj = NULL;
for (i = 0; input[i] && input[i] != ' '; i++)
;
@ -468,7 +454,15 @@ static int cmd_info(void *data, const char *input) {
case 'q': mode = R_MODE_SIMPLE; break;
}
}
#define INIT_PJ()\
if (!pj) {\
pj = r_core_pj_new (core);\
if (!pj) {\
return 1;\
}\
}
if (mode == R_MODE_JSON) {
INIT_PJ ();
int suffix_shift = 0;
if (!strncmp (input, "SS", 2) || !strncmp (input, "ee", 2)
|| !strncmp (input, "zz", 2)) {
@ -485,10 +479,10 @@ static int cmd_info(void *data, const char *input) {
}
}
if (is_array && !is_izzzj && !is_idpij) {
r_cons_printf ("{");
pj_o (pj);
}
if (!*input) {
cmd_info_bin (core, va, mode);
cmd_info_bin (core, va, pj, mode);
}
/* i* is an alias for iI* */
if (!strcmp (input, "*")) {
@ -592,19 +586,17 @@ static int cmd_info(void *data, const char *input) {
break;
#define RBININFO(n,x,y,z)\
if (is_array) {\
if (is_array == 1) { is_array++;\
} else { r_cons_printf (",");}\
r_cons_printf ("\"%s\":",n);\
pj_k (pj, n);\
}\
if (z) { playMsg (core, n, z);}\
r_core_bin_info (core, x, mode, va, NULL, y);
r_core_bin_info (core, x, pj, mode, va, NULL, y);
case 'A': // "iA"
if (input[1] == 'j') {
r_cons_print ("{");
r_bin_list_archs (core->bin, 'j');
r_cons_print ("}");
pj_o (pj);
r_bin_list_archs (core->bin, pj, 'j');
pj_end (pj);
} else {
r_bin_list_archs (core->bin, 1);
r_bin_list_archs (core->bin, NULL, 1);
newline = false;
}
break;
@ -612,6 +604,7 @@ static int cmd_info(void *data, const char *input) {
{
if (input[1] == 'j' && input[2] == '.') {
mode = R_MODE_JSON;
INIT_PJ ();
RBININFO ("exports", R_CORE_BIN_ACC_EXPORTS, input + 2, 0);
} else {
RBININFO ("exports", R_CORE_BIN_ACC_EXPORTS, input + 1, 0);
@ -643,12 +636,6 @@ static int cmd_info(void *data, const char *input) {
RListIter *hiter_old, *hiter_new;
const bool is_json = input[1] == 'j'; // "itj"
if (is_json) { // "itj"
PJ *pj = pj_new ();
if (!pj) {
eprintf ("JSON mode failed\n");
r_list_free (old_hashes);
return 0;
}
pj_o (pj);
r_list_foreach (new_hashes, hiter_new, fh_new) {
pj_ks (pj, fh_new->type, fh_new->hex);
@ -662,8 +649,6 @@ static int cmd_info(void *data, const char *input) {
}
}
pj_end (pj);
r_cons_print (pj_string (pj));
pj_free (pj);
} else { // "it"
if (!equal) {
eprintf ("File has been modified.\n");
@ -731,6 +716,7 @@ static int cmd_info(void *data, const char *input) {
mode = R_MODE_SIMPLE;
} else if (input[1] == 'j' && input[2] == '.') {
mode = R_MODE_JSON;
INIT_PJ ();
}
RBinObject *obj = r_bin_cur_object (core->bin);
if (mode == R_MODE_RADARE || mode == R_MODE_JSON || mode == R_MODE_SIMPLE) {
@ -767,11 +753,11 @@ static int cmd_info(void *data, const char *input) {
if (ptr && ptr[1]) {
const char *plugin_name = ptr + 1;
if (is_array) {
r_cons_printf ("\"plugin\": ");
pj_k (pj, "plugin");
}
r_bin_list_plugin (core->bin, plugin_name, json);
r_bin_list_plugin (core->bin, plugin_name, pj, json);
} else {
r_bin_list (core->bin, json);
r_bin_list (core->bin, pj, json);
}
newline = false;
goto done;
@ -781,6 +767,7 @@ static int cmd_info(void *data, const char *input) {
// Case for isj.
if (input[1] == 'j' && input[2] == '.') {
mode = R_MODE_JSON;
INIT_PJ ();
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, (obj && obj->symbols)? r_list_length (obj->symbols): 0);
} else if (input[1] == 'q' && input[2] == 'q') {
mode = R_MODE_SIMPLEST;
@ -796,11 +783,6 @@ static int cmd_info(void *data, const char *input) {
break;
}
case 'R': // "iR"
if (input[1] == '*') {
mode = R_MODE_RADARE;
} else if (input[1] == 'j') {
mode = R_MODE_JSON;
}
RBININFO ("resources", R_CORE_BIN_ACC_RESOURCES, NULL, 0);
break;
case 'r': // "ir"
@ -837,7 +819,7 @@ static int cmd_info(void *data, const char *input) {
int r = 1;
r_list_foreach (server_l, it, server) {
pdbopts.symbol_server = server;
r = r_bin_pdb_download (core, input[3] == 'j', NULL, &pdbopts);
r = r_bin_pdb_download (core, pj, input[3] == 'j', &pdbopts);
if (!r) {
break;
}
@ -906,7 +888,7 @@ static int cmd_info(void *data, const char *input) {
free (filename);
break;
}
r_core_pdb_info (core, filename, mode);
r_core_pdb_info (core, filename, pj, mode);
free (filename);
break;
case '?':
@ -987,6 +969,7 @@ static int cmd_info(void *data, const char *input) {
break;
case 'j':
mode = R_MODE_JSON;
INIT_PJ ();
break;
case 'q': //izzq
if (input[3] == 'q') { //izzqq
@ -1115,24 +1098,22 @@ static int cmd_info(void *data, const char *input) {
input++;
break;
case 'j':
//TODO PJ
input++;
r_cons_printf ("\"class\":\"%s\"", cls->name);
r_cons_printf (",\"methods\":[");
pj_ks (pj, "class", cls->name);
pj_ka (pj, "methods");
r_list_foreach (cls->methods, iter2, sym) {
const char *comma = iter2->p? ",": "";
pj_o (pj);
pj_ks (pj, "name", sym->name);
if (sym->method_flags) {
char *flags = r_core_bin_method_flags_str (sym->method_flags, R_MODE_JSON);
r_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"vaddr\":%"PFMT64d "}",
comma, sym->name, flags, sym->vaddr);
R_FREE (flags);
} else {
r_cons_printf ("%s{\"name\":\"%s\",\"vaddr\":%"PFMT64d "}",
comma, sym->name, sym->vaddr);
pj_k (pj, "flags");
pj_j (pj, flags);
free (flags);
}
pj_kN (pj, "vaddr", sym->vaddr);
pj_end (pj);
}
r_cons_printf ("]");
pj_end (pj);
break;
default:
r_cons_printf ("class %s\n", cls->name);
@ -1214,20 +1195,20 @@ static int cmd_info(void *data, const char *input) {
goto done;
case 'q': // "iq"
mode = R_MODE_SIMPLE;
cmd_info_bin (core, va, mode);
cmd_info_bin (core, va, pj, mode);
goto done;
case 'j': // "ij"
mode = R_MODE_JSON;
if (is_array > 1) {
mode |= R_MODE_ARRAY;
}
cmd_info_bin (core, va, mode);
cmd_info_bin (core, va, pj, mode);
goto done;
case '.': // "i."
cmd_info_here (core, input[1]);
cmd_info_here (core, pj, input[1]);
goto done;
default:
cmd_info_bin (core, va, mode);
cmd_info_bin (core, va, pj, mode);
break;
}
// input can be overwritten like the 'input = " ";' a few lines above
@ -1241,10 +1222,13 @@ static int cmd_info(void *data, const char *input) {
}
}
done:
if (is_array && !is_izzzj && !is_idpij) {
r_cons_printf ("}");
}
if (newline || mode == R_MODE_JSON) {
if (mode & R_MODE_JSON) {
if (is_array && !is_izzzj && !is_idpij) {
pj_end (pj);
}
r_cons_println (pj_string (pj));
pj_free (pj);
} else if (newline) {
r_cons_newline ();
}
redone:

View File

@ -686,8 +686,8 @@ R_API void r_bin_bind(RBin *b, RBinBind *bnd);
R_API bool r_bin_add(RBin *bin, RBinPlugin *foo);
R_API bool r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo);
R_API bool r_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo);
R_API void r_bin_list(RBin *bin, int format);
R_API bool r_bin_list_plugin(RBin *bin, const char *name, int json);
R_API void r_bin_list(RBin *bin, PJ *pj, int format);
R_API bool r_bin_list_plugin(RBin *bin, const char *name, PJ *pj, int json);
R_API RBinPlugin *r_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64 sz);
R_API RBinPlugin *r_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf);
R_API void r_bin_force_plugin(RBin *bin, const char *pname);
@ -734,7 +734,7 @@ R_API RBinObject *r_bin_cur_object(RBin *bin);
R_API bool r_bin_select(RBin *bin, const char *arch, int bits, const char *name);
R_API bool r_bin_select_bfid(RBin *bin, ut32 bf_id);
R_API bool r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name);
R_API void r_bin_list_archs(RBin *bin, int mode);
R_API void r_bin_list_archs(RBin *bin, PJ *pj, int mode);
R_API RBuffer *r_bin_create(RBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt);
R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files);

View File

@ -744,11 +744,11 @@ typedef struct r_core_bin_filter_t {
const char *name;
} RCoreBinFilter;
R_API int r_core_bin_info (RCore *core, int action, int mode, int va, RCoreBinFilter *filter, const char *chksum);
R_API int r_core_bin_info (RCore *core, int action, PJ *pj, int mode, int va, RCoreBinFilter *filter, const char *chksum);
R_API int r_core_bin_set_arch_bits (RCore *r, const char *name, const char * arch, ut16 bits);
R_API int r_core_bin_update_arch_bits (RCore *r);
R_API char *r_core_bin_method_flags_str(ut64 flags, int mode);
R_API bool r_core_pdb_info(RCore *core, const char *file, int mode);
R_API bool r_core_pdb_info(RCore *core, const char *file, PJ *pj, int mode);
/* rtr */
R_API int r_core_rtr_cmds (RCore *core, const char *port);

View File

@ -527,13 +527,13 @@ static char *__demangleAs(RBin *bin, int type, const char *file) {
return res;
}
static void __listPlugins(RBin *bin, const char* plugin_name, int rad) {
static void __listPlugins(RBin *bin, const char* plugin_name, PJ *pj, int rad) {
int format = (rad == R_MODE_JSON) ? 'j': rad? 'q': 0;
bin->cb_printf = (PrintfCallback)printf;
if (plugin_name) {
r_bin_list_plugin (bin, plugin_name, format);
r_bin_list_plugin (bin, plugin_name, pj, format);
} else {
r_bin_list (bin, format);
r_bin_list (bin, pj, format);
}
}
@ -547,7 +547,7 @@ R_API int r_main_rabin2(int argc, const char **argv) {
ut64 baddr = UT64_MAX;
const char *do_demangle = NULL;
const char *query = NULL;
int c, bits = 0, actions_done = 0, actions = 0;
int c, bits = 0, actions = 0;
char* create = NULL;
bool va = true;
ut64 action = R_BIN_REQ_UNK;
@ -836,12 +836,25 @@ R_API int r_main_rabin2(int argc, const char **argv) {
}
}
PJ *pj = NULL;
if (rad == R_MODE_JSON) {
pj = r_core_pj_new (&core);
if (!pj) {
return 1;
}
}
if (is_active (R_BIN_REQ_LISTPLUGINS)) {
const char* plugin_name = NULL;
if (opt.ind < argc) {
plugin_name = argv[opt.ind];
}
__listPlugins (bin, plugin_name, rad);
__listPlugins (bin, plugin_name, pj, rad);
if (rad == R_MODE_JSON) {
r_cons_println (pj_string (pj));
r_cons_flush ();
pj_free (pj);
}
r_core_fini (&core);
return 0;
}
@ -1095,11 +1108,10 @@ R_API int r_main_rabin2(int argc, const char **argv) {
#define isradjson (rad==R_MODE_JSON&&actions>0)
#define run_action(n,x,y) {\
if (action&(x)) {\
if (isradjson) r_cons_printf ("%s\"%s\":",actions_done?",":"",n);\
if (!r_core_bin_info (&core, y, rad, va, &filter, chksum)) {\
if (isradjson) r_cons_print ("false");\
if (isradjson) pj_k (pj, n);\
if (!r_core_bin_info (&core, y, pj, rad, va, &filter, chksum)) {\
if (isradjson) pj_b (pj, false);\
};\
actions_done++;\
}\
}
core.bin = bin;
@ -1109,17 +1121,16 @@ R_API int r_main_rabin2(int argc, const char **argv) {
r_cons_new ()->context->is_interactive = false;
if (isradjson) {
r_cons_print ("{");
pj_o (pj);
}
// List fatmach0 sub-binaries, etc
if (action & R_BIN_REQ_LISTARCHS || ((arch || bits || arch_name) &&
!r_bin_select (bin, arch, bits, arch_name))) {
if (rad == R_MODE_SIMPLEST || rad == R_MODE_SIMPLE) {
r_bin_list_archs (bin, 'q');
r_bin_list_archs (bin, pj, 'q');
} else {
r_bin_list_archs (bin, (rad == R_MODE_JSON)? 'j': 1);
r_bin_list_archs (bin, pj, (rad == R_MODE_JSON)? 'j': 1);
}
actions_done++;
free (arch_name);
}
if (action & R_BIN_REQ_PDB_DWNLD) {
@ -1133,7 +1144,7 @@ R_API int r_main_rabin2(int argc, const char **argv) {
R_FREE (tmp);
}
pdbopts.symbol_store_path = (char *)r_config_get (core.config, "pdb.symstore");
r_bin_pdb_download (&core, isradjson, &actions_done, &pdbopts);
r_bin_pdb_download (&core, pj, isradjson, &pdbopts);
}
if ((tmp = r_sys_getenv ("RABIN2_PREFIX"))) {
@ -1181,8 +1192,10 @@ R_API int r_main_rabin2(int argc, const char **argv) {
rabin_do_operation (bin, op, rad, output, file);
}
if (isradjson) {
r_cons_print ("}\n");
pj_end (pj);
r_cons_println (pj_string (pj));
}
pj_free (pj);
r_cons_flush ();
r_core_file_free (fh);
r_core_fini (&core);