2018-01-10 13:45:37 +01:00
|
|
|
/* radare - LGPL - Copyright 2009-2018 - 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"
|
2017-07-11 15:39:25 +02:00
|
|
|
#include "../bin/pdb/pdb_downloader.h"
|
2014-01-12 01:20:40 +01:00
|
|
|
|
2017-07-26 06:45:42 -07:00
|
|
|
static const char *help_msg_i[] = {
|
|
|
|
"Usage: i", "", "Get info from opened file (see rabin2's manpage)",
|
|
|
|
"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)",
|
|
|
|
"ic", "", "List classes, methods and fields",
|
2017-08-10 16:41:46 +02:00
|
|
|
"icc", "", "List classes, methods and fields in Header Format",
|
2017-07-26 06:45:42 -07:00
|
|
|
"iC", "", "Show signature info (entitlements, ...)",
|
|
|
|
"id", "[?]", "Debug information (source lines)",
|
2017-09-20 13:34:44 +02:00
|
|
|
"idp", "", "Load pdb file information",
|
2017-07-26 06:45:42 -07:00
|
|
|
"iD", " lang sym", "demangle symbolname for given language",
|
|
|
|
"ie", "", "Entrypoint",
|
2018-01-02 20:16:30 -05:00
|
|
|
"iee", "", "Show Entry and Exit (init and fini)",
|
2017-07-26 06:45:42 -07:00
|
|
|
"iE", "", "Exports (global symbols)",
|
2018-01-05 10:13:24 +01:00
|
|
|
"iE.", "", "Current export",
|
2017-07-26 06:45:42 -07:00
|
|
|
"ih", "", "Headers (alias for iH)",
|
|
|
|
"iHH", "", "Verbose Headers in raw text",
|
|
|
|
"ii", "", "Imports",
|
|
|
|
"iI", "", "Binary info",
|
|
|
|
"ik", " [query]", "Key-value database from RBinObject",
|
|
|
|
"il", "", "Libraries",
|
|
|
|
"iL ", "[plugin]", "List all RBin plugins loaded or plugin details",
|
|
|
|
"im", "", "Show info about predefined memory allocation",
|
|
|
|
"iM", "", "Show main address",
|
|
|
|
"io", " [file]", "Load info from file (or last opened) use bin.baddr",
|
|
|
|
"ir", "", "Relocs",
|
|
|
|
"iR", "", "Resources",
|
|
|
|
"is", "", "Symbols",
|
2018-01-05 10:13:24 +01:00
|
|
|
"is.", "", "Current symbol",
|
2017-07-26 06:45:42 -07:00
|
|
|
"iS ", "[entropy,sha1]", "Sections (choose which hash algorithm to use)",
|
2018-01-02 10:56:49 +01:00
|
|
|
"iS.", "", "Current section",
|
2017-07-26 06:45:42 -07:00
|
|
|
"iV", "", "Display file version info",
|
|
|
|
"iz|izj", "", "Strings in data sections (in JSON/Base64)",
|
|
|
|
"izz", "", "Search for Strings in the whole binary",
|
2018-01-12 02:29:05 +05:30
|
|
|
"izzz", "", "Dump Strings from whole binary to r2 shell (for huge files)",
|
2017-07-26 06:45:42 -07:00
|
|
|
"iZ", "", "Guess size of binary program",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *help_msg_id[] = {
|
|
|
|
"Usage: id", "", "Debug information",
|
|
|
|
"Output mode:", "", "",
|
|
|
|
"'*'", "", "Output in radare commands",
|
|
|
|
"id", "", "Source lines",
|
2017-09-20 13:34:44 +02:00
|
|
|
"idp", " [file.pdb]", "Load pdb file information",
|
|
|
|
"idpi", " [file.pdb]", "Show pdb file information",
|
2017-07-26 06:45:42 -07:00
|
|
|
"idpd", "", "Download pdb file on remote server",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-07-27 05:52:17 -07:00
|
|
|
static void cmd_info_init(RCore *core) {
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, i);
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, id);
|
2017-07-26 06:45:42 -07: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);
|
2016-10-18 01:02:35 +02: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;
|
2016-10-18 01:02:35 +02:00
|
|
|
if (al < 0) {
|
|
|
|
al = 0;
|
|
|
|
}
|
2014-12-03 13:15:07 +01:00
|
|
|
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) {
|
2016-11-22 14:58:42 +01:00
|
|
|
case R_BIN_NM_CXX: res = r_bin_demangle_cxx (core->bin->cur, s, 0); break;
|
2015-01-10 01:00:01 +01:00
|
|
|
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) {
|
2017-02-20 02:54:16 +01:00
|
|
|
if (*res) {
|
2017-08-14 01:24:55 +02:00
|
|
|
r_cons_printf ("%s\n", res);
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
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, ' ');
|
2017-02-20 02:54:16 +01:00
|
|
|
if (!*s) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-10 01:00:01 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-20 02:54:16 +01:00
|
|
|
#define STR(x) (x)? (x): ""
|
|
|
|
static void r_core_file_info(RCore *core, int mode) {
|
2012-12-23 20:51:23 +01:00
|
|
|
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);
|
2018-01-10 13:45:37 +01:00
|
|
|
int fd = r_io_fd_get_current (core->io);
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
2014-05-08 18:35:04 -05:00
|
|
|
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
|
2017-02-20 02:54:16 +01:00
|
|
|
if (mode == R_CORE_BIN_JSON) {
|
2012-12-23 20:51:23 +01:00
|
|
|
r_cons_printf ("{");
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
|
|
|
if (mode == R_CORE_BIN_RADARE) {
|
2013-01-22 18:08:33 +01:00
|
|
|
return;
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
|
|
|
if (mode == R_CORE_BIN_SIMPLE) {
|
2014-12-01 11:54:58 +01:00
|
|
|
return;
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
2012-12-23 20:51:23 +01:00
|
|
|
if (info) {
|
|
|
|
fn = info->file;
|
2017-04-04 11:37:28 +03:00
|
|
|
if (mode == R_CORE_BIN_JSON) {
|
2017-02-20 02:54:16 +01:00
|
|
|
r_cons_printf ("\"type\":\"%s\"", STR (info->type));
|
2012-12-23 20:51:23 +01:00
|
|
|
}
|
2015-11-09 15:14:41 +01:00
|
|
|
} else {
|
2017-08-22 07:42:16 +00:00
|
|
|
fn = desc ? desc->name: NULL;
|
2015-11-09 15:14:41 +01:00
|
|
|
}
|
2018-01-10 13:45:37 +01:00
|
|
|
if (desc && mode == R_CORE_BIN_JSON) {
|
2015-04-15 12:13:50 +02:00
|
|
|
const char *uri = fn;
|
|
|
|
if (!uri) {
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc && desc->uri && *desc->uri) {
|
|
|
|
uri = desc->uri;
|
2015-11-09 15:14:41 +01:00
|
|
|
} else {
|
|
|
|
uri = "";
|
|
|
|
}
|
2015-04-15 12:13:50 +02:00
|
|
|
}
|
2017-04-06 15:58:16 +02:00
|
|
|
{
|
2017-04-17 11:54:37 -03:00
|
|
|
char *escapedFile = r_str_utf16_encode (uri, -1);
|
2017-04-06 15:58:16 +02:00
|
|
|
r_cons_printf (",\"file\":\"%s\"", escapedFile);
|
|
|
|
free (escapedFile);
|
|
|
|
}
|
2017-02-20 02:54:16 +01:00
|
|
|
if (dbg) {
|
|
|
|
dbg = R_IO_WRITE | R_IO_EXEC;
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc) {
|
|
|
|
ut64 fsz = r_io_desc_size (desc);
|
|
|
|
r_cons_printf (",\"fd\":%d", desc->fd);
|
2015-06-30 11:34:38 +02:00
|
|
|
if (fsz != UT64_MAX) {
|
|
|
|
r_cons_printf (",\"size\":%"PFMT64d, fsz);
|
2017-04-05 10:38:52 +02:00
|
|
|
char *humansz = r_num_units (NULL, fsz);
|
|
|
|
if (humansz) {
|
|
|
|
r_cons_printf (",\"humansz\":\"%s\"", humansz);
|
|
|
|
free (humansz);
|
|
|
|
}
|
2015-06-30 11:34:38 +02:00
|
|
|
}
|
2017-02-20 02:54:16 +01:00
|
|
|
r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache ||\
|
2017-08-22 07:42:16 +00:00
|
|
|
desc->flags & R_IO_WRITE ));
|
2014-10-08 13:27:33 +02:00
|
|
|
r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (
|
2017-08-22 07:42:16 +00:00
|
|
|
desc->flags & 7 ));
|
2017-02-20 02:54:16 +01:00
|
|
|
r_cons_printf (",\"obsz\":%"PFMT64d, (ut64) core->io->desc->obsz);
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc->referer && *desc->referer) {
|
|
|
|
r_cons_printf (",\"referer\":\"%s\"", desc->referer);
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
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) {
|
2017-02-20 02:54:16 +01:00
|
|
|
if (binfile->curxtr) {
|
2014-05-06 11:17:03 +02:00
|
|
|
r_cons_printf (",\"packet\":\"%s\"",
|
|
|
|
binfile->curxtr->name);
|
2017-02-20 02:54:16 +01: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);
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
2014-05-06 11:17:03 +02:00
|
|
|
}
|
2012-12-23 20:51:23 +01:00
|
|
|
r_cons_printf ("}");
|
2018-01-10 13:45:37 +01:00
|
|
|
} else if (desc && mode != R_CORE_BIN_SIMPLE) {
|
2013-02-20 02:24:37 +01:00
|
|
|
//r_cons_printf ("# Core file info\n");
|
2017-02-20 02:54:16 +01:00
|
|
|
if (dbg) {
|
|
|
|
dbg = R_IO_WRITE | R_IO_EXEC;
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc) {
|
2017-04-04 11:37:28 +03:00
|
|
|
pair ("blksz", sdb_fmt (0, "0x%"PFMT64x, (ut64) core->io->desc->obsz));
|
|
|
|
}
|
|
|
|
pair ("block", sdb_fmt (0, "0x%x", core->blocksize));
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc) {
|
|
|
|
pair ("fd", sdb_fmt (0, "%d", desc->fd));
|
2017-04-04 11:37:28 +03:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
if (fn || (desc && desc->uri)) {
|
|
|
|
pair ("file", fn? fn: desc->uri);
|
2017-04-05 10:38:52 +02:00
|
|
|
}
|
2017-04-04 11:37:28 +03:00
|
|
|
if (plugin) {
|
|
|
|
pair ("format", plugin->name);
|
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc) {
|
|
|
|
pair ("iorw", r_str_bool (io_cache || desc->flags & R_IO_WRITE ));
|
|
|
|
pair ("mode", r_str_rwx_i (desc->flags & 7));
|
2014-10-08 13:27:33 +02:00
|
|
|
}
|
2017-02-20 02:54:16 +01:00
|
|
|
if (binfile && binfile->curxtr) {
|
2014-12-03 13:15:07 +01:00
|
|
|
pair ("packet", binfile->curxtr->name);
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc && desc->referer && *desc->referer) {
|
|
|
|
pair ("referer", desc->referer);
|
2017-04-04 11:37:28 +03:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
if (desc) {
|
|
|
|
ut64 fsz = r_io_desc_size (desc);
|
2017-04-04 11:37:28 +03:00
|
|
|
if (fsz != UT64_MAX) {
|
|
|
|
pair ("size", sdb_fmt (0,"0x%"PFMT64x, fsz));
|
2017-04-05 10:38:52 +02:00
|
|
|
char *humansz = r_num_units (NULL, fsz);
|
|
|
|
if (humansz) {
|
|
|
|
pair ("humansz", humansz);
|
|
|
|
free (humansz);
|
|
|
|
}
|
2017-04-04 11:37:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info) {
|
|
|
|
pair ("type", info->type);
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
2012-12-23 20:51:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 02:54:16 +01:00
|
|
|
static int bin_is_executable(RBinObject *obj){
|
2015-04-09 15:30:36 +02:00
|
|
|
RListIter *it;
|
2017-02-20 02:54:16 +01:00
|
|
|
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){
|
2017-02-20 02:54:16 +01:00
|
|
|
if (R_BIN_SCN_EXECUTABLE & sec->srwx) {
|
2016-02-16 02:08:09 +01:00
|
|
|
return true;
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
2016-02-16 02:08:09 +01:00
|
|
|
}
|
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);
|
2017-04-09 00:29:44 +02:00
|
|
|
if (bin_is_executable (obj)) {
|
2015-10-22 02:13:26 +02:00
|
|
|
if ((mode & R_CORE_BIN_JSON)) {
|
|
|
|
r_cons_printf (",\"bin\":");
|
|
|
|
}
|
2017-04-04 14:47:53 +02:00
|
|
|
r_core_bin_info (core, R_CORE_BIN_ACC_INFO, mode, va, NULL, NULL);
|
2015-04-07 20:03:13 +02:00
|
|
|
}
|
2017-01-04 03:00:06 +01:00
|
|
|
if (mode == R_CORE_BIN_JSON && array == 0) {
|
2014-01-18 12:56:38 +01:00
|
|
|
r_cons_printf ("}\n");
|
2017-01-04 03:00:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintf ("No file selected\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void playMsg(RCore *core, const char *n, int len) {
|
|
|
|
if (r_config_get_i (core->config, "scr.tts")) {
|
|
|
|
if (len > 0) {
|
|
|
|
char *s = r_str_newf ("%d %s", len, n);
|
|
|
|
r_sys_tts (s, true);
|
|
|
|
free (s);
|
|
|
|
} else if (len == 0) {
|
|
|
|
char *s = r_str_newf ("there are no %s", n);
|
|
|
|
r_sys_tts (s, true);
|
|
|
|
free (s);
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2017-02-20 02:54:16 +01:00
|
|
|
RCore *core = (RCore *) data;
|
2016-01-11 00:24:18 +01:00
|
|
|
bool newline = r_config_get_i (core->config, "scr.interactive");
|
2018-01-10 13:45:37 +01:00
|
|
|
int fd = r_io_fd_get_current (core->io);
|
|
|
|
RIODesc *desc = r_io_desc_get (core->io, fd);
|
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;
|
2018-01-12 14:02:33 +05:30
|
|
|
bool rdump = false;
|
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
|
|
|
|
2017-05-30 04:35:17 +08:00
|
|
|
for (i = 0; input[i] && input[i] != ' '; i++)
|
|
|
|
;
|
|
|
|
if (i > 0) {
|
|
|
|
switch (input[i - 1]) {
|
2015-01-10 01:00:01 +01:00
|
|
|
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) {
|
2017-02-20 02:54:16 +01:00
|
|
|
if (strlen (input + 1) > 1) {
|
2014-01-18 04:53:33 +01:00
|
|
|
is_array = 1;
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
2014-01-18 04:53:33 +01:00
|
|
|
}
|
2017-01-04 03:00:06 +01:00
|
|
|
if (is_array) {
|
2014-01-18 04:53:33 +01:00
|
|
|
r_cons_printf ("{");
|
2017-01-04 03:00:06 +01:00
|
|
|
}
|
|
|
|
if (!*input) {
|
2015-08-28 20:14:26 +02:00
|
|
|
cmd_info_bin (core, va, mode);
|
2017-01-04 03:00:06 +01:00
|
|
|
}
|
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"
|
2017-02-20 02:54:16 +01:00
|
|
|
{
|
2014-01-18 04:53:33 +01:00
|
|
|
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
2017-01-04 03:00:06 +01:00
|
|
|
if (input[1] == ' ') {
|
2017-02-20 02:54:16 +01:00
|
|
|
baddr = r_num_math (core->num, input + 1);
|
2017-01-04 03:00:06 +01:00
|
|
|
}
|
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);
|
2016-08-15 13:56:23 -05:00
|
|
|
r_core_block_read (core);
|
2016-01-11 00:24:18 +01:00
|
|
|
newline = false;
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-01-18 04:53:33 +01:00
|
|
|
case 'k':
|
2017-10-03 15:37:18 +02:00
|
|
|
{
|
|
|
|
RBinObject *o = r_bin_cur_object (core->bin);
|
2017-02-20 02:54:16 +01: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) {
|
2017-02-20 02:54:16 +01:00
|
|
|
char *o = sdb_querys (db, NULL, 0, input + 3);
|
|
|
|
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;
|
2016-10-27 23:51:22 +02:00
|
|
|
case '*':
|
2016-11-03 11:51:10 +01:00
|
|
|
r_core_bin_export_info_rad (core);
|
2016-10-27 23:51:22 +02:00
|
|
|
break;
|
2014-01-18 04:53:33 +01:00
|
|
|
case '.':
|
|
|
|
case ' ':
|
2014-09-17 15:23:56 +02:00
|
|
|
if (db) {
|
2017-01-04 22:01:53 +01:00
|
|
|
char *o = sdb_querys (db, NULL, 0, input + 2);
|
|
|
|
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, "*");
|
2017-02-20 02:54:16 +01: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");
|
2016-10-27 23:51:22 +02:00
|
|
|
eprintf ("Usage: ik* # load all header information\n");
|
2014-01-18 04:53:33 +01:00
|
|
|
}
|
2015-10-22 02:13:26 +02:00
|
|
|
goto done;
|
2017-10-03 15:37:18 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-09-24 23:01:03 +02:00
|
|
|
case 'o':
|
2017-02-20 02:54:16 +01:00
|
|
|
{
|
2018-01-10 13:45:37 +01:00
|
|
|
if (!desc) {
|
2017-02-20 02:54:16 +01:00
|
|
|
eprintf ("Core file not open\n");
|
|
|
|
return 0;
|
2016-10-27 00:54:48 +02:00
|
|
|
}
|
2017-08-22 07:42:16 +00:00
|
|
|
const char *fn = input[1] == ' '? input + 2: desc->name;
|
2017-02-20 02:54:16 +01:00
|
|
|
ut64 baddr = r_config_get_i (core->config, "bin.baddr");
|
|
|
|
r_core_bin_load (core, fn, baddr);
|
|
|
|
}
|
|
|
|
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);\
|
|
|
|
}\
|
|
|
|
if (z) { playMsg (core, n, z);}\
|
|
|
|
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;
|
2017-02-20 02:54:16 +01:00
|
|
|
if (input[1] == 'j') {
|
2015-05-29 01:38:31 +02:00
|
|
|
r_cons_printf ("{");
|
|
|
|
r_bin_list_archs (core->bin, 'j');
|
|
|
|
r_cons_printf ("}\n");
|
|
|
|
} else {
|
|
|
|
r_bin_list_archs (core->bin, 1);
|
|
|
|
}
|
|
|
|
break;
|
2018-01-05 10:13:24 +01:00
|
|
|
case 'E':
|
|
|
|
{
|
|
|
|
// case for iEj.
|
|
|
|
if (input[1] == 'j' && input[2] == '.') {
|
|
|
|
mode = R_CORE_BIN_JSON;
|
|
|
|
RBININFO ("exports", R_CORE_BIN_ACC_EXPORTS, input + 2, 0);
|
|
|
|
} else {
|
|
|
|
RBININFO ("exports", R_CORE_BIN_ACC_EXPORTS, input + 1, 0);
|
|
|
|
}
|
|
|
|
while (*(++input)) ;
|
|
|
|
input--;
|
|
|
|
break;
|
|
|
|
}
|
2017-01-04 03:00:06 +01:00
|
|
|
case 'Z': RBININFO ("size", R_CORE_BIN_ACC_SIZE, NULL, 0); break;
|
2015-10-15 17:17:45 +02:00
|
|
|
case 'S':
|
|
|
|
//we comes from ia or iS
|
|
|
|
if ((input[1] == 'm' && input[2] == 'z') || !input[1]) {
|
2017-01-04 03:00:06 +01:00
|
|
|
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, NULL, 0);
|
2017-02-20 02:54:16 +01:00
|
|
|
} else { //iS entropy,sha1
|
2018-01-02 10:56:49 +01:00
|
|
|
// case for iSj.
|
|
|
|
if (input[1] == 'j' && input[2] == '.') {
|
|
|
|
mode = R_CORE_BIN_JSON;
|
|
|
|
}
|
2017-01-04 03:00:06 +01:00
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
|
|
|
if (mode == R_CORE_BIN_RADARE || mode == R_CORE_BIN_JSON || mode == R_CORE_BIN_SIMPLE) {
|
2017-02-20 02:54:16 +01:00
|
|
|
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 2,
|
|
|
|
obj? r_list_length (obj->sections): 0);
|
2017-01-04 03:00:06 +01:00
|
|
|
} else {
|
2017-02-20 02:54:16 +01:00
|
|
|
RBININFO ("sections", R_CORE_BIN_ACC_SECTIONS, input + 1,
|
|
|
|
obj? r_list_length (obj->sections): 0);
|
2017-01-04 03:00:06 +01:00
|
|
|
}
|
2015-10-15 17:17:45 +02:00
|
|
|
//we move input until get '\0'
|
2017-02-20 02:54:16 +01:00
|
|
|
while (*(++input)) ;
|
2015-10-15 17:17:45 +02:00
|
|
|
//input-- because we are inside a while that does input++
|
|
|
|
// oob read if not input--
|
|
|
|
input--;
|
|
|
|
}
|
|
|
|
break;
|
2016-09-29 11:33:44 +02:00
|
|
|
case 'H':
|
2017-02-24 02:33:11 +01:00
|
|
|
if (input[1] == 'H') { // "iHH"
|
2017-01-04 03:00:06 +01:00
|
|
|
RBININFO ("header", R_CORE_BIN_ACC_HEADER, NULL, -1);
|
2016-12-15 00:14:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-01-04 03:00:06 +01:00
|
|
|
case 'h': RBININFO ("fields", R_CORE_BIN_ACC_FIELDS, NULL, 0); break;
|
2017-07-11 15:39:25 +02:00
|
|
|
case 'l':
|
2017-06-12 15:50:52 +02:00
|
|
|
{
|
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
2017-07-11 15:39:25 +02:00
|
|
|
RBININFO ("libs", R_CORE_BIN_ACC_LIBS, NULL, obj? r_list_length (obj->libs): 0);
|
2017-06-12 15:50:52 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-01-04 22:01:53 +01:00
|
|
|
case 'L':
|
2017-03-01 20:05:40 +01:00
|
|
|
{
|
|
|
|
char *ptr = strchr (input, ' ');
|
|
|
|
int json = input[1] == 'j'? 'j': 0;
|
|
|
|
|
|
|
|
if (ptr && ptr[1]) {
|
|
|
|
const char *plugin_name = ptr + 1;
|
|
|
|
if (is_array) {
|
|
|
|
r_cons_printf ("\"plugin\": ");
|
|
|
|
}
|
|
|
|
r_bin_list_plugin (core->bin, plugin_name, json);
|
|
|
|
} else {
|
|
|
|
r_bin_list (core->bin, json);
|
|
|
|
}
|
|
|
|
|
|
|
|
newline = false;
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
2016-11-15 23:18:41 +01:00
|
|
|
case 's':
|
2018-01-05 10:13:24 +01:00
|
|
|
{
|
2017-01-04 03:00:06 +01:00
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
2018-01-05 10:13:24 +01:00
|
|
|
// Case for isj.
|
|
|
|
if (input[1] == 'j' && input[2] == '.') {
|
|
|
|
mode = R_CORE_BIN_JSON;
|
|
|
|
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, obj? r_list_length (obj->symbols): 0);
|
|
|
|
} else {
|
|
|
|
RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, obj? r_list_length (obj->symbols): 0);
|
|
|
|
}
|
|
|
|
while (*(++input)) ;
|
|
|
|
input--;
|
2016-11-15 23:18:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-07-11 15:39:25 +02:00
|
|
|
case 'R':
|
2017-05-15 01:00:49 +02:00
|
|
|
if (input[1] == '*') {
|
|
|
|
mode = R_CORE_BIN_RADARE;
|
|
|
|
} else if (input[1] == 'j') {
|
|
|
|
mode = R_CORE_BIN_JSON;
|
|
|
|
}
|
2017-07-11 15:39:25 +02:00
|
|
|
RBININFO ("resources", R_CORE_BIN_ACC_RESOURCES, NULL, 0);
|
2017-05-15 01:00:49 +02:00
|
|
|
break;
|
2017-01-04 03:00:06 +01:00
|
|
|
case 'r': RBININFO ("relocs", R_CORE_BIN_ACC_RELOCS, NULL, 0); break;
|
2017-07-10 09:51:29 +02:00
|
|
|
case 'd': // "id"
|
|
|
|
if (input[1] == 'p') { // "idp"
|
2017-09-20 13:34:44 +02:00
|
|
|
SPDBOptions pdbopts;
|
|
|
|
RBinInfo *info;
|
|
|
|
bool file_found;
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
switch (input[2]) {
|
|
|
|
case ' ':
|
|
|
|
r_core_cmdf (core, ".idpi* %s", input + 3);
|
|
|
|
while (input[2]) input++;
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
r_core_cmd0 (core, ".idpi*");
|
|
|
|
break;
|
|
|
|
case 'd':
|
2017-07-11 15:39:25 +02:00
|
|
|
pdbopts.user_agent = (char*) r_config_get (core->config, "pdb.useragent");
|
|
|
|
pdbopts.symbol_server = (char*) r_config_get (core->config, "pdb.server");
|
|
|
|
pdbopts.extract = r_config_get_i (core->config, "pdb.extract");
|
2017-08-30 09:49:31 +02:00
|
|
|
int r = r_bin_pdb_download (core, 0, NULL, &pdbopts);
|
2017-07-11 15:39:25 +02:00
|
|
|
if (r > 0) {
|
2017-09-11 23:53:44 +02:00
|
|
|
eprintf ("Error while downloading pdb file");
|
2017-07-11 15:39:25 +02:00
|
|
|
}
|
2017-09-20 13:34:44 +02:00
|
|
|
input++;
|
2017-07-11 15:39:25 +02:00
|
|
|
break;
|
2017-09-20 13:34:44 +02:00
|
|
|
case 'i':
|
|
|
|
info = r_bin_get_info (core->bin);
|
|
|
|
file_found = false;
|
|
|
|
filename = strchr (input, ' ');
|
2017-10-03 22:09:30 +02:00
|
|
|
while (input[2]) input++;
|
2017-09-20 13:34:44 +02:00
|
|
|
if (filename) {
|
|
|
|
*filename++ = '\0';
|
|
|
|
filename = strdup (filename);
|
|
|
|
file_found = r_file_exists (filename);
|
2017-07-11 15:39:25 +02:00
|
|
|
} else {
|
2017-09-20 13:34:44 +02:00
|
|
|
/* Autodetect local file */
|
|
|
|
if (!info || !info->debug_file_name) {
|
|
|
|
eprintf ("Cannot get file's debug information");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Check raw path for debug filename
|
|
|
|
file_found = r_file_exists (info->debug_file_name);
|
|
|
|
if (file_found) {
|
|
|
|
filename = strdup (info->debug_file_name);
|
2017-09-11 23:53:44 +02:00
|
|
|
} else {
|
2017-09-20 13:34:44 +02:00
|
|
|
// Check debug filename basename in current directory
|
|
|
|
char* basename = (char*) r_file_basename (info->debug_file_name);
|
|
|
|
file_found = r_file_exists (basename);
|
|
|
|
if (!file_found) {
|
|
|
|
// Check if debug file is in file directory
|
|
|
|
char* dir = r_file_dirname (core->bin->cur->file);
|
|
|
|
filename = r_str_newf ("%s/%s", dir, basename);
|
|
|
|
file_found = r_file_exists (filename);
|
2017-10-03 22:09:30 +02:00
|
|
|
} else {
|
|
|
|
filename = strdup (basename);
|
2017-09-11 23:53:44 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-10 09:51:29 +02:00
|
|
|
}
|
2017-09-20 13:34:44 +02:00
|
|
|
|
|
|
|
if (!file_found) {
|
|
|
|
eprintf ("File '%s' not found", filename);
|
|
|
|
free (filename);
|
|
|
|
break;
|
2017-07-10 09:51:29 +02:00
|
|
|
}
|
2017-09-20 13:34:44 +02:00
|
|
|
ut64 baddr = 0;
|
|
|
|
if (core->bin->cur && core->bin->cur->o) {
|
|
|
|
baddr = core->bin->cur->o->baddr;
|
|
|
|
} else {
|
|
|
|
eprintf ("Warning: Cannot find base address, flags will probably be misplaced\n");
|
|
|
|
}
|
2018-01-10 13:45:37 +01:00
|
|
|
void *res = r_core_file_open (core, filename, R_IO_READ, baddr);
|
|
|
|
if (!res) {
|
2017-09-20 13:34:44 +02:00
|
|
|
eprintf ("Error while opening '%s'", filename);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 13:45:37 +01:00
|
|
|
int fd = r_io_fd_get_current (core->io);
|
|
|
|
r_core_bin_load (core, filename, baddr);
|
2017-09-20 13:34:44 +02:00
|
|
|
RCoreBinFilter filter = { 0 };
|
|
|
|
r_core_bin_info (core, R_CORE_BIN_ACC_PDB, mode, true, &filter, NULL);
|
2018-01-10 13:45:37 +01:00
|
|
|
r_core_file_close_fd (core, fd);
|
2017-09-20 13:34:44 +02:00
|
|
|
free (filename);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
r_core_cmd_help (core, help_msg_id);
|
|
|
|
input++;
|
2017-07-11 15:39:25 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-09-20 13:34:44 +02:00
|
|
|
input++;
|
2017-07-10 09:51:29 +02:00
|
|
|
} else if (input[1] == '?') { // "id?"
|
2017-07-26 06:45:42 -07:00
|
|
|
r_core_cmd_help (core, help_msg_id);
|
2017-07-11 15:39:25 +02:00
|
|
|
input++;
|
2017-07-10 09:51:29 +02:00
|
|
|
} else { // "id"
|
|
|
|
RBININFO ("dwarf", R_CORE_BIN_ACC_DWARF, NULL, -1);
|
|
|
|
}
|
|
|
|
break;
|
2017-06-12 15:50:52 +02:00
|
|
|
case 'i': {
|
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
|
|
|
RBININFO ("imports", R_CORE_BIN_ACC_IMPORTS, NULL,
|
|
|
|
obj? r_list_length (obj->imports): 0);
|
|
|
|
}
|
|
|
|
break;
|
2017-01-04 03:00:06 +01:00
|
|
|
case 'I': RBININFO ("info", R_CORE_BIN_ACC_INFO, NULL, 0); break;
|
2017-10-30 18:31:01 +01:00
|
|
|
case 'e':
|
|
|
|
if (input[1] == 'e') {
|
|
|
|
RBININFO ("entries", R_CORE_BIN_ACC_INITFINI, NULL, 0);
|
|
|
|
input++;
|
|
|
|
} else {
|
|
|
|
RBININFO ("entries", R_CORE_BIN_ACC_ENTRIES, NULL, 0);
|
|
|
|
}
|
|
|
|
break;
|
2017-01-04 03:00:06 +01:00
|
|
|
case 'M': RBININFO ("main", R_CORE_BIN_ACC_MAIN, NULL, 0); break;
|
|
|
|
case 'm': RBININFO ("memory", R_CORE_BIN_ACC_MEM, NULL, 0); break;
|
|
|
|
case 'V': RBININFO ("versioninfo", R_CORE_BIN_ACC_VERSIONINFO, NULL, 0); break;
|
|
|
|
case 'C': RBININFO ("signature", R_CORE_BIN_ACC_SIGNATURE, NULL, 0); break;
|
2014-09-24 23:01:03 +02:00
|
|
|
case 'z':
|
2016-11-09 17:21:37 +01:00
|
|
|
if (input[1] == 'z') { //izz
|
|
|
|
switch (input[2]) {
|
2018-01-12 02:29:05 +05:30
|
|
|
case 'z'://izzz
|
2018-01-12 14:02:33 +05:30
|
|
|
rdump = true;
|
|
|
|
break;
|
2014-09-15 23:49:51 +02:00
|
|
|
case '*':
|
2016-08-28 17:35:28 +02:00
|
|
|
mode = R_CORE_BIN_RADARE;
|
2014-09-15 23:49:51 +02:00
|
|
|
break;
|
|
|
|
case 'j':
|
2016-08-28 17:35:28 +02:00
|
|
|
mode = R_CORE_BIN_JSON;
|
2014-09-15 23:49:51 +02:00
|
|
|
break;
|
2016-10-18 01:02:35 +02:00
|
|
|
case 'q': //izzq
|
2016-11-09 17:21:37 +01:00
|
|
|
if (input[3] == 'q') { //izzqq
|
|
|
|
mode = R_CORE_BIN_SIMPLEST;
|
|
|
|
input++;
|
2016-10-18 01:02:35 +02:00
|
|
|
} else {
|
2016-11-09 17:21:37 +01:00
|
|
|
mode = R_CORE_BIN_SIMPLE;
|
2016-10-18 01:02:35 +02:00
|
|
|
}
|
2014-09-15 23:49:51 +02:00
|
|
|
break;
|
2017-02-20 02:54:16 +01:00
|
|
|
default:
|
2016-11-09 17:21:37 +01:00
|
|
|
mode = R_CORE_BIN_PRINT;
|
|
|
|
break;
|
2014-09-15 23:49:51 +02:00
|
|
|
}
|
2014-09-15 23:47:23 +02:00
|
|
|
input++;
|
2018-01-12 14:02:33 +05:30
|
|
|
if (rdump) {
|
|
|
|
RBinFile *bf = r_core_bin_cur (core);
|
|
|
|
int min = r_config_get_i (core->config, "bin.minstr");
|
|
|
|
if (bf) {
|
|
|
|
int tmp = bf->rawstr;
|
|
|
|
bf->rawstr = 2;
|
|
|
|
bf->strmode = mode;
|
|
|
|
r_bin_dump_strings (bf, min);
|
|
|
|
bf->rawstr = tmp;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
2017-01-04 03:00:06 +01:00
|
|
|
RBININFO ("strings", R_CORE_BIN_ACC_RAW_STRINGS, NULL, 0);
|
2014-09-15 23:47:23 +02:00
|
|
|
} else {
|
2017-01-04 03:00:06 +01:00
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
2017-01-11 21:24:52 +01:00
|
|
|
if (input[1] == 'q') {
|
2016-08-23 01:39:16 +02:00
|
|
|
mode = (input[2] == 'q')
|
2017-01-11 21:24:52 +01:00
|
|
|
? R_CORE_BIN_SIMPLEST
|
|
|
|
: R_CORE_BIN_SIMPLE;
|
2016-05-23 22:49:32 +02:00
|
|
|
input++;
|
|
|
|
}
|
2017-01-11 21:24:52 +01:00
|
|
|
if (obj) {
|
2017-02-20 02:54:16 +01:00
|
|
|
RBININFO ("strings", R_CORE_BIN_ACC_STRINGS, NULL,
|
2017-01-12 16:52:00 +01:00
|
|
|
obj? r_list_length (obj->strings): 0);
|
2017-01-11 21:24:52 +01:00
|
|
|
}
|
2014-09-15 23:47:23 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-07-06 01:08:14 +02:00
|
|
|
case 'c': // for r2 `ic`
|
2017-02-20 02:54:16 +01:00
|
|
|
if (input[1] == '?') {
|
2017-08-10 16:41:46 +02:00
|
|
|
eprintf ("Usage: ic[ljqc*] [class-index or name]\n");
|
|
|
|
} else if (input[1] == ' ' || input[1] == 'q' || input[1] == 'j' || input[1] == 'l' || input[1] == 'c') {
|
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);
|
2017-01-12 16:52:00 +01:00
|
|
|
if (obj) {
|
|
|
|
if (input[2]) {
|
2017-05-02 05:44:46 +02:00
|
|
|
int idx = -1;
|
|
|
|
const char * cls_name = NULL;
|
|
|
|
if (r_num_is_valid_input (core->num, input + 2)) {
|
|
|
|
idx = r_num_math (core->num, input + 2);
|
|
|
|
} else {
|
|
|
|
const char * first_char = input + ((input[1] == ' ') ? 1 : 2);
|
|
|
|
int not_space = strspn (first_char, " ");
|
|
|
|
if (first_char[not_space]) {
|
|
|
|
cls_name = first_char + not_space;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int count = 0;
|
2015-07-06 11:46:21 +02:00
|
|
|
r_list_foreach (obj->classes, iter, cls) {
|
2017-05-02 05:44:46 +02:00
|
|
|
if ((idx >= 0 && idx != count++) ||
|
|
|
|
(cls_name && strcmp (cls_name, cls->name) != 0)){
|
2017-01-12 16:52:00 +01:00
|
|
|
continue;
|
2015-07-06 11:46:21 +02:00
|
|
|
}
|
2017-01-12 16:52:00 +01:00
|
|
|
switch (input[1]) {
|
|
|
|
case '*':
|
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
2017-02-20 02:54:16 +01:00
|
|
|
r_cons_printf ("f sym.%s @ 0x%"PFMT64x "\n",
|
|
|
|
sym->name, sym->vaddr);
|
2017-01-12 16:52:00 +01:00
|
|
|
}
|
|
|
|
input++;
|
|
|
|
break;
|
|
|
|
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 ();
|
2017-01-12 16:52:00 +01:00
|
|
|
input++;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
input++;
|
|
|
|
r_cons_printf ("\"class\":\"%s\"", cls->name);
|
|
|
|
r_cons_printf (",\"methods\":[");
|
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
|
|
|
const char *comma = iter2->p? ",": "";
|
2017-04-12 10:47:31 +02:00
|
|
|
|
|
|
|
if (sym->method_flags) {
|
2017-06-27 17:02:14 +02:00
|
|
|
char *flags = r_core_bin_method_flags_str (sym->method_flags, R_CORE_BIN_JSON);
|
2017-04-12 10:47:31 +02:00
|
|
|
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);
|
|
|
|
}
|
2017-01-12 16:52:00 +01:00
|
|
|
}
|
|
|
|
r_cons_printf ("]");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r_cons_printf ("class %s\n", cls->name);
|
|
|
|
r_list_foreach (cls->methods, iter2, sym) {
|
2017-06-27 17:02:14 +02:00
|
|
|
char *flags = r_core_bin_method_flags_str (sym->method_flags, 0);
|
2017-04-12 02:27:27 +02:00
|
|
|
r_cons_printf ("0x%08"PFMT64x " method %s %s %s\n",
|
|
|
|
sym->vaddr, cls->name, flags, sym->name);
|
|
|
|
R_FREE (flags);
|
2017-01-12 16:52:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2017-01-04 03:00:06 +01:00
|
|
|
}
|
2017-01-12 16:52:00 +01:00
|
|
|
goto done;
|
2015-07-06 11:46:21 +02:00
|
|
|
}
|
2017-05-02 05:44:46 +02:00
|
|
|
goto done;
|
2015-07-06 11:46:21 +02:00
|
|
|
} else {
|
2017-01-12 16:52:00 +01:00
|
|
|
playMsg (core, "classes", r_list_length (obj->classes));
|
|
|
|
if (input[1] == 'l' && obj) { // "icl"
|
|
|
|
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)) {
|
|
|
|
r_cons_newline ();
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 16:41:46 +02:00
|
|
|
} else if (input[1] == 'c' && obj) { // "icc"
|
2017-08-09 10:21:52 +02:00
|
|
|
mode = R_CORE_BIN_CLASSDUMP;
|
|
|
|
RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, r_list_length (obj->classes));
|
2017-08-10 16:41:46 +02:00
|
|
|
input = " ";
|
2017-01-12 16:52:00 +01:00
|
|
|
} else {
|
|
|
|
RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, r_list_length (obj->classes));
|
|
|
|
}
|
2015-07-06 11:46:21 +02:00
|
|
|
}
|
2017-08-09 10:21:52 +02:00
|
|
|
}
|
2015-07-06 01:08:14 +02:00
|
|
|
} else {
|
2017-01-04 03:00:06 +01:00
|
|
|
RBinObject *obj = r_bin_cur_object (core->bin);
|
2017-01-04 22:01:53 +01:00
|
|
|
int len = obj? r_list_length (obj->classes): 0;
|
2017-01-04 03:00:06 +01:00
|
|
|
RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, len);
|
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':
|
2017-02-20 02:54:16 +01:00
|
|
|
if (input[1] != ' ' || !demangle (core, input + 2)) {
|
2015-01-10 01:00:01 +01:00
|
|
|
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) {
|
2017-08-20 10:37:30 +02:00
|
|
|
case R_CORE_BIN_RADARE: cmd_info (core, "IieEcsSmz*"); break;
|
|
|
|
case R_CORE_BIN_JSON: cmd_info (core, "IieEcsSmzj"); break;
|
|
|
|
case R_CORE_BIN_SIMPLE: cmd_info (core, "IieEcsSmzq"); break;
|
2016-12-29 17:57:58 +01:00
|
|
|
default: cmd_info (core, "IiEecsSmz"); break;
|
2014-01-18 04:53:33 +01:00
|
|
|
}
|
2013-12-20 01:20:17 +01:00
|
|
|
break;
|
2017-07-26 06:45:42 -07:00
|
|
|
case '?':
|
|
|
|
r_core_cmd_help (core, help_msg_i);
|
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
|
|
|
}
|
2017-08-26 13:08:53 +02:00
|
|
|
// input can be overwritten like the 'input = " ";' a few lines above
|
|
|
|
if (input[0] != ' ') {
|
|
|
|
input++;
|
|
|
|
if ((*input == 'j' || *input == 'q') && (input[0] && !input[1])) {
|
|
|
|
break;
|
|
|
|
}
|
2017-08-28 00:18:27 -07:00
|
|
|
} else {
|
|
|
|
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:
|
2017-02-20 02:54:16 +01:00
|
|
|
if (is_array) {
|
2014-01-18 04:53:33 +01:00
|
|
|
r_cons_printf ("}\n");
|
2017-02-20 02:54:16 +01:00
|
|
|
}
|
|
|
|
if (newline) {
|
|
|
|
r_cons_newline ();
|
|
|
|
}
|
2012-02-27 03:07:32 +01:00
|
|
|
return 0;
|
|
|
|
}
|