mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-26 07:44:29 +00:00
* Disassemble branch-in-the-middle instructions
- Uses reflines code analysis to get some hints * Rename RAnalysis into RAnal
This commit is contained in:
parent
3b326d6a41
commit
6d6ede7ee6
15
TODO.nitecon
Normal file
15
TODO.nitecon
Normal file
@ -0,0 +1,15 @@
|
||||
Dan palo
|
||||
8======D
|
||||
* anal fastargs
|
||||
* console grep
|
||||
* x@esp&&x@eip # BUG
|
||||
|
||||
nibble
|
||||
======
|
||||
* code analysis con parse
|
||||
* dcu broken in x86-64
|
||||
|
||||
pancake
|
||||
=======
|
||||
* stack analysis
|
||||
* r_anal.vapi is empty
|
@ -7,10 +7,10 @@
|
||||
#include <r_list.h>
|
||||
#include "../config.h"
|
||||
|
||||
static RAnalysisHandle *anal_static_plugins[] =
|
||||
static RAnalHandle *anal_static_plugins[] =
|
||||
{ R_ANAL_STATIC_PLUGINS };
|
||||
|
||||
static RAnalysisVarType anal_default_vartypes[] =
|
||||
static RAnalVarType anal_default_vartypes[] =
|
||||
{{ "char", "b", 1 },
|
||||
{ "byte", "b", 1 },
|
||||
{ "int", "d", 4 },
|
||||
@ -19,11 +19,11 @@ static RAnalysisVarType anal_default_vartypes[] =
|
||||
{ "float", "f", 4 },
|
||||
{ NULL, NULL, 0 }};
|
||||
|
||||
R_API RAnalysis *r_anal_new() {
|
||||
return r_anal_init (R_NEW (RAnalysis));
|
||||
R_API RAnal *r_anal_new() {
|
||||
return r_anal_init (R_NEW (RAnal));
|
||||
}
|
||||
|
||||
R_API RAnalysis *r_anal_free(RAnalysis *a) {
|
||||
R_API RAnal *r_anal_free(RAnal *a) {
|
||||
if (a) {
|
||||
/* TODO: Free a->anals here */
|
||||
if (a->bbs)
|
||||
@ -37,11 +37,11 @@ R_API RAnalysis *r_anal_free(RAnalysis *a) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API RAnalysis *r_anal_init(RAnalysis *anal) {
|
||||
R_API RAnal *r_anal_init(RAnal *anal) {
|
||||
int i;
|
||||
|
||||
if (anal) {
|
||||
memset (anal, 0, sizeof (RAnalysis));
|
||||
memset (anal, 0, sizeof (RAnal));
|
||||
anal->bbs = r_anal_bb_list_new ();
|
||||
anal->fcns = r_anal_fcn_list_new ();
|
||||
anal->vartypes = r_anal_var_type_list_new ();
|
||||
@ -57,11 +57,11 @@ R_API RAnalysis *r_anal_init(RAnalysis *anal) {
|
||||
return anal;
|
||||
}
|
||||
|
||||
R_API void r_anal_set_user_ptr(RAnalysis *anal, void *user) {
|
||||
R_API void r_anal_set_user_ptr(RAnal *anal, void *user) {
|
||||
anal->user = user;
|
||||
}
|
||||
|
||||
R_API int r_anal_add(RAnalysis *anal, RAnalysisHandle *foo) {
|
||||
R_API int r_anal_add(RAnal *anal, RAnalHandle *foo) {
|
||||
if (foo->init)
|
||||
foo->init(anal->user);
|
||||
list_add_tail(&(foo->list), &(anal->anals));
|
||||
@ -69,19 +69,19 @@ R_API int r_anal_add(RAnalysis *anal, RAnalysisHandle *foo) {
|
||||
}
|
||||
|
||||
// TODO: Must be deprecated
|
||||
R_API int r_anal_list(RAnalysis *anal) {
|
||||
R_API int r_anal_list(RAnal *anal) {
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &anal->anals) {
|
||||
RAnalysisHandle *h = list_entry(pos, RAnalysisHandle, list);
|
||||
RAnalHandle *h = list_entry(pos, RAnalHandle, list);
|
||||
printf (" %s: %s\n", h->name, h->desc);
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_anal_use(RAnalysis *anal, const char *name) {
|
||||
R_API int r_anal_use(RAnal *anal, const char *name) {
|
||||
struct list_head *pos;
|
||||
list_for_each_prev (pos, &anal->anals) {
|
||||
RAnalysisHandle *h = list_entry(pos, RAnalysisHandle, list);
|
||||
RAnalHandle *h = list_entry(pos, RAnalHandle, list);
|
||||
if (!strcmp (h->name, name)) {
|
||||
anal->cur = h;
|
||||
return R_TRUE;
|
||||
@ -90,7 +90,7 @@ R_API int r_anal_use(RAnalysis *anal, const char *name) {
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_anal_set_bits(RAnalysis *anal, int bits) {
|
||||
R_API int r_anal_set_bits(RAnal *anal, int bits) {
|
||||
switch (bits) {
|
||||
case 8:
|
||||
case 16:
|
||||
@ -102,7 +102,7 @@ R_API int r_anal_set_bits(RAnalysis *anal, int bits) {
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_anal_set_big_endian(RAnalysis *anal, int bigend) {
|
||||
R_API int r_anal_set_big_endian(RAnal *anal, int bigend) {
|
||||
anal->big_endian = bigend;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <r_util.h>
|
||||
#include <r_list.h>
|
||||
|
||||
R_API RAnalysisAop *r_anal_aop_new() {
|
||||
return r_anal_aop_init (R_NEW (RAnalysisAop));
|
||||
R_API RAnalAop *r_anal_aop_new() {
|
||||
return r_anal_aop_init (R_NEW (RAnalAop));
|
||||
}
|
||||
|
||||
R_API RList *r_anal_aop_list_new() {
|
||||
@ -20,9 +20,9 @@ R_API void r_anal_aop_free(void *aop) {
|
||||
free (aop);
|
||||
}
|
||||
|
||||
R_API RAnalysisAop *r_anal_aop_init(RAnalysisAop *aop) {
|
||||
R_API RAnalAop *r_anal_aop_init(RAnalAop *aop) {
|
||||
if (aop) {
|
||||
memset (aop, 0, sizeof (RAnalysisAop));
|
||||
memset (aop, 0, sizeof (RAnalAop));
|
||||
aop->addr = -1;
|
||||
aop->jump = -1;
|
||||
aop->fail = -1;
|
||||
@ -30,7 +30,7 @@ R_API RAnalysisAop *r_anal_aop_init(RAnalysisAop *aop) {
|
||||
return aop;
|
||||
}
|
||||
|
||||
R_API int r_anal_aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, int len) {
|
||||
R_API int r_anal_aop(RAnal *anal, RAnalAop *aop, ut64 addr, const ut8 *data, int len) {
|
||||
if (anal && aop && anal->cur && anal->cur->aop)
|
||||
return anal->cur->aop(anal, aop, addr, data, len);
|
||||
return 0;
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <r_util.h>
|
||||
#include <r_list.h>
|
||||
|
||||
R_API RAnalysisBB *r_anal_bb_new() {
|
||||
return r_anal_bb_init (R_NEW (RAnalysisBB));
|
||||
R_API RAnalBB *r_anal_bb_new() {
|
||||
return r_anal_bb_init (R_NEW (RAnalBB));
|
||||
}
|
||||
|
||||
R_API RList *r_anal_bb_list_new() {
|
||||
@ -17,14 +17,14 @@ R_API RList *r_anal_bb_list_new() {
|
||||
}
|
||||
|
||||
R_API void r_anal_bb_free(void *bb) {
|
||||
if (bb && ((RAnalysisBB*)bb)->aops)
|
||||
r_list_destroy (((RAnalysisBB*)bb)->aops);
|
||||
if (bb && ((RAnalBB*)bb)->aops)
|
||||
r_list_destroy (((RAnalBB*)bb)->aops);
|
||||
free (bb);
|
||||
}
|
||||
|
||||
R_API RAnalysisBB *r_anal_bb_init(RAnalysisBB *bb) {
|
||||
R_API RAnalBB *r_anal_bb_init(RAnalBB *bb) {
|
||||
if (bb) {
|
||||
memset (bb, 0, sizeof (RAnalysisBB));
|
||||
memset (bb, 0, sizeof (RAnalBB));
|
||||
bb->addr = -1;
|
||||
bb->jump = -1;
|
||||
bb->fail = -1;
|
||||
@ -33,8 +33,8 @@ R_API RAnalysisBB *r_anal_bb_init(RAnalysisBB *bb) {
|
||||
return bb;
|
||||
}
|
||||
|
||||
R_API int r_anal_bb(RAnalysis *anal, RAnalysisBB *bb, ut64 addr, ut8 *buf, ut64 len) {
|
||||
RAnalysisAop *aop;
|
||||
R_API int r_anal_bb(RAnal *anal, RAnalBB *bb, ut64 addr, ut8 *buf, ut64 len) {
|
||||
RAnalAop *aop;
|
||||
int oplen, idx = 0;
|
||||
|
||||
if (bb->addr == -1)
|
||||
@ -65,9 +65,9 @@ R_API int r_anal_bb(RAnalysis *anal, RAnalysisBB *bb, ut64 addr, ut8 *buf, ut64
|
||||
return bb->size;
|
||||
}
|
||||
|
||||
R_API int r_anal_bb_split(RAnalysis *anal, RAnalysisBB *bb, RList *bbs, ut64 addr) {
|
||||
RAnalysisBB *bbi;
|
||||
RAnalysisAop *aopi;
|
||||
R_API int r_anal_bb_split(RAnal *anal, RAnalBB *bb, RList *bbs, ut64 addr) {
|
||||
RAnalBB *bbi;
|
||||
RAnalAop *aopi;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach (bbs, iter, bbi)
|
||||
@ -95,9 +95,9 @@ R_API int r_anal_bb_split(RAnalysis *anal, RAnalysisBB *bb, RList *bbs, ut64 add
|
||||
return R_ANAL_RET_NEW;
|
||||
}
|
||||
|
||||
R_API int r_anal_bb_overlap(RAnalysis *anal, RAnalysisBB *bb, RList *bbs) {
|
||||
RAnalysisBB *bbi;
|
||||
RAnalysisAop *aopi;
|
||||
R_API int r_anal_bb_overlap(RAnal *anal, RAnalBB *bb, RList *bbs) {
|
||||
RAnalBB *bbi;
|
||||
RAnalAop *aopi;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach (bbs, iter, bbi)
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <r_util.h>
|
||||
#include <r_list.h>
|
||||
|
||||
R_API RAnalysisFcn *r_anal_fcn_new() {
|
||||
return r_anal_fcn_init (R_NEW (RAnalysisFcn));
|
||||
R_API RAnalFcn *r_anal_fcn_new() {
|
||||
return r_anal_fcn_init (R_NEW (RAnalFcn));
|
||||
}
|
||||
|
||||
R_API RList *r_anal_fcn_list_new() {
|
||||
@ -18,21 +18,21 @@ R_API RList *r_anal_fcn_list_new() {
|
||||
|
||||
R_API void r_anal_fcn_free(void *fcn) {
|
||||
if (fcn) {
|
||||
if (((RAnalysisFcn*)fcn)->name)
|
||||
free (((RAnalysisFcn*)fcn)->name);
|
||||
if (((RAnalysisFcn*)fcn)->refs)
|
||||
r_list_destroy (((RAnalysisFcn*)fcn)->refs);
|
||||
if (((RAnalysisFcn*)fcn)->xrefs)
|
||||
r_list_destroy (((RAnalysisFcn*)fcn)->xrefs);
|
||||
if (((RAnalysisFcn*)fcn)->vars)
|
||||
r_list_destroy (((RAnalysisFcn*)fcn)->vars);
|
||||
if (((RAnalFcn*)fcn)->name)
|
||||
free (((RAnalFcn*)fcn)->name);
|
||||
if (((RAnalFcn*)fcn)->refs)
|
||||
r_list_destroy (((RAnalFcn*)fcn)->refs);
|
||||
if (((RAnalFcn*)fcn)->xrefs)
|
||||
r_list_destroy (((RAnalFcn*)fcn)->xrefs);
|
||||
if (((RAnalFcn*)fcn)->vars)
|
||||
r_list_destroy (((RAnalFcn*)fcn)->vars);
|
||||
}
|
||||
free (fcn);
|
||||
}
|
||||
|
||||
R_API RAnalysisFcn *r_anal_fcn_init(RAnalysisFcn *fcn) {
|
||||
R_API RAnalFcn *r_anal_fcn_init(RAnalFcn *fcn) {
|
||||
if (fcn) {
|
||||
memset (fcn, 0, sizeof (RAnalysisFcn));
|
||||
memset (fcn, 0, sizeof (RAnalFcn));
|
||||
fcn->addr = -1;
|
||||
fcn->vars = r_anal_var_list_new ();
|
||||
fcn->refs = r_anal_ref_list_new ();
|
||||
@ -41,10 +41,10 @@ R_API RAnalysisFcn *r_anal_fcn_init(RAnalysisFcn *fcn) {
|
||||
return fcn;
|
||||
}
|
||||
|
||||
R_API int r_anal_fcn(RAnalysis *anal, RAnalysisFcn *fcn, ut64 addr, ut8 *buf, ut64 len) {
|
||||
RAnalysisRef *ref, *refi;
|
||||
R_API int r_anal_fcn(RAnal *anal, RAnalFcn *fcn, ut64 addr, ut8 *buf, ut64 len) {
|
||||
RAnalRef *ref, *refi;
|
||||
RListIter *iter;
|
||||
RAnalysisAop aop;
|
||||
RAnalAop aop;
|
||||
ut64 *jump;
|
||||
char *varname;
|
||||
int oplen, idx = 0;
|
||||
|
@ -43,7 +43,7 @@ static unsigned int disarm_branch_offset ( unsigned int pc, unsigned int insoff
|
||||
#define IS_EXITPOINT(x) \
|
||||
(IS_BRANCH (x) || IS_RETURN (x) || IS_UNKJMP (x))
|
||||
|
||||
static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, int len) {
|
||||
static int aop(RAnal *anal, RAnalAop *aop, ut64 addr, const ut8 *data, int len) {
|
||||
unsigned int i = 0;
|
||||
unsigned int* code = (unsigned int *)data;
|
||||
unsigned int branch_dst_addr;
|
||||
@ -52,7 +52,7 @@ static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, i
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
memset (aop, '\0', sizeof(RAnalysisAop));
|
||||
memset (aop, '\0', sizeof(RAnalAop));
|
||||
aop->addr = addr;
|
||||
aop->type = R_ANAL_OP_TYPE_UNK;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
// NOTE: buf should be at least 16 bytes!
|
||||
// XXX addr should be off_t for 64 love
|
||||
int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *bytes, int len) {
|
||||
int aop(RAnal *anal, RAnalAop *aop, ut64 addr, const ut8 *bytes, int len) {
|
||||
//int arch_ppc_aop(ut64 addr, const u8 *bytes, struct aop_t *aop)
|
||||
// TODO swap endian here??
|
||||
int opcode = (bytes[0] & 0xf8) >> 3; // bytes 0-5
|
||||
@ -17,7 +17,7 @@ int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *bytes, int len
|
||||
//if (baddr>0x7fff)
|
||||
// baddr = -baddr;
|
||||
|
||||
memset (aop, '\0', sizeof (RAnalysisAop));
|
||||
memset (aop, '\0', sizeof (RAnalAop));
|
||||
aop->addr = addr;
|
||||
aop->type = R_ANAL_OP_TYPE_NOP;
|
||||
aop->length = 4;
|
||||
|
@ -26,12 +26,12 @@
|
||||
|
||||
// NOTE: buf should be at least 16 bytes!
|
||||
// XXX addr should be off_t for 64 love
|
||||
static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, int len) {
|
||||
static int aop(RAnal *anal, RAnalAop *aop, ut64 addr, const ut8 *data, int len) {
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
ut8 *buf = (ut8*)data;
|
||||
memset(aop, '\0', sizeof(RAnalysisAop));
|
||||
memset(aop, '\0', sizeof(RAnalAop));
|
||||
aop->type = R_ANAL_OP_TYPE_UNK;
|
||||
aop->addr = addr;
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <r_util.h>
|
||||
#include <r_list.h>
|
||||
|
||||
R_API RAnalysisRef *r_anal_ref_new() {
|
||||
return r_anal_ref_init (R_NEW (RAnalysisRef));
|
||||
R_API RAnalRef *r_anal_ref_new() {
|
||||
return r_anal_ref_init (R_NEW (RAnalRef));
|
||||
}
|
||||
|
||||
R_API RList *r_anal_ref_list_new() {
|
||||
@ -20,7 +20,7 @@ R_API void r_anal_ref_free(void *ref) {
|
||||
free (ref);
|
||||
}
|
||||
|
||||
R_API RAnalysisRef *r_anal_ref_init(RAnalysisRef *ref) {
|
||||
R_API RAnalRef *r_anal_ref_init(RAnalRef *ref) {
|
||||
if (ref)
|
||||
*ref = -1;
|
||||
return ref;
|
||||
|
@ -71,18 +71,15 @@ R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *li
|
||||
struct list_head *pos;
|
||||
int dir = 0;
|
||||
char ch = ' ';
|
||||
|
||||
int linestyle = opts & R_ANAL_REFLINE_STYLE;
|
||||
int wide = opts & R_ANAL_REFLINE_WIDE;
|
||||
|
||||
if (!list)
|
||||
return R_FALSE;
|
||||
|
||||
strcpy (str, " ");
|
||||
|
||||
for (pos = linestyle?(&(list->list))->next:(&(list->list))->prev;
|
||||
pos != (&(list->list)); pos = linestyle?pos->next:pos->prev) {
|
||||
ref = list_entry(pos, struct r_anal_refline_t, list);
|
||||
ref = list_entry (pos, struct r_anal_refline_t, list);
|
||||
|
||||
if (addr == ref->to) dir = 1;
|
||||
// TODO: use else here
|
||||
@ -91,26 +88,26 @@ R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *li
|
||||
// TODO: if dir==1
|
||||
if (addr == ref->to) {
|
||||
if (ref->from > ref->to)
|
||||
strcat(str, ".");
|
||||
else strcat(str, "`");
|
||||
strcat (str, ".");
|
||||
else strcat (str, "`");
|
||||
ch = '-';
|
||||
} else if (addr == ref->from) {
|
||||
if (ref->from > ref->to)
|
||||
strcat(str, "`");
|
||||
else strcat(str, ".");
|
||||
strcat (str, "`");
|
||||
else strcat (str, ".");
|
||||
ch = '=';
|
||||
} else if (ref->from < ref->to) { /* down */
|
||||
if (addr > ref->from && addr < ref->to) {
|
||||
if (ch=='-'||ch=='=')
|
||||
r_str_concatch(str, ch);
|
||||
else strcat(str, "|");
|
||||
} else r_str_concatch(str, ch);
|
||||
} else r_str_concatch (str, ch);
|
||||
} else { /* up */
|
||||
if (addr < ref->from && addr > ref->to) {
|
||||
if (ch=='-'||ch=='=')
|
||||
r_str_concatch(str, ch);
|
||||
else strcat(str, "|");
|
||||
} else r_str_concatch(str, ch);
|
||||
r_str_concatch (str, ch);
|
||||
else strcat (str, "|");
|
||||
} else r_str_concatch (str, ch);
|
||||
}
|
||||
if (wide) {
|
||||
if (ch == '=' || ch == '-')
|
||||
@ -118,12 +115,18 @@ R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *li
|
||||
else strcat (str, " ");
|
||||
}
|
||||
}
|
||||
|
||||
switch (dir) {
|
||||
case 1: strcat (str, "-> "); break;
|
||||
case 2: strcat (str, "=< "); break;
|
||||
default: strcat (str, " "); break;
|
||||
}
|
||||
|
||||
strcat (str, (dir==1)?"-> ":(dir==2)?"=< ":" ");
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_anal_reflines_middle(RAnal *anal, RAnalRefline *list, ut64 addr, int len) {
|
||||
struct list_head *pos;
|
||||
int linestyle = 1;
|
||||
for (pos = (&(list->list))->next; pos != (&(list->list)); pos = pos->next) {
|
||||
RAnalRefline *ref = list_entry (pos, RAnalRefline, list);
|
||||
//if ((addr > ref->to) && (addr < ref->to+len))
|
||||
if ((ref->to> addr) && (ref->to < addr+len))
|
||||
return R_TRUE;
|
||||
}
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -6,16 +6,16 @@
|
||||
#include <r_util.h>
|
||||
#include <r_list.h>
|
||||
|
||||
R_API RAnalysisVar *r_anal_var_new() {
|
||||
return r_anal_var_init (R_NEW (RAnalysisVar));
|
||||
R_API RAnalVar *r_anal_var_new() {
|
||||
return r_anal_var_init (R_NEW (RAnalVar));
|
||||
}
|
||||
|
||||
R_API RAnalysisVarType *r_anal_var_type_new() {
|
||||
return r_anal_var_type_init (R_NEW (RAnalysisVarType));
|
||||
R_API RAnalVarType *r_anal_var_type_new() {
|
||||
return r_anal_var_type_init (R_NEW (RAnalVarType));
|
||||
}
|
||||
|
||||
R_API RAnalysisVarAccess *r_anal_var_access_new() {
|
||||
return r_anal_var_access_init (R_NEW (RAnalysisVarAccess));
|
||||
R_API RAnalVarAccess *r_anal_var_access_new() {
|
||||
return r_anal_var_access_init (R_NEW (RAnalVarAccess));
|
||||
}
|
||||
|
||||
R_API RList *r_anal_var_list_new() {
|
||||
@ -38,22 +38,22 @@ R_API RList *r_anal_var_access_list_new() {
|
||||
|
||||
R_API void r_anal_var_free(void *var) {
|
||||
if (var) {
|
||||
if (((RAnalysisVar*)var)->name)
|
||||
free (((RAnalysisVar*)var)->name);
|
||||
if (((RAnalysisVar*)var)->vartype)
|
||||
free (((RAnalysisVar*)var)->vartype);
|
||||
if (((RAnalysisVar*)var)->accesses)
|
||||
r_list_destroy (((RAnalysisVar*)var)->accesses);
|
||||
if (((RAnalVar*)var)->name)
|
||||
free (((RAnalVar*)var)->name);
|
||||
if (((RAnalVar*)var)->vartype)
|
||||
free (((RAnalVar*)var)->vartype);
|
||||
if (((RAnalVar*)var)->accesses)
|
||||
r_list_destroy (((RAnalVar*)var)->accesses);
|
||||
}
|
||||
free (var);
|
||||
}
|
||||
|
||||
R_API void r_anal_var_type_free(void *vartype) {
|
||||
if (vartype) {
|
||||
if (((RAnalysisVarType*)vartype)->name)
|
||||
free (((RAnalysisVarType*)vartype)->name);
|
||||
if (((RAnalysisVarType*)vartype)->fmt)
|
||||
free (((RAnalysisVarType*)vartype)->fmt);
|
||||
if (((RAnalVarType*)vartype)->name)
|
||||
free (((RAnalVarType*)vartype)->name);
|
||||
if (((RAnalVarType*)vartype)->fmt)
|
||||
free (((RAnalVarType*)vartype)->fmt);
|
||||
}
|
||||
free (vartype);
|
||||
}
|
||||
@ -62,28 +62,28 @@ R_API void r_anal_var_access_free(void *access) {
|
||||
free (access);
|
||||
}
|
||||
|
||||
R_API RAnalysisVar *r_anal_var_init(RAnalysisVar *var) {
|
||||
R_API RAnalVar *r_anal_var_init(RAnalVar *var) {
|
||||
if (var) {
|
||||
memset (var, 0, sizeof (RAnalysisVar));
|
||||
memset (var, 0, sizeof (RAnalVar));
|
||||
var->accesses = r_anal_var_access_list_new ();
|
||||
}
|
||||
return var;
|
||||
}
|
||||
|
||||
R_API RAnalysisVarType *r_anal_var_type_init(RAnalysisVarType *vartype) {
|
||||
R_API RAnalVarType *r_anal_var_type_init(RAnalVarType *vartype) {
|
||||
if (vartype)
|
||||
memset (vartype, 0, sizeof (RAnalysisVarType));
|
||||
memset (vartype, 0, sizeof (RAnalVarType));
|
||||
return vartype;
|
||||
}
|
||||
|
||||
R_API RAnalysisVarAccess *r_anal_var_access_init(RAnalysisVarAccess *access) {
|
||||
R_API RAnalVarAccess *r_anal_var_access_init(RAnalVarAccess *access) {
|
||||
if (access)
|
||||
memset (access, 0, sizeof (RAnalysisVarAccess));
|
||||
memset (access, 0, sizeof (RAnalVarAccess));
|
||||
return access;
|
||||
}
|
||||
|
||||
R_API int r_anal_var_type_add(RAnalysis *anal, const char *name, int size, const char *fmt) {
|
||||
RAnalysisVarType *t;
|
||||
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;
|
||||
@ -96,8 +96,8 @@ R_API int r_anal_var_type_add(RAnalysis *anal, const char *name, int size, const
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_anal_var_type_del(RAnalysis *anal, const char *name) {
|
||||
RAnalysisVarType *vti;
|
||||
R_API int r_anal_var_type_del(RAnal *anal, const char *name) {
|
||||
RAnalVarType *vti;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(anal->vartypes, iter, vti)
|
||||
@ -108,8 +108,8 @@ R_API int r_anal_var_type_del(RAnalysis *anal, const char *name) {
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API RAnalysisVarType *r_anal_var_type_get(RAnalysis *anal, const char *name) {
|
||||
RAnalysisVarType *vti;
|
||||
R_API RAnalVarType *r_anal_var_type_get(RAnal *anal, const char *name) {
|
||||
RAnalVarType *vti;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(anal->vartypes, iter, vti)
|
||||
@ -118,8 +118,8 @@ R_API RAnalysisVarType *r_anal_var_type_get(RAnalysis *anal, const char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_anal_var_add(RAnalysis *anal, RAnalysisFcn *fcn, ut64 from, int delta, int type, const char *vartype, const char *name, int set) {
|
||||
RAnalysisVar *var, *vari;
|
||||
R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int type, const char *vartype, const char *name, int set) {
|
||||
RAnalVar *var, *vari;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(fcn->vars, iter, vari)
|
||||
@ -138,8 +138,8 @@ R_API int r_anal_var_add(RAnalysis *anal, RAnalysisFcn *fcn, ut64 from, int delt
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_anal_var_del(RAnalysis *anal, RAnalysisFcn *fcn, int delta, int type) {
|
||||
RAnalysisVar *vari;
|
||||
R_API int r_anal_var_del(RAnal *anal, RAnalFcn *fcn, int delta, int type) {
|
||||
RAnalVar *vari;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(fcn->vars, iter, vari)
|
||||
@ -150,8 +150,8 @@ R_API int r_anal_var_del(RAnalysis *anal, RAnalysisFcn *fcn, int delta, int type
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API RAnalysisVar *r_anal_var_get(RAnalysis *anal, RAnalysisFcn *fcn, int delta, int type) {
|
||||
RAnalysisVar *vari;
|
||||
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFcn *fcn, int delta, int type) {
|
||||
RAnalVar *vari;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(fcn->vars, iter, vari)
|
||||
@ -160,7 +160,7 @@ R_API RAnalysisVar *r_anal_var_get(RAnalysis *anal, RAnalysisFcn *fcn, int delta
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API const char *r_anal_var_type_to_str (RAnalysis *anal, int type) {
|
||||
R_API const char *r_anal_var_type_to_str (RAnal *anal, int type) {
|
||||
switch(type) {
|
||||
case R_ANAL_VAR_TYPE_GLOBAL: return "global";
|
||||
case R_ANAL_VAR_TYPE_LOCAL: return "local";
|
||||
@ -170,8 +170,8 @@ R_API const char *r_anal_var_type_to_str (RAnalysis *anal, int type) {
|
||||
return "(?)";
|
||||
}
|
||||
|
||||
R_API int r_anal_var_access_add(RAnalysis *anal, RAnalysisVar *var, ut64 from, int set) {
|
||||
RAnalysisVarAccess *acc, *acci;
|
||||
R_API int r_anal_var_access_add(RAnal *anal, RAnalVar *var, ut64 from, int set) {
|
||||
RAnalVarAccess *acc, *acci;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(var->accesses, iter, acci)
|
||||
@ -185,8 +185,8 @@ R_API int r_anal_var_access_add(RAnalysis *anal, RAnalysisVar *var, ut64 from, i
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_anal_var_access_del(RAnalysis *anal, RAnalysisVar *var, ut64 from) {
|
||||
RAnalysisVarAccess *acci;
|
||||
R_API int r_anal_var_access_del(RAnal *anal, RAnalVar *var, ut64 from) {
|
||||
RAnalVarAccess *acci;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(var->accesses, iter, acci)
|
||||
@ -197,8 +197,8 @@ R_API int r_anal_var_access_del(RAnalysis *anal, RAnalysisVar *var, ut64 from) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API RAnalysisVarAccess *r_anal_var_access_get(RAnalysis *anal, RAnalysisVar *var, ut64 from) {
|
||||
RAnalysisVarAccess *acci;
|
||||
R_API RAnalVarAccess *r_anal_var_access_get(RAnal *anal, RAnalVar *var, ut64 from) {
|
||||
RAnalVarAccess *acci;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach(var->accesses, iter, acci)
|
||||
|
@ -76,8 +76,8 @@ static void r_core_anal_graph_nodes(struct r_core_t *core, RList *pbb, ut64 addr
|
||||
r_list_foreach (core->anal.bbs, iter, bbi) {
|
||||
if (addr == 0 || (addr >= bbi->addr && addr < bbi->addr+bbi->size)) {
|
||||
if (pbb) { /* Copy BB and append to the list of printed bbs */
|
||||
bbc = R_NEW (RAnalysisBB);
|
||||
memcpy (bbc, bbi, sizeof (RAnalysisBB));
|
||||
bbc = R_NEW (RAnalBB);
|
||||
memcpy (bbc, bbi, sizeof (RAnalBB));
|
||||
r_list_append (pbb, bbc);
|
||||
}
|
||||
if (bbi->jump != -1) {
|
||||
|
@ -655,7 +655,7 @@ static int cmd_cmp(void *data, const char *input) {
|
||||
" cD [file] Like above, but using radiff -b\n");
|
||||
break;
|
||||
default:
|
||||
eprintf("Usage: c[?Ddxf] [argument]\n");
|
||||
eprintf ("Usage: c[?Ddxf] [argument]\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -736,7 +736,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
// TODO: move to a function...we need a flag instead of thousand config_foo's
|
||||
{
|
||||
int ret, idx;
|
||||
int i;
|
||||
int middle, i;
|
||||
ut8 *buf = core->block;
|
||||
char str[128];
|
||||
char line[128];
|
||||
@ -744,8 +744,8 @@ static int cmd_print(void *data, const char *input) {
|
||||
char *opstr;
|
||||
char *osl = NULL; // old source line
|
||||
RAsmAop asmop;
|
||||
struct r_anal_aop_t analop;
|
||||
struct r_anal_refline_t *reflines;
|
||||
RAnalAop analop;
|
||||
RAnalRefline *reflines;
|
||||
RFlagItem *flag;
|
||||
|
||||
//r_anal_set_pc(&core->anal, core->offset);
|
||||
@ -772,6 +772,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
continue;
|
||||
}
|
||||
r_anal_aop (&core->anal, &analop, addr, buf+idx, (int)(len-idx));
|
||||
middle = r_anal_reflines_middle (&core->anal, reflines, addr, analop.length);
|
||||
|
||||
if (show_lines)
|
||||
r_cons_strcat (line);
|
||||
@ -850,12 +851,16 @@ static int cmd_print(void *data, const char *input) {
|
||||
osl = sl;
|
||||
}
|
||||
}
|
||||
r_cons_strcat ("\n");
|
||||
if (middle != 0) {
|
||||
ret = ret-middle;
|
||||
r_cons_printf (" ; *middle* %d", ret);
|
||||
}
|
||||
r_cons_newline ();
|
||||
if (show_lines && analop.type == R_ANAL_OP_TYPE_RET) {
|
||||
if (strchr(line, '>'))
|
||||
memset(line, ' ', strlen(line));
|
||||
r_cons_printf("%s", line);
|
||||
r_cons_printf("; ------------------------------------\n");
|
||||
if (strchr (line, '>'))
|
||||
memset (line, ' ', strlen (line));
|
||||
r_cons_strcat (line);
|
||||
r_cons_strcat ("; ------------------------------------\n");
|
||||
}
|
||||
}
|
||||
free (reflines);
|
||||
|
@ -123,7 +123,7 @@ typedef struct r_anal_t {
|
||||
struct r_anal_ctx_t *ctx;
|
||||
struct r_anal_handle_t *cur;
|
||||
struct list_head anals;
|
||||
} RAnalysis;
|
||||
} RAnal;
|
||||
|
||||
typedef struct r_anal_aop_t {
|
||||
ut64 addr;
|
||||
@ -139,7 +139,7 @@ typedef struct r_anal_aop_t {
|
||||
ut64 value; /* reference to value */ /* XXX signed? */
|
||||
int r_dst[R_ANAL_MAXREG]; /* register arguments */
|
||||
ut64 i_dst[R_ANAL_MAXREG]; /* inmediate arguments */
|
||||
} RAnalysisAop;
|
||||
} RAnalAop;
|
||||
|
||||
typedef struct r_anal_bb_t {
|
||||
ut64 addr;
|
||||
@ -147,7 +147,7 @@ typedef struct r_anal_bb_t {
|
||||
ut64 jump;
|
||||
ut64 fail;
|
||||
RList *aops;
|
||||
} RAnalysisBB;
|
||||
} RAnalBB;
|
||||
|
||||
typedef struct r_anal_fcn_t {
|
||||
char *name;
|
||||
@ -156,7 +156,7 @@ typedef struct r_anal_fcn_t {
|
||||
RList *vars;
|
||||
RList *refs;
|
||||
RList *xrefs;
|
||||
} RAnalysisFcn;
|
||||
} RAnalFcn;
|
||||
|
||||
typedef struct r_anal_var_t {
|
||||
char *name;
|
||||
@ -164,29 +164,29 @@ typedef struct r_anal_var_t {
|
||||
int type; /* global, local... */
|
||||
char *vartype; /* float, int... */
|
||||
RList *accesses; /* list of accesses for this var */
|
||||
} RAnalysisVar;
|
||||
} RAnalVar;
|
||||
|
||||
typedef struct r_anal_var_type_t {
|
||||
char *name;
|
||||
char *fmt;
|
||||
unsigned int size;
|
||||
} RAnalysisVarType;
|
||||
} RAnalVarType;
|
||||
|
||||
typedef struct r_anal_var_access_t {
|
||||
ut64 addr;
|
||||
int set;
|
||||
} RAnalysisVarAccess;
|
||||
} RAnalVarAccess;
|
||||
|
||||
typedef ut64 RAnalysisRef;
|
||||
typedef ut64 RAnalRef;
|
||||
|
||||
typedef struct r_anal_refline_t {
|
||||
ut64 from;
|
||||
ut64 to;
|
||||
int index;
|
||||
struct list_head list;
|
||||
} RAnalysisRefline;
|
||||
} RAnalRefline;
|
||||
|
||||
//TODO: typedef RAnalysisAopCallback
|
||||
//TODO: typedef RAnalAopCallback
|
||||
typedef struct r_anal_handle_t {
|
||||
char *name;
|
||||
char *desc;
|
||||
@ -196,13 +196,13 @@ typedef struct r_anal_handle_t {
|
||||
int (*aop)(struct r_anal_t *a, struct r_anal_aop_t *aop, ut64 addr,
|
||||
const ut8 *data, int len);
|
||||
struct list_head list;
|
||||
} RAnalysisHandle;
|
||||
} RAnalHandle;
|
||||
|
||||
#ifdef R_API
|
||||
/* anal.c */
|
||||
R_API RAnalysis *r_anal_new();
|
||||
R_API RAnalysis *r_anal_free(struct r_anal_t *r);
|
||||
R_API RAnalysis *r_anal_init(struct r_anal_t *anal);
|
||||
R_API RAnal *r_anal_new();
|
||||
R_API RAnal *r_anal_free(struct r_anal_t *r);
|
||||
R_API RAnal *r_anal_init(struct r_anal_t *anal);
|
||||
R_API void r_anal_set_user_ptr(struct r_anal_t *anal, void *user);
|
||||
R_API int r_anal_add(struct r_anal_t *anal, struct r_anal_handle_t *foo);
|
||||
R_API int r_anal_list(struct r_anal_t *anal);
|
||||
@ -212,71 +212,72 @@ R_API int r_anal_set_big_endian(struct r_anal_t *anal, int boolean);
|
||||
R_API int r_anal_set_pc(struct r_anal_t *a, ut64 pc);
|
||||
|
||||
/* bb.c */
|
||||
R_API RAnalysisBB *r_anal_bb_new();
|
||||
R_API RAnalBB *r_anal_bb_new();
|
||||
R_API RList *r_anal_bb_list_new();
|
||||
R_API void r_anal_bb_free(void *bb);
|
||||
R_API RAnalysisBB *r_anal_bb_init(struct r_anal_bb_t *bb);
|
||||
R_API RAnalBB *r_anal_bb_init(struct r_anal_bb_t *bb);
|
||||
R_API int r_anal_bb(struct r_anal_t *anal, struct r_anal_bb_t *bb,
|
||||
ut64 addr, ut8 *buf, ut64 len);
|
||||
R_API int r_anal_bb_split(RAnalysis *anal, RAnalysisBB *bb, RList *bbs, ut64 addr);
|
||||
R_API int r_anal_bb_overlap(RAnalysis *anal, RAnalysisBB *bb, RList *bbs);
|
||||
R_API int r_anal_bb_split(RAnal *anal, RAnalBB *bb, RList *bbs, ut64 addr);
|
||||
R_API int r_anal_bb_overlap(RAnal *anal, RAnalBB *bb, RList *bbs);
|
||||
|
||||
/* aop.c */
|
||||
R_API RAnalysisAop *r_anal_aop_new();
|
||||
R_API RAnalAop *r_anal_aop_new();
|
||||
R_API RList *r_anal_aop_list_new();
|
||||
R_API void r_anal_aop_free(void *aop);
|
||||
R_API RAnalysisAop *r_anal_aop_init(struct r_anal_aop_t *aop);
|
||||
R_API int r_anal_aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr,
|
||||
R_API RAnalAop *r_anal_aop_init(struct r_anal_aop_t *aop);
|
||||
R_API int r_anal_aop(RAnal *anal, RAnalAop *aop, ut64 addr,
|
||||
const ut8 *data, int len);
|
||||
|
||||
/* fcn.c */
|
||||
R_API RAnalysisFcn *r_anal_fcn_new();
|
||||
R_API RAnalFcn *r_anal_fcn_new();
|
||||
R_API RList *r_anal_fcn_list_new();
|
||||
R_API void r_anal_fcn_free(void *fcn);
|
||||
R_API RAnalysisFcn *r_anal_fcn_init(RAnalysisFcn *fcn);
|
||||
R_API int r_anal_fcn(RAnalysis *anal, RAnalysisFcn *fcn, ut64 addr, ut8 *buf, ut64 len);
|
||||
R_API RAnalFcn *r_anal_fcn_init(RAnalFcn *fcn);
|
||||
R_API int r_anal_fcn(RAnal *anal, RAnalFcn *fcn, ut64 addr, ut8 *buf, ut64 len);
|
||||
|
||||
/* ref.c */
|
||||
R_API RAnalysisRef *r_anal_ref_new();
|
||||
R_API RAnalRef *r_anal_ref_new();
|
||||
R_API RList *r_anal_ref_list_new();
|
||||
R_API void r_anal_ref_free(void *ref);
|
||||
R_API RAnalysisRef *r_anal_ref_init(RAnalysisRef *ref);
|
||||
R_API RAnalRef *r_anal_ref_init(RAnalRef *ref);
|
||||
|
||||
/* var.c */
|
||||
R_API RAnalysisVar *r_anal_var_new();
|
||||
R_API RAnalysisVarType *r_anal_var_type_new();
|
||||
R_API RAnalysisVarAccess *r_anal_var_access_new();
|
||||
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 RAnalysisVar *r_anal_var_init(RAnalysisVar *var);
|
||||
R_API RAnalysisVarType *r_anal_var_type_init(RAnalysisVarType *vartype);
|
||||
R_API RAnalysisVarAccess *r_anal_var_access_init(RAnalysisVarAccess *access);
|
||||
R_API int r_anal_var_type_add(RAnalysis *anal, const char *name, int size, const char *fmt);
|
||||
R_API int r_anal_var_type_del(RAnalysis *anal, const char *name);
|
||||
R_API RAnalysisVarType *r_anal_var_type_get(RAnalysis *anal, const char *name);
|
||||
R_API int r_anal_var_add(RAnalysis *anal, RAnalysisFcn *fcn, ut64 from, int delta, int type,
|
||||
R_API RAnalVar *r_anal_var_init(RAnalVar *var);
|
||||
R_API RAnalVarType *r_anal_var_type_init(RAnalVarType *vartype);
|
||||
R_API RAnalVarAccess *r_anal_var_access_init(RAnalVarAccess *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 RAnalVarType *r_anal_var_type_get(RAnal *anal, const char *name);
|
||||
R_API int r_anal_var_add(RAnal *anal, RAnalFcn *fcn, ut64 from, int delta, int type,
|
||||
const char *vartype, const char *name, int set);
|
||||
R_API int r_anal_var_del(RAnalysis *anal, RAnalysisFcn *fcn, int delta, int type);
|
||||
R_API RAnalysisVar *r_anal_var_get(RAnalysis *anal, RAnalysisFcn *fcn, int delta, int type);
|
||||
R_API const char *r_anal_var_type_to_str (RAnalysis *anal, int type);
|
||||
R_API int r_anal_var_access_add(RAnalysis *anal, RAnalysisVar *var, ut64 from, int set);
|
||||
R_API int r_anal_var_access_del(RAnalysis *anal, RAnalysisVar *var, ut64 from);
|
||||
R_API RAnalysisVarAccess *r_anal_var_access_get(RAnalysis *anal, RAnalysisVar *var, ut64 from);
|
||||
R_API int r_anal_var_del(RAnal *anal, RAnalFcn *fcn, int delta, int type);
|
||||
R_API RAnalVar *r_anal_var_get(RAnal *anal, RAnalFcn *fcn, int delta, int type);
|
||||
R_API const char *r_anal_var_type_to_str (RAnal *anal, int type);
|
||||
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);
|
||||
|
||||
/* reflines.c */
|
||||
R_API struct r_anal_refline_t *r_anal_reflines_get(struct r_anal_t *anal,
|
||||
ut64 addr, ut8 *buf, ut64 len, int nlines, int linesout);
|
||||
R_API int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *list,
|
||||
ut64 addr, char *str, int opts);
|
||||
R_API int r_anal_reflines_middle(struct r_anal_t *anal, RAnalRefline *list, ut64 addr, int len);
|
||||
|
||||
/* plugin pointers */
|
||||
extern RAnalysisHandle r_anal_plugin_arm;
|
||||
extern RAnalysisHandle r_anal_plugin_x86;
|
||||
extern RAnalysisHandle r_anal_plugin_ppc;
|
||||
extern RAnalHandle r_anal_plugin_arm;
|
||||
extern RAnalHandle r_anal_plugin_x86;
|
||||
extern RAnalHandle r_anal_plugin_ppc;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,9 +1,10 @@
|
||||
class Radare.RAnalysis {
|
||||
class Radare.RAnal {
|
||||
struct Refline {
|
||||
uint64 from;
|
||||
uint64 to;
|
||||
int index;
|
||||
}
|
||||
|
||||
/* XXX dupped in r_asm ?? */
|
||||
struct Aop {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user