2016-02-16 02:08:09 +01:00
|
|
|
/* radare - LGPL - Copyright 2009-2016 - pancake */
|
2016-05-02 22:52:41 -04:00
|
|
|
|
2016-07-03 21:57:00 +02:00
|
|
|
#include <string.h>
|
2016-05-02 22:52:41 -04:00
|
|
|
#include "r_bin.h"
|
|
|
|
#include "r_config.h"
|
|
|
|
#include "r_cons.h"
|
|
|
|
#include "r_core.h"
|
2014-01-12 01:20:40 +01:00
|
|
|
|
2014-12-03 13:15:07 +01:00
|
|
|
#define PAIR_WIDTH 9
|
2015-09-25 23:28:29 +02:00
|
|
|
// TODO: reuse implementation in core/bin.c
|
2014-12-03 13:15:07 +01:00
|
|
|
static void pair(const char *a, const char *b) {
|
|
|
|
char ws[16];
|
|
|
|
int al = strlen (a);
|
2015-11-26 13:18:11 +01:00
|
|
|
if (!b) return;
|
2014-12-03 13:15:07 +01:00
|
|
|
memset (ws, ' ', sizeof (ws));
|
2015-01-10 01:00:01 +01:00
|
|
|
al = PAIR_WIDTH - al;
|
2014-12-03 13:15:07 +01:00
|
|
|
if (al<0) al = 0;
|
|
|
|
ws[al] = 0;
|
|
|
|
r_cons_printf ("%s%s%s\n", a, ws, b);
|
|
|
|
}
|
|
|
|
|
2015-11-26 13:18:11 +01:00
|
|
|
static bool demangle_internal(RCore *core, const char *lang, const char *s) {
|
2015-01-10 01:00:01 +01:00
|
|
|
char *res = NULL;
|
|
|
|
int type = r_bin_demangle_type (lang);
|
|
|
|
switch (type) {
|
|
|
|
case R_BIN_NM_CXX: res = r_bin_demangle_cxx (s); break;
|
|
|
|
case R_BIN_NM_JAVA: res = r_bin_demangle_java (s); break;
|
|
|
|
case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, s); break;
|
2016-05-03 04:31:36 +02:00
|
|
|
case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (s, core->bin->demanglercmd); break;
|
2015-02-11 02:05:22 +01:00
|
|
|
case R_BIN_NM_DLANG: res = r_bin_demangle_plugin (core->bin, "dlang", s); break;
|
2015-01-10 01:00:01 +01:00
|
|
|
default:
|
2015-02-11 02:05:22 +01:00
|
|
|
r_bin_demangle_list (core->bin);
|
2015-11-26 13:18:11 +01:00
|
|
|
return true;
|
2015-01-10 01:00:01 +01:00
|
|
|
}
|
2015-01-10 17:55:59 +01:00
|
|
|
if (res) {
|
2015-11-26 13:18:11 +01:00
|
|
|
if (*res) printf ("%s\n", res);
|
2015-01-10 17:55:59 +01:00
|
|
|
free (res);
|
2015-11-26 13:18:11 +01:00
|
|
|
return false;
|
2015-01-10 01:00:01 +01:00
|
|
|
}
|
2015-11-26 13:18:11 +01:00
|
|
|
return true;
|
2015-01-10 01:00:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int demangle(RCore *core, const char *s) {
|
|
|
|
char *p, *q;
|
|
|
|
const char *ss = strchr (s, ' ');
|
|
|
|
if (!*s) return 0;
|
|
|
|
if (!ss) {
|
|
|
|
const char *lang = r_config_get (core->config, "bin.lang");
|
2015-02-11 02:05:22 +01:00
|
|
|
demangle_internal (core, lang, s);
|
2015-01-10 01:00:01 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
p = strdup (s);
|
2016-05-24 14:54:34 +02:00
|
|
|
q = p + (ss - s);
|
2015-01-10 01:00:01 +01:00
|
|
|
*q = 0;
|
2016-05-24 14:54:34 +02:00
|
|
|
demangle_internal (core, p, q + 1);
|
2015-01-10 01:00:01 +01:00
|
|
|
free (p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-07-10 03:16:48 +02:00
|
|
|
#define STR(x) (x)?(x):""
|
2012-12-23 20:51:23 +01:00
|
|
|
static void r_core_file_info (RCore *core, int mode) {
|
|
|
|
const char *fn = NULL;
|
|
|
|
int dbg = r_config_get_i (core->config, "cfg.debug");
|
2016-07-03 21:04:50 +02:00
|
|
|
bool io_cache = r_config_get_i (core->config, "io.cache");
|
2012-12-23 20:51:23 +01:00
|
|
|
RBinInfo *info = r_bin_get_info (core->bin);
|
2014-04-27 02:06:50 -05:00
|
|
|
RBinFile *binfile = r_core_bin_cur (core);
|
|
|
|
RCoreFile *cf = core->file;
|
2014-05-08 18:35:04 -05:00
|
|
|
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
|
2012-12-23 20:51:23 +01:00
|
|
|
if (mode == R_CORE_BIN_JSON)
|
|
|
|
r_cons_printf ("{");
|
2013-01-22 18:08:33 +01:00
|
|
|
if (mode == R_CORE_BIN_RADARE)
|
|
|
|
return;
|
2014-12-01 11:54:58 +01:00
|
|
|
if (mode == R_CORE_BIN_SIMPLE)
|
|
|
|
return;
|
2012-12-23 20:51:23 +01:00
|
|
|
if (info) {
|
|
|
|
fn = info->file;
|
|
|
|
switch (mode) {
|
|
|
|
case R_CORE_BIN_JSON:
|
2015-04-13 23:16:42 +02:00
|
|
|
r_cons_printf ("\"type\":\"%s\"", STR(info->type));
|
2012-12-23 20:51:23 +01:00
|
|
|
break;
|
|
|
|
default:
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("type", info->type);
|
2012-12-23 20:51:23 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-11-09 15:14:41 +01:00
|
|
|
} else {
|
|
|
|
fn = (cf && cf->desc) ? cf->desc->name : NULL;
|
|
|
|
}
|
2014-04-27 02:06:50 -05:00
|
|
|
if (cf && mode == R_CORE_BIN_JSON) {
|
2015-04-15 12:13:50 +02:00
|
|
|
const char *uri = fn;
|
|
|
|
if (!uri) {
|
|
|
|
if (cf->desc && cf->desc->uri && *cf->desc->uri) {
|
|
|
|
uri = cf->desc->uri;
|
2015-11-09 15:14:41 +01:00
|
|
|
} else {
|
|
|
|
uri = "";
|
|
|
|
}
|
2015-04-15 12:13:50 +02:00
|
|
|
}
|
|
|
|
r_cons_printf (",\"file\":\"%s\"", uri);
|
2012-12-23 20:51:23 +01:00
|
|
|
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
|
2014-10-08 13:27:33 +02:00
|
|
|
if (cf->desc) {
|
2015-06-30 11:34:38 +02:00
|
|
|
ut64 fsz = r_io_desc_size (core->io, cf->desc);
|
2014-09-10 02:21:10 +02:00
|
|
|
r_cons_printf (",\"fd\":%d", cf->desc->fd);
|
2015-06-30 11:34:38 +02:00
|
|
|
if (fsz != UT64_MAX) {
|
|
|
|
r_cons_printf (",\"size\":%"PFMT64d, fsz);
|
|
|
|
}
|
2016-07-03 21:04:50 +02:00
|
|
|
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache || \
|
|
|
|
cf->desc->flags & R_IO_WRITE ));
|
2014-10-08 13:27:33 +02:00
|
|
|
r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (
|
|
|
|
cf->desc->flags & 7 ));
|
2015-06-03 10:26:11 +02:00
|
|
|
r_cons_printf (",\"obsz\":%"PFMT64d, (ut64)core->io->desc->obsz);
|
2014-11-10 05:17:25 +01:00
|
|
|
if (cf->desc->referer && *cf->desc->referer)
|
2016-07-18 00:39:03 +02:00
|
|
|
r_cons_printf (",\"referer\":\"%s\"", cf->desc->referer);
|
2014-10-08 13:27:33 +02:00
|
|
|
}
|
2012-12-23 20:51:23 +01:00
|
|
|
r_cons_printf (",\"block\":%d", core->blocksize);
|
2014-05-06 11:17:03 +02:00
|
|
|
if (binfile) {
|
|
|
|
if (binfile->curxtr)
|
|
|
|
r_cons_printf (",\"packet\":\"%s\"",
|
|
|
|
binfile->curxtr->name);
|
2014-05-08 18:35:04 -05:00
|
|
|
if (plugin)
|
2014-05-06 11:17:03 +02:00
|
|
|
r_cons_printf (",\"format\":\"%s\"",
|
2014-05-08 18:35:04 -05:00
|
|
|
plugin->name);
|
2014-05-06 11:17:03 +02:00
|
|
|
}
|
2012-12-23 20:51:23 +01:00
|
|
|
r_cons_printf ("}");
|
2014-12-01 11:54:58 +01:00
|
|
|
} else if (cf && mode != R_CORE_BIN_SIMPLE) {
|
2013-02-20 02:24:37 +01:00
|
|
|
//r_cons_printf ("# Core file info\n");
|
2015-04-14 09:53:14 +02:00
|
|
|
pair ("file", fn ? fn : cf->desc->uri);
|
2012-12-23 20:51:23 +01:00
|
|
|
if (dbg) dbg = R_IO_WRITE | R_IO_EXEC;
|
2014-10-08 13:27:33 +02:00
|
|
|
if (cf->desc) {
|
2015-06-30 11:34:38 +02:00
|
|
|
ut64 fsz = r_io_desc_size (core->io, cf->desc);
|
2014-11-10 05:17:25 +01:00
|
|
|
if (cf->desc->referer && *cf->desc->referer)
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("referer", cf->desc->referer);
|
|
|
|
pair ("fd", sdb_fmt (0, "%d", cf->desc->fd));
|
2015-06-30 11:34:38 +02:00
|
|
|
if (fsz != UT64_MAX) {
|
|
|
|
pair ("size", sdb_fmt (0,"0x%"PFMT64x, fsz));
|
|
|
|
}
|
2016-07-03 21:04:50 +02:00
|
|
|
pair ("iorw", r_str_bool ( io_cache || \
|
|
|
|
cf->desc->flags & R_IO_WRITE ));
|
2015-04-01 03:33:12 +02:00
|
|
|
pair ("blksz", sdb_fmt (0, "0x%"PFMT64x,
|
2015-02-16 22:40:05 +01:00
|
|
|
(ut64)core->io->desc->obsz));
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("mode", r_str_rwx_i (cf->desc->flags & 7));
|
2014-10-08 13:27:33 +02:00
|
|
|
}
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("block", sdb_fmt (0, "0x%x", core->blocksize));
|
2014-04-27 02:06:50 -05:00
|
|
|
if (binfile && binfile->curxtr)
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("packet", binfile->curxtr->name);
|
2014-05-08 18:35:04 -05:00
|
|
|
if (plugin)
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("format", plugin->name);
|
2012-12-23 20:51:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 15:30:36 +02:00
|
|
|
static int bin_is_executable (RBinObject *obj){
|
|
|
|
RListIter *it;
|
|
|
|
RBinSection* sec;
|
2016-02-16 02:08:09 +01:00
|
|
|
if (obj) {
|
|
|
|
if (obj->info && obj->info->arch) {
|
2015-09-14 12:35:38 +02:00
|
|
|
return true;
|
2016-02-16 02:08:09 +01:00
|
|
|
}
|
|
|
|
r_list_foreach (obj->sections, it, sec){
|
|
|
|
if (R_BIN_SCN_EXECUTABLE & sec->srwx)
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-09 15:30:36 +02:00
|
|
|
}
|
2015-09-14 12:35:38 +02:00
|
|
|
return false;
|
2015-04-09 15:30:36 +02:00
|
|
|
}
|
|
|
|
|
2015-08-28 20:14:26 +02:00
|
|
|
static void cmd_info_bin(RCore *core, int va, int mode) {
|
2015-04-13 00:43:42 -04:00
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
2015-10-14 15:53:48 +02:00
|
|
|
int array = 0;
|
2015-06-14 20:01:44 +02:00
|
|
|
if (core->file) {
|
2015-10-14 15:53:48 +02:00
|
|
|
if ((mode & R_CORE_BIN_JSON) && !(mode & R_CORE_BIN_ARRAY)) {
|
|
|
|
mode = R_CORE_BIN_JSON;
|
2015-04-07 20:03:13 +02:00
|
|
|
r_cons_printf ("{\"core\":");
|
2015-10-14 15:53:48 +02:00
|
|
|
}
|
|
|
|
if ((mode & R_CORE_BIN_JSON) && (mode & R_CORE_BIN_ARRAY)) {
|
|
|
|
mode = R_CORE_BIN_JSON;
|
|
|
|
array = 1;
|
|
|
|
r_cons_printf (",\"core\":");
|
|
|
|
}
|
2014-01-18 12:56:38 +01:00
|
|
|
r_core_file_info (core, mode);
|
2015-06-17 01:04:25 +02:00
|
|
|
if (obj && bin_is_executable (obj)) {
|
2015-10-22 02:13:26 +02:00
|
|
|
if ((mode & R_CORE_BIN_JSON)) {
|
|
|
|
r_cons_printf (",\"bin\":");
|
|
|
|
}
|
|
|
|
r_core_bin_info (core, R_CORE_BIN_ACC_INFO,
|
|
|
|
mode, va, NULL, NULL);
|
2015-04-07 20:03:13 +02:00
|
|
|
}
|
2015-10-14 15:53:48 +02:00
|
|
|
if (mode == R_CORE_BIN_JSON && array == 0)
|
2014-01-18 12:56:38 +01:00
|
|
|
r_cons_printf ("}\n");
|
2015-10-22 02:13:26 +02:00
|
|
|
} else eprintf ("No file selected\n");
|
2014-01-18 12:56:38 +01:00
|
|
|
}
|
|
|
|
|
2012-02-27 03:07:32 +01:00
|
|
|
static int cmd_info(void *data, const char *input) {
|
|
|
|
RCore *core = (RCore *)data;
|
2016-01-11 00:24:18 +01:00
|
|
|
bool newline = r_config_get_i (core->config, "scr.interactive");
|
2014-04-27 02:06:50 -05:00
|
|
|
RBinObject *o = r_bin_cur_object (core->bin);
|
|
|
|
RCoreFile *cf = core->file;
|
2015-01-10 01:00:01 +01:00
|
|
|
int i, va = core->io->va || core->io->debug;
|
2014-01-18 12:56:38 +01:00
|
|
|
int mode = 0; //R_CORE_BIN_SIMPLE;
|
2014-01-18 04:53:33 +01:00
|
|
|
int is_array = 0;
|
2013-12-20 01:20:17 +01:00
|
|
|
Sdb *db;
|
2012-12-23 20:51:23 +01:00
|
|
|
|
2015-01-24 02:11:14 +01:00
|
|
|
for (i = 0; input[i] && i<2; i++) {
|
2015-01-10 01:00:01 +01:00
|
|
|
switch (input[i]) {
|
|
|
|
case '*': mode = R_CORE_BIN_RADARE; break;
|
|
|
|
case 'j': mode = R_CORE_BIN_JSON; break;
|
|
|
|
case 'q': mode = R_CORE_BIN_SIMPLE; break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
|
|
|
|
if (mode == R_CORE_BIN_JSON) {
|
|
|
|
if (strlen (input+1)>1)
|
|
|
|
is_array = 1;
|
|
|
|
}
|
|
|
|
if (is_array)
|
|
|
|
r_cons_printf ("{");
|
2014-01-18 12:56:38 +01:00
|
|
|
if (!*input)
|
2015-08-28 20:14:26 +02:00
|
|
|
cmd_info_bin (core, va, mode);
|
2015-04-01 04:14:10 +02:00
|
|
|
/* i* is an alias for iI* */
|
|
|
|
if (!strcmp (input, "*")) {
|
|
|
|
input = "I*";
|
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
while (*input) {
|
|
|
|
switch (*input) {
|
2016-01-11 00:24:18 +01:00
|
|
|
case 'b': // "ib"
|
2014-01-18 04:53:33 +01:00
|
|
|
{
|
|
|
|
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
2014-05-26 03:06:29 +02:00
|
|
|
if (input[1]==' ')
|
|
|
|
baddr = r_num_math (core->num, input+1);
|
2014-01-18 04:53:33 +01:00
|
|
|
// XXX: this will reload the bin using the buffer.
|
|
|
|
// An assumption is made that assumes there is an underlying
|
|
|
|
// plugin that will be used to load the bin (e.g. malloc://)
|
|
|
|
// TODO: Might be nice to reload a bin at a specified offset?
|
|
|
|
r_core_bin_reload (core, NULL, baddr);
|
|
|
|
r_core_block_read (core, 0);
|
2016-01-11 00:24:18 +01:00
|
|
|
newline = false;
|
2014-01-18 04:53:33 +01:00
|
|
|
}
|
2013-12-20 01:20:17 +01:00
|
|
|
break;
|
2014-01-18 04:53:33 +01:00
|
|
|
case 'k':
|
2014-04-27 02:06:50 -05:00
|
|
|
db = o ? o->kv : NULL;
|
2014-01-18 04:53:33 +01:00
|
|
|
//:eprintf ("db = %p\n", db);
|
|
|
|
switch (input[1]) {
|
|
|
|
case 'v':
|
2014-09-17 15:23:56 +02:00
|
|
|
if (db) {
|
|
|
|
char *o = sdb_querys (db, NULL, 0, input+3);
|
2016-06-26 00:51:17 -04:00
|
|
|
if (o && *o) r_cons_print (o);
|
2014-09-17 15:23:56 +02:00
|
|
|
free (o);
|
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
case ' ':
|
2014-09-17 15:23:56 +02:00
|
|
|
if (db) {
|
|
|
|
char *o = sdb_querys (db, NULL, 0, input+2);
|
2016-06-26 00:51:17 -04:00
|
|
|
if (o && *o) r_cons_print (o);
|
2014-09-17 15:23:56 +02:00
|
|
|
free (o);
|
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
break;
|
|
|
|
case '\0':
|
2014-09-17 15:23:56 +02:00
|
|
|
if (db) {
|
|
|
|
char *o = sdb_querys (db, NULL, 0, "*");
|
2016-06-26 00:51:17 -04:00
|
|
|
if (o && *o) r_cons_print (o);
|
2014-09-17 15:23:56 +02:00
|
|
|
free (o);
|
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
eprintf ("Usage: ik [sdb-query]\n");
|
|
|
|
}
|
2015-10-22 02:13:26 +02:00
|
|
|
goto done;
|
2013-12-20 01:20:17 +01:00
|
|
|
break;
|
2014-09-24 23:01:03 +02:00
|
|
|
case 'o':
|
2014-08-28 03:11:13 +02:00
|
|
|
{
|
2014-12-22 23:26:56 -05:00
|
|
|
if (!cf) {
|
|
|
|
eprintf ("Core file not open\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-09 17:01:04 +02:00
|
|
|
const char *fn = input[1]==' '? input+2: cf->desc->name;
|
2015-08-27 23:00:38 +02:00
|
|
|
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
|
|
|
r_core_bin_load (core, fn, baddr);
|
2014-08-28 03:11:13 +02:00
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
break;
|
2015-10-15 17:17:45 +02:00
|
|
|
#define RBININFO(n,x,y) \
|
2014-01-18 04:53:33 +01:00
|
|
|
if (is_array) { \
|
|
|
|
if (is_array==1) is_array++; else r_cons_printf (","); \
|
|
|
|
r_cons_printf ("\"%s\":",n); \
|
|
|
|
}\
|
2015-10-15 17:17:45 +02:00
|
|
|
r_core_bin_info (core, x, mode, va, NULL, y);
|
2015-05-29 01:38:31 +02:00
|
|
|
case 'A':
|
2016-01-11 00:24:18 +01:00
|
|
|
newline = false;
|
2015-05-29 01:38:31 +02:00
|
|
|
if (input[1]=='j') {
|
|
|
|
r_cons_printf ("{");
|
|
|
|
r_bin_list_archs (core->bin, 'j');
|
|
|
|
r_cons_printf ("}\n");
|
|
|
|
} else {
|
|
|
|
r_bin_list_archs (core->bin, 1);
|
|
|
|
}
|
|
|
|
break;
|
2015-10-15 17:17:45 +02:00
|
|
|
case 'E': RBININFO ("exports", R_CORE_BIN_ACC_EXPORTS, NULL); break;
|
|
|
|
case 'Z': RBININFO ("size", R_CORE_BIN_ACC_SIZE, NULL); break;
|
|
|
|
case 'S':
|
|
|
|
//we comes from ia or iS
|
|
|
|
if ((input[1] == 'm' && input[2] == 'z') || !input[1]) {
|
|
|
|
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, NULL);
|
|
|
|
} else { //iS entropy,sha1
|
|
|
|
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 2);
|
|
|
|
//we move input until get '\0'
|
|
|
|
while (*(++input));
|
|
|
|
//input-- because we are inside a while that does input++
|
|
|
|
// oob read if not input--
|
|
|
|
input--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'h': RBININFO ("fields", R_CORE_BIN_ACC_FIELDS, NULL); break;
|
|
|
|
case 'l': RBININFO ("libs", R_CORE_BIN_ACC_LIBS, NULL); break;
|
2015-10-20 11:17:24 +02:00
|
|
|
case 'L': r_bin_list (core->bin, input[1]=='j'); break;
|
2015-10-15 17:17:45 +02:00
|
|
|
case 's': RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, NULL); break;
|
2014-01-18 04:53:33 +01:00
|
|
|
case 'R':
|
2015-10-15 17:17:45 +02:00
|
|
|
case 'r': RBININFO ("relocs", R_CORE_BIN_ACC_RELOCS, NULL); break;
|
|
|
|
case 'd': RBININFO ("dwarf", R_CORE_BIN_ACC_DWARF, NULL); break;
|
|
|
|
case 'i': RBININFO ("imports",R_CORE_BIN_ACC_IMPORTS, NULL); break;
|
|
|
|
case 'I': RBININFO ("info", R_CORE_BIN_ACC_INFO, NULL); break;
|
|
|
|
case 'e': RBININFO ("entries", R_CORE_BIN_ACC_ENTRIES, NULL); break;
|
|
|
|
case 'M': RBININFO ("main", R_CORE_BIN_ACC_MAIN, NULL); break;
|
|
|
|
case 'm': RBININFO ("memory", R_CORE_BIN_ACC_MEM, NULL); break;
|
2016-02-19 23:34:56 +01:00
|
|
|
case 'V': RBININFO ("versioninfo", R_CORE_BIN_ACC_VERSIONINFO, NULL); break;
|
2016-05-09 23:42:28 +02:00
|
|
|
case 'C': RBININFO ("signature", R_CORE_BIN_ACC_SIGNATURE, NULL); break;
|
2014-09-24 23:01:03 +02:00
|
|
|
case 'z':
|
2014-09-15 23:47:23 +02:00
|
|
|
if (input[1] == 'z') {
|
2016-04-24 16:31:25 -04:00
|
|
|
char *biname;
|
2016-02-22 22:51:37 +01:00
|
|
|
char *ret;
|
|
|
|
const int min = core->bin->minstrlen;
|
|
|
|
const int max = core->bin->maxstrlen;
|
2014-09-15 23:47:23 +02:00
|
|
|
/* TODO: reimplement in C to avoid forks */
|
2014-12-22 23:26:56 -05:00
|
|
|
if (!core->file) {
|
|
|
|
eprintf ("Core file not open\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-24 16:31:25 -04:00
|
|
|
biname = r_str_escape (core->file->desc->name);
|
2014-09-15 23:49:51 +02:00
|
|
|
switch (input[2]) {
|
|
|
|
case '*':
|
2016-04-24 16:31:25 -04:00
|
|
|
ret = r_sys_cmd_strf ("rabin2 -N %d:%d -rzz %s", min, max, biname);
|
2014-09-15 23:49:51 +02:00
|
|
|
break;
|
2014-12-01 11:54:58 +01:00
|
|
|
case 'q':
|
2016-05-23 22:49:32 +02:00
|
|
|
if (input[3] == 'q') {
|
|
|
|
ret = r_sys_cmd_strf ("rabin2 -N %d:%d -qqzz %s", min, max, biname);
|
|
|
|
input++;
|
|
|
|
} else {
|
|
|
|
ret = r_sys_cmd_strf ("rabin2 -N %d:%d -qzz %s", min, max, biname);
|
|
|
|
}
|
2014-12-01 11:54:58 +01:00
|
|
|
break;
|
2014-09-15 23:49:51 +02:00
|
|
|
case 'j':
|
2016-04-24 16:31:25 -04:00
|
|
|
ret = r_sys_cmd_strf ("rabin2 -N %d:%d -jzz %s", min, max, biname);
|
2014-09-15 23:49:51 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-04-24 16:31:25 -04:00
|
|
|
ret = r_sys_cmd_strf ("rabin2 -N %d:%d -zz %s", min, max, biname);
|
2014-09-15 23:49:51 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-09-15 23:47:23 +02:00
|
|
|
if (ret && *ret) {
|
|
|
|
r_cons_strcat (ret);
|
|
|
|
}
|
|
|
|
free (ret);
|
2016-04-24 16:31:25 -04:00
|
|
|
free (biname);
|
2014-09-15 23:47:23 +02:00
|
|
|
input++;
|
|
|
|
} else {
|
2016-05-23 22:49:32 +02:00
|
|
|
if (input[1] == 'q') {
|
|
|
|
mode = (input[2] == 'q') ? R_CORE_BIN_SIMPLEST : R_CORE_BIN_SIMPLE;
|
|
|
|
input++;
|
|
|
|
}
|
2015-10-15 17:17:45 +02:00
|
|
|
RBININFO ("strings", R_CORE_BIN_ACC_STRINGS, NULL);
|
2014-09-15 23:47:23 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-07-06 01:08:14 +02:00
|
|
|
case 'c': // for r2 `ic`
|
2015-07-06 02:38:54 +02:00
|
|
|
if (input[1]== '?') {
|
2015-08-19 02:23:42 +02:00
|
|
|
eprintf ("Usage: ic[ljq*] [class-index]\n");
|
2015-07-06 11:46:21 +02:00
|
|
|
} else if (input[1]== ' ' || input[1] == 'q' || input[1] == 'j' || input[1] == 'l') {
|
2015-07-06 02:38:54 +02:00
|
|
|
RBinClass *cls;
|
|
|
|
RBinSymbol *sym;
|
2015-07-06 11:46:21 +02:00
|
|
|
RListIter *iter, *iter2;
|
2015-07-06 02:38:54 +02:00
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
|
|
|
int idx = r_num_math (core->num, input +2);
|
|
|
|
int count = 0;
|
2015-07-07 13:10:53 -04:00
|
|
|
if (input[2] && obj) {
|
2015-07-06 02:38:54 +02:00
|
|
|
r_list_foreach (obj->classes, iter, cls) {
|
|
|
|
if (idx != count++)
|
|
|
|
continue;
|
|
|
|
switch (input[1]) {
|
|
|
|
case '*':
|
2015-07-06 11:46:21 +02:00
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
2015-08-19 02:23:42 +02:00
|
|
|
r_cons_printf ("f sym.%s @ 0x%"PFMT64x"\n",
|
|
|
|
sym->name, sym->vaddr);
|
2015-07-06 02:38:54 +02:00
|
|
|
}
|
2015-08-19 02:23:42 +02:00
|
|
|
input++;
|
2015-07-06 02:38:54 +02:00
|
|
|
break;
|
2015-07-06 11:46:21 +02:00
|
|
|
case 'l':
|
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
|
|
|
const char *comma = iter2->p? " ": "";
|
|
|
|
r_cons_printf ("%s0x%"PFMT64d, comma, sym->vaddr);
|
|
|
|
}
|
2015-08-19 02:23:42 +02:00
|
|
|
r_cons_newline ();
|
|
|
|
input++;
|
2015-07-06 11:46:21 +02:00
|
|
|
break;
|
2015-07-06 02:38:54 +02:00
|
|
|
case 'j':
|
2015-08-19 02:23:42 +02:00
|
|
|
input++;
|
2015-07-06 02:38:54 +02:00
|
|
|
r_cons_printf ("\"class\":\"%s\"", cls->name);
|
|
|
|
r_cons_printf (",\"methods\":[");
|
2015-07-06 11:46:21 +02:00
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
|
|
|
const char *comma = iter2->p? ",": "";
|
2015-07-06 02:38:54 +02:00
|
|
|
r_cons_printf ("%s{\"name\":\"%s\",\"vaddr\":%"PFMT64d"}",
|
|
|
|
comma, sym->name, sym->vaddr);
|
|
|
|
}
|
|
|
|
r_cons_printf ("]");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r_cons_printf ("class %s\n", cls->name);
|
2015-07-06 11:46:21 +02:00
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
2015-08-19 02:23:42 +02:00
|
|
|
r_cons_printf ("0x%08"PFMT64x" method %s %s\n",
|
|
|
|
sym->vaddr, cls->name, sym->name);
|
2015-07-06 02:38:54 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-07 13:10:53 -04:00
|
|
|
if (input[1] == 'l' && obj) { // "icl"
|
2015-07-06 11:46:21 +02:00
|
|
|
r_list_foreach (obj->classes, iter, cls) {
|
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
|
|
|
const char *comma = iter2->p? " ": "";
|
|
|
|
r_cons_printf ("%s0x%"PFMT64d, comma, sym->vaddr);
|
|
|
|
}
|
|
|
|
if (!r_list_empty (cls->methods))
|
2015-08-19 02:23:42 +02:00
|
|
|
r_cons_newline ();
|
2015-07-06 11:46:21 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-15 17:17:45 +02:00
|
|
|
RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL);
|
2015-07-06 11:46:21 +02:00
|
|
|
}
|
2015-07-06 02:38:54 +02:00
|
|
|
}
|
2015-07-06 01:08:14 +02:00
|
|
|
} else {
|
2015-10-15 17:17:45 +02:00
|
|
|
RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL);
|
2015-07-06 01:08:14 +02:00
|
|
|
}
|
2015-07-06 02:38:54 +02:00
|
|
|
break;
|
2015-01-10 01:00:01 +01:00
|
|
|
case 'D':
|
|
|
|
if (input[1]!=' ' || !demangle (core, input+2)) {
|
|
|
|
eprintf ("|Usage: iD lang symbolname\n");
|
|
|
|
}
|
|
|
|
return 0;
|
2014-01-18 04:53:33 +01:00
|
|
|
case 'a':
|
2015-08-19 02:23:42 +02:00
|
|
|
switch (mode) {
|
|
|
|
case R_CORE_BIN_RADARE: cmd_info (core, "i*IiecsSmz"); break;
|
|
|
|
case R_CORE_BIN_JSON: cmd_info (core, "ijIiecsSmz"); break;
|
|
|
|
case R_CORE_BIN_SIMPLE: cmd_info (core, "iqIiecsSmz"); break;
|
|
|
|
default: cmd_info (core, "iIiecsSmz"); break;
|
2014-01-18 04:53:33 +01:00
|
|
|
}
|
2013-12-20 01:20:17 +01:00
|
|
|
break;
|
2014-06-30 12:25:46 -04:00
|
|
|
case '?': {
|
2015-08-19 02:23:42 +02:00
|
|
|
const char * help_message[] = {
|
2014-06-30 12:25:46 -04:00
|
|
|
"Usage: i", "", "Get info from opened file",
|
|
|
|
"Output mode:", "", "",
|
|
|
|
"'*'", "", "Output in radare commands",
|
|
|
|
"'j'", "", "Output in json",
|
|
|
|
"'q'", "", "Simple quiet output",
|
|
|
|
"Actions:", "", "",
|
|
|
|
"i|ij", "", "Show info of current file (in JSON)",
|
|
|
|
"iA", "", "List archs",
|
|
|
|
"ia", "", "Show all info (imports, exports, sections..)",
|
|
|
|
"ib", "", "Reload the current buffer for setting of the bin (use once only)",
|
2015-08-19 02:23:42 +02:00
|
|
|
"ic", "", "List classes, methods and fields",
|
2016-05-09 23:42:28 +02:00
|
|
|
"iC", "", "Show signature info (entitlements, ...)",
|
2014-06-30 12:25:46 -04:00
|
|
|
"id", "", "Debug information (source lines)",
|
2015-01-29 03:19:32 +01:00
|
|
|
"iD", " lang sym", "demangle symbolname for given language",
|
2014-06-30 12:25:46 -04:00
|
|
|
"ie", "", "Entrypoint",
|
2015-09-23 12:23:03 +02:00
|
|
|
"iE", "", "Exports (global symbols)",
|
2014-06-30 12:25:46 -04:00
|
|
|
"ih", "", "Headers",
|
|
|
|
"ii", "", "Imports",
|
|
|
|
"iI", "", "Binary info",
|
|
|
|
"ik", " [query]", "Key-value database from RBinObject",
|
|
|
|
"il", "", "Libraries",
|
2015-09-16 16:32:33 +02:00
|
|
|
"iL", "", "List all RBin plugins loaded",
|
2015-03-18 22:03:59 +01:00
|
|
|
"im", "", "Show info about predefined memory allocation",
|
2015-05-06 02:38:59 +02:00
|
|
|
"iM", "", "Show main address",
|
2014-06-30 12:25:46 -04:00
|
|
|
"io", " [file]", "Load info from file (or last opened) use bin.baddr",
|
|
|
|
"ir|iR", "", "Relocs",
|
|
|
|
"is", "", "Symbols",
|
2015-10-15 17:17:45 +02:00
|
|
|
"iS ", "[entropy,sha1]", "Sections (choose which hash algorithm to use)",
|
2016-03-10 16:21:57 +01:00
|
|
|
"iV", "", "Display file version info",
|
2014-09-24 23:01:03 +02:00
|
|
|
"iz", "", "Strings in data sections",
|
|
|
|
"izz", "", "Search for Strings in the whole binary",
|
2016-07-05 16:16:28 +05:30
|
|
|
"iZ", "", "Guess size of binary program",
|
2014-06-30 12:25:46 -04:00
|
|
|
NULL
|
|
|
|
};
|
2015-08-19 02:23:42 +02:00
|
|
|
r_core_cmd_help (core, help_message);
|
|
|
|
}
|
2014-06-19 01:43:59 +02:00
|
|
|
goto done;
|
2014-01-18 04:53:33 +01:00
|
|
|
case '*':
|
|
|
|
mode = R_CORE_BIN_RADARE;
|
2014-06-19 01:43:59 +02:00
|
|
|
goto done;
|
2014-12-01 11:54:58 +01:00
|
|
|
case 'q':
|
|
|
|
mode = R_CORE_BIN_SIMPLE;
|
2015-08-28 20:14:26 +02:00
|
|
|
cmd_info_bin (core, va, mode);
|
2014-12-01 11:54:58 +01:00
|
|
|
goto done;
|
2014-01-18 04:53:33 +01:00
|
|
|
case 'j':
|
|
|
|
mode = R_CORE_BIN_JSON;
|
2015-10-14 15:53:48 +02:00
|
|
|
if (is_array > 1) {
|
|
|
|
mode |= R_CORE_BIN_ARRAY;
|
|
|
|
}
|
2015-08-28 20:14:26 +02:00
|
|
|
cmd_info_bin (core, va, mode);
|
2014-06-19 01:43:59 +02:00
|
|
|
goto done;
|
2013-12-20 01:20:17 +01:00
|
|
|
default:
|
2015-08-28 20:14:26 +02:00
|
|
|
cmd_info_bin (core, va, mode);
|
2014-05-13 00:38:06 +02:00
|
|
|
break;
|
2012-02-27 03:07:32 +01:00
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
input++;
|
2015-08-19 02:23:42 +02:00
|
|
|
if ((*input == 'j' || *input == 'q') && !input[1]) {
|
2014-12-01 11:54:58 +01:00
|
|
|
break;
|
2015-08-19 02:23:42 +02:00
|
|
|
}
|
2012-02-27 03:07:32 +01:00
|
|
|
}
|
2014-06-19 01:43:59 +02:00
|
|
|
done:
|
2014-01-18 04:53:33 +01:00
|
|
|
if (is_array)
|
|
|
|
r_cons_printf ("}\n");
|
|
|
|
if (newline) r_cons_newline();
|
2012-02-27 03:07:32 +01:00
|
|
|
return 0;
|
|
|
|
}
|