2016-04-07 13:42:06 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2016 - nibble, pancake */
|
2010-05-28 15:15:20 +00:00
|
|
|
|
2012-06-01 12:50:24 +00:00
|
|
|
#include <getopt.c>
|
2011-11-12 03:20:22 +00:00
|
|
|
#include <r_core.h>
|
2016-07-27 09:01:57 +00:00
|
|
|
#include <r_types.h>
|
|
|
|
#include <r_util.h>
|
2016-09-28 10:05:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-12-11 14:33:32 +00:00
|
|
|
#include "../../libr/bin/pdb/pdb_downloader.h"
|
2016-09-28 10:05:12 +00:00
|
|
|
#include "../blob/version.c"
|
2010-05-28 15:15:20 +00:00
|
|
|
|
|
|
|
static struct r_bin_t *bin = NULL;
|
2012-11-02 02:35:50 +00:00
|
|
|
static char* output = NULL;
|
|
|
|
static char* create = NULL;
|
2015-09-14 00:08:31 +00:00
|
|
|
static int rad = false;
|
2015-08-17 22:18:04 +00:00
|
|
|
static ut64 laddr = UT64_MAX;
|
|
|
|
static ut64 baddr = UT64_MAX;
|
2010-05-28 15:15:20 +00:00
|
|
|
static char* file = NULL;
|
2010-08-17 11:15:18 +00:00
|
|
|
static char *name = NULL;
|
2015-09-14 00:08:31 +00:00
|
|
|
static int rw = false;
|
|
|
|
static int va = true;
|
2016-08-02 00:11:32 +00:00
|
|
|
static char *stdin_buf = NULL;
|
2015-01-10 00:00:01 +00:00
|
|
|
static const char *do_demangle = NULL;
|
2012-11-02 02:35:50 +00:00
|
|
|
static ut64 at = 0LL;
|
|
|
|
static RLib *l;
|
2010-05-28 15:15:20 +00:00
|
|
|
|
2013-04-02 10:11:20 +00:00
|
|
|
static int rabin_show_help(int v) {
|
2015-10-08 09:14:10 +00:00
|
|
|
printf ("Usage: rabin2 [-AcdeEghHiIjlLMqrRsSvVxzZ] [-@ addr] [-a arch] [-b bits]\n"
|
2015-07-05 23:08:14 +00:00
|
|
|
" [-B addr] [-C F:C:D] [-f str] [-m addr] [-n str] [-N m:M]\n"
|
2015-06-22 09:36:28 +00:00
|
|
|
" [-o str] [-O str] [-k query] [-D lang symname] | file\n");
|
2016-10-17 20:21:00 +00:00
|
|
|
if (v) {
|
|
|
|
printf (
|
2012-12-09 00:39:27 +00:00
|
|
|
" -@ [addr] show section, symbol or import at addr\n"
|
2015-11-05 12:37:21 +00:00
|
|
|
" -A list sub-binaries and their arch-bits pairs\n"
|
2012-08-04 21:48:06 +00:00
|
|
|
" -a [arch] set arch (x86, arm, .. or <arch>_<bits>)\n"
|
2011-11-21 23:59:20 +00:00
|
|
|
" -b [bits] set bits (32, 64 ...)\n"
|
2013-11-06 00:36:40 +00:00
|
|
|
" -B [addr] override base address (pie bins)\n"
|
2015-07-05 23:08:14 +00:00
|
|
|
" -c list classes\n"
|
|
|
|
" -C [fmt:C:D] create [elf,mach0,pe] with Code and Data hexpairs (see -a)\n"
|
2012-07-12 00:47:04 +00:00
|
|
|
" -d show debug/dwarf information\n"
|
2015-06-22 09:36:28 +00:00
|
|
|
" -D lang name demangle symbol name (-D all for bin.demangle=true)\n"
|
2011-07-25 19:10:25 +00:00
|
|
|
" -e entrypoint\n"
|
2015-10-08 09:14:10 +00:00
|
|
|
" -E globally exportable symbols\n"
|
2011-07-25 19:10:25 +00:00
|
|
|
" -f [str] select sub-bin named str\n"
|
2015-01-11 18:40:26 +00:00
|
|
|
" -F [binfmt] force to use that bin plugin (ignore header check)\n"
|
2015-03-08 17:07:27 +00:00
|
|
|
" -g same as -SMResiz (show all info)\n"
|
2015-04-18 19:57:24 +00:00
|
|
|
" -G [addr] load address . offset to header\n"
|
2015-10-08 09:14:10 +00:00
|
|
|
" -h this help message\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
" -H header fields\n"
|
2011-07-25 19:10:25 +00:00
|
|
|
" -i imports (symbols imported from libraries)\n"
|
|
|
|
" -I binary info\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
" -j output in json\n"
|
2014-12-20 23:54:42 +00:00
|
|
|
" -k [sdb-query] run sdb query. for example: '*'\n"
|
2015-09-23 10:23:03 +00:00
|
|
|
" -K [algo] calculate checksums (md5, sha1, ..)\n"
|
2011-07-25 19:10:25 +00:00
|
|
|
" -l linked libraries\n"
|
|
|
|
" -L list supported bin plugins\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
" -m [addr] show source line at addr\n"
|
|
|
|
" -M main (show address of main symbol)\n"
|
2011-07-25 19:10:25 +00:00
|
|
|
" -n [str] show section, symbol or import named str\n"
|
2014-10-21 02:39:37 +00:00
|
|
|
" -N [min:max] force min:max number of chars per string (see -z and -zz)\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
" -o [str] output file/folder for write operations (out by default)\n"
|
|
|
|
" -O [str] write/extract operations (-O help)\n"
|
2014-08-24 08:41:32 +00:00
|
|
|
" -p show physical addresses\n"
|
2015-01-11 18:40:26 +00:00
|
|
|
" -P show debug/pdb information\n"
|
|
|
|
" -PP download pdb file for binary\n"
|
2012-11-05 01:00:34 +00:00
|
|
|
" -q be quiet, just show fewer data\n"
|
2016-05-23 17:33:36 +00:00
|
|
|
" -qq show less info (no offset/size for -z for ex.)\n"
|
2015-09-23 10:23:03 +00:00
|
|
|
" -Q show load address used by dlopen (non-aslr libs)\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
" -r radare output\n"
|
|
|
|
" -R relocations\n"
|
2015-10-08 09:14:10 +00:00
|
|
|
" -s symbols\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
" -S sections\n"
|
2015-07-05 01:25:20 +00:00
|
|
|
" -u unfiltered (no rename duplicated symbols/sections)\n"
|
2014-08-23 00:40:24 +00:00
|
|
|
" -v display version and quit\n"
|
2016-09-28 10:05:12 +00:00
|
|
|
" -V Show binary version information\n"
|
2011-07-25 19:10:25 +00:00
|
|
|
" -x extract bins contained in file\n"
|
2016-08-30 02:26:20 +00:00
|
|
|
" -X [fmt] [f] .. package in fat or zip the given files andbins contained in file\n"
|
2012-12-26 01:01:26 +00:00
|
|
|
" -z strings (from data section)\n"
|
|
|
|
" -zz strings (from raw bins [e bin.rawstr=1])\n"
|
2014-10-24 16:25:27 +00:00
|
|
|
" -zzz dump raw strings to stdout (for huge files)\n"
|
2013-04-02 10:11:20 +00:00
|
|
|
" -Z guess size of binary program\n"
|
2012-12-09 00:39:27 +00:00
|
|
|
);
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2015-10-13 01:50:14 +00:00
|
|
|
if (v) {
|
|
|
|
printf ("Environment:\n"
|
2016-05-03 02:31:36 +00:00
|
|
|
" RABIN2_LANG: e bin.lang # assume lang for demangling\n"
|
2015-11-04 23:38:42 +00:00
|
|
|
" RABIN2_NOPLUGINS: # do not load shared plugins (speedup loading)\n"
|
2016-05-03 02:31:36 +00:00
|
|
|
" RABIN2_DEMANGLE=0:e bin.demangle # do not demangle symbols\n"
|
|
|
|
" RABIN2_MAXSTRBUF: e bin.maxstrbuf # specify maximum buffer size\n"
|
|
|
|
" RABIN2_STRFILTER: e bin.strfilter # r2 -qe bin.strfilter=? -c '' --\n"
|
|
|
|
" RABIN2_STRPURGE: e bin.strpurge # try to purge false positives\n"
|
|
|
|
" RABIN2_DMNGLRCMD: e bin.demanglercmd # try to purge false positives\n"
|
|
|
|
" RABIN2_PREFIX: e bin.prefix # prefix symbols/sections/relocs with a specific string\n");
|
2015-10-13 01:50:14 +00:00
|
|
|
}
|
2010-09-24 19:23:13 +00:00
|
|
|
return 1;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 22:12:30 +00:00
|
|
|
static char *stdin_gets() {
|
2016-08-02 00:11:32 +00:00
|
|
|
#define STDIN_BUF_SIZE 96096
|
|
|
|
if (!stdin_buf) {
|
|
|
|
/* XXX: never freed. leaks! */
|
|
|
|
stdin_buf = malloc (STDIN_BUF_SIZE);
|
|
|
|
}
|
|
|
|
memset (stdin_buf, 0, STDIN_BUF_SIZE);
|
|
|
|
fgets (stdin_buf, sizeof (stdin_buf) - 1, stdin);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (feof (stdin)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-08-02 00:11:32 +00:00
|
|
|
stdin_buf[strlen (stdin_buf) - 1] = 0;
|
|
|
|
return strdup (stdin_buf);
|
2014-05-21 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __sdb_prompt(Sdb *sdb) {
|
|
|
|
char *line;
|
2016-10-17 20:21:00 +00:00
|
|
|
for (; (line = stdin_gets ());) {
|
2014-05-21 22:12:30 +00:00
|
|
|
sdb_query (sdb, line);
|
|
|
|
free (line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-29 23:10:28 +00:00
|
|
|
static bool isBinopHelp(const char *op) {
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!op) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!strcmp (op, "help")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!strcmp (op, "?")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!strcmp (op, "h")) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-29 23:10:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-27 09:01:57 +00:00
|
|
|
static bool extract_binobj(const RBinFile *bf, const RBinXtrData *data, int idx) {
|
|
|
|
ut64 bin_size = data ? data->size : 0;
|
|
|
|
ut8 *bytes;
|
|
|
|
ut8 *bytes_encoded;
|
2014-05-17 00:37:29 +00:00
|
|
|
//ut64 sz = bf ? r_buf_size (bf->buf) : 0;
|
2016-07-27 09:01:57 +00:00
|
|
|
char *arch = "unknown";
|
|
|
|
int bits = 0;
|
|
|
|
char *libname = NULL;
|
2014-05-08 23:35:04 +00:00
|
|
|
const char *filename = bf ? bf->file : NULL;
|
|
|
|
char *path = NULL, *outpath = NULL, *outfile = NULL, *ptr = NULL;
|
|
|
|
ut32 outfile_sz = 0, outpath_sz = 0;
|
2015-11-29 23:10:28 +00:00
|
|
|
bool res = false;
|
2014-05-08 23:35:04 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!bf || !data || !filename) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-27 09:01:57 +00:00
|
|
|
if (data->metadata) {
|
|
|
|
arch = data->metadata->arch;
|
|
|
|
bits = data->metadata->bits;
|
|
|
|
libname = data->metadata->libname;
|
|
|
|
}
|
2015-11-05 21:59:29 +00:00
|
|
|
if (bin_size == bf->size && bin_size) {
|
|
|
|
eprintf ("This is not a fat bin\n");
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-27 09:01:57 +00:00
|
|
|
bytes_encoded = (ut8 *) sdb_get (data->sdb, sdb_fmt (0, "%d", data->offset), 0);
|
|
|
|
bytes = sdb_decode ((const char *)bytes_encoded, NULL);
|
|
|
|
free (bytes_encoded);
|
|
|
|
|
2015-07-08 17:13:30 +00:00
|
|
|
if (!bytes) {
|
|
|
|
eprintf ("error: BinFile buffer is empty\n");
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2015-07-08 17:13:30 +00:00
|
|
|
}
|
2014-05-08 23:35:04 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!arch) {
|
|
|
|
arch = "unknown";
|
|
|
|
}
|
2015-07-13 09:21:21 +00:00
|
|
|
path = strdup (filename);
|
2016-10-17 20:21:00 +00:00
|
|
|
|
2015-07-13 09:21:21 +00:00
|
|
|
if (!path) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2015-07-13 09:21:21 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 23:35:04 +00:00
|
|
|
// XXX: Wrong for w32 (/)
|
2015-03-08 16:29:53 +00:00
|
|
|
ptr = strrchr (path, DIRSEP);
|
|
|
|
if (ptr) {
|
|
|
|
*ptr++ = '\0';
|
|
|
|
} else {
|
|
|
|
ptr = path;
|
|
|
|
}
|
2014-05-08 23:35:04 +00:00
|
|
|
|
|
|
|
outpath_sz = strlen (path) + 20;
|
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (outpath_sz > 0) {
|
2014-05-08 23:35:04 +00:00
|
|
|
outpath = malloc (outpath_sz);
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2014-05-08 23:35:04 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (outpath) {
|
2014-05-08 23:35:04 +00:00
|
|
|
snprintf (outpath, outpath_sz, "%s.fat", ptr);
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2015-10-18 22:25:08 +00:00
|
|
|
if (!outpath || !r_sys_mkdirp (outpath)) {
|
2014-05-08 23:35:04 +00:00
|
|
|
free (path);
|
|
|
|
free (outpath);
|
|
|
|
eprintf ("Error creating dir structure\n");
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2014-05-08 23:35:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-08 16:29:53 +00:00
|
|
|
outfile_sz = outpath_sz + strlen (ptr) + strlen (arch) + 23;
|
2016-07-27 09:01:57 +00:00
|
|
|
if (outfile_sz) {
|
2014-05-08 23:35:04 +00:00
|
|
|
outfile = malloc (outfile_sz);
|
2016-07-27 09:01:57 +00:00
|
|
|
}
|
2014-05-08 23:35:04 +00:00
|
|
|
|
2016-07-27 09:01:57 +00:00
|
|
|
if (outfile) {
|
|
|
|
if (libname) {
|
|
|
|
snprintf (outfile, outfile_sz, "%s/%s.%s.%s_%i.%d",
|
|
|
|
outpath, ptr, arch, libname, bits, idx);
|
|
|
|
} else {
|
|
|
|
snprintf (outfile, outfile_sz, "%s/%s.%s_%i.%d",
|
|
|
|
outpath, ptr, arch, bits, idx);
|
|
|
|
}
|
|
|
|
}
|
2010-10-01 06:12:43 +00:00
|
|
|
|
2016-07-27 09:01:57 +00:00
|
|
|
|
|
|
|
if (!outfile || !r_file_dump (outfile, bytes, bin_size, 0)) {
|
|
|
|
eprintf ("Error extracting %s\n", outfile);
|
2015-09-14 00:08:31 +00:00
|
|
|
res = false;
|
2014-05-08 23:35:04 +00:00
|
|
|
} else {
|
2016-07-27 09:01:57 +00:00
|
|
|
printf ("%s created (%"PFMT64d")\n", outfile, bin_size);
|
|
|
|
res = true;
|
2014-05-08 23:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free (outfile);
|
|
|
|
free (outpath);
|
|
|
|
free (path);
|
2016-07-27 09:01:57 +00:00
|
|
|
free (bytes);
|
|
|
|
|
2014-05-08 23:35:04 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rabin_extract(int all) {
|
2016-07-27 09:01:57 +00:00
|
|
|
RBinXtrData *data = NULL;
|
2015-09-14 00:08:31 +00:00
|
|
|
int res = false;
|
2014-05-08 23:35:04 +00:00
|
|
|
RBinFile *bf = r_bin_cur (bin);
|
2016-02-04 14:44:49 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!bf) {
|
|
|
|
return res;
|
|
|
|
}
|
2010-09-25 10:33:30 +00:00
|
|
|
if (all) {
|
2014-05-08 23:35:04 +00:00
|
|
|
int idx = 0;
|
2015-11-05 21:59:29 +00:00
|
|
|
RListIter *iter;
|
2016-07-27 09:01:57 +00:00
|
|
|
r_list_foreach (bf->xtr_data, iter, data) {
|
|
|
|
res = extract_binobj (bf, data, idx++);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!res) {
|
|
|
|
break;
|
|
|
|
}
|
2016-02-04 14:44:49 +00:00
|
|
|
}
|
2014-05-08 23:35:04 +00:00
|
|
|
} else {
|
2016-07-27 09:01:57 +00:00
|
|
|
data = r_list_get_n (bf->xtr_data, 0);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!data) {
|
|
|
|
return res;
|
|
|
|
}
|
2016-07-27 09:01:57 +00:00
|
|
|
res = extract_binobj (bf, data, 0);
|
2010-09-25 10:33:30 +00:00
|
|
|
}
|
2014-05-08 23:35:04 +00:00
|
|
|
return res;
|
2010-07-29 14:04:18 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 15:15:20 +00:00
|
|
|
static int rabin_dump_symbols(int len) {
|
|
|
|
RList *symbols;
|
|
|
|
RListIter *iter;
|
|
|
|
RBinSymbol *symbol;
|
|
|
|
ut8 *buf;
|
|
|
|
char *ret;
|
|
|
|
int olen = len;
|
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!(symbols = r_bin_get_symbols (bin))) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
|
|
|
|
r_list_foreach (symbols, iter, symbol) {
|
2016-10-17 20:21:00 +00:00
|
|
|
if (symbol->size && (olen > symbol->size || !olen)) {
|
2010-05-28 15:15:20 +00:00
|
|
|
len = symbol->size;
|
2016-10-17 20:21:00 +00:00
|
|
|
} else if (!symbol->size && !olen) {
|
2010-05-28 15:15:20 +00:00
|
|
|
len = 32;
|
2016-10-17 20:21:00 +00:00
|
|
|
} else {
|
|
|
|
len = olen;
|
|
|
|
}
|
2014-01-16 23:10:09 +00:00
|
|
|
if (!(buf = malloc (len))) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2014-01-16 23:10:09 +00:00
|
|
|
}
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!(ret = malloc (len * 2 + 1))) {
|
2014-01-16 23:10:09 +00:00
|
|
|
free (buf);
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2014-01-16 23:10:09 +00:00
|
|
|
}
|
2014-05-21 01:18:00 +00:00
|
|
|
r_buf_read_at (bin->cur->buf, symbol->paddr, buf, len);
|
2010-05-28 15:15:20 +00:00
|
|
|
r_hex_bin2str (buf, len, ret);
|
|
|
|
printf ("%s %s\n", symbol->name, ret);
|
|
|
|
free (buf);
|
|
|
|
free (ret);
|
|
|
|
}
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 11:15:18 +00:00
|
|
|
static int rabin_dump_sections(char *scnname) {
|
2010-05-28 15:15:20 +00:00
|
|
|
RList *sections;
|
|
|
|
RListIter *iter;
|
|
|
|
RBinSection *section;
|
|
|
|
ut8 *buf;
|
|
|
|
char *ret;
|
2015-11-03 19:50:42 +00:00
|
|
|
int r;
|
2010-05-28 15:15:20 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!(sections = r_bin_get_sections (bin))) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
|
|
|
|
r_list_foreach (sections, iter, section) {
|
2010-08-17 11:15:18 +00:00
|
|
|
if (!strcmp (scnname, section->name)) {
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!(buf = malloc (section->size))) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2015-11-03 19:50:42 +00:00
|
|
|
if ((section->size * 2) + 1 < section->size) {
|
|
|
|
free (buf);
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-30 19:18:43 +00:00
|
|
|
if (!(ret = malloc (section->size*2+1))) {
|
|
|
|
free (buf);
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2014-04-30 19:18:43 +00:00
|
|
|
}
|
2015-11-03 19:50:42 +00:00
|
|
|
if (section->paddr > bin->cur->buf->length ||
|
2016-10-17 20:21:00 +00:00
|
|
|
section->paddr + section->size > bin->cur->buf->length) {
|
2015-11-03 19:50:42 +00:00
|
|
|
free (buf);
|
|
|
|
free (ret);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
r = r_buf_read_at (bin->cur->buf, section->paddr,
|
|
|
|
buf, section->size);
|
|
|
|
if (r < 1) {
|
|
|
|
free (buf);
|
|
|
|
free (ret);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-30 19:59:58 +00:00
|
|
|
if (output) {
|
2015-04-03 02:04:46 +00:00
|
|
|
r_file_dump (output, buf, section->size, 0);
|
2011-11-30 19:59:58 +00:00
|
|
|
} else {
|
|
|
|
r_hex_bin2str (buf, section->size, ret);
|
|
|
|
printf ("%s\n", ret);
|
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
free (buf);
|
|
|
|
free (ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rabin_do_operation(const char *op) {
|
|
|
|
char *arg = NULL, *ptr = NULL, *ptr2 = NULL;
|
2015-11-29 23:10:28 +00:00
|
|
|
bool rc = true;
|
2010-05-28 15:15:20 +00:00
|
|
|
|
|
|
|
/* Implement alloca with fixed-size buffer? */
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!(arg = strdup (op))) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
|
|
|
|
if ((ptr = strchr (arg, '/'))) {
|
2015-11-29 23:10:28 +00:00
|
|
|
*ptr++ = 0;
|
2010-05-28 15:15:20 +00:00
|
|
|
if ((ptr2 = strchr (ptr, '/'))) {
|
|
|
|
ptr2[0] = '\0';
|
2011-11-30 19:59:58 +00:00
|
|
|
ptr2++;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!output) {
|
|
|
|
output = file;
|
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
|
|
|
|
switch (arg[0]) {
|
2016-01-14 13:42:26 +00:00
|
|
|
case 'e':
|
|
|
|
rc = r_bin_wr_entry (bin, r_num_math (NULL, ptr));
|
2016-10-17 20:21:00 +00:00
|
|
|
if (rc) {
|
|
|
|
rc = r_bin_wr_output (bin, output);
|
|
|
|
}
|
2016-01-14 13:42:26 +00:00
|
|
|
break;
|
2010-05-28 15:15:20 +00:00
|
|
|
case 'd':
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!ptr) {
|
|
|
|
goto _rabin_do_operation_error;
|
|
|
|
}
|
2011-07-17 22:07:45 +00:00
|
|
|
switch (*ptr) {
|
|
|
|
case 's':
|
2010-05-28 15:15:20 +00:00
|
|
|
if (ptr2) {
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!rabin_dump_symbols (r_num_math (NULL, ptr2))) {
|
2015-08-29 16:08:38 +00:00
|
|
|
goto error;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2015-11-29 23:10:28 +00:00
|
|
|
} else if (!rabin_dump_symbols (0)) {
|
2015-08-29 16:08:38 +00:00
|
|
|
goto error;
|
2015-11-29 23:10:28 +00:00
|
|
|
}
|
2011-07-17 22:07:45 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!ptr2) {
|
2010-05-28 15:15:20 +00:00
|
|
|
goto _rabin_do_operation_error;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
|
|
|
if (!rabin_dump_sections (ptr2)) {
|
2016-04-07 13:42:06 +00:00
|
|
|
goto error;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2016-04-07 13:42:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto _rabin_do_operation_error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'a':
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!ptr) {
|
|
|
|
goto _rabin_do_operation_error;
|
|
|
|
}
|
2016-04-07 13:42:06 +00:00
|
|
|
switch (*ptr) {
|
|
|
|
case 'l':
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!ptr2 || !r_bin_wr_addlib (bin, ptr2)) {
|
2015-08-29 16:08:38 +00:00
|
|
|
goto error;
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
2011-07-17 22:07:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto _rabin_do_operation_error;
|
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
break;
|
2015-11-27 19:35:40 +00:00
|
|
|
case 'R':
|
|
|
|
r_bin_wr_rpath_del (bin);
|
2015-11-29 23:10:28 +00:00
|
|
|
rc = r_bin_wr_output (bin, output);
|
2015-11-27 19:35:40 +00:00
|
|
|
break;
|
2016-09-28 10:05:12 +00:00
|
|
|
case 'C':
|
2016-05-09 21:42:28 +00:00
|
|
|
{
|
|
|
|
RBinFile *cur = r_bin_cur (bin);
|
|
|
|
RBinPlugin *plg = r_bin_file_cur_plugin (cur);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!plg) {
|
|
|
|
break;
|
|
|
|
}
|
2016-05-09 21:42:28 +00:00
|
|
|
if (plg->signature) {
|
|
|
|
const char *sign = plg->signature (cur);
|
2016-06-25 17:49:58 +00:00
|
|
|
r_cons_println (sign);
|
2016-05-09 21:42:28 +00:00
|
|
|
r_cons_flush ();
|
|
|
|
}
|
|
|
|
}
|
2016-09-28 10:05:12 +00:00
|
|
|
break;
|
2010-05-28 15:15:20 +00:00
|
|
|
case 'r':
|
|
|
|
r_bin_wr_scn_resize (bin, ptr, r_num_math (NULL, ptr2));
|
2015-11-29 23:10:28 +00:00
|
|
|
rc = r_bin_wr_output (bin, output);
|
2010-05-28 15:15:20 +00:00
|
|
|
break;
|
2015-11-27 19:35:40 +00:00
|
|
|
case 'p':
|
|
|
|
{
|
2015-11-29 23:10:28 +00:00
|
|
|
int perms = (int)r_num_math (NULL, ptr2);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!perms) {
|
|
|
|
perms = r_str_rwx (ptr2);
|
|
|
|
}
|
2015-11-27 19:35:40 +00:00
|
|
|
r_bin_wr_scn_perms (bin, ptr, perms);
|
2015-11-29 23:10:28 +00:00
|
|
|
rc = r_bin_wr_output (bin, output);
|
2015-11-27 19:35:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-05-28 15:15:20 +00:00
|
|
|
default:
|
|
|
|
_rabin_do_operation_error:
|
2010-09-24 19:23:13 +00:00
|
|
|
eprintf ("Unknown operation. use -O help\n");
|
2015-08-29 16:08:38 +00:00
|
|
|
goto error;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
2015-11-29 23:10:28 +00:00
|
|
|
if (!rc) {
|
|
|
|
eprintf ("Cannot dump :(\n");
|
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
free (arg);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2015-08-29 16:08:38 +00:00
|
|
|
error:
|
|
|
|
free (arg);
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
2011-10-09 23:48:08 +00:00
|
|
|
static int rabin_show_srcline(ut64 at) {
|
2010-05-28 15:15:20 +00:00
|
|
|
char *srcline;
|
2016-05-31 21:42:53 +00:00
|
|
|
if ((srcline = r_bin_addr2text (bin, at, true))) {
|
2010-05-28 15:15:20 +00:00
|
|
|
printf ("%s\n", srcline);
|
|
|
|
free (srcline);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* bin callback */
|
|
|
|
static int __lib_bin_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
|
|
|
|
struct r_bin_plugin_t *hand = (struct r_bin_plugin_t *)data;
|
|
|
|
//printf(" * Added (dis)assembly plugin\n");
|
|
|
|
r_bin_add (bin, hand);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __lib_bin_dt(struct r_lib_plugin_t *pl, void *p, void *u) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 19:23:13 +00:00
|
|
|
/* binxtr callback */
|
|
|
|
static int __lib_bin_xtr_cb(struct r_lib_plugin_t *pl, void *user, void *data) {
|
|
|
|
struct r_bin_xtr_plugin_t *hand = (struct r_bin_xtr_plugin_t *)data;
|
|
|
|
//printf(" * Added (dis)assembly plugin\n");
|
|
|
|
r_bin_xtr_add (bin, hand);
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-09-24 19:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __lib_bin_xtr_dt(struct r_lib_plugin_t *pl, void *p, void *u) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2010-09-24 19:23:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 23:10:28 +00:00
|
|
|
static char *demangleAs(int type) {
|
|
|
|
char *res = NULL;
|
|
|
|
switch (type) {
|
|
|
|
case R_BIN_NM_CXX: res = r_bin_demangle_cxx (file); break;
|
|
|
|
case R_BIN_NM_JAVA: res = r_bin_demangle_java (file); break;
|
|
|
|
case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, file); break;
|
2016-05-03 02:31:36 +00:00
|
|
|
case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (file, 0); break; // XX: use
|
2015-11-29 23:10:28 +00:00
|
|
|
case R_BIN_NM_MSVC: res = r_bin_demangle_msvc(file); break;
|
2016-04-28 00:02:16 +00:00
|
|
|
default:
|
|
|
|
eprintf ("Unsupported demangler\n");
|
|
|
|
break;
|
2015-11-29 23:10:28 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-10-03 22:42:11 +00:00
|
|
|
int main(int argc, char **argv) {
|
2014-05-18 23:42:36 +00:00
|
|
|
const char *query = NULL;
|
2016-04-22 22:47:00 +00:00
|
|
|
int c, bits = 0, actions_done = 0, actions = 0;
|
|
|
|
ut64 action = R_BIN_REQ_UNK;
|
2015-11-29 23:10:28 +00:00
|
|
|
char *tmp, *ptr, *arch = NULL, *arch_name = NULL;
|
2015-01-11 18:40:26 +00:00
|
|
|
const char *forcebin = NULL;
|
2015-11-29 23:10:28 +00:00
|
|
|
const char *chksum = NULL;
|
|
|
|
const char *op = NULL;
|
2016-04-05 17:51:24 +00:00
|
|
|
const char *path = NULL;
|
2013-04-02 10:11:20 +00:00
|
|
|
RCoreBinFilter filter;
|
2014-04-27 07:06:50 +00:00
|
|
|
RCoreFile *cf = NULL;
|
|
|
|
int xtr_idx = 0; // load all files if extraction is necessary.
|
2014-05-19 00:41:53 +00:00
|
|
|
int rawstr = 0;
|
2015-11-29 23:10:28 +00:00
|
|
|
int fd = -1;
|
|
|
|
RCore core;
|
2010-05-28 15:15:20 +00:00
|
|
|
|
2012-12-26 01:01:26 +00:00
|
|
|
r_core_init (&core);
|
2013-04-02 10:11:20 +00:00
|
|
|
bin = core.bin;
|
2015-11-04 23:38:42 +00:00
|
|
|
|
2016-03-06 12:27:01 +00:00
|
|
|
if (!(tmp = r_sys_getenv ("RABIN2_NOPLUGINS"))) {
|
2016-10-17 20:21:00 +00:00
|
|
|
char *homeplugindir = r_str_home (R2_HOMEDIR "/plugins");
|
2015-11-04 23:38:42 +00:00
|
|
|
l = r_lib_new ("radare_plugin");
|
2016-10-17 20:21:00 +00:00
|
|
|
|
2015-11-04 23:38:42 +00:00
|
|
|
r_lib_add_handler (l, R_LIB_TYPE_BIN, "bin plugins",
|
2016-10-17 20:21:00 +00:00
|
|
|
&__lib_bin_cb, &__lib_bin_dt, NULL);
|
2015-11-04 23:38:42 +00:00
|
|
|
r_lib_add_handler (l, R_LIB_TYPE_BIN_XTR, "bin xtr plugins",
|
2016-10-17 20:21:00 +00:00
|
|
|
&__lib_bin_xtr_cb, &__lib_bin_xtr_dt, NULL);
|
2015-11-04 23:38:42 +00:00
|
|
|
/* load plugins everywhere */
|
2016-09-28 10:05:12 +00:00
|
|
|
|
2016-04-05 17:51:24 +00:00
|
|
|
path = r_sys_getenv (R_LIB_ENV);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (path && *path) {
|
2016-04-05 17:51:24 +00:00
|
|
|
r_lib_opendir (l, path);
|
|
|
|
}
|
2016-10-17 20:21:00 +00:00
|
|
|
r_lib_opendir (l, homeplugindir);
|
|
|
|
free (homeplugindir);
|
|
|
|
r_lib_opendir (l, R2_LIBDIR "/radare2/" R2_VERSION);
|
|
|
|
r_lib_opendir (l, R2_LIBDIR "/radare2-extras/" R2_VERSION);
|
|
|
|
r_lib_opendir (l, R2_LIBDIR "/radare2-bindings/" R2_VERSION);
|
2015-11-04 23:38:42 +00:00
|
|
|
}
|
2016-03-06 12:27:01 +00:00
|
|
|
free (tmp);
|
2015-10-22 18:26:24 +00:00
|
|
|
|
2016-05-03 02:31:36 +00:00
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_DMNGLRCMD"))) {
|
|
|
|
r_config_set (core.config, "bin.demanglecmd", tmp);
|
|
|
|
free (tmp);
|
|
|
|
}
|
2015-10-19 11:21:12 +00:00
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_LANG"))) {
|
|
|
|
r_config_set (core.config, "bin.lang", tmp);
|
|
|
|
free (tmp);
|
|
|
|
}
|
2015-10-19 01:28:22 +00:00
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_DEMANGLE"))) {
|
|
|
|
r_config_set (core.config, "bin.demangle", tmp);
|
|
|
|
free (tmp);
|
|
|
|
}
|
2015-10-13 01:50:14 +00:00
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_MAXSTRBUF"))) {
|
|
|
|
r_config_set (core.config, "bin.maxstrbuf", tmp);
|
|
|
|
free (tmp);
|
|
|
|
}
|
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_STRFILTER"))) {
|
|
|
|
r_config_set (core.config, "bin.strfilter", tmp);
|
|
|
|
free (tmp);
|
|
|
|
}
|
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_STRPURGE"))) {
|
|
|
|
r_config_set (core.config, "bin.strpurge", tmp);
|
|
|
|
free (tmp);
|
2015-10-07 00:52:50 +00:00
|
|
|
}
|
2012-11-02 02:35:50 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
#define is_active(x) (action & x)
|
2014-10-24 16:25:27 +00:00
|
|
|
#define set_action(x) actions++; action |= x
|
|
|
|
#define unset_action(x) action &= ~x
|
2016-08-30 02:26:20 +00:00
|
|
|
while ((c = getopt (argc, argv, "DjgAf:F:a:B:G:b:cC:k:K:dD:Mm:n:N:@:isSVIHeElRwO:o:pPqQrvLhuxXzZ")) != -1) {
|
2012-11-02 02:35:50 +00:00
|
|
|
switch (c) {
|
2013-11-09 02:11:03 +00:00
|
|
|
case 'g':
|
2016-04-22 22:47:00 +00:00
|
|
|
set_action (R_BIN_REQ_CLASSES);
|
|
|
|
set_action (R_BIN_REQ_IMPORTS);
|
|
|
|
set_action (R_BIN_REQ_SYMBOLS);
|
|
|
|
set_action (R_BIN_REQ_SECTIONS);
|
|
|
|
set_action (R_BIN_REQ_STRINGS);
|
|
|
|
set_action (R_BIN_REQ_SIZE);
|
|
|
|
set_action (R_BIN_REQ_INFO);
|
|
|
|
set_action (R_BIN_REQ_FIELDS);
|
|
|
|
set_action (R_BIN_REQ_DWARF);
|
|
|
|
set_action (R_BIN_REQ_ENTRIES);
|
|
|
|
set_action (R_BIN_REQ_MAIN);
|
|
|
|
set_action (R_BIN_REQ_LIBS);
|
|
|
|
set_action (R_BIN_REQ_RELOCS);
|
|
|
|
set_action (R_BIN_REQ_VERSIONINFO);
|
2013-11-09 02:11:03 +00:00
|
|
|
break;
|
2016-04-22 22:47:00 +00:00
|
|
|
case 'V': set_action (R_BIN_REQ_VERSIONINFO); break;
|
2016-05-23 17:33:36 +00:00
|
|
|
case 'q':
|
|
|
|
rad = (rad & R_CORE_BIN_SIMPLE ?
|
|
|
|
R_CORE_BIN_SIMPLEST : R_CORE_BIN_SIMPLE);
|
|
|
|
break;
|
2012-11-02 02:35:50 +00:00
|
|
|
case 'j': rad = R_CORE_BIN_JSON; break;
|
2016-04-22 22:47:00 +00:00
|
|
|
case 'A': set_action (R_BIN_REQ_LISTARCHS); break;
|
2016-03-04 01:43:31 +00:00
|
|
|
case 'a': arch = optarg; break;
|
2015-07-05 23:08:14 +00:00
|
|
|
case 'C':
|
2016-04-22 22:47:00 +00:00
|
|
|
set_action (R_BIN_REQ_CREATE);
|
2011-07-25 19:10:25 +00:00
|
|
|
create = strdup (optarg);
|
|
|
|
break;
|
2015-07-05 01:25:20 +00:00
|
|
|
case 'u': bin->filter = 0; break;
|
2014-05-18 23:42:36 +00:00
|
|
|
case 'k': query = optarg; break;
|
2014-08-15 01:30:45 +00:00
|
|
|
case 'K': chksum = optarg; break;
|
2016-04-22 22:47:00 +00:00
|
|
|
case 'c': set_action (R_BIN_REQ_CLASSES); break;
|
2016-03-04 01:43:31 +00:00
|
|
|
case 'f': arch_name = strdup (optarg); break;
|
2015-01-11 18:40:26 +00:00
|
|
|
case 'F': forcebin = optarg; break;
|
2012-07-01 22:38:02 +00:00
|
|
|
case 'b': bits = r_num_math (NULL, optarg); break;
|
2010-05-28 15:15:20 +00:00
|
|
|
case 'm':
|
|
|
|
at = r_num_math (NULL, optarg);
|
2016-04-22 22:47:00 +00:00
|
|
|
set_action (R_BIN_REQ_SRCLINE);
|
2010-09-24 19:23:13 +00:00
|
|
|
break;
|
2016-04-22 22:47:00 +00:00
|
|
|
case 'i': set_action (R_BIN_REQ_IMPORTS); break;
|
|
|
|
case 's': set_action (R_BIN_REQ_SYMBOLS); break;
|
|
|
|
case 'S': set_action (R_BIN_REQ_SECTIONS); break;
|
2014-04-26 22:31:04 +00:00
|
|
|
case 'z':
|
2016-04-22 22:47:00 +00:00
|
|
|
if (is_active (R_BIN_REQ_STRINGS)) {
|
2014-10-24 16:25:27 +00:00
|
|
|
if (rawstr) {
|
|
|
|
/* rawstr mode 2 means that we are not going */
|
|
|
|
/* to store them just dump'm all to stdout */
|
|
|
|
rawstr = 2;
|
|
|
|
} else {
|
2015-09-14 00:08:31 +00:00
|
|
|
rawstr = true;
|
2014-10-24 16:25:27 +00:00
|
|
|
}
|
2016-10-17 20:21:00 +00:00
|
|
|
} else {
|
|
|
|
set_action (R_BIN_REQ_STRINGS);
|
|
|
|
}
|
2012-12-26 01:01:26 +00:00
|
|
|
break;
|
2016-04-22 22:47:00 +00:00
|
|
|
case 'Z': set_action (R_BIN_REQ_SIZE); break;
|
|
|
|
case 'I': set_action (R_BIN_REQ_INFO); break;
|
|
|
|
case 'H': set_action (R_BIN_REQ_FIELDS); break;
|
|
|
|
case 'd': set_action (R_BIN_REQ_DWARF); break;
|
2014-12-11 14:33:32 +00:00
|
|
|
case 'P':
|
2016-04-22 22:47:00 +00:00
|
|
|
if (is_active (R_BIN_REQ_PDB)) {
|
|
|
|
set_action (R_BIN_REQ_PDB_DWNLD);
|
2014-12-11 14:33:32 +00:00
|
|
|
} else {
|
2016-04-22 22:47:00 +00:00
|
|
|
set_action (R_BIN_REQ_PDB);
|
2014-12-11 14:33:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-06-22 09:36:28 +00:00
|
|
|
case 'D':
|
|
|
|
if (argv[optind] && argv[optind+1] && \
|
|
|
|
(!argv[optind+1][0] || !strcmp (argv[optind+1], "all"))) {
|
|
|
|
r_config_set (core.config, "bin.lang", argv[optind]);
|
|
|
|
r_config_set (core.config, "bin.demangle", "true");
|
|
|
|
optind += 2;
|
|
|
|
} else {
|
|
|
|
do_demangle = argv[optind];
|
|
|
|
}
|
|
|
|
break;
|
2016-04-22 22:47:00 +00:00
|
|
|
case 'e': set_action (R_BIN_REQ_ENTRIES); break;
|
|
|
|
case 'E': set_action (R_BIN_REQ_EXPORTS); break;
|
|
|
|
case 'Q': set_action (R_BIN_REQ_DLOPEN); break;
|
|
|
|
case 'M': set_action (R_BIN_REQ_MAIN); break;
|
|
|
|
case 'l': set_action (R_BIN_REQ_LIBS); break;
|
|
|
|
case 'R': set_action (R_BIN_REQ_RELOCS); break;
|
|
|
|
case 'x': set_action (R_BIN_REQ_EXTRACT); break;
|
2016-08-30 02:26:20 +00:00
|
|
|
case 'X': set_action (R_BIN_REQ_PACKAGE); break;
|
2015-09-14 00:08:31 +00:00
|
|
|
case 'w': rw = true; break;
|
2010-05-28 15:15:20 +00:00
|
|
|
case 'O':
|
|
|
|
op = optarg;
|
2016-04-22 22:47:00 +00:00
|
|
|
set_action (R_BIN_REQ_OPERATION);
|
2015-11-29 23:10:28 +00:00
|
|
|
if (isBinopHelp (op)) {
|
2013-03-10 13:27:01 +00:00
|
|
|
printf ("Operation string:\n"
|
2016-01-14 13:42:26 +00:00
|
|
|
" Change Entrypoint: e/0x8048000\n"
|
2016-04-07 13:42:06 +00:00
|
|
|
" Dump Symbols: d/s/1024\n"
|
|
|
|
" Dump Section: d/S/.text\n"
|
|
|
|
" Resize Section: r/.data/1024\n"
|
2015-11-27 19:35:40 +00:00
|
|
|
" Remove RPATH: R\n"
|
2016-04-07 13:42:06 +00:00
|
|
|
" Add Library: a/l/libfoo.dylib\n"
|
|
|
|
" Change Permissions: p/.data/rwx\n");
|
2014-08-19 23:21:31 +00:00
|
|
|
r_core_fini (&core);
|
2013-03-10 13:27:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-11-27 19:35:40 +00:00
|
|
|
if (optind == argc) {
|
2012-05-30 01:32:20 +00:00
|
|
|
eprintf ("Missing filename\n");
|
2014-08-19 23:21:31 +00:00
|
|
|
r_core_fini (&core);
|
2012-05-30 01:32:20 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2010-05-28 15:15:20 +00:00
|
|
|
break;
|
2012-07-01 22:38:02 +00:00
|
|
|
case 'o': output = optarg; break;
|
2015-09-14 00:08:31 +00:00
|
|
|
case 'p': va = false; break;
|
|
|
|
case 'r': rad = true; break;
|
2014-08-23 00:40:24 +00:00
|
|
|
case 'v': return blob_version ("rabin2");
|
2016-08-07 16:57:31 +00:00
|
|
|
case 'L':
|
|
|
|
bin->cb_printf = (PrintfCallback)printf;
|
2016-10-04 12:34:06 +00:00
|
|
|
if (rad) {
|
|
|
|
r_bin_list (bin, 'q');
|
|
|
|
} else {
|
|
|
|
r_bin_list (bin, rad == R_CORE_BIN_JSON);
|
|
|
|
}
|
2016-08-07 16:57:31 +00:00
|
|
|
return 1;
|
2015-01-29 00:45:39 +00:00
|
|
|
case 'G':
|
2014-08-23 01:18:03 +00:00
|
|
|
laddr = r_num_math (NULL, optarg);
|
2016-07-27 09:01:57 +00:00
|
|
|
if (laddr == UT64_MAX) {
|
2015-09-14 00:08:31 +00:00
|
|
|
va = false;
|
2016-07-27 09:01:57 +00:00
|
|
|
}
|
2014-08-23 01:18:03 +00:00
|
|
|
break;
|
2015-01-29 00:45:39 +00:00
|
|
|
case 'B':
|
|
|
|
baddr = r_num_math (NULL, optarg);
|
|
|
|
break;
|
2016-08-07 16:57:31 +00:00
|
|
|
case '@':
|
|
|
|
at = r_num_math (NULL, optarg);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
name = optarg;
|
|
|
|
break;
|
2016-03-04 01:43:31 +00:00
|
|
|
case 'N':
|
|
|
|
tmp = strchr (optarg, ':');
|
|
|
|
r_config_set (core.config, "bin.minstr", optarg);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (tmp) {
|
|
|
|
r_config_set (core.config, "bin.maxstr", tmp + 1);
|
|
|
|
}
|
2015-07-02 07:33:05 +00:00
|
|
|
break;
|
2014-08-19 23:21:31 +00:00
|
|
|
case 'h':
|
2015-01-10 00:00:01 +00:00
|
|
|
r_core_fini (&core);
|
|
|
|
return rabin_show_help (1);
|
2016-04-22 22:47:00 +00:00
|
|
|
default: action |= R_BIN_REQ_HELP;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 00:00:01 +00:00
|
|
|
if (do_demangle) {
|
|
|
|
char *res = NULL;
|
|
|
|
int type;
|
2016-04-28 00:02:16 +00:00
|
|
|
if ((argc - optind) < 2) {
|
2015-01-10 00:00:01 +00:00
|
|
|
return rabin_show_help (0);
|
|
|
|
}
|
|
|
|
type = r_bin_demangle_type (do_demangle);
|
2016-08-30 02:26:20 +00:00
|
|
|
file = argv[optind + 1];
|
2015-07-06 22:38:51 +00:00
|
|
|
if (!strcmp (file, "-")) {
|
|
|
|
for (;;) {
|
|
|
|
file = stdin_gets();
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!file || !*file) {
|
|
|
|
break;
|
|
|
|
}
|
2016-04-28 00:02:16 +00:00
|
|
|
res = demangleAs (type);
|
2015-11-29 23:10:28 +00:00
|
|
|
if (!res) {
|
|
|
|
eprintf ("Unknown lang to demangle. Use: cxx, java, objc, swift\n");
|
|
|
|
return 1;
|
2015-07-06 22:38:51 +00:00
|
|
|
}
|
|
|
|
if (res && *res) {
|
|
|
|
printf ("%s\n", res);
|
|
|
|
} else if (file && *file) {
|
|
|
|
printf ("%s\n", file);
|
|
|
|
}
|
|
|
|
R_FREE (res);
|
|
|
|
R_FREE (file);
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-28 00:02:16 +00:00
|
|
|
res = demangleAs (type);
|
2015-07-06 22:38:51 +00:00
|
|
|
if (res && *res) {
|
|
|
|
printf ("%s\n", res);
|
|
|
|
free(res);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
printf ("%s\n", file);
|
|
|
|
}
|
2015-01-10 00:00:01 +00:00
|
|
|
}
|
|
|
|
free (res);
|
|
|
|
//eprintf ("%s\n", file);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-06-22 09:36:28 +00:00
|
|
|
file = argv[optind];
|
|
|
|
if (!query) {
|
2016-04-22 22:47:00 +00:00
|
|
|
if (action & R_BIN_REQ_HELP || action == R_BIN_REQ_UNK || !file) {
|
2015-06-22 09:36:28 +00:00
|
|
|
r_core_fini (&core);
|
|
|
|
return rabin_show_help (0);
|
|
|
|
}
|
2012-11-02 02:35:50 +00:00
|
|
|
}
|
2010-09-25 01:45:03 +00:00
|
|
|
if (arch) {
|
|
|
|
ptr = strchr (arch, '_');
|
|
|
|
if (ptr) {
|
|
|
|
*ptr = '\0';
|
|
|
|
bits = r_num_math (NULL, ptr+1);
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 22:47:00 +00:00
|
|
|
if (action & R_BIN_REQ_CREATE) {
|
2011-07-25 21:42:39 +00:00
|
|
|
// TODO: move in a function outside
|
2011-07-25 19:10:25 +00:00
|
|
|
RBuffer *b;
|
|
|
|
int datalen, codelen;
|
|
|
|
ut8 *data = NULL, *code = NULL;
|
|
|
|
char *p2, *p = strchr (create, ':');
|
|
|
|
if (!p) {
|
2015-07-05 23:08:14 +00:00
|
|
|
eprintf ("Invalid format for -C flag. Use 'format:codehexpair:datahexpair'\n");
|
2014-08-19 23:21:31 +00:00
|
|
|
r_core_fini (&core);
|
2011-07-25 19:10:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*p++ = 0;
|
|
|
|
p2 = strchr (p, ':');
|
|
|
|
if (p2) {
|
|
|
|
// has data
|
|
|
|
*p2++ = 0;
|
2013-12-02 23:14:59 +00:00
|
|
|
data = malloc (strlen (p2)+1);
|
2011-07-25 19:10:25 +00:00
|
|
|
datalen = r_hex_str2bin (p2, data);
|
2016-01-23 06:27:00 +00:00
|
|
|
if (datalen < 0) datalen = -datalen;
|
2011-12-05 23:27:57 +00:00
|
|
|
} else {
|
|
|
|
data = NULL;
|
|
|
|
datalen = 0;
|
2011-07-25 19:10:25 +00:00
|
|
|
}
|
2016-08-30 02:26:20 +00:00
|
|
|
code = malloc (strlen (p) + 1);
|
2014-08-19 23:21:31 +00:00
|
|
|
if (!code) {
|
|
|
|
r_core_fini (&core);
|
2015-04-18 19:57:24 +00:00
|
|
|
return 1;
|
2014-08-19 23:21:31 +00:00
|
|
|
}
|
2011-07-25 19:10:25 +00:00
|
|
|
codelen = r_hex_str2bin (p, code);
|
2016-10-17 20:21:00 +00:00
|
|
|
if (!arch) {
|
|
|
|
arch = R_SYS_ARCH;
|
|
|
|
}
|
|
|
|
if (!bits) {
|
|
|
|
bits = 32;
|
|
|
|
}
|
2011-07-25 19:10:25 +00:00
|
|
|
if (!r_bin_use_arch (bin, arch, bits, create)) {
|
|
|
|
eprintf ("Cannot set arch\n");
|
2014-08-19 23:21:31 +00:00
|
|
|
r_core_fini (&core);
|
2011-07-25 19:10:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
b = r_bin_create (bin, code, codelen, data, datalen);
|
|
|
|
if (b) {
|
2015-04-03 02:04:46 +00:00
|
|
|
if (r_file_dump (file, b->buf, b->length, 0)) {
|
2016-07-05 13:58:09 +00:00
|
|
|
eprintf ("Dumped %"PFMT64d" bytes in '%s'\n", b->length, file);
|
2011-07-25 21:42:39 +00:00
|
|
|
r_file_chmod (file, "+x", 0);
|
2015-10-22 18:26:24 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Error dumping into a.out\n");
|
|
|
|
}
|
2011-07-25 19:10:25 +00:00
|
|
|
r_buf_free (b);
|
2015-10-22 18:26:24 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Cannot create binary for this format '%s'.\n", create);
|
|
|
|
}
|
2014-08-19 23:21:31 +00:00
|
|
|
r_core_fini (&core);
|
2011-07-25 19:10:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-24 16:25:27 +00:00
|
|
|
if (rawstr == 2) {
|
2016-04-22 22:47:00 +00:00
|
|
|
unset_action (R_BIN_REQ_STRINGS);
|
2014-10-24 16:25:27 +00:00
|
|
|
}
|
2014-05-19 00:41:53 +00:00
|
|
|
r_config_set_i (core.config, "bin.rawstr", rawstr);
|
2015-04-18 19:57:24 +00:00
|
|
|
|
2015-11-24 09:17:24 +00:00
|
|
|
if (!file) {
|
|
|
|
eprintf ("Missing file.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-04-22 22:47:00 +00:00
|
|
|
if (file && *file && action & R_BIN_REQ_DLOPEN) {
|
2015-04-18 19:57:24 +00:00
|
|
|
void *addr = r_lib_dl_open (file);
|
|
|
|
if (addr) {
|
2015-06-22 09:36:28 +00:00
|
|
|
eprintf ("%s is loaded at 0x%"PFMT64x"\n", file, (ut64)(size_t)(addr));
|
2015-04-18 19:57:24 +00:00
|
|
|
r_lib_dl_close (addr);
|
2015-11-24 09:17:24 +00:00
|
|
|
return 0;
|
2015-10-22 18:26:24 +00:00
|
|
|
}
|
2015-11-24 09:17:24 +00:00
|
|
|
eprintf ("Cannot open the '%s' library\n", file);
|
|
|
|
return 1;
|
2015-04-18 19:57:24 +00:00
|
|
|
}
|
2016-08-30 02:26:20 +00:00
|
|
|
if (action & R_BIN_REQ_PACKAGE) {
|
|
|
|
RList *files = r_list_newf (NULL);
|
|
|
|
const char *format = argv[optind];
|
|
|
|
const char *file = argv[optind + 1];
|
|
|
|
int i, rc = 0;
|
|
|
|
|
|
|
|
if (optind + 3 > argc) {
|
|
|
|
eprintf ("Usage: rabin2 -X [fat|zip] foo.zip a b c\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
eprintf ("FMT %s\n", format);
|
|
|
|
eprintf ("PKG %s\n", file);
|
|
|
|
for (i = optind + 2; i < argc; i++) {
|
|
|
|
eprintf ("ADD %s\n", argv[i]);
|
|
|
|
r_list_append (files, argv[i]);
|
|
|
|
}
|
|
|
|
RBuffer *buf = r_bin_package (core.bin, format, file, files);
|
|
|
|
/* TODO: return bool or something to catch errors\n") */
|
|
|
|
if (buf) {
|
|
|
|
bool ret = r_buf_dump (buf, file);
|
|
|
|
r_buf_free (buf);
|
|
|
|
if (!ret) {
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_core_fini (&core);
|
|
|
|
return rc;
|
|
|
|
}
|
2015-04-18 19:57:24 +00:00
|
|
|
|
2015-03-21 01:04:49 +00:00
|
|
|
if (file && *file) {
|
|
|
|
cf = r_core_file_open (&core, file, R_IO_READ, 0);
|
|
|
|
fd = cf ? r_core_file_cur_fd (&core) : -1;
|
|
|
|
if (!cf || fd == -1) {
|
2015-06-22 09:36:28 +00:00
|
|
|
eprintf ("r_core: Cannot open file '%s'\n", file);
|
2015-03-21 01:04:49 +00:00
|
|
|
r_core_fini (&core);
|
|
|
|
return 1;
|
|
|
|
}
|
2011-07-25 19:10:25 +00:00
|
|
|
}
|
2014-05-26 01:06:29 +00:00
|
|
|
|
2014-10-24 18:13:18 +00:00
|
|
|
bin->minstrlen = r_config_get_i (core.config, "bin.minstr");
|
2015-10-07 00:52:50 +00:00
|
|
|
bin->maxstrbuf = r_config_get_i (core.config, "bin.maxstrbuf");
|
|
|
|
|
2015-01-11 18:40:26 +00:00
|
|
|
r_bin_force_plugin (bin, forcebin);
|
2016-04-22 22:47:00 +00:00
|
|
|
r_bin_load_filter (bin, action);
|
2015-08-17 22:18:04 +00:00
|
|
|
if (!r_bin_load (bin, file, baddr, laddr, xtr_idx, fd, rawstr)) {
|
2016-08-26 20:21:06 +00:00
|
|
|
eprintf ("r_bin: Cannot open file\n");
|
|
|
|
r_core_fini (&core);
|
|
|
|
return 1;
|
2014-04-27 07:06:50 +00:00
|
|
|
}
|
2015-08-17 22:18:04 +00:00
|
|
|
if (baddr != UT64_MAX) {
|
2015-08-17 00:05:39 +00:00
|
|
|
r_bin_set_baddr (bin, baddr);
|
2015-01-29 00:45:39 +00:00
|
|
|
}
|
2014-10-24 16:25:27 +00:00
|
|
|
if (rawstr == 2) {
|
2015-09-14 00:08:31 +00:00
|
|
|
rawstr = false;
|
2014-10-24 16:25:27 +00:00
|
|
|
r_bin_dump_strings (core.bin->cur, bin->minstrlen);
|
|
|
|
}
|
2011-09-04 00:19:43 +00:00
|
|
|
|
2014-05-18 23:42:36 +00:00
|
|
|
if (query) {
|
2014-09-08 02:17:38 +00:00
|
|
|
if (rad) {
|
|
|
|
// TODO: Should be moved into core, to load those flags and formats into r2
|
|
|
|
Sdb *db = sdb_ns (bin->cur->sdb, "info", 0);
|
|
|
|
char *flagname;
|
|
|
|
if (db) {
|
|
|
|
SdbListIter *iter;
|
|
|
|
SdbKv *kv;
|
2014-09-08 10:20:50 +00:00
|
|
|
printf ("fs format\n");
|
2014-09-08 02:17:38 +00:00
|
|
|
// iterate over all keys
|
|
|
|
ls_foreach (db->ht->list, iter, kv) {
|
|
|
|
char *k = kv->key;
|
|
|
|
char *v = kv->value;
|
|
|
|
char *dup = strdup (k);
|
|
|
|
|
2016-02-04 14:44:49 +00:00
|
|
|
if ((flagname = strstr (dup, ".offset"))) {
|
2014-09-08 02:17:38 +00:00
|
|
|
*flagname = 0;
|
|
|
|
flagname = dup;
|
2014-09-08 02:37:34 +00:00
|
|
|
printf ("f %s @ %s\n", flagname, v);
|
2014-09-08 02:17:38 +00:00
|
|
|
}
|
2016-02-04 14:44:49 +00:00
|
|
|
if ((flagname = strstr (dup, ".cparse"))) {
|
2014-09-23 08:23:28 +00:00
|
|
|
printf ("\"td %s\"\n", v);
|
|
|
|
}
|
2016-02-04 14:44:49 +00:00
|
|
|
if ((flagname = strstr (dup, ".format"))) {
|
2014-09-08 02:17:38 +00:00
|
|
|
*flagname = 0;
|
|
|
|
flagname = dup;
|
2014-09-08 02:37:34 +00:00
|
|
|
printf ("pf.%s %s\n", flagname, v);
|
2014-09-08 02:17:38 +00:00
|
|
|
}
|
|
|
|
free (dup);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//sdb_query (bin->cur->sdb, "info/*");
|
|
|
|
} else {
|
|
|
|
if (!strcmp (query, "-")) {
|
|
|
|
__sdb_prompt (bin->cur->sdb);
|
2016-10-17 20:21:00 +00:00
|
|
|
} else {
|
|
|
|
sdb_query (bin->cur->sdb, query);
|
|
|
|
}
|
2014-09-08 02:17:38 +00:00
|
|
|
}
|
2014-08-19 23:21:31 +00:00
|
|
|
r_core_fini (&core);
|
2014-05-18 23:42:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-03-08 16:29:53 +00:00
|
|
|
#define isradjson (rad==R_CORE_BIN_JSON&&actions>0)
|
|
|
|
#define run_action(n,x,y) {\
|
|
|
|
if (action&x) {\
|
2015-05-28 23:38:31 +00:00
|
|
|
if (isradjson) r_cons_printf ("%s\"%s\":",actions_done?",":"",n);\
|
2015-08-28 18:14:26 +00:00
|
|
|
if (!r_core_bin_info (&core, y, rad, va, &filter, chksum)) {\
|
2016-06-26 04:16:57 +00:00
|
|
|
if (isradjson) r_cons_print ("false");\
|
2015-03-08 16:29:53 +00:00
|
|
|
};\
|
|
|
|
actions_done++;\
|
|
|
|
}\
|
|
|
|
}
|
2015-05-28 23:38:31 +00:00
|
|
|
core.bin = bin;
|
2015-08-08 18:15:13 +00:00
|
|
|
bin->cb_printf = r_cons_printf;
|
2015-05-28 23:38:31 +00:00
|
|
|
filter.offset = at;
|
|
|
|
filter.name = name;
|
2015-09-14 00:08:31 +00:00
|
|
|
r_cons_new ()->is_interactive = false;
|
2015-05-28 23:38:31 +00:00
|
|
|
|
2016-08-30 02:26:20 +00:00
|
|
|
if (isradjson) {
|
|
|
|
r_cons_print ("{");
|
|
|
|
}
|
2015-05-28 23:38:31 +00:00
|
|
|
// List fatmach0 sub-binaries, etc
|
2016-04-22 22:47:00 +00:00
|
|
|
if (action & R_BIN_REQ_LISTARCHS || ((arch || bits || arch_name) &&
|
2015-05-28 23:38:31 +00:00
|
|
|
!r_bin_select (bin, arch, bits, arch_name))) {
|
2016-10-04 12:34:06 +00:00
|
|
|
if (rad == R_CORE_BIN_SIMPLEST || rad == R_CORE_BIN_SIMPLE) {
|
|
|
|
r_bin_list_archs (bin, 'q');
|
|
|
|
} else {
|
|
|
|
r_bin_list_archs (bin, (rad == R_CORE_BIN_JSON)? 'j': 1);
|
|
|
|
}
|
2015-05-28 23:38:31 +00:00
|
|
|
actions_done++;
|
|
|
|
free (arch_name);
|
|
|
|
}
|
2016-04-22 22:47:00 +00:00
|
|
|
if (action & R_BIN_REQ_PDB_DWNLD) {
|
2015-03-08 16:29:53 +00:00
|
|
|
int ret;
|
2015-11-29 23:10:28 +00:00
|
|
|
char *path;
|
|
|
|
SPDBDownloaderOpt opt;
|
|
|
|
SPDBDownloader pdb_downloader;
|
|
|
|
RBinInfo *info = r_bin_get_info (core.bin);
|
2015-04-02 01:10:49 +00:00
|
|
|
char *env_pdbserver = r_sys_getenv ("PDB_SERVER");
|
2015-05-25 18:45:37 +00:00
|
|
|
char *env_pdbextract = r_sys_getenv("PDB_EXTRACT");
|
|
|
|
char *env_useragent = r_sys_getenv("PDB_USER_AGENT");
|
2015-05-09 22:05:34 +00:00
|
|
|
|
|
|
|
if (!info || !info->debug_file_name) {
|
|
|
|
eprintf ("Can't find debug filename\n");
|
|
|
|
r_core_fini (&core);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-01 12:57:36 +00:00
|
|
|
if (info->file) {
|
|
|
|
path = r_file_dirname (info->file);
|
|
|
|
} else {
|
|
|
|
path = strdup (".");
|
|
|
|
}
|
2015-05-25 18:45:37 +00:00
|
|
|
|
2016-10-17 20:21:00 +00:00
|
|
|
if (env_pdbserver && *env_pdbserver) {
|
2014-12-24 18:49:07 +00:00
|
|
|
r_config_set (core.config, "pdb.server", env_pdbserver);
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
|
|
|
if (env_useragent && *env_useragent) {
|
2015-05-26 00:45:25 +00:00
|
|
|
r_config_set (core.config, "pdb.user_agent", env_useragent);
|
2016-10-17 20:21:00 +00:00
|
|
|
}
|
|
|
|
if (env_pdbextract && *env_pdbextract) {
|
|
|
|
r_config_set_i (core.config, "pdb.extract", !(*env_pdbextract == '0'));
|
|
|
|
}
|
2015-05-26 00:45:25 +00:00
|
|
|
free (env_pdbextract);
|
|
|
|
free (env_useragent);
|
2015-05-25 18:45:37 +00:00
|
|
|
|
2014-12-11 14:33:32 +00:00
|
|
|
opt.dbg_file = info->debug_file_name;
|
|
|
|
opt.guid = info->guid;
|
2015-03-08 16:29:53 +00:00
|
|
|
opt.symbol_server = (char *)r_config_get (core.config, "pdb.server");
|
|
|
|
opt.user_agent = (char *)r_config_get (core.config, "pdb.user_agent");
|
2014-12-11 14:33:32 +00:00
|
|
|
opt.path = path;
|
2015-05-25 14:48:43 +00:00
|
|
|
opt.extract = r_config_get_i(core.config, "pdb.extract");
|
2014-12-11 14:33:32 +00:00
|
|
|
|
2015-03-08 16:29:53 +00:00
|
|
|
init_pdb_downloader (&opt, &pdb_downloader);
|
|
|
|
ret = pdb_downloader.download (&pdb_downloader);
|
|
|
|
if (isradjson) {
|
2015-05-28 23:38:31 +00:00
|
|
|
printf ("%s\"pdb\":{\"file\":\"%s\",\"download\":%s}",
|
|
|
|
actions_done?",":"", opt.dbg_file, ret?"true":"false");
|
2014-12-11 14:33:32 +00:00
|
|
|
} else {
|
2015-03-08 16:29:53 +00:00
|
|
|
printf ("PDB \"%s\" download %s\n",
|
|
|
|
opt.dbg_file, ret? "success": "failed");
|
2014-12-11 14:33:32 +00:00
|
|
|
}
|
2015-05-28 23:38:31 +00:00
|
|
|
actions_done++;
|
2015-03-08 16:29:53 +00:00
|
|
|
deinit_pdb_downloader (&pdb_downloader);
|
2014-12-11 14:33:32 +00:00
|
|
|
|
2015-03-08 16:29:53 +00:00
|
|
|
free (path);
|
2014-12-11 14:33:32 +00:00
|
|
|
r_core_fini (&core);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-22 09:36:28 +00:00
|
|
|
|
2015-10-22 18:26:24 +00:00
|
|
|
if ((tmp = r_sys_getenv ("RABIN2_PREFIX"))) {
|
|
|
|
r_config_set (core.config, "bin.prefix", tmp);
|
|
|
|
free (tmp);
|
|
|
|
}
|
|
|
|
|
2016-04-22 22:47:00 +00:00
|
|
|
run_action ("sections", R_BIN_REQ_SECTIONS, R_CORE_BIN_ACC_SECTIONS);
|
|
|
|
run_action ("entries", R_BIN_REQ_ENTRIES, R_CORE_BIN_ACC_ENTRIES);
|
|
|
|
run_action ("main", R_BIN_REQ_MAIN, R_CORE_BIN_ACC_MAIN);
|
|
|
|
run_action ("imports", R_BIN_REQ_IMPORTS, R_CORE_BIN_ACC_IMPORTS);
|
|
|
|
run_action ("classes", R_BIN_REQ_CLASSES, R_CORE_BIN_ACC_CLASSES);
|
|
|
|
run_action ("symbols", R_BIN_REQ_SYMBOLS, R_CORE_BIN_ACC_SYMBOLS);
|
|
|
|
run_action ("exports", R_BIN_REQ_EXPORTS, R_CORE_BIN_ACC_EXPORTS);
|
|
|
|
run_action ("strings", R_BIN_REQ_STRINGS, R_CORE_BIN_ACC_STRINGS);
|
|
|
|
run_action ("info", R_BIN_REQ_INFO, R_CORE_BIN_ACC_INFO);
|
|
|
|
run_action ("fields", R_BIN_REQ_FIELDS, R_CORE_BIN_ACC_FIELDS);
|
|
|
|
run_action ("libs", R_BIN_REQ_LIBS, R_CORE_BIN_ACC_LIBS);
|
|
|
|
run_action ("relocs", R_BIN_REQ_RELOCS, R_CORE_BIN_ACC_RELOCS);
|
|
|
|
run_action ("dwarf", R_BIN_REQ_DWARF, R_CORE_BIN_ACC_DWARF);
|
|
|
|
run_action ("pdb", R_BIN_REQ_PDB, R_CORE_BIN_ACC_PDB);
|
|
|
|
run_action ("size", R_BIN_REQ_SIZE, R_CORE_BIN_ACC_SIZE);
|
|
|
|
run_action ("versioninfo", R_BIN_REQ_VERSIONINFO, R_CORE_BIN_ACC_VERSIONINFO);
|
|
|
|
if (action & R_BIN_REQ_SRCLINE) {
|
2011-10-09 23:48:08 +00:00
|
|
|
rabin_show_srcline (at);
|
2016-02-04 14:44:49 +00:00
|
|
|
}
|
2016-04-22 22:47:00 +00:00
|
|
|
if (action & R_BIN_REQ_EXTRACT) {
|
2016-02-04 14:44:49 +00:00
|
|
|
RListIter *iter;
|
|
|
|
RBinXtrPlugin *xtr;
|
2016-03-24 07:09:21 +00:00
|
|
|
bool supported = false;
|
|
|
|
|
2016-02-04 14:44:49 +00:00
|
|
|
r_list_foreach (bin->binxtrs, iter, xtr) {
|
|
|
|
if (xtr->check (bin)) {
|
|
|
|
// xtr->extractall (bin);
|
|
|
|
rabin_extract ((!arch && !arch_name && !bits));
|
2016-03-24 07:09:21 +00:00
|
|
|
supported = true;
|
2016-02-04 14:44:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-24 07:09:21 +00:00
|
|
|
|
|
|
|
if (!supported) {
|
|
|
|
// if we reach here, no supported xtr plugins found
|
|
|
|
eprintf ("Cannot extract bins from '%s'. No supported plugins found!\n", bin->file);
|
|
|
|
}
|
2016-02-04 14:44:49 +00:00
|
|
|
}
|
2016-08-30 02:26:20 +00:00
|
|
|
if (op && action & R_BIN_REQ_OPERATION) {
|
2010-05-28 15:15:20 +00:00
|
|
|
rabin_do_operation (op);
|
2016-08-30 02:26:20 +00:00
|
|
|
}
|
|
|
|
if (isradjson) {
|
2012-11-02 02:35:50 +00:00
|
|
|
printf ("}");
|
2016-08-30 02:26:20 +00:00
|
|
|
}
|
2011-11-12 03:51:45 +00:00
|
|
|
r_cons_flush ();
|
2013-09-27 18:24:59 +00:00
|
|
|
r_core_fini (&core);
|
2016-08-02 00:11:32 +00:00
|
|
|
free (stdin_buf);
|
2010-05-28 15:15:20 +00:00
|
|
|
|
2010-09-24 19:23:13 +00:00
|
|
|
return 0;
|
2010-05-28 15:15:20 +00:00
|
|
|
}
|