- Update build system
  - Fix analysis of bb longer than blocksize
  - Code cleanup
* build
  - Add anal plugins to plugins.def.cfg
This commit is contained in:
Nibble 2010-02-28 20:07:36 +01:00
parent e8d3c0580b
commit cbb5fe143b
14 changed files with 158 additions and 88 deletions

View File

@ -1,5 +1,19 @@
NAME=r_anal
DEPS=r_util r_lib
OBJ=anal.o ctx.o reflines.o
CFLAGS+=-DCORELIB -Iarch
include ../config.mk
foo: pre libr_anal.${EXT_SO} libr_anal.${EXT_AR} plugins
include ${STATIC_ANAL_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst anal_,p/anal_,$(STATIC_OBJ)))
OBJ=${STATIC_OBJS} ctx.o reflines.o anal.o
pre:
if [ ! -e libr_anal.${EXT_SO} ]; then rm -f ${STATIC_OBJS} ; fi
plugins:
cd p && ${MAKE} all
include ../rules.mk

View File

@ -5,17 +5,26 @@
#include <r_anal.h>
#include <r_util.h>
#include <r_list.h>
#include "../config.h"
/* plugin pointers */
extern RAnalysisHandle r_anal_plugin_x86;
extern RAnalysisHandle r_anal_plugin_x86_bea;
extern RAnalysisHandle r_anal_plugin_ppc;
static struct r_anal_handle_t *anal_static_plugins[] =
{ R_ANAL_STATIC_PLUGINS };
R_API RAnalysis *r_anal_new() {
return r_anal_init (MALLOC_STRUCT (struct r_anal_t));
return r_anal_init (MALLOC_STRUCT (RAnalysis));
}
R_API RAnalysisBB *r_anal_bb_new() {
return r_anal_bb_init (MALLOC_STRUCT (struct r_anal_bb_t));
return r_anal_bb_init (MALLOC_STRUCT (RAnalysisBB));
}
R_API RAnalysisAop *r_anal_aop_new() {
return r_anal_aop_init (MALLOC_STRUCT (struct r_anal_aop_t));
return r_anal_aop_init (MALLOC_STRUCT (RAnalysisAop));
}
R_API RList *r_anal_bb_list_new() {
@ -30,7 +39,7 @@ R_API RList *r_anal_aop_list_new() {
return list;
}
R_API RAnalysis *r_anal_free(struct r_anal_t *a) {
R_API RAnalysis *r_anal_free(RAnalysis *a) {
/* TODO: Free a->anals here */
r_list_destroy (a->bbs);
free (a);
@ -48,18 +57,22 @@ R_API void r_anal_aop_free(void *aop) {
free (aop);
}
R_API RAnalysis *r_anal_init(struct r_anal_t *anal) {
R_API RAnalysis *r_anal_init(RAnalysis *anal) {
int i;
if (anal) {
memset (anal, 0, sizeof (RAnalysis));
anal->bbs = r_anal_bb_list_new();
r_anal_set_bits (anal, 32);
r_anal_set_big_endian (anal, R_FALSE);
INIT_LIST_HEAD (&anal->anals);
for (i=0; anal_static_plugins[i]; i++)
r_anal_add (anal, anal_static_plugins[i]);
}
return anal;
}
R_API RAnalysisBB *r_anal_bb_init(struct r_anal_bb_t *bb) {
R_API RAnalysisBB *r_anal_bb_init(RAnalysisBB *bb) {
if (bb) {
memset (bb, 0, sizeof (RAnalysisBB));
bb->addr = -1;
@ -70,7 +83,7 @@ R_API RAnalysisBB *r_anal_bb_init(struct r_anal_bb_t *bb) {
return bb;
}
R_API RAnalysisAop *r_anal_aop_init(struct r_anal_aop_t *aop) {
R_API RAnalysisAop *r_anal_aop_init(RAnalysisAop *aop) {
if (aop) {
memset (aop, 0, sizeof (RAnalysisAop));
aop->jump = -1;
@ -79,11 +92,11 @@ R_API RAnalysisAop *r_anal_aop_init(struct r_anal_aop_t *aop) {
return aop;
}
R_API void r_anal_set_user_ptr(struct r_anal_t *anal, void *user) {
R_API void r_anal_set_user_ptr(RAnalysis *anal, void *user) {
anal->user = user;
}
R_API int r_anal_add(struct r_anal_t *anal, struct r_anal_handle_t *foo) {
R_API int r_anal_add(RAnalysis *anal, struct r_anal_handle_t *foo) {
if (foo->init)
foo->init(anal->user);
list_add_tail(&(foo->list), &(anal->anals));
@ -91,7 +104,7 @@ R_API int r_anal_add(struct r_anal_t *anal, struct r_anal_handle_t *foo) {
}
// TODO: Must be deprecated
R_API int r_anal_list(struct r_anal_t *anal) {
R_API int r_anal_list(RAnalysis *anal) {
struct list_head *pos;
list_for_each_prev(pos, &anal->anals) {
struct r_anal_handle_t *h = list_entry(pos, struct r_anal_handle_t, list);
@ -100,7 +113,7 @@ R_API int r_anal_list(struct r_anal_t *anal) {
return R_FALSE;
}
R_API int r_anal_use(struct r_anal_t *anal, const char *name) {
R_API int r_anal_use(RAnalysis *anal, const char *name) {
struct list_head *pos;
list_for_each_prev (pos, &anal->anals) {
struct r_anal_handle_t *h = list_entry(pos, struct r_anal_handle_t, list);
@ -112,7 +125,7 @@ R_API int r_anal_use(struct r_anal_t *anal, const char *name) {
return R_FALSE;
}
R_API int r_anal_set_bits(struct r_anal_t *anal, int bits) {
R_API int r_anal_set_bits(RAnalysis *anal, int bits) {
switch (bits) {
case 8:
case 16:
@ -124,44 +137,43 @@ R_API int r_anal_set_bits(struct r_anal_t *anal, int bits) {
return R_FALSE;
}
R_API int r_anal_set_big_endian(struct r_anal_t *anal, int bigend) {
R_API int r_anal_set_big_endian(RAnalysis *anal, int bigend) {
anal->big_endian = bigend;
return R_TRUE;
}
R_API int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, void *data, int len) {
if (anal && anal->cur && anal->cur->aop)
R_API int r_anal_aop(RAnalysis *anal, RAnalysisAop *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 R_FALSE;
return 0;
}
R_API int r_anal_bb(struct r_anal_t *anal, struct r_anal_bb_t *bb, ut64 addr, ut8 *buf, ut64 len) {
struct r_anal_aop_t *aop;
R_API int r_anal_bb(RAnalysis *anal, RAnalysisBB *bb, ut64 addr, ut8 *buf, ut64 len) {
RAnalysisAop *aop;
int oplen, idx = 0;
bb->addr = addr;
if (bb->addr == -1)
bb->addr = addr;
while (idx < len) {
if (!(aop = r_anal_aop_new())) {
eprintf ("Error: new (aop)\n");
return 0;
return -1;
}
if (!(oplen = r_anal_aop (anal, aop, addr+idx, buf+idx, len-idx))) {
free (aop);
if ((oplen = r_anal_aop (anal, aop, addr+idx, buf+idx, len-idx)) == 0) {
r_anal_aop_free (aop);
break;
}
idx += oplen;
bb->size += oplen;
r_list_append (bb->aops, aop);
switch (aop->type) {
case R_ANAL_OP_TYPE_CJMP:
bb->fail = aop->fail;
case R_ANAL_OP_TYPE_JMP:
bb->jump = aop->jump;
bb->size = idx;
return bb->size;
case R_ANAL_OP_TYPE_RET:
bb->size = idx;
return bb->size;
return 0;
}
}
return 0;
return bb->size;
}

View File

@ -1,30 +1,19 @@
BINDEPS=foo
include ../../config.mk
CFLAGS=-I../../include -I../../asm/arch/ -I../arch/ -Wall -fPIC ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}.. -L..
CFLAGS+=-DR_DEBUG=1
CFLAGS=-I../../include -I../arch -I../../asm/arch -Wall -fPIC ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
CFLAGS+=-L../../util -lr_util
ANAL_X86_OBJ=../arch/x86/dislen.o
foo: all
# TODO: use .mk files
all: anal_dummy.${EXT_SO} anal_x86.${EXT_SO} anal_x86_bea.${EXT_SO} anal_ppc.${EXT_SO}
ALL_TARGETS=
# TODO: rename to enabled plugins
ARCHS=dummy.mk x86.mk x86_bea.mk ppc.mk
include $(ARCHS)
all: ${ALL_TARGETS}
@true
anal_dummy.${EXT_SO}: anal_dummy.o
${CC} ${CFLAGS} -o anal_dummy.${EXT_SO} anal_dummy.o
@#strip -s anal_dummy.so
anal_x86.${EXT_SO}: anal_x86.o ${ANAL_X86_OBJ}
${CC} ${CFLAGS} -o anal_x86.${EXT_SO} anal_x86.o ${ANAL_X86_OBJ}
@#strip -s anal_x86.so
anal_ppc.${EXT_SO}: anal_ppc.o
${CC} ${CFLAGS} -o anal_ppc.${EXT_SO} anal_ppc.o
@#strip -s anal_ppc.so
anal_x86_bea.${EXT_SO}: anal_x86_bea.o
${CC} ${CFLAGS} -o anal_x86_bea.${EXT_SO} anal_x86_bea.o ../../asm/arch/x86/bea/BeaEngine.o
@#strip -s anal_x86_bea.so
clean:
-rm -f *.so *.o ${ANAL_X86_OBJ}
-rm -f *.${EXT_SO} *.o ${STATIC_OBJ}
.PHONY: all clean foo

View File

@ -4,22 +4,17 @@
#include <r_lib.h>
#include <r_anal.h>
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
{
printf("Dummy analysis plugin");
return R_FALSE;
}
static struct r_anal_handle_t r_anal_plugin_dummy = {
struct r_anal_handle_t r_anal_plugin_dummy = {
.name = "dummy",
.desc = "Dummy analysis plugin",
.init = NULL,
.fini = NULL,
.aop = &aop
.aop = NULL
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_dummy
};
#endif

View File

@ -7,7 +7,7 @@
// NOTE: buf should be at least 16 bytes!
// XXX addr should be off_t for 64 love
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, const ut8 *bytes, int len) {
int aop(RAnalysis *anal, RAnalysisAop *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 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, const
//if (baddr>0x7fff)
// baddr = -baddr;
memset (aop, '\0', sizeof (struct r_anal_aop_t));
memset (aop, '\0', sizeof (RAnalysisAop));
aop->type = R_ANAL_OP_TYPE_NOP;
aop->length = 4;
@ -70,10 +70,11 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, const
break;
}
aop->addr = addr;
return 4;
aop->length = 4;
return aop->length;
}
static struct r_anal_handle_t r_anal_plugin_ppc = {
struct r_anal_handle_t r_anal_plugin_ppc = {
.name = "ppc",
.desc = "PowerPC analysis plugin",
.init = NULL,
@ -81,10 +82,12 @@ static struct r_anal_handle_t r_anal_plugin_ppc = {
.aop = &aop
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_ppc
};
#endif
#if 0
NOTES:

View File

@ -26,12 +26,12 @@
// NOTE: buf should be at least 16 bytes!
// XXX addr should be off_t for 64 love
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, void *data, int len) {
if (anal == NULL || aop == NULL || data == NULL)
static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, int len) {
if (data == NULL)
return 0;
ut8 *buf = (ut8*)data;
memset(aop, '\0', sizeof(struct r_anal_aop_t));
memset(aop, '\0', sizeof(RAnalysisAop));
aop->type = R_ANAL_OP_TYPE_UNK;
switch(buf[0]) {
@ -374,8 +374,8 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, void
aop->jump = addr+bo+2; //(unsigned long)((buf+1)+5);
aop->fail = addr+2;
aop->eob = 1;
aop->addr = addr;
return 2;
//aop->addr = addr;
//return 2;
}
break;
//default:
@ -391,7 +391,7 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, void
return aop->length;
}
static struct r_anal_handle_t r_anal_plugin_x86 = {
struct r_anal_handle_t r_anal_plugin_x86 = {
.name = "x86",
.desc = "X86 analysis plugin",
.init = NULL,
@ -399,7 +399,9 @@ static struct r_anal_handle_t r_anal_plugin_x86 = {
.aop = &aop
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_x86
};
#endif

View File

@ -10,13 +10,16 @@
#include "x86/bea/BeaEngine.h"
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, ut64 addr, void *data, int len) {
int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, int len) {
DISASM disasm_obj;
ARGTYPE *argptr = NULL;
//unsigned long long addr = (ut64)data;
char category[1024], argtype[1024];
int i;
if (data == NULL)
return 0;
memset(&disasm_obj, '\0', sizeof(DISASM));
disasm_obj.EIP = (long long)(data);
disasm_obj.VirtualAddr = addr;
@ -394,7 +397,7 @@ struct r_anal_handle_t r_anal_plugin_x86_bea = {
.aop = &aop
};
#if !CORELIB
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_x86_bea

10
libr/anal/p/dummy.mk Normal file
View File

@ -0,0 +1,10 @@
OBJ_DUMMY=anal_dummy.o
STATIC_OBJ+=${OBJ_DUMMY}
TARGET_DUMMY=anal_dummy.${EXT_SO}
ALL_TARGETS+=${TARGET_DUMMY}
${TARGET_DUMMY}: ${OBJ_DUMMY}
${CC} ${CFLAGS} -o ${TARGET_DUMMY} ${OBJ_DUMMY}
@#strip -s ${TARGET_DUMMY}

10
libr/anal/p/ppc.mk Normal file
View File

@ -0,0 +1,10 @@
OBJ_PPC=anal_ppc.o
STATIC_OBJ+=${OBJ_PPC}
TARGET_PPC=anal_ppc.${EXT_SO}
ALL_TARGETS+=${TARGET_PPC}
${TARGET_PPC}: ${OBJ_PPC}
${CC} ${CFLAGS} -o anal_ppc.${EXT_SO} ${OBJ_PPC}
@#strip -s anal_ppc.${EXT_SO}

11
libr/anal/p/x86.mk Normal file
View File

@ -0,0 +1,11 @@
OBJ_X86=anal_x86.o
OBJ_X86+=../arch/x86/dislen.o
STATIC_OBJ+=${OBJ_X86}
TARGET_X86=anal_x86.${EXT_SO}
ALL_TARGETS+=${TARGET_X86}
${TARGET_X86}: ${OBJ_X86}
${CC} ${CFLAGS} -o anal_x86.${EXT_SO} ${OBJ_X86}
@#strip -s anal_x86.${EXT_SO}

11
libr/anal/p/x86_bea.mk Normal file
View File

@ -0,0 +1,11 @@
OBJ_X86_BEA=anal_x86_bea.o
OBJ_X86_BEA+=../../asm/arch/x86/bea/BeaEngine.o
STATIC_OBJ+=${OBJ_X86_BEA}
TARGET_X86_BEA=anal_x86_bea.${EXT_SO}
ALL_TARGETS+=${TARGET_X86_BEA}
${TARGET_X86_BEA}: ${OBJ_X86_BEA}
${CC} ${CFLAGS} -o anal_x86_bea.${EXT_SO} ${OBJ_X86_BEA}
@#strip -s anal_x86_bea.${EXT_SO}

View File

@ -40,7 +40,7 @@ R_API int r_core_anal_bb (struct r_core_t *core, ut64 at, int depth) {
RListIter *iter;
ut64 jump, fail;
ut8 *buf;
int len, split = 0;
int len, bblen = 0, split = 0;
if (depth < 0)
return R_FALSE;
@ -76,17 +76,23 @@ R_API int r_core_anal_bb (struct r_core_t *core, ut64 at, int depth) {
} else {
if (!(buf = malloc (core->blocksize)))
return R_FALSE;
if ((len = r_io_read_at (&core->io, at, buf, core->blocksize)) == -1)
return R_FALSE;
if (r_anal_bb (&core->anal, bb, at, buf, len) > 0) {
r_list_append (core->anal.bbs, bb);
fail = bb->fail;
jump = bb->jump;
if (fail != -1)
r_core_anal_bb (core, fail, depth-1);
if (jump != -1)
r_core_anal_bb (core, jump, depth-1);
} else r_anal_bb_free (bb);
do {
if ((len = r_io_read_at (&core->io, at+bblen, buf, core->blocksize)) == -1)
return R_FALSE;
bblen = r_anal_bb (&core->anal, bb, at+bblen, buf, len);
if (bblen == -1) {
r_anal_bb_free (bb);
return R_FALSE;
} else if (bblen == 0) {
r_list_append (core->anal.bbs, bb);
fail = bb->fail;
jump = bb->jump;
if (fail != -1)
r_core_anal_bb (core, fail, depth-1);
if (jump != -1)
r_core_anal_bb (core, jump, depth-1);
}
} while (bblen > 0);
free (buf);
}
return R_TRUE;

View File

@ -155,8 +155,8 @@ typedef struct r_anal_handle_t {
int (*init)(void *user);
int (*fini)(void *user);
// TODO: typedef
int (*aop)(struct r_anal_t *a, struct r_anal_aop_t *aop,
ut64 addr, const ut8 *data, int len);
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;
@ -180,8 +180,8 @@ R_API int r_anal_use(struct r_anal_t *anal, const char *name);
R_API int r_anal_set_bits(struct r_anal_t *anal, int bits);
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);
R_API int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop,
ut64 addr, void *data, int len);
R_API int r_anal_aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr,
const ut8 *data, int len);
R_API int r_anal_bb(struct r_anal_t *anal, struct r_anal_bb_t *bb,
ut64 addr, ut8 *buf, ut64 len);

View File

@ -5,6 +5,8 @@ asm.ppc
asm.x86
asm.x86_nasm
asm.x86_olly
anal.x86
anal.ppc
bin.dummy
bin.elf
bin.elf64
@ -32,5 +34,7 @@ asm.dummy
asm.m68k
asm.psosvm
asm.sparc
anal.dummy
anal.x86_bea
debug.gdb
io.shm"