Deep integration of complex types - build fixed

This commit is contained in:
Anton Kochkov 2012-07-22 12:00:35 +04:00
parent e075a18b56
commit e43a1f921d
23 changed files with 249 additions and 277 deletions

View File

@ -10,6 +10,7 @@
static RAnalPlugin *anal_static_plugins[] =
{ R_ANAL_STATIC_PLUGINS };
/*
static RAnalVarType anal_default_vartypes[] =
{{ "char", "c", 1 },
{ "byte", "b", 1 },
@ -19,6 +20,7 @@ static RAnalVarType anal_default_vartypes[] =
{ "dword", "x", 4 },
{ "float", "f", 4 },
{ NULL, NULL, 0 }};
*/
R_API RAnal *r_anal_new() {
int i;
@ -49,9 +51,11 @@ R_API RAnal *r_anal_new() {
memcpy (static_plugin, anal_static_plugins[i], sizeof (RAnalPlugin));
r_anal_add (anal, static_plugin);
}
/*
for (i=0; anal_default_vartypes[i].name; i++)
r_anal_var_type_add (anal, anal_default_vartypes[i].name,
anal_default_vartypes[i].size, anal_default_vartypes[i].fmt);
*/
return anal;
}
@ -62,7 +66,7 @@ R_API void r_anal_free(RAnal *anal) {
r_list_free (anal->fcns);
// r_listrange_free (anal->fcnstore); // might provoke double frees since this is used in r_anal_fcn_insert()
r_list_free (anal->refs);
r_list_free (anal->vartypes);
r_list_free (anal->types);
r_list_free (anal->meta->data);
r_reg_free(anal->reg);
r_syscall_free(anal->syscall);
@ -166,7 +170,7 @@ R_API char *r_anal_strmask (RAnal *anal, const char *data) {
R_API void r_anal_trace_bb(RAnal *anal, ut64 addr) {
RAnalBlock *bbi;
RAnalFcn *fcni;
RAnalFunction *fcni;
RListIter *iter, *iter2;
VERBOSE_ANAL eprintf ("bbtraced\n"); // XXX Debug msg
r_list_foreach (anal->fcns, iter, fcni) {

View File

@ -114,7 +114,7 @@ R_API inline int r_anal_bb_is_in_offset (RAnalBlock *bb, ut64 off) {
R_API RAnalBlock *r_anal_bb_from_offset(RAnal *anal, ut64 off) {
RListIter *iter, *iter2;
RAnalFcn *fcn;
RAnalFunction *fcn;
RAnalBlock *bb;
r_list_foreach (anal->fcns, iter, fcn)
r_list_foreach (fcn->bbs, iter2, bb)

View File

@ -39,7 +39,7 @@ R_API void r_anal_cc_reset (RAnalCC *cc) {
//XXX: may overflow. this is vulnerable. needs fix
R_API char *r_anal_cc_to_string (RAnal *anal, RAnalCC* cc) {
RSyscallItem *si;
RAnalFcn *fcn;
RAnalFunction *fcn;
char str[1024], buf[64];
int i, eax = 0; // eax = arg0

View File

@ -7,6 +7,7 @@ static int new_tree() {
return 0;
}
#if 0
static int print_tree(RAnalType *t) {
RAnalType *p = t;
if (!p) {
@ -44,6 +45,7 @@ static int print_tree(RAnalType *t) {
}
return R_TRUE;
}
#endif
RAnalType* new_variable_node(char* name, short type, short sign, short modifier) {
RAnalTypeVar *ivar = R_NEW (RAnalTypeVar);

View File

@ -75,7 +75,7 @@ R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) {
return bb->size;
}
R_API int r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFcn *fcn) {
R_API int r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn) {
RAnalBlock *bb;
RListIter *iter;
int len = 0;
@ -94,7 +94,7 @@ R_API int r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFcn *fcn) {
return len;
}
R_API int r_anal_diff_bb(RAnal *anal, RAnalFcn *fcn, RAnalFcn *fcn2) {
R_API int r_anal_diff_bb(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2) {
RAnalBlock *bb, *bb2, *mbb, *mbb2;
RListIter *iter, *iter2;
double t, ot;
@ -141,7 +141,7 @@ R_API int r_anal_diff_bb(RAnal *anal, RAnalFcn *fcn, RAnalFcn *fcn2) {
}
R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) {
RAnalFcn *fcn, *fcn2, *mfcn, *mfcn2;
RAnalFunction *fcn, *fcn2, *mfcn, *mfcn2;
RListIter *iter, *iter2;
ut64 maxsize, minsize;
double t, ot;

View File

@ -24,8 +24,6 @@ R_API RAnalFunction *r_anal_fcn_new() {
/* Function attributes: weak/noreturn/format/etc */
fcn->attr = NULL;
fcn->addr = -1;
fcn->stack = 0;
fcn->size = 0;
fcn->vars = r_anal_var_list_new ();
fcn->refs = r_anal_ref_list_new ();
fcn->xrefs = r_anal_ref_list_new ();
@ -123,11 +121,11 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut64
if (op.ref > 0) {
varname = r_str_dup_printf ("arg_%x", op.ref);
r_anal_var_add (anal, fcn, op.addr, op.ref,
R_ANAL_VAR_TYPE_ARG|R_ANAL_VAR_DIR_IN, NULL, varname, 1);
R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_DIR_IN, NULL, varname, 1);
} else {
varname = r_str_dup_printf ("local_%x", -op.ref);
r_anal_var_add (anal, fcn, op.addr, -op.ref,
R_ANAL_VAR_TYPE_LOCAL|R_ANAL_VAR_DIR_NONE, NULL, varname, 1);
R_ANAL_VAR_SCOPE_LOCAL|R_ANAL_VAR_DIR_NONE, NULL, varname, 1);
}
free (varname);
break;
@ -135,11 +133,11 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut64
if (op.ref > 0) {
varname = r_str_dup_printf ("arg_%x", op.ref);
r_anal_var_add (anal, fcn, op.addr, op.ref,
R_ANAL_VAR_TYPE_ARG|R_ANAL_VAR_DIR_IN, NULL, varname, 0);
R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_DIR_IN, NULL, varname, 0);
} else {
varname = r_str_dup_printf ("local_%x", -op.ref);
r_anal_var_add (anal, fcn, op.addr, -op.ref,
R_ANAL_VAR_TYPE_LOCAL|R_ANAL_VAR_DIR_NONE, NULL, varname, 0);
R_ANAL_VAR_SCOPE_LOCAL|R_ANAL_VAR_DIR_NONE, NULL, varname, 0);
}
free (varname);
break;
@ -406,36 +404,57 @@ R_API char *r_anal_fcn_to_string(RAnal *a, RAnalFunction* fs) {
RAnalVar *arg, *ret;
if (fs->type != R_ANAL_FCN_TYPE_FCN || fs->type != R_ANAL_FCN_TYPE_SYM)
return NULL;
ret = r_anal_fcn_get_var (fs, 0, R_ANAL_VAR_TYPE_RET);
ret = r_anal_fcn_get_var (fs, 0, R_ANAL_VAR_SCOPE_RET);
sign = ret? r_str_newf ("%s %s (", ret->name, fs->name):
r_str_newf ("void %s (", fs->name);
/* FIXME: Use RAnalType instead */
for (i=0; ; i++) {
if (!(arg = r_anal_fcn_get_var (fs, i,
R_ANAL_VAR_TYPE_ARG|R_ANAL_VAR_TYPE_ARGREG)))
R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_SCOPE_ARGREG)))
break;
if (arg->type->type == R_ANAL_TYPE_ARRAY)
sign = r_str_concatf (sign, i?", %s %s:%02x[%d]":"%s %s:%02x[%d]",
arg->vartype, arg->name, arg->delta, arg->array);
arg->type, arg->name, arg->delta, arg->type->custom.a->count);
else sign = r_str_concatf (sign, i?", %s %s:%02x":"%s %s:%02x",
arg->vartype, arg->name, arg->delta);
arg->type, arg->name, arg->delta);
}
return (sign = r_str_concatf (sign, ");"));
}
// TODO: This function is not fully implemented
/* set function signature from string */
R_API int r_anal_fcn_from_string(RAnal *a, RAnalFunction *f, const char *sig) {
R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *sig) {
char *p, *q, *r, *str;
RAnalVar *var;
RAnalType *t;
int i, arg;
if (!a || !f || !sig) {
eprintf ("r_anal_fcn_from_string: No function received\n");
eprintf ("r_anal_str_to_fcn: No function received\n");
return R_FALSE;
}
/* Add 'function' keyword */
str = malloc(strlen(sig) + 10);
strcpy(str, "function ");
strcat(str, sig);
/* Send whole definition to cparse */
int yv, yylval;
void *pParser = cdataParseAlloc(malloc);
yy_scan_string(str);
while ((yv = yylex()) != 0) {
cdataParse(pParser, yv, yylval);
}
cdataParse(pParser, 0, yylval);
cdataParseFree(pParser, free);
/* TODO: Improve arguments parsing */
/*
str = strdup (sig);
/* TODO : implement parser */
// TODO : implement parser
//r_list_destroy (fs->vars);
//set: fs->vars = r_list_new ();
//set: fs->name
@ -448,15 +467,15 @@ R_API int r_anal_fcn_from_string(RAnal *a, RAnalFunction *f, const char *sig) {
*q = 0;
printf ("RET=(%s)\n", str);
printf ("NAME=(%s)\n", q+1);
/* set function name */
// set function name
free (f->name);
f->name = strdup (q+1);
/* set return value */
// set return value
// TODO: simplify this complex api usage
r_anal_var_add (a, f, 0LL, 0,
R_ANAL_VAR_TYPE_RET|R_ANAL_VAR_DIR_OUT, str, "ret", 1);
R_ANAL_VAR_SCOPE_RET|R_ANAL_VAR_DIR_OUT, t, "ret", 1);
/* parse arguments */
// parse arguments
for (i=arg=0,p++;;p=q+1,i++) {
q = strchr (p, ',');
if (!q) {
@ -471,20 +490,22 @@ R_API int r_anal_fcn_from_string(RAnal *a, RAnalFunction *f, const char *sig) {
r = r_str_chop (r+1);
printf ("VAR %d=(%s)(%s)\n", arg, p, r);
// TODO : increment arg by var size
if ((var = r_anal_fcn_get_var (f, i, R_ANAL_VAR_TYPE_ARG|R_ANAL_VAR_TYPE_ARGREG))) {
free (var->name); var->name = strdup (r);
free (var->vartype); var->vartype = strdup (p);
} else r_anal_var_add (a, f, 0LL, arg, R_ANAL_VAR_TYPE_ARG|R_ANAL_VAR_DIR_IN, p, r, 0);
if ((var = r_anal_fcn_get_var (f, i, R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_SCOPE_ARGREG))) {
free (var->name); var->name = strdup(r);
// FIXME: add cparse function
free (var->type); var->type = r_anal_str_to_type(p);
} else r_anal_var_add (a, f, 0LL, arg, R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_DIR_IN, p, r, 0);
arg++;
}
// r_anal_fcn_set_var (fs, 0, R_ANAL_VAR_DIR_OUT, );
free (str);
*/
return R_TRUE;
parsefail:
free (str);
eprintf ("Function string parse fail\n");
return R_FALSE;
//parsefail:
//free (str);
//eprintf ("Function string parse fail\n");
//return R_FALSE;
}
R_API RAnalFunction *r_anal_get_fcn_at(RAnal *anal, ut64 addr) {

View File

@ -32,37 +32,52 @@ R_API RAnalType *r_anal_type_new() {
return t;
}
R_API RAnalType *r_anal_type_list_new() {
RAnalType *t = R_NEW(RAnalType);
R_API RList *r_anal_type_list_new() {
RList *t = R_NEW(RList);
return t;
}
R_API void r_anal_type_del() {
// TODO: Insert type in types list
R_API void r_anal_type_add(RList *l, RAnalType *t) {
}
R_API void r_anal_type_cleanup() {
// TODO: Remove type from types list
R_API void r_anal_type_del(RList *l, const char* name) {
}
R_API void r_anal_type_free(RAnalType *t) {
R_API RAnalType *r_anal_type_free(RAnalType *t) {
free(t);
return t;
}
R_API void r_anal_type_list(RAnalType *t, short category, short enabled) {
R_API void r_anal_type_list(RList *t, short category, short enabled) {
// List all types by category: var/struct/unions/pointers
}
R_API RAnalType *r_anal_type_find(char *name) {
return NULL;
}
R_API char* r_anal_type_to_string(RAnalType *t) {
R_API char* r_anal_type_to_str(RAnal *a, RAnalType *t) {
return "<none>";
}
R_API RAnalType *r_anal_type_loadfile(char *path) {
R_API RAnalType *r_anal_str_to_type(RAnal *a, const char* type) {
int yv;
void *pParser = cdataParseAlloc(malloc);
yy_scan_string(type);
while ((yv = yylex()) != 0) {
cdataParse(pParser, yv, yylval);
}
cdataParse(pParser, 0, yylval);
cdataParseFree(pParser, free);
return NULL;
}
R_API RAnalType *r_anal_type_loadfile(RAnal *a, const char *path) {
FILE *cfile;
int n;
int yv;
int yv, yylval;
char buf[4096];
void *pParser = cdataParseAlloc(malloc);
@ -77,8 +92,5 @@ R_API RAnalType *r_anal_type_loadfile(char *path) {
fclose(cfile);
cdataParse(pParser, 0, yylval);
cdataParseFree(pParser, free);
}
R_API RAnalType *r_anal_type_loadstring(char *buf) {
return NULL;
}

View File

@ -15,15 +15,6 @@ R_API RAnalVar *r_anal_var_new() {
return var;
}
/*
R_API RAnalVarType *r_anal_var_type_new() {
RAnalVarType *vartype = R_NEW (RAnalVarType);
if (vartype)
memset (vartype, 0, sizeof (RAnalVarType));
return vartype;
}
*/
R_API RAnalVarAccess *r_anal_var_access_new() {
RAnalVarAccess *access = R_NEW (RAnalVarAccess);
if (access)
@ -37,14 +28,6 @@ R_API RList *r_anal_var_list_new() {
return list;
}
/*
R_API RList *r_anal_var_type_list_new() {
RList *list = r_list_new ();
list->free = &r_anal_var_type_free;
return list;
}
*/
R_API RList *r_anal_var_access_list_new() {
RList *list = r_list_new ();
list->free = &r_anal_var_access_free;
@ -55,70 +38,24 @@ R_API void r_anal_var_free(void *var) {
if (var) {
if (((RAnalVar*)var)->name)
free (((RAnalVar*)var)->name);
if (((RAnalVar*)var)->vartype)
free (((RAnalVar*)var)->vartype);
if (((RAnalVar*)var)->type)
free (((RAnalVar*)var)->type);
if (((RAnalVar*)var)->accesses)
r_list_free (((RAnalVar*)var)->accesses);
free (var);
}
}
/*
R_API void r_anal_var_type_free(void *vartype) {
if (vartype) {
if (((RAnalVarType*)vartype)->name)
free (((RAnalVarType*)vartype)->name);
if (((RAnalVarType*)vartype)->fmt)
free (((RAnalVarType*)vartype)->fmt);
}
free (vartype);
}
*/
R_API void r_anal_var_access_free(void *access) {
free (access);
}
R_API int r_anal_var_type_add(RAnal *anal, const char *name, int size, const char *fmt) {
RAnalVarType *t;
if (!(t = r_anal_var_type_new ()))
return R_FALSE;
if (name)
t->name = strdup (name);
if (fmt)
t->fmt = strdup (fmt);
t->size = size;
r_list_append (anal->vartypes, t);
return R_TRUE;
}
R_API int r_anal_var_type_del(RAnal *anal, const char *name) {
RAnalVarType *vti;
RListIter *iter;
/* No _safe loop necessary because we return immediately after the delete. */
r_list_foreach(anal->vartypes, iter, vti)
if (!strcmp (name, vti->name)) {
r_list_unlink (anal->vartypes, vti);
return R_TRUE;
}
return R_FALSE;
}
R_API RAnalType *r_anal_var_type_get(RAnal *anal, const char *name) {
RAnalType *vti;
RListIter *iter;
r_list_foreach (anal->vartypes, iter, vti)
if (!strcmp (name, vti->name))
return vti;
return NULL;
}
static int cmpdelta(RAnalVar *a, RAnalVar *b) {
return (a->delta - b->delta);
}
/* Add local variable for selected function */
R_API int r_anal_var_add(RAnal *anal, RAnalFunction *fcn, ut64 from, int delta, int type, const char *vartype, const char *name, int set) {
R_API int r_anal_var_add(RAnal *anal, RAnalFunction *fcn, ut64 from, int delta, int scope, const RAnalType *type, const char *name, int set) {
RAnalVar *var, *vari;
RListIter *iter;
if (from != 0LL)
@ -129,10 +66,10 @@ R_API int r_anal_var_add(RAnal *anal, RAnalFunction *fcn, ut64 from, int delta,
return R_FALSE;
if (name)
var->name = strdup (name);
if (vartype)
var->vartype = strdup (vartype);
if (type)
var->type = type;
var->type = type;
if ((type & R_ANAL_VAR_TYPE_ARG) || (type & R_ANAL_VAR_TYPE_ARGREG))
if ((scope & R_ANAL_VAR_SCOPE_ARG) || (scope & R_ANAL_VAR_SCOPE_ARGREG))
fcn->nargs++;
var->delta = delta;
if (from != 0LL)
@ -142,39 +79,39 @@ R_API int r_anal_var_add(RAnal *anal, RAnalFunction *fcn, ut64 from, int delta,
}
/* Remove local variable from selected function */
R_API int r_anal_var_del(RAnal *anal, RAnalFunction *fcn, int delta, int type) {
R_API int r_anal_var_del(RAnal *anal, RAnalFunction *fcn, int delta, int scope) {
RAnalVar *vari;
RListIter *iter;
/* No _safe loop necessary because we return immediately after the delete. */
r_list_foreach(fcn->vars, iter, vari)
if (vari->type == type && vari->delta == delta) {
if (vari->scope == scope && vari->delta == delta) {
r_list_unlink (fcn->vars, vari);
return R_TRUE;
}
return R_FALSE;
}
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFunction *fcn, int delta, int type) {
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFunction *fcn, int delta, int scope) {
RAnalVar *vari;
RListIter *iter;
r_list_foreach (fcn->vars, iter, vari)
if ((type==-1||vari->type == type) && vari->delta == delta)
if ((scope==-1||vari->scope == scope) && vari->delta == delta)
return vari;
return NULL;
}
R_API const char *r_anal_var_scope_to_str (RAnal *anal, int scope) {
if (type & R_ANAL_VAR_SCOPE_GLOBAL)
if (scope & R_ANAL_VAR_SCOPE_GLOBAL)
return "global";
else if (type & R_ANAL_SCOPE_TYPE_LOCAL)
else if (scope & R_ANAL_VAR_SCOPE_LOCAL)
return "local";
else if (type & R_ANAL_SCOPE_TYPE_ARG)
else if (scope & R_ANAL_VAR_SCOPE_ARG)
return "arg";
else if (type & R_ANAL_SCOPE_TYPE_ARGREG)
else if (scope & R_ANAL_VAR_SCOPE_ARGREG)
return "fastarg";
else if (type & R_ANAL_SCOPE_TYPE_RET)
else if (scope & R_ANAL_VAR_SCOPE_RET)
return "ret";
return "(?)";
}
@ -225,12 +162,14 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, ut64 addr) {
r_list_foreach (fcn->vars, iter, v) {
if (addr == 0 || (addr >= v->addr && addr <= v->eaddr)) {
//ut32 value = r_var_dbg_read(v->delta);
if (v->array>1)
if (v->type->type == R_ANAL_TYPE_ARRAY)
eprintf ("%s %s %s[%d] = ",
r_anal_var_type_to_str(anal, v->type), v->vartype,
v->name, v->array);
else eprintf ("%s %s %s = ", r_anal_var_type_to_str (anal, v->type),
v->vartype, v->name);
r_anal_var_scope_to_str(anal, v->scope),
r_anal_type_to_str(anal, v->type),
v->name, v->type->custom.a->count);
else
eprintf ("%s %s %s = ", r_anal_var_scope_to_str (anal, v->scope),
r_anal_type_to_str(anal, v->type), v->name);
// TODO: implement r_var_dbg_read using r_vm or r_num maybe?? sounds dupped
// XXX: not fully implemented
eprintf ("0x%"PFMT64x, 0LL);
@ -252,9 +191,15 @@ R_API void r_anal_var_list(RAnal *anal, RAnalFunction *fcn, ut64 addr, int delta
if (fcn && fcn->vars)
r_list_foreach (fcn->vars, iter, v) {
if (addr == 0 || (addr >= v->addr && addr <= v->eaddr)) {
eprintf ("0x%08"PFMT64x" - 0x%08"PFMT64x" type=%s type=%s name=%s delta=%d array=%d\n",
v->addr, v->eaddr, r_anal_var_type_to_str(anal, v->type),
v->vartype, v->name, v->delta, v->array);
if (v->type->type == R_ANAL_TYPE_ARRAY)
eprintf ("0x%08"PFMT64x" - 0x%08"PFMT64x" type=%s type=%s name=%s delta=%d array=%d\n",
v->addr, v->eaddr, r_anal_var_scope_to_str(anal, v->scope),
r_anal_type_to_str(anal, v->type), v->name, v->delta, v->type->custom.a->count);
else
eprintf ("0x%08"PFMT64x" - 0x%08"PFMT64x" type=%s type=%s name=%s delta=%d\n",
v->addr, v->eaddr, r_anal_var_scope_to_str(anal, v->scope),
r_anal_type_to_str(anal, v->type), v->name, v->delta);
r_list_foreach (v->accesses, iter2, x) {
eprintf (" 0x%08"PFMT64x" %s\n", x->addr, x->set?"set":"get");
}

View File

@ -69,7 +69,7 @@ static char *r_core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) {
return str;
}
static void r_core_anal_graph_nodes(RCore *core, RAnalFcn *fcn, int opts) {
static void r_core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts) {
struct r_anal_bb_t *bbi;
RListIter *iter;
char *str;
@ -107,7 +107,7 @@ static void r_core_anal_graph_nodes(RCore *core, RAnalFcn *fcn, int opts) {
}
}
R_API int r_core_anal_bb(RCore *core, RAnalFcn *fcn, ut64 at, int head) {
R_API int r_core_anal_bb(RCore *core, RAnalFunction *fcn, ut64 at, int head) {
struct r_anal_bb_t *bb = NULL, *bbi;
RListIter *iter;
ut64 jump, fail;
@ -164,7 +164,7 @@ error:
R_API int r_core_anal_bb_seek(RCore *core, ut64 addr) {
RAnalBlock *bbi;
RAnalFcn *fcni;
RAnalFunction *fcni;
RListIter *iter, *iter2;
r_list_foreach (core->anal->fcns, iter, fcni)
r_list_foreach (fcni->bbs, iter2, bbi)
@ -182,7 +182,7 @@ static int cmpaddr (void *_a, void *_b) {
R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth) {
RListIter *iter, *iter2;
int buflen, fcnlen = 0;
RAnalFcn *fcn = NULL, *fcni;
RAnalFunction *fcn = NULL, *fcni;
RAnalRef *ref = NULL, *refi;
ut8 *buf;
@ -223,7 +223,7 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept
goto error;
if (r_cons_singleton ()->breaked)
break;
fcnlen = r_anal_fcn (core->anal, fcn, at+fcnlen, buf, buflen, reftype);
fcnlen = r_anal_fcn (core->anal, fcn, at+fcnlen, buf, buflen, reftype);
if (fcnlen == R_ANAL_RET_ERROR ||
(fcnlen == R_ANAL_RET_END && fcn->size < 1)) { /* Error analyzing function */
goto error;
@ -285,7 +285,7 @@ error:
}
R_API int r_core_anal_fcn_clean(RCore *core, ut64 addr) {
RAnalFcn *fcni;
RAnalFunction *fcni;
RListIter *iter, *iter_tmp;
if (addr == 0) {
@ -306,7 +306,7 @@ R_API void r_core_anal_refs(RCore *core, ut64 addr, int gv) {
const char *font = r_config_get (core->config, "graph.font");
RListIter *iter, *iter2;
RAnalRef *fcnr;
RAnalFcn *fcni;
RAnalFunction *fcni;
int showhdr = 0;
r_list_foreach (core->anal->fcns, iter, fcni) {
@ -342,7 +342,7 @@ R_API void r_core_anal_refs(RCore *core, ut64 addr, int gv) {
r_cons_printf ("}\n");
}
static void fcn_list_bbs(RAnalFcn *fcn) {
static void fcn_list_bbs(RAnalFunction *fcn) {
RAnalBlock *bbi;
RListIter *iter;
@ -371,7 +371,7 @@ static void fcn_list_bbs(RAnalFcn *fcn) {
}
R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
RAnalFcn *fcni;
RAnalFunction *fcni;
struct r_anal_ref_t *refi;
struct r_anal_var_t *vari;
RListIter *iter, *iter2;
@ -420,7 +420,7 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
r_cons_printf ("\n vars:");
r_list_foreach (fcni->vars, iter2, vari)
r_cons_printf ("\n %-10s delta=0x%02x type=%s", vari->name,
vari->delta, r_anal_var_type_to_str (core->anal, vari->type));
vari->delta, r_anal_type_to_str (core->anal, vari->type));
r_cons_printf ("\n diff: type=%s",
fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"match":
fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"unmatch":"new");
@ -478,7 +478,7 @@ R_API RList* r_core_anal_graph_to(RCore *core, ut64 addr, int n) {
RAnalBlock *bb, *root, *dest;
RListIter *iter, *iter2;
RList *list2, *list = NULL;
RAnalFcn *fcn;
RAnalFunction *fcn;
r_list_foreach (core->anal->fcns, iter, fcn) {
if (!r_anal_fcn_is_in_offset (fcn, core->offset))
@ -512,7 +512,7 @@ R_API RList* r_core_anal_graph_to(RCore *core, ut64 addr, int n) {
}
R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
RAnalFcn *fcni;
RAnalFunction *fcni;
RListIter *iter;
int reflines, bytes, dwarf;
const char *font = r_config_get (core->config, "graph.font");
@ -618,24 +618,24 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref) {
}
R_API int r_core_anal_ref_list(RCore *core, int rad) {
RAnalFcn *fcni;
RAnalFunction *fcni;
struct r_anal_ref_t *refi;
RListIter *iter, *iter2;
r_list_foreach (core->anal->fcns, iter, fcni)
r_list_foreach (fcni->refs, iter2, refi) {
if (rad)
r_cons_printf ("ar%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n",
r_cons_printf ("ar%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n",
refi->type==R_ANAL_REF_TYPE_DATA?"d":"",
refi->at, refi->addr);
else r_cons_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" (%c)\n",
else r_cons_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" (%c)\n",
refi->at, refi->addr, refi->type);
}
r_list_foreach (core->anal->refs, iter2, refi) {
if (rad) r_cons_printf ("ar%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n",
if (rad) r_cons_printf ("ar%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n",
refi->type==R_ANAL_REF_TYPE_DATA?"d":"",
refi->at, refi->addr);
else r_cons_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" (%c)\n",
else r_cons_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" (%c)\n",
refi->at, refi->addr, refi->type);
}
r_cons_flush ();
@ -645,13 +645,13 @@ R_API int r_core_anal_ref_list(RCore *core, int rad) {
R_API int r_core_anal_all(RCore *core) {
RList *list;
RListIter *iter;
RAnalFcn *fcni;
RAnalFunction *fcni;
RBinAddr *binmain;
RBinAddr *entry;
RBinSymbol *symbol;
ut64 baddr;
ut64 offset;
int depth =r_config_get_i (core->config, "anal.depth");
int depth =r_config_get_i (core->config, "anal.depth");
int va = core->io->va || core->io->debug;
baddr = r_bin_get_baddr (core->bin);

View File

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2009-2012 // nibble<.ds@gmail.com>, pancake<nopcode.org> */
#include "r_core.h"
#include <r_core.h>
#include <r_anal.h>
#include <sys/types.h>
#include <ctype.h>

View File

@ -14,10 +14,10 @@ static void var_help() {
}
static int var_cmd(RCore *core, const char *str) {
RAnalFcn *fcn = r_anal_fcn_find (core->anal, core->offset,
RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset,
R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM);
char *p, *p2, *p3, *ostr;
int type, delta;
int scope, delta;
ostr = p = strdup (str);
str = (const char *)ostr;
@ -34,9 +34,9 @@ static int var_cmd(RCore *core, const char *str) {
case 'A': // fastcall arg
// XXX nested dup
switch (*str) {
case 'v': type = R_ANAL_VAR_TYPE_LOCAL|R_ANAL_VAR_DIR_NONE; break;
case 'a': type = R_ANAL_VAR_TYPE_ARG|R_ANAL_VAR_DIR_IN; break;
case 'A': type = R_ANAL_VAR_TYPE_ARGREG|R_ANAL_VAR_DIR_IN; break;
case 'v': scope = R_ANAL_VAR_SCOPE_LOCAL|R_ANAL_VAR_DIR_NONE; break;
case 'a': scope = R_ANAL_VAR_SCOPE_ARG|R_ANAL_VAR_DIR_IN; break;
case 'A': scope = R_ANAL_VAR_SCOPE_ARGREG|R_ANAL_VAR_DIR_IN; break;
default:
eprintf ("Unknown type\n");
return 0;
@ -51,7 +51,7 @@ static int var_cmd(RCore *core, const char *str) {
case 'g':
if (str[2]!='\0') {
if (fcn != NULL) {
RAnalVar *var = r_anal_var_get (core->anal, fcn, atoi (str+2), R_ANAL_VAR_TYPE_LOCAL);
RAnalVar *var = r_anal_var_get (core->anal, fcn, atoi (str+2), R_ANAL_VAR_SCOPE_LOCAL);
if (var != NULL)
return r_anal_var_access_add (core->anal, var, atoi (str+2), (str[1]=='g')?0:1);
eprintf ("Can not find variable in: '%s'\n", str);
@ -68,6 +68,7 @@ static int var_cmd(RCore *core, const char *str) {
var_help();
break;
}
// TODO: Improve parsing error handling
p[0]='\0'; p++;
p2 = strchr (p, ' ');
if (p2) {
@ -77,7 +78,9 @@ static int var_cmd(RCore *core, const char *str) {
p3[0]='\0';
p3=p3+1;
}
r_anal_var_add (core->anal, fcn, core->offset, delta, type, p, p2, p3?atoi(p3):0);
// p2 - name of variable
r_anal_var_add (core->anal, fcn, core->offset, delta, scope,
r_anal_str_to_type(core->anal, p), p2, p3?atoi(p3):0);
} else var_help ();
break;
default:
@ -202,7 +205,7 @@ static int cmd_anal(void *data, const char *input) {
// list xrefs from current address
{
ut64 addr = input[1]? r_num_math (core->num, input+1): core->offset;
RAnalFcn *fcn = r_anal_fcn_find (core->anal, addr, R_ANAL_FCN_TYPE_NULL);
RAnalFunction *fcn = r_anal_fcn_find (core->anal, addr, R_ANAL_FCN_TYPE_NULL);
if (fcn) {
RAnalRef *ref;
RListIter *iter;
@ -218,7 +221,7 @@ static int cmd_anal(void *data, const char *input) {
case 'C': {
char *p;
ut64 a, b;
RAnalFcn *fcn;
RAnalFunction *fcn;
char *mi = strdup (input);
if (mi && mi[2]==' ' && (p=strchr (mi+3, ' '))) {
*p = 0;
@ -235,7 +238,7 @@ static int cmd_anal(void *data, const char *input) {
case '-': {
char *p;
ut64 a, b;
RAnalFcn *fcn;
RAnalFunction *fcn;
char *mi = strdup (input);
if (mi && mi[2]==' ' && (p=strchr (mi+3, ' '))) {
*p = 0;
@ -331,7 +334,7 @@ static int cmd_anal(void *data, const char *input) {
break;
case 'l':
{
RAnalFcn *fcn;
RAnalFunction *fcn;
RListIter *iter;
r_list_foreach (core->anal->fcns, iter, fcn) {
@ -346,7 +349,7 @@ static int cmd_anal(void *data, const char *input) {
break;
case 's': {
ut64 addr;
RAnalFcn *f;
RAnalFunction *f;
const char *arg = input+3;
if (input[2] && (addr = r_num_math (core->num, arg))) {
arg = strchr (arg, ' ');
@ -354,7 +357,7 @@ static int cmd_anal(void *data, const char *input) {
} else addr = core->offset;
if ((f = r_anal_fcn_find (core->anal, addr, R_ANAL_FCN_TYPE_NULL))) {
if (arg && *arg) {
r_anal_fcn_from_string (core->anal, f, arg);
r_anal_str_to_fcn (core->anal, f, arg);
} else {
char *str = r_anal_fcn_to_string (core->anal, f);
r_cons_printf ("%s\n", str);
@ -370,7 +373,7 @@ static int cmd_anal(void *data, const char *input) {
break;
case 'c':
{
RAnalFcn *fcn;
RAnalFunction *fcn;
int cc;
if ((fcn = r_anal_get_fcn_at (core->anal, core->offset)) != NULL) {
cc = r_anal_fcn_cc (fcn);
@ -388,7 +391,7 @@ static int cmd_anal(void *data, const char *input) {
ut64 jump = -1LL;
ut64 fail = -1LL;
int type = R_ANAL_BB_TYPE_NULL;
RAnalFcn *fcn = NULL;
RAnalFunction *fcn = NULL;
RAnalDiff *diff = NULL;
switch(r_str_word_set0 (ptr)) {
@ -433,7 +436,7 @@ static int cmd_anal(void *data, const char *input) {
break;
case 'r':
{
RAnalFcn *fcn;
RAnalFunction *fcn;
ut64 off = core->offset;
char *p, *name = strdup (input+3);
if ((p=strchr (name, ' '))) {
@ -452,7 +455,7 @@ static int cmd_anal(void *data, const char *input) {
break;
case 'e':
{
RAnalFcn *fcn;
RAnalFunction *fcn;
ut64 off = core->offset;
char *p, *name = strdup (input+3);
if ((p=strchr (name, ' '))) {

View File

@ -2,7 +2,6 @@
// XXX this command is broken. output of _list is not compatible with input
static int cmd_meta(void *data, const char *input) {
RAnalVarType *var;
RListIter *iter;
RCore *core = (RCore*)data;
int i, ret, line = 0;
@ -13,40 +12,6 @@ static int cmd_meta(void *data, const char *input) {
case '*':
r_meta_list (core->anal->meta, R_META_TYPE_ANY, 1);
break;
case 't':
switch (input[1]) {
case '-':
r_anal_var_type_del (core->anal, input+2);
break;
case ' ':
{
int size;
const char *fmt = NULL;
const char *ptr, *name = input+2;
ptr = strchr (name, ' ');
if (ptr) {
size = atoi (ptr+1);
ptr = strchr (ptr+2, ' ');
if (ptr)
fmt = ptr+1;
}
if (fmt==NULL)
eprintf ("Usage: Ct name size format\n");
else r_anal_var_type_add (core->anal, name, size, fmt);
}
break;
case '\0':
r_list_foreach (core->anal->vartypes, iter, var) {
r_cons_printf ("Ct %s %d %s\n", var->name, var->size, var->fmt);
}
break;
default:
eprintf ("Usage: Ct[..]\n"
" Ct-int : remove 'int' type\n"
" Ct int 4 d : define int type\n");
break;
}
break;
case 'l':
// XXX: this should be moved to CL?
if (input[2]=='a') {
@ -190,7 +155,7 @@ static int cmd_meta(void *data, const char *input) {
switch (input[1]) {
case '-':
{
RAnalFcn *f;
RAnalFunction *f;
RListIter *iter;
ut64 offset;
if (input[2]==' ') {
@ -205,7 +170,7 @@ static int cmd_meta(void *data, const char *input) {
break;
case '*':
{
RAnalFcn *f;
RAnalFunction *f;
RListIter *iter;
r_list_foreach (core->anal->fcns, iter, f) {
for (i = 0; i < R_ANAL_VARSUBS; i++) {
@ -218,7 +183,7 @@ static int cmd_meta(void *data, const char *input) {
break;
default:
{
RAnalFcn *f;
RAnalFunction *f;
char *ptr = strdup (input+2);
const char *varsub = NULL;
const char *pattern = NULL;
@ -267,9 +232,9 @@ static int cmd_meta(void *data, const char *input) {
break;
case 'F':
{
RAnalFcn *f = r_anal_fcn_find (core->anal, core->offset,
RAnalFunction *f = r_anal_fcn_find (core->anal, core->offset,
R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM);
if (f) r_anal_fcn_from_string (core->anal, f, input+2);
if (f) r_anal_str_to_fcn (core->anal, f, input+2);
else eprintf ("Cannot find function here\n");
}
break;

View File

@ -74,7 +74,7 @@ static int cmd_print(void *data, const char *input) {
}
if (input[0] && input[1] == 'f') {
RAnalFcn *f = r_anal_fcn_find (core->anal, core->offset,
RAnalFunction *f = r_anal_fcn_find (core->anal, core->offset,
R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM);
if (f) len = f->size;
else eprintf ("Cannot find function at 0x%08"PFMT64x"\n", core->offset);
@ -180,7 +180,7 @@ free (ptr);
int bs = core->blocksize;
if (input[1]=='f') {
RAnalFcn *f = r_anal_fcn_find (core->anal, core->offset,
RAnalFunction *f = r_anal_fcn_find (core->anal, core->offset,
R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM);
if (f) {
len = bs = f->size;
@ -251,7 +251,7 @@ free (ptr);
} break;
break;
case 'f': {
RAnalFcn *f = r_anal_fcn_find (core->anal, core->offset,
RAnalFunction *f = r_anal_fcn_find (core->anal, core->offset,
R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM);
if (f) {
ut8 *block = malloc (f->size+1);

View File

@ -2,14 +2,12 @@
static int cmd_type(void *data, const char *input) {
RCore *core = (RCore*)data;
#if USED
RAnalVarType *var;
RListIter *iter;
RAnalType *t;
int i, ret, line = 0;
ut64 addr_end = 0LL;
ut64 addr = core->offset;
char file[1024];
#endif
switch (*input) {
case '*':
r_anal_type_list (core->anal->types, R_ANAL_TYPE_ANY, 1);
@ -22,7 +20,9 @@ static int cmd_type(void *data, const char *input) {
{
char *out, *ctype = "";
out = r_core_editor (core, ctype);
r_anal_type_loadstring (core->anal->types, out);
t = r_anal_str_to_type (core->anal, out);
if (t != NULL)
r_anal_type_add (core->anal->types, t);
free (out);
free (ctype);
}
@ -32,7 +32,7 @@ static int cmd_type(void *data, const char *input) {
const char *ptr, *filename = input + 2;
ptr = strchr (filename, ' ');
if (ptr && !ptr[1]) {
r_anal_type_loadfile(core->anal->types, filename);
r_anal_type_loadfile(core->anal, filename);
eprintf ("Usage: tf name\n");
} else eprintf ("Usage: tf[!] [name]\n");
}
@ -61,14 +61,24 @@ static int cmd_type(void *data, const char *input) {
ut64 n = r_num_math (core->num, input + ((input[1] == ' ') ? 2 : 1));
eprintf ("val 0x%"PFMT64x"\n", n);
//TODO r_anal_type_del (core->anal->types, R_ANAL_TYPE_ANY, core->offset, i, "");
} else r_anal_type_cleanup (core->anal->types, 0LL, UT64_MAX);
} else {
const char *ntr, *name = input + 2;
ntr = strchr(name, ' ');
if (ntr && !ntr[1]) {
r_anal_type_del (core->anal->types, name);
} else
eprintf ("Usage: t- name\n"
"t- name : delete type by its name\n");
}
break;
case '\0':
case '!':
{
char *out, *ctype = "";
out = r_core_editor (core, ctype);
r_anal_type_loadstring (core->anal->types, out);
t = r_anal_str_to_type(core->anal, out);
if (t != NULL)
r_anal_type_add (core->anal->types, t);
free (out);
free (ctype);
}

View File

@ -2,7 +2,7 @@
static int cmd_zign(void *data, const char *input) {
RCore *core = (RCore *)data;
RAnalFcn *fcni;
RAnalFunction *fcni;
RListIter *iter;
RSignItem *item;
int i, fd = -1, len;

View File

@ -34,7 +34,7 @@ static void printoffset(ut64 off, int show_color, int invert, int opt) {
// int l is for lines
R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len, int l, int invbreak) {
RAnalCC cc = {0};
RAnalFcn *f = NULL;
RAnalFunction *f = NULL;
int ret, idx, i, j, k, lines, ostackptr = 0, stackptr = 0;
int counter = 0;
int middle = 0;
@ -84,7 +84,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
int show_comment_right = 0;
int ocols = 0;
int lcols = 0;
if (show_lines) ocols += 10;
if (show_offset) ocols += 14;
lcols = ocols+2;
@ -112,7 +112,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
#if 0
/* find last function else stackptr=0 */
{
RAnalFcn *fcni;
RAnalFunction *fcni;
RListIter *iter;
r_list_foreach (core->anal.fcns, iter, fcni) {
@ -290,7 +290,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
RListIter *iter;
if ((xrefs = r_anal_xref_get (core->anal, at))) {
r_list_foreach (xrefs, iter, refi) {
RAnalFcn *fun = r_anal_fcn_find (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL);
RAnalFunction *fun = r_anal_fcn_find (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL);
r_cons_printf ("%s%s", pre, refline);
if (show_color)
r_cons_printf (Color_TURQOISE"; %s XREF 0x%08"PFMT64x" (%s)"Color_RESET"\n",
@ -360,7 +360,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
ostackptr = stackptr;
stackptr += analop.stackptr;
/* XXX if we reset the stackptr 'ret 0x4' has not effect.
* Use RAnalFcn->RAnalOp->stackptr? */
* Use RAnalFunction->RAnalOp->stackptr? */
if (analop.type == R_ANAL_OP_TYPE_RET)
stackptr = 0;
}
@ -510,7 +510,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
opstr = str;
} else opstr = asmop.buf_asm;
if (varsub) {
RAnalFcn *f = r_anal_fcn_find (core->anal, at, R_ANAL_FCN_TYPE_NULL);
RAnalFunction *f = r_anal_fcn_find (core->anal, at, R_ANAL_FCN_TYPE_NULL);
if (f) {
r_parse_varsub (core->parser, f, opstr, strsub, sizeof (strsub));
if (decode) free (opstr);

View File

@ -9,7 +9,7 @@
R_API int r_core_gdiff(RCore *c, RCore *c2) {
RCore *cores[2] = {c, c2};
RAnalFcn *fcn;
RAnalFunction *fcn;
RAnalBlock *bb;
RListIter *iter, *iter2;
int i;
@ -45,7 +45,7 @@ static void diffrow(ut64 addr, const char *name, ut64 addr2, const char *name2,
R_API void r_core_diff_show(RCore *c, RCore *c2) {
const char *match;
RListIter *iter;
RAnalFcn *f;
RAnalFunction *f;
RList *fcns = r_anal_get_fcns (c->anal);
r_list_foreach (fcns, iter, f) {
switch (f->type) {

View File

@ -92,7 +92,7 @@ static int visual_fkey(RCore *core, int ch) {
switch (ch) {
case R_CONS_KEY_F1:
cmd = r_config_get (core->config, "key.f1");
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
if (cmd && *cmd) return r_core_cmd0 (core, cmd);
ch = '?';
break;
case R_CONS_KEY_F2:
@ -145,7 +145,7 @@ static int visual_fkey(RCore *core, int ch) {
void setcursor (RCore *core, int cur) {
curset = cur;
if (curset) flags|=R_PRINT_FLAGS_CURSOR;
if (curset) flags|=R_PRINT_FLAGS_CURSOR;
else flags &= ~(flags&R_PRINT_FLAGS_CURSOR);
r_print_set_flags (core->print, flags);
core->print->col = curset? 1: 0;
@ -171,7 +171,6 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'c':
// XXX dupped flag imho
setcursor (core, curset ^ 1);
break;
case 'd':
r_core_visual_define (core);
@ -253,7 +252,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
RList *xrefs = NULL;
RAnalRef *refi;
RListIter *iter;
RAnalFcn *fun;
RAnalFunction *fun;
if ((xrefs = r_anal_xref_get (core->anal, core->offset))) {
r_cons_printf ("XREFS:\n");
@ -793,7 +792,7 @@ R_API int r_core_visual(RCore *core, const char *input) {
flags = R_PRINT_FLAGS_ADDRMOD | R_PRINT_FLAGS_HEADER;
if (color) flags |= R_PRINT_FLAGS_COLOR;
do {
scrseek = r_num_math (core->num,
scrseek = r_num_math (core->num,
r_config_get (core->config, "scr.seek"));
if (scrseek != 0LL)
r_core_seek (core, scrseek, 1);

View File

@ -27,7 +27,7 @@ R_API int r_core_visual_trackflags(RCore *core) {
i = j = 0;
r_list_foreach (core->flags->flags, iter, flag) {
/* filter per flag spaces */
if ((core->flags->space_idx != -1) &&
if ((core->flags->space_idx != -1) &&
(flag->space != core->flags->space_idx))
continue;
if (option==i) {
@ -67,7 +67,7 @@ R_API int r_core_visual_trackflags(RCore *core) {
if ((i >=option-delta) && ((i<option+delta)|| \
((option<delta)&&(i<(delta<<1))))) {
r_cons_printf(" %c %02d %c %s\n",
(option==i)?'>':' ', j,
(option==i)?'>':' ', j,
(i==core->flags->space_idx)?'*':' ',
core->flags->spaces[i]);
j++;
@ -80,7 +80,7 @@ R_API int r_core_visual_trackflags(RCore *core) {
hit = 1;
}
r_cons_printf (" %c %02d %c %s\n",
(option==j)?'>':' ', j,
(option==j)?'>':' ', j,
(i==core->flags->space_idx)?'*':' ',
"*");
}
@ -267,7 +267,7 @@ R_API int r_core_visual_comments (RCore *core) {
int found = 0;
ut64 from = 0, size = 0;
RListIter *iter;
RAnalFcn *fcn;
RAnalFunction *fcn;
RMetaItem *d;
for (;;) {
@ -860,7 +860,7 @@ R_API void r_core_visual_mounts (RCore *core) {
}
#if 1
static void var_index_show(RAnal *anal, RAnalFcn *fcn, ut64 addr, int idx) {
static void var_index_show(RAnal *anal, RAnalFunction *fcn, ut64 addr, int idx) {
int i = 0;
RAnalVar *v;
RAnalVarAccess *x;
@ -878,9 +878,14 @@ static void var_index_show(RAnal *anal, RAnalFcn *fcn, ut64 addr, int idx) {
}
if (idx == i) r_cons_printf (" * ");
else r_cons_printf (" ");
r_cons_printf ("0x%08llx - 0x%08llx type=%s type=%s name=%s delta=%d array=%d\n",
v->addr, v->eaddr, r_anal_var_type_to_str (anal, v->type),
v->vartype, v->name, v->delta, v->array);
if (v->type->type == R_ANAL_TYPE_ARRAY)
r_cons_printf ("0x%08llx - 0x%08llx scope=%s type=%s name=%s delta=%d array=%d\n",
v->addr, v->eaddr, r_anal_var_scope_to_str (anal, v->scope),
r_anal_type_to_str(anal, v->type), v->name, v->delta, v->type->custom.a->count);
else
r_cons_printf ("0x%08llx - 0x%08llx scope=%s type=%s name=%s delta=%d\n",
v->addr, v->eaddr, r_anal_var_scope_to_str (anal, v->scope),
r_anal_type_to_str(anal, v->type), v->name, v->delta);
r_list_foreach (v->accesses, iter2, x) {
r_cons_printf (" 0x%08llx %s\n", x->addr, x->set?"set":"get");
}
@ -893,7 +898,7 @@ static void var_index_show(RAnal *anal, RAnalFcn *fcn, ut64 addr, int idx) {
// helper
static void function_rename(RCore *core, ut64 addr, const char *name) {
RListIter *iter;
RAnalFcn *fcn;
RAnalFunction *fcn;
r_list_foreach (core->anal->fcns, iter, fcn) {
if (fcn->addr == addr) {
@ -913,7 +918,7 @@ static ut64 var_functions_show(RCore *core, int idx, int show) {
int window = 15;
int wdelta = (idx>5)?idx-5:0;
RListIter *iter;
RAnalFcn *fcn;
RAnalFunction *fcn;
r_list_foreach (core->anal->fcns, iter, fcn) {
if (i>=wdelta) {
@ -925,7 +930,7 @@ static ut64 var_functions_show(RCore *core, int idx, int show) {
if (idx == i)
addr = fcn->addr;
if (show)
r_cons_printf ("%c%c 0x%08llx (%s)\n",
r_cons_printf ("%c%c 0x%08llx (%s)\n",
(seek == fcn->addr)?'>':' ',
(idx==i)?'*':' ',
fcn->addr, fcn->name);
@ -944,7 +949,7 @@ static void r_core_visual_anal_refresh (RCore *core) {
char old[1024];
old[0]='\0';
int cols = r_cons_get_size (NULL);
RAnalFcn *fcn = r_anal_fcn_find (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); // once
RAnalFunction *fcn = r_anal_fcn_find (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); // once
char *oprofile;
cols -= 50;
@ -1056,7 +1061,7 @@ eprintf ("TODO: Add new function manually\n");
if (!r_cons_fgets (old, sizeof (old), 0, NULL)) break;
//old[strlen (old)-1] = 0;
function_rename (core, addr, old);
r_cons_set_raw (R_TRUE);
r_cons_show_cursor (R_FALSE);
break;
@ -1108,7 +1113,7 @@ eprintf ("TODO: Add new function manually\n");
beach:
core->cons->event_resize = olde;
level = 0;
}
#endif
@ -1122,7 +1127,7 @@ R_API void r_core_seek_next(RCore *core, const char *type) {
else eprintf ("Invalid opcode\n");
} else
if (strstr (type, "fun")) {
RAnalFcn *fcni;
RAnalFunction *fcni;
r_list_foreach (core->anal->fcns, iter, fcni) {
if (fcni->addr < next && fcni->addr > core->offset)
next = fcni->addr;
@ -1154,7 +1159,7 @@ R_API void r_core_seek_previous (RCore *core, const char *type) {
eprintf ("TODO: r_core_seek_previous (opc)\n");
} else
if (strstr (type, "fun")) {
RAnalFcn *fcni;
RAnalFunction *fcni;
r_list_foreach (core->anal->fcns, iter, fcni) {
if (fcni->addr > next && fcni->addr < core->offset)
next = fcni->addr;
@ -1234,7 +1239,7 @@ R_API void r_core_visual_define (RCore *core) {
case 'd': // TODO: check
r_meta_add (core->anal->meta, R_META_TYPE_DATA, off, off+core->blocksize, "");
break;
case 'c': // TODO: check
case 'c': // TODO: check
r_meta_add (core->anal->meta, R_META_TYPE_CODE, off, off+core->blocksize, "");
break;
case 'u':

View File

@ -46,6 +46,7 @@ enum {
R_ANAL_TYPE_STRUCT = 4,
R_ANAL_TYPE_UNION = 5,
R_ANAL_TYPE_FUNCTION = 6,
R_ANAL_TYPE_ANY = 7,
};
// [0:3] bits - place to store variable size
@ -262,6 +263,7 @@ typedef struct r_anal_type_function_t {
/*item_list *rets; // Type of return value */
short rets;
short fmod; // static, inline or volatile?
/* TODO: Change to RAnalCC ??? */
short call; // calling convention
char* attr; // __attribute__(()) list
ut64 addr;
@ -369,13 +371,13 @@ enum {
};
enum {
R_ANAL_VAR_TYPE_NULL = 0,
R_ANAL_VAR_TYPE_GLOBAL = 0x01,
R_ANAL_VAR_TYPE_LOCAL = 0x02,
R_ANAL_VAR_TYPE_ARG = 0x04,
R_ANAL_VAR_TYPE_ARGREG = 0x08,
R_ANAL_VAR_TYPE_RET = 0x10,
};
R_ANAL_VAR_SCOPE_NULL = 0,
R_ANAL_VAR_SCOPE_GLOBAL = 0x01,
R_ANAL_VAR_SCOPE_LOCAL = 0x02,
R_ANAL_VAR_SCOPE_ARG = 0x04,
R_ANAL_VAR_SCOPE_ARGREG = 0x08,
R_ANAL_VAR_SCOPE_RET = 0x10,
} _RAnalVarScope;
typedef enum {
R_ANAL_VAR_DIR_NONE = 0,
@ -518,9 +520,7 @@ typedef struct r_anal_var_t {
ut64 addr; // not used correctly?
ut64 eaddr; // not used correctly?
int delta; /* delta offset inside stack frame */
int props; /* global, local... | in, out... */
//int array; /* array size */
//char *vartype; /* float, int... */
int scope; /* global, local... | in, out... */
RAnalType *type;
/* probably dupped or so */
RList/*RAnalVarAccess*/ *accesses; /* list of accesses for this var */
@ -591,6 +591,17 @@ R_API void r_listrange_resize(RListRange *s, RAnalFunction *f, int newsize);
R_API RAnalFunction *r_listrange_find_in_range(RListRange* s, ut64 addr);
R_API RAnalFunction *r_listrange_find_root(RListRange* s, ut64 addr);
/* --------- */ /* REFACTOR */ /* ---------- */
/* type.c */
R_API RAnalType *r_anal_type_new();
R_API void r_anal_type_add(RList *l, RAnalType *t);
R_API void r_anal_type_del(RList *l, const char *name);
R_API RList *r_anal_type_list_new();
R_API void r_anal_type_list(RList *l, short category, short enabled);
R_API RAnalType *r_anal_str_to_type(RAnal *a, const char* s);
R_API char *r_anal_type_to_str(RAnal *a, RAnalType *t);
R_API RAnalType *r_anal_type_free(RAnalType *t);
R_API RAnalType *r_anal_type_loadfile(RAnal *a, const char *path);
/* anal.c */
R_API RAnal *r_anal_new();
R_API void r_anal_free(RAnal *r);
@ -642,7 +653,7 @@ R_API int r_anal_fcn_split_bb(RAnalFunction *fcn, RAnalBlock *bb, ut64 addr);
R_API int r_anal_fcn_overlap_bb(RAnalFunction *fcn, RAnalBlock *bb);
R_API RAnalVar *r_anal_fcn_get_var(RAnalFunction *fs, int num, int dir);
R_API char *r_anal_fcn_to_string(RAnal *a, RAnalFunction* fs);
R_API int r_anal_fcn_from_string(RAnal *a, RAnalFunction *f, const char *_str);
R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *_str);
#if 0
#define r_anal_fcn_get_refs(x) x->refs
@ -667,22 +678,16 @@ R_API RList *r_anal_xref_get(RAnal *anal, ut64 addr);
/* var.c */
R_API RAnalVar *r_anal_var_new();
//R_API RAnalVarType *r_anal_var_type_new();
R_API RAnalVarAccess *r_anal_var_access_new();
R_API RList *r_anal_var_list_new();
R_API RList *r_anal_var_type_list_new();
R_API RList *r_anal_var_access_list_new();
R_API void r_anal_var_free(void *var);
R_API void r_anal_var_type_free(void *vartype);
R_API void r_anal_var_access_free(void *access);
R_API int r_anal_var_type_add(RAnal *anal, const char *name, int size, const char *fmt);
R_API int r_anal_var_type_del(RAnal *anal, const char *name);
R_API RAnalType *r_anal_var_type_get(RAnal *anal, const char *name);
R_API int r_anal_var_add(RAnal *anal, RAnalFunction *fcn, ut64 from, int delta, int type,
const char *vartype, const char *name, int set);
R_API int r_anal_var_del(RAnal *anal, RAnalFunction *fcn, int delta, int type);
R_API int r_anal_var_add(RAnal *anal, RAnalFunction *fcn, ut64 from, int delta, int scope,
const RAnalType *type, const char *name, int set);
R_API int r_anal_var_del(RAnal *anal, RAnalFunction *fcn, int delta, int scope);
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFunction *fcn, int delta, int type);
R_API const char *r_anal_var_type_to_str (RAnal *anal, int type);
R_API const char *r_anal_var_scope_to_str(RAnal *anal, int scope);
R_API int r_anal_var_access_add(RAnal *anal, RAnalVar *var, ut64 from, int set);
R_API int r_anal_var_access_del(RAnal *anal, RAnalVar *var, ut64 from);
R_API RAnalVarAccess *r_anal_var_access_get(RAnal *anal, RAnalVar *var, ut64 from);

View File

@ -196,7 +196,7 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len) {
return R_FALSE;
}
static int varsub(RParse *p, struct r_anal_fcn_t *f, char *data, char *str, int len) {
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
char *ptr, *ptr2;
int i;

View File

@ -124,7 +124,7 @@ static int parse(RParse *p, const char *data, char *str) {
return R_TRUE;
}
static int assemble(struct r_parse_t *p, char *data, char *str) {
static int assemble(RParse *p, char *data, char *str) {
char *ptr;
printf ("assembling '%s' to generate real asm code\n", str);
ptr = strchr (str, '=');
@ -135,7 +135,7 @@ static int assemble(struct r_parse_t *p, char *data, char *str) {
return R_TRUE;
}
static int filter(struct r_parse_t *p, struct r_flag_t *f, char *data, char *str, int len) {
static int filter(RParse *p, RFlag *f, char *data, char *str, int len) {
RListIter *iter;
RFlagItem *flag;
char *ptr, *ptr2;
@ -161,7 +161,7 @@ static int filter(struct r_parse_t *p, struct r_flag_t *f, char *data, char *str
return R_FALSE;
}
static int varsub(struct r_parse_t *p, struct r_anal_fcn_t *f, char *data, char *str, int len) {
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
char *ptr, *ptr2;
int i;

View File

@ -7,7 +7,7 @@
#include <list.h>
#include "../config.h"
static RParsePlugin *parse_static_plugins[] =
static RParsePlugin *parse_static_plugins[] =
{ R_PARSE_STATIC_PLUGINS };
R_API RParse *r_parse_new() {
@ -94,13 +94,13 @@ R_API int r_parse_parse(RParse *p, const char *data, char *str) {
return R_FALSE;
}
R_API int r_parse_filter(RParse *p, struct r_flag_t *f, char *data, char *str, int len) {
R_API int r_parse_filter(RParse *p, RFlag *f, char *data, char *str, int len) {
if (p->cur && p->cur->filter)
return p->cur->filter (p, f, data, str, len);
return R_FALSE;
}
R_API int r_parse_varsub(RParse *p, struct r_anal_fcn_t *f, char *data, char *str, int len) {
R_API int r_parse_varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
if (p->cur && p->cur->varsub)
return p->cur->varsub (p, f, data, str, len);
return R_FALSE;