2015-03-16 01:52:26 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2015 - pancake, nibble */
|
2009-02-06 17:22:27 +00:00
|
|
|
|
2009-02-15 23:57:03 +00:00
|
|
|
#include <r_anal.h>
|
|
|
|
#include <r_util.h>
|
2010-02-26 12:08:42 +00:00
|
|
|
#include <r_list.h>
|
2011-12-16 15:33:06 +00:00
|
|
|
#include <r_io.h>
|
2010-02-28 19:07:36 +00:00
|
|
|
#include "../config.h"
|
|
|
|
|
2013-06-14 00:51:33 +00:00
|
|
|
R_LIB_VERSION(r_anal);
|
|
|
|
|
2012-07-19 02:54:22 +00:00
|
|
|
static RAnalPlugin *anal_static_plugins[] =
|
2010-02-28 19:07:36 +00:00
|
|
|
{ R_ANAL_STATIC_PLUGINS };
|
2009-02-15 23:57:03 +00:00
|
|
|
|
2013-08-13 01:23:39 +00:00
|
|
|
static void r_anal_type_init(RAnal *anal) {
|
|
|
|
Sdb *D = anal->sdb_types;
|
2013-09-01 23:20:12 +00:00
|
|
|
sdb_set (D, "unsigned int", "type", 0);
|
2014-07-01 21:59:44 +00:00
|
|
|
sdb_set (D, "unsigned char", "type", 0);
|
|
|
|
sdb_set (D, "unsigned short", "type", 0);
|
2013-09-01 23:20:12 +00:00
|
|
|
sdb_set (D, "int", "type", 0);
|
|
|
|
sdb_set (D, "long", "type", 0);
|
|
|
|
sdb_set (D, "void *", "type", 0);
|
|
|
|
sdb_set (D, "char", "type", 0);
|
2014-07-01 21:59:44 +00:00
|
|
|
sdb_set (D, "char *", "type", 0);
|
2013-09-01 23:20:12 +00:00
|
|
|
sdb_set (D, "const char*", "type", 0);
|
2015-08-04 22:37:53 +00:00
|
|
|
sdb_set (D, "uint8_t", "type", 0);
|
|
|
|
sdb_set (D, "uint16_t", "type", 0);
|
|
|
|
sdb_set (D, "uint32_t", "type", 0);
|
|
|
|
sdb_set (D, "uint64_t", "type", 0);
|
2013-08-13 01:23:39 +00:00
|
|
|
sdb_set (D, "type.unsigned int", "i", 0);
|
2014-07-01 21:59:44 +00:00
|
|
|
sdb_set (D, "type.unsigned char", "b", 0);
|
|
|
|
sdb_set (D, "type.unsigned short", "w", 0);
|
2013-08-13 01:23:39 +00:00
|
|
|
sdb_set (D, "type.int", "d", 0);
|
|
|
|
sdb_set (D, "type.long", "x", 0);
|
|
|
|
sdb_set (D, "type.void *", "p", 0);
|
2015-08-04 22:37:53 +00:00
|
|
|
sdb_set (D, "type.char", "b", 0);
|
2014-07-01 21:59:44 +00:00
|
|
|
sdb_set (D, "type.char *", "*z", 0);
|
2013-08-13 01:23:39 +00:00
|
|
|
sdb_set (D, "type.const char*", "*z", 0);
|
2015-08-04 22:37:53 +00:00
|
|
|
sdb_set (D, "type.uint8_t", "b", 0);
|
|
|
|
sdb_set (D, "type.uint16_t", "w", 0);
|
|
|
|
sdb_set (D, "type.uint32_t", "d", 0);
|
|
|
|
sdb_set (D, "type.uint64_t", "q", 0);
|
2013-08-13 01:23:39 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 03:05:19 +00:00
|
|
|
R_API void r_anal_set_limits(RAnal *anal, ut64 from, ut64 to) {
|
|
|
|
free (anal->limit);
|
|
|
|
anal->limit = R_NEW0 (RAnalRange);
|
2015-06-17 10:36:08 +00:00
|
|
|
if (anal->limit) {
|
|
|
|
anal->limit->from = from;
|
|
|
|
anal->limit->to = to;
|
|
|
|
}
|
2014-11-03 03:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_anal_unset_limits(RAnal *anal) {
|
|
|
|
free (anal->limit);
|
|
|
|
anal->limit = NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-15 02:19:29 +00:00
|
|
|
static void meta_unset_for(void *user, int idx) {
|
|
|
|
RSpaces *s = (RSpaces*)user;
|
|
|
|
RAnal *anal = (RAnal*)s->user;
|
|
|
|
r_meta_space_unset_for (anal, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meta_count_for(void *user, int idx) {
|
|
|
|
int ret;
|
|
|
|
RSpaces *s = (RSpaces*)user;
|
|
|
|
RAnal *anal = (RAnal*)s->user;
|
|
|
|
ret = r_meta_space_count_for (anal, idx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API RAnal *r_anal_new() {
|
2010-02-28 19:07:36 +00:00
|
|
|
int i;
|
2010-06-04 21:47:35 +00:00
|
|
|
RAnalPlugin *static_plugin;
|
2013-04-18 01:58:44 +00:00
|
|
|
RAnal *anal = R_NEW0 (RAnal);
|
2013-02-12 01:42:34 +00:00
|
|
|
if (!anal) return NULL;
|
2015-10-30 02:07:22 +00:00
|
|
|
anal->os = strdup (R_SYS_OS);
|
2015-11-12 12:47:44 +00:00
|
|
|
anal->noreturn = r_list_newf ((RListFree)&r_anal_noreturn_free);
|
2015-09-08 21:21:35 +00:00
|
|
|
anal->reflines = anal->reflines2 = NULL;
|
2015-03-31 22:38:24 +00:00
|
|
|
anal->esil_goto_limit = R_ANAL_ESIL_GOTO_LIMIT;
|
2014-11-03 03:05:19 +00:00
|
|
|
anal->limit = NULL;
|
2015-09-14 09:31:54 +00:00
|
|
|
anal->opt.nopskip = true; // skip nops in code analysis
|
|
|
|
anal->decode = true; // slow slow if not used
|
2014-11-07 02:48:27 +00:00
|
|
|
anal->gp = 0LL;
|
|
|
|
anal->sdb = sdb_new0 ();
|
2015-09-14 09:31:54 +00:00
|
|
|
anal->opt.noncode = false; // do not analyze data by default
|
2014-06-05 22:06:30 +00:00
|
|
|
anal->sdb_fcns = sdb_ns (anal->sdb, "fcns", 1);
|
|
|
|
anal->sdb_meta = sdb_ns (anal->sdb, "meta", 1);
|
2015-06-15 02:19:29 +00:00
|
|
|
r_space_init (&anal->meta_spaces,
|
|
|
|
meta_unset_for, meta_count_for, anal);
|
2014-06-05 22:06:30 +00:00
|
|
|
anal->sdb_hints = sdb_ns (anal->sdb, "hints", 1);
|
|
|
|
anal->sdb_xrefs = sdb_ns (anal->sdb, "xrefs", 1);
|
|
|
|
anal->sdb_types = sdb_ns (anal->sdb, "types", 1);
|
2015-08-08 18:15:13 +00:00
|
|
|
anal->cb_printf = (PrintfCallback) printf;
|
2015-06-30 08:50:46 +00:00
|
|
|
r_anal_pin_init (anal);
|
2013-08-13 01:23:39 +00:00
|
|
|
r_anal_type_init (anal);
|
2013-04-18 01:58:44 +00:00
|
|
|
r_anal_xrefs_init (anal);
|
2011-10-14 08:09:53 +00:00
|
|
|
anal->diff_thbb = R_ANAL_THRESHOLDBB;
|
|
|
|
anal->diff_thfcn = R_ANAL_THRESHOLDFCN;
|
2015-09-14 09:31:54 +00:00
|
|
|
anal->split = true; // used from core
|
2011-02-03 08:31:50 +00:00
|
|
|
anal->syscall = r_syscall_new ();
|
|
|
|
r_io_bind_init (anal->iob);
|
2014-09-26 12:24:33 +00:00
|
|
|
r_flag_bind_init (anal->flb);
|
2011-02-18 12:08:09 +00:00
|
|
|
anal->reg = r_reg_new ();
|
2011-02-03 08:31:50 +00:00
|
|
|
anal->lineswidth = 0;
|
|
|
|
anal->fcns = r_anal_fcn_list_new ();
|
2013-02-12 01:42:34 +00:00
|
|
|
#if USE_NEW_FCN_STORE
|
2011-09-14 00:07:06 +00:00
|
|
|
anal->fcnstore = r_listrange_new ();
|
2013-02-12 01:42:34 +00:00
|
|
|
#endif
|
2011-02-03 08:31:50 +00:00
|
|
|
anal->refs = r_anal_ref_list_new ();
|
2012-07-19 02:54:22 +00:00
|
|
|
anal->types = r_anal_type_list_new ();
|
2011-02-03 08:31:50 +00:00
|
|
|
r_anal_set_bits (anal, 32);
|
2015-09-14 09:31:54 +00:00
|
|
|
r_anal_set_big_endian (anal, false);
|
2014-03-25 11:05:34 +00:00
|
|
|
anal->plugins = r_list_new ();
|
2014-04-18 15:18:48 +00:00
|
|
|
anal->plugins->free = (RListFree) r_anal_plugin_free;
|
2011-02-03 08:31:50 +00:00
|
|
|
for (i=0; anal_static_plugins[i]; i++) {
|
|
|
|
static_plugin = R_NEW (RAnalPlugin);
|
2014-03-26 16:23:46 +00:00
|
|
|
*static_plugin = *anal_static_plugins[i];
|
2011-02-03 08:31:50 +00:00
|
|
|
r_anal_add (anal, static_plugin);
|
2010-01-31 01:30:59 +00:00
|
|
|
}
|
2015-07-31 10:40:04 +00:00
|
|
|
|
2010-01-31 01:30:59 +00:00
|
|
|
return anal;
|
2009-02-06 17:22:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 11:05:34 +00:00
|
|
|
R_API void r_anal_plugin_free (RAnalPlugin *p) {
|
|
|
|
if (p && p->fini) {
|
|
|
|
p->fini (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-29 14:26:43 +00:00
|
|
|
R_API RAnal *r_anal_free(RAnal *a) {
|
|
|
|
if (!a) return NULL;
|
2011-11-13 23:21:25 +00:00
|
|
|
/* TODO: Free anals here */
|
2014-09-21 23:39:24 +00:00
|
|
|
R_FREE (a->cpu);
|
2014-03-25 11:05:34 +00:00
|
|
|
r_list_free (a->plugins);
|
2015-11-12 12:47:44 +00:00
|
|
|
r_list_free (a->noreturn);
|
2014-02-20 01:11:04 +00:00
|
|
|
a->fcns->free = r_anal_fcn_free;
|
|
|
|
r_list_free (a->fcns);
|
2015-06-15 02:19:29 +00:00
|
|
|
r_space_fini (&a->meta_spaces);
|
2015-06-30 08:50:46 +00:00
|
|
|
r_anal_pin_fini (a);
|
2014-02-20 01:11:04 +00:00
|
|
|
r_list_free (a->refs);
|
|
|
|
r_list_free (a->types);
|
2014-04-01 23:32:18 +00:00
|
|
|
r_reg_free (a->reg);
|
2014-02-20 01:11:04 +00:00
|
|
|
r_anal_op_free (a->queued);
|
2014-04-01 02:03:48 +00:00
|
|
|
a->sdb = NULL;
|
2014-04-01 23:32:18 +00:00
|
|
|
r_syscall_free (a->syscall);
|
|
|
|
sdb_ns_free (a->sdb);
|
2014-12-09 22:28:26 +00:00
|
|
|
if (a->esil) {
|
2014-08-07 12:37:55 +00:00
|
|
|
r_anal_esil_free (a->esil);
|
2014-12-09 22:28:26 +00:00
|
|
|
a->esil = NULL;
|
|
|
|
}
|
2014-08-29 14:26:43 +00:00
|
|
|
memset (a, 0, sizeof (RAnal));
|
2014-02-20 01:11:04 +00:00
|
|
|
free (a);
|
2014-08-29 14:26:43 +00:00
|
|
|
return NULL;
|
2010-05-20 15:40:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API void r_anal_set_user_ptr(RAnal *anal, void *user) {
|
2009-02-15 23:57:03 +00:00
|
|
|
anal->user = user;
|
2009-02-06 17:22:27 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 23:42:22 +00:00
|
|
|
R_API int r_anal_add(RAnal *anal, RAnalPlugin *foo) {
|
2009-02-15 23:57:03 +00:00
|
|
|
if (foo->init)
|
2010-06-16 07:42:46 +00:00
|
|
|
foo->init (anal->user);
|
2014-03-25 11:05:34 +00:00
|
|
|
r_list_append (anal->plugins, foo);
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2009-02-06 17:22:27 +00:00
|
|
|
}
|
2009-02-08 23:19:06 +00:00
|
|
|
|
2009-10-12 15:41:52 +00:00
|
|
|
// TODO: Must be deprecated
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API int r_anal_list(RAnal *anal) {
|
2014-03-25 11:05:34 +00:00
|
|
|
RAnalPlugin *h;
|
|
|
|
RListIter *it;
|
|
|
|
r_list_foreach (anal->plugins, it, h) {
|
2015-08-08 18:15:13 +00:00
|
|
|
anal->cb_printf ("anal %-10s %s\n", h->name, h->desc);
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
2015-09-14 09:31:54 +00:00
|
|
|
return false;
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API int r_anal_use(RAnal *anal, const char *name) {
|
2014-03-25 11:05:34 +00:00
|
|
|
RListIter *it;
|
|
|
|
RAnalPlugin *h;
|
|
|
|
r_list_foreach (anal->plugins, it, h) {
|
2010-02-02 10:09:52 +00:00
|
|
|
if (!strcmp (h->name, name)) {
|
2009-02-15 23:57:03 +00:00
|
|
|
anal->cur = h;
|
2011-02-18 12:08:09 +00:00
|
|
|
r_anal_set_reg_profile (anal);
|
2015-10-30 02:07:22 +00:00
|
|
|
r_anal_set_fcnsign (anal, NULL);
|
2014-08-07 12:37:55 +00:00
|
|
|
if (anal->esil) {
|
|
|
|
r_anal_esil_free (anal->esil);
|
|
|
|
anal->esil = NULL;
|
|
|
|
}
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-14 09:31:54 +00:00
|
|
|
return false;
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 12:08:09 +00:00
|
|
|
R_API int r_anal_set_reg_profile(RAnal *anal) {
|
2011-09-14 00:07:06 +00:00
|
|
|
if (anal && anal->cur && anal->cur->set_reg_profile)
|
2011-02-18 12:08:09 +00:00
|
|
|
return anal->cur->set_reg_profile (anal);
|
2015-09-14 09:31:54 +00:00
|
|
|
return false;
|
2011-02-18 12:08:09 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 02:07:22 +00:00
|
|
|
R_API bool r_anal_set_fcnsign(RAnal *anal, const char *name) {
|
|
|
|
#define FCNSIGNPATH R2_LIBDIR"/radare2/"R2_VERSION"/fcnsign"
|
|
|
|
char *file = NULL;
|
|
|
|
const char *arch;
|
|
|
|
if (anal->cur && anal->cur->arch) {
|
|
|
|
arch = anal->cur->arch;
|
|
|
|
} else arch = R_SYS_ARCH;
|
2016-01-18 23:35:13 +00:00
|
|
|
if (!arch) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-30 02:07:22 +00:00
|
|
|
if (name && *name) {
|
|
|
|
file = sdb_fmt (0, "%s/%s.sdb", FCNSIGNPATH, name);
|
|
|
|
} else {
|
|
|
|
file = sdb_fmt (0, "%s/%s-%s-%d.sdb", FCNSIGNPATH,
|
|
|
|
anal->os, arch, anal->bits);
|
|
|
|
}
|
|
|
|
if (r_file_exists (file)) {
|
|
|
|
sdb_close (anal->sdb_fcnsign);
|
|
|
|
sdb_free (anal->sdb_fcnsign);
|
|
|
|
anal->sdb_fcnsign = sdb_new (0, file, 0);
|
|
|
|
return (anal->sdb_fcnsign != NULL);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API const char *r_anal_get_fcnsign(RAnal *anal, const char *sym) {
|
|
|
|
return sdb_const_get (anal->sdb_fcnsign, sym, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_anal_set_triplet(RAnal *anal, const char *os, const char *arch, int bits) {
|
|
|
|
if (!os || !*os) os = R_SYS_OS;
|
|
|
|
if (!arch || !*arch) arch = anal->cur? anal->cur->arch: R_SYS_ARCH;
|
|
|
|
if (bits<1) bits = anal->bits;
|
|
|
|
free (anal->os);
|
|
|
|
anal->os = strdup (os);
|
|
|
|
r_anal_set_bits (anal, bits);
|
|
|
|
return r_anal_use (anal, arch);
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_anal_set_os(RAnal *anal, const char *os) {
|
|
|
|
return r_anal_set_triplet (anal, os, NULL, -1);
|
|
|
|
}
|
|
|
|
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API int r_anal_set_bits(RAnal *anal, int bits) {
|
2009-02-15 23:57:03 +00:00
|
|
|
switch (bits) {
|
2009-08-14 00:37:18 +00:00
|
|
|
case 8:
|
2009-02-15 23:57:03 +00:00
|
|
|
case 16:
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
anal->bits = bits;
|
2015-10-30 02:07:22 +00:00
|
|
|
r_anal_set_fcnsign (anal, NULL);
|
2011-02-18 12:08:09 +00:00
|
|
|
r_anal_set_reg_profile (anal);
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
2015-09-14 09:31:54 +00:00
|
|
|
return false;
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 20:08:46 +00:00
|
|
|
R_API void r_anal_set_cpu(RAnal *anal, const char *cpu) {
|
2014-02-21 00:59:32 +00:00
|
|
|
free (anal->cpu);
|
|
|
|
anal->cpu = cpu ? strdup (cpu) : NULL;
|
2014-02-05 20:08:46 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 11:00:04 +00:00
|
|
|
R_API int r_anal_set_big_endian(RAnal *anal, int bigend) {
|
2009-09-09 00:35:00 +00:00
|
|
|
anal->big_endian = bigend;
|
2014-11-03 19:49:37 +00:00
|
|
|
anal->reg->big_endian = bigend;
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2009-02-15 23:57:03 +00:00
|
|
|
}
|
2010-05-16 12:04:08 +00:00
|
|
|
|
|
|
|
R_API char *r_anal_strmask (RAnal *anal, const char *data) {
|
2011-02-24 13:06:49 +00:00
|
|
|
RAnalOp *op;
|
2010-05-16 12:04:08 +00:00
|
|
|
ut8 *buf;
|
|
|
|
char *ret = NULL;
|
|
|
|
int oplen, len, idx = 0;
|
|
|
|
|
|
|
|
ret = strdup (data);
|
2011-05-11 17:19:53 +00:00
|
|
|
buf = malloc (1+strlen (data));
|
2011-02-24 13:06:49 +00:00
|
|
|
op = r_anal_op_new ();
|
|
|
|
if (op == NULL || ret == NULL || buf == NULL) {
|
|
|
|
free (op);
|
2010-05-16 12:04:08 +00:00
|
|
|
free (buf);
|
|
|
|
free (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
len = r_hex_str2bin (data, buf);
|
|
|
|
while (idx < len) {
|
2014-09-30 01:38:24 +00:00
|
|
|
if ((oplen = r_anal_op (anal, op, 0, buf+idx, len-idx)) <1)
|
2010-05-16 12:04:08 +00:00
|
|
|
break;
|
2011-02-24 13:06:49 +00:00
|
|
|
switch (op->type) {
|
2010-05-16 12:04:08 +00:00
|
|
|
case R_ANAL_OP_TYPE_CALL:
|
2010-11-21 18:01:41 +00:00
|
|
|
case R_ANAL_OP_TYPE_UCALL:
|
2010-05-16 12:04:08 +00:00
|
|
|
case R_ANAL_OP_TYPE_CJMP:
|
|
|
|
case R_ANAL_OP_TYPE_JMP:
|
2010-11-21 18:01:41 +00:00
|
|
|
case R_ANAL_OP_TYPE_UJMP:
|
2011-02-24 13:06:49 +00:00
|
|
|
if (op->nopcode != 0)
|
2014-09-23 07:35:37 +00:00
|
|
|
memset (ret+(idx+op->nopcode)*2,
|
|
|
|
'.', (oplen-op->nopcode)*2);
|
2010-05-16 12:04:08 +00:00
|
|
|
}
|
|
|
|
idx += oplen;
|
|
|
|
}
|
2011-02-24 13:06:49 +00:00
|
|
|
free (op);
|
2010-05-16 12:04:08 +00:00
|
|
|
free (buf);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-12-06 15:26:21 +00:00
|
|
|
|
2011-02-11 10:22:43 +00:00
|
|
|
R_API void r_anal_trace_bb(RAnal *anal, ut64 addr) {
|
|
|
|
RAnalBlock *bbi;
|
2012-07-22 08:00:35 +00:00
|
|
|
RAnalFunction *fcni;
|
2014-11-03 10:47:51 +00:00
|
|
|
RListIter *iter2;
|
2014-11-02 00:21:45 +00:00
|
|
|
#define OLD 0
|
|
|
|
#if OLD
|
2014-11-07 02:48:27 +00:00
|
|
|
RListIter *iter;
|
2011-09-03 03:09:31 +00:00
|
|
|
r_list_foreach (anal->fcns, iter, fcni) {
|
2011-02-11 10:22:43 +00:00
|
|
|
r_list_foreach (fcni->bbs, iter2, bbi) {
|
|
|
|
if (addr>=bbi->addr && addr<(bbi->addr+bbi->size)) {
|
2015-09-14 09:31:54 +00:00
|
|
|
bbi->traced = true;
|
2011-02-11 10:22:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-09-03 03:09:31 +00:00
|
|
|
}
|
2014-11-02 00:21:45 +00:00
|
|
|
#else
|
|
|
|
fcni = r_anal_get_fcn_in (anal, addr, 0);
|
|
|
|
if (fcni) {
|
|
|
|
r_list_foreach (fcni->bbs, iter2, bbi) {
|
|
|
|
if (addr>=bbi->addr && addr<(bbi->addr+bbi->size)) {
|
2015-09-14 09:31:54 +00:00
|
|
|
bbi->traced = true;
|
2014-11-02 00:21:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-11 10:22:43 +00:00
|
|
|
}
|
2012-06-05 15:50:12 +00:00
|
|
|
|
2014-12-11 15:43:33 +00:00
|
|
|
R_API RList* r_anal_get_fcns (RAnal *anal) {
|
|
|
|
// avoid received to free this thing
|
|
|
|
anal->fcns->free = NULL;
|
|
|
|
return anal->fcns;
|
|
|
|
}
|
2013-04-18 01:58:44 +00:00
|
|
|
|
|
|
|
R_API int r_anal_project_load(RAnal *anal, const char *prjfile) {
|
2014-09-21 23:39:24 +00:00
|
|
|
if (prjfile && *prjfile)
|
|
|
|
return r_anal_xrefs_load (anal, prjfile);
|
2015-09-14 09:31:54 +00:00
|
|
|
return false;
|
2013-04-18 01:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_anal_project_save(RAnal *anal, const char *prjfile) {
|
|
|
|
if (!prjfile || !*prjfile)
|
2015-09-14 09:31:54 +00:00
|
|
|
return false;
|
2013-04-18 01:58:44 +00:00
|
|
|
r_anal_xrefs_save (anal, prjfile);
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2013-04-18 01:58:44 +00:00
|
|
|
}
|
2013-07-19 09:51:51 +00:00
|
|
|
|
|
|
|
R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr, const char *str) {
|
|
|
|
int len;
|
2013-10-24 11:59:19 +00:00
|
|
|
ut8 *buf;
|
2013-07-19 09:51:51 +00:00
|
|
|
RAnalOp *op = R_NEW0 (RAnalOp);
|
2014-05-12 00:15:57 +00:00
|
|
|
if (!op) return NULL;
|
2013-12-02 23:14:59 +00:00
|
|
|
buf = malloc (strlen (str)+1);
|
2014-05-16 23:04:52 +00:00
|
|
|
if (!buf) {
|
|
|
|
free (op);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-19 09:51:51 +00:00
|
|
|
len = r_hex_str2bin (str, buf);
|
|
|
|
r_anal_op (anal, op, addr, buf, len);
|
|
|
|
return op;
|
|
|
|
}
|
2014-08-24 12:35:15 +00:00
|
|
|
|
2015-12-01 11:39:12 +00:00
|
|
|
R_API bool r_anal_op_is_eob (RAnalOp *op) {
|
2014-08-24 12:35:15 +00:00
|
|
|
switch (op->type) {
|
|
|
|
case R_ANAL_OP_TYPE_JMP:
|
|
|
|
case R_ANAL_OP_TYPE_UJMP:
|
|
|
|
case R_ANAL_OP_TYPE_CJMP:
|
|
|
|
case R_ANAL_OP_TYPE_RET:
|
2014-08-27 01:42:32 +00:00
|
|
|
case R_ANAL_OP_TYPE_TRAP:
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
2014-08-24 12:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-22 01:22:29 +00:00
|
|
|
|
|
|
|
R_API int r_anal_purge (RAnal *anal) {
|
|
|
|
sdb_reset (anal->sdb_fcns);
|
|
|
|
sdb_reset (anal->sdb_meta);
|
|
|
|
sdb_reset (anal->sdb_hints);
|
|
|
|
sdb_reset (anal->sdb_xrefs);
|
|
|
|
sdb_reset (anal->sdb_types);
|
|
|
|
r_list_free (anal->fcns);
|
|
|
|
anal->fcns = r_anal_fcn_list_new ();
|
|
|
|
#if USE_NEW_FCN_STORE
|
|
|
|
r_listrange_free (anal->fcnstore);
|
|
|
|
anal->fcnstore = r_listrange_new ();
|
|
|
|
#endif
|
|
|
|
r_list_free (anal->refs);
|
|
|
|
anal->refs = r_anal_ref_list_new ();
|
|
|
|
r_list_free (anal->types);
|
|
|
|
anal->types = r_anal_type_list_new ();
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-14 00:11:53 +00:00
|
|
|
|
|
|
|
R_API int r_anal_archinfo(RAnal *anal, int query) {
|
|
|
|
switch (query) {
|
|
|
|
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
|
|
|
|
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
|
|
|
|
case R_ANAL_ARCHINFO_ALIGN:
|
|
|
|
if (anal && anal->cur && anal->cur->archinfo) {
|
|
|
|
return anal->cur->archinfo (anal, query);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2015-11-12 12:47:44 +00:00
|
|
|
|
|
|
|
R_API void r_anal_noreturn_free(RAnalNoreturn *nr) {
|
|
|
|
free (nr->name);
|
|
|
|
free (nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_anal_noreturn_list(RAnal *anal, int mode) {
|
|
|
|
RListIter *iter;
|
|
|
|
RAnalNoreturn *nr;
|
|
|
|
r_list_foreach (anal->noreturn, iter, nr) {
|
|
|
|
switch (mode) {
|
|
|
|
case 1:
|
|
|
|
case '*':
|
|
|
|
case 'r':
|
|
|
|
if (nr->name) anal->cb_printf ("ann %s\n", nr->name);
|
|
|
|
else anal->cb_printf ("0x%08"PFMT64x"\n", nr->addr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (nr->name) anal->cb_printf ("%s\n", nr->name);
|
|
|
|
else anal->cb_printf ("0x%08"PFMT64x"\n", nr->addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_anal_noreturn_add(RAnal *anal, const char *name, ut64 addr) {
|
|
|
|
RAnalNoreturn *nr = R_NEW0(RAnalNoreturn);
|
|
|
|
if (!nr) return false;
|
|
|
|
if (name && *name) nr->name = strdup (name);
|
|
|
|
nr->addr = addr;
|
|
|
|
if (!nr->name && !nr->addr) {
|
|
|
|
free (nr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
r_list_append (anal->noreturn, nr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_anal_noreturn_drop(RAnal *anal, const char *expr) {
|
|
|
|
bool ret = false;
|
|
|
|
if (!strcmp (expr, "*")) {
|
|
|
|
if (!r_list_empty (anal->noreturn)) {
|
|
|
|
r_list_free (anal->noreturn);
|
|
|
|
anal->noreturn = r_list_newf ((RListFree)&r_anal_noreturn_free);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RListIter *iter, *iter2;
|
|
|
|
RAnalNoreturn *nr;
|
|
|
|
if (!strncmp (expr, "0x", 2)) {
|
|
|
|
ut64 n = r_num_math (NULL, expr);
|
|
|
|
r_list_foreach_safe (anal->noreturn, iter, iter2, nr) {
|
|
|
|
if (nr->addr == n) {
|
|
|
|
r_list_delete (anal->noreturn, iter);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r_list_foreach_safe (anal->noreturn, iter, iter2, nr) {
|
|
|
|
if (r_str_glob (nr->name, expr)) {
|
|
|
|
r_list_delete (anal->noreturn, iter);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool r_anal_noreturn_at(RAnal *anal, ut64 addr) {
|
|
|
|
RListIter *iter;
|
|
|
|
RAnalNoreturn *nr;
|
|
|
|
RAnalFunction *f = r_anal_get_fcn_at (anal, addr, 0);
|
|
|
|
RFlagItem *fi = anal->flb.get_at (anal->flb.f, addr);
|
|
|
|
r_list_foreach (anal->noreturn, iter, nr) {
|
|
|
|
if (nr->name) {
|
|
|
|
RFlagItem *fi2 = anal->flb.get (anal->flb.f, nr->name);
|
|
|
|
if (fi2 && fi2->offset == addr)
|
|
|
|
return true;
|
|
|
|
if (f && !strcmp (f->name, nr->name))
|
|
|
|
return true;
|
|
|
|
if (fi && fi->name && !strcmp (fi->name, nr->name))
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (addr == nr->addr)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|