mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 02:23:58 +00:00
* Merge local commits with head
This commit is contained in:
commit
1f02a3f1be
@ -48,10 +48,10 @@ int r_anal_set(struct r_anal_t *anal, const char *name)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
int r_anal_aop(struct r_anal_t *anal)
|
||||
int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
if (anal->cur && anal->cur->aop)
|
||||
return anal->cur->aop(anal->user);
|
||||
return anal->cur->aop(aop, data);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <r_lib.h>
|
||||
#include <r_anal.h>
|
||||
|
||||
static int aop(void *user)
|
||||
static int aop(struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
printf("Dummy analysis plugin");
|
||||
|
||||
|
@ -23,11 +23,10 @@
|
||||
|
||||
// NOTE: buf should be at least 16 bytes!
|
||||
// XXX addr should be off_t for 64 love
|
||||
static int aop(void *user)
|
||||
static int aop(struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
struct r_asm_t *a = (struct r_asm_t*)user;
|
||||
struct r_anal_aop_t *aop = a->aux;
|
||||
u8 *buf = a->buf;
|
||||
struct r_asm_t *asmdata = (struct r_asm_t*)data;
|
||||
u8 *buf = asmdata->buf;
|
||||
|
||||
memset(aop, '\0', sizeof(struct r_anal_aop_t));
|
||||
aop->type = R_ANAL_AOP_TYPE_UNK;
|
||||
@ -124,8 +123,8 @@ static int aop(void *user)
|
||||
} else
|
||||
if (buf[1]>=0x80 && buf[1]<=0x8f) {
|
||||
aop->type = R_ANAL_AOP_TYPE_CJMP;
|
||||
aop->jump = a->pc+6+buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24);//((unsigned long)((buf+2))+6);
|
||||
aop->fail = a->pc+6;
|
||||
aop->jump = asmdata->pc+6+buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24);//((unsigned long)((buf+2))+6);
|
||||
aop->fail = asmdata->pc+6;
|
||||
aop->length = 6;
|
||||
//aop->eob = 1;
|
||||
}
|
||||
@ -143,24 +142,24 @@ static int aop(void *user)
|
||||
case 0xe8: // call
|
||||
aop->type = R_ANAL_AOP_TYPE_CALL;
|
||||
aop->length = 5;
|
||||
//aop->jump = a->pc+*ptr+5; //(unsigned long)((buf+1)+5);
|
||||
aop->jump = a->pc+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
|
||||
aop->fail = a->pc+5;
|
||||
//printf("a->pc: %08llx\n call %08llx \n ret %08llx\n", a->pc, aop->jump, aop->fail);
|
||||
//aop->jump = asmdata->pc+*ptr+5; //(unsigned long)((buf+1)+5);
|
||||
aop->jump = asmdata->pc+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
|
||||
aop->fail = asmdata->pc+5;
|
||||
//printf("asmdata->pc: %08llx\n call %08llx \n ret %08llx\n", asmdata->pc, aop->jump, aop->fail);
|
||||
// aop->eob = 1;
|
||||
break;
|
||||
case 0xe9: // jmp
|
||||
aop->type = R_ANAL_AOP_TYPE_JMP;
|
||||
aop->length = 5;
|
||||
//aop->jump = (unsigned long)((buf+1)+5);
|
||||
aop->jump = a->pc+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
|
||||
aop->jump = asmdata->pc+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
|
||||
aop->fail = 0L;
|
||||
aop->eob = 1;
|
||||
break;
|
||||
case 0xeb: // short jmp
|
||||
aop->type = R_ANAL_AOP_TYPE_JMP;
|
||||
aop->length = 2;
|
||||
aop->jump = a->pc+((unsigned long)((char)buf[1])+2);
|
||||
aop->jump = asmdata->pc+((unsigned long)((char)buf[1])+2);
|
||||
aop->fail = 0L;
|
||||
aop->eob = 1;
|
||||
break;
|
||||
@ -191,7 +190,7 @@ static int aop(void *user)
|
||||
aop->length = 2;
|
||||
aop->eob = 1;
|
||||
//aop->jump = vm_arch_x86_regs[VM_X86_EAX+buf[1]-0xd0];
|
||||
aop->fail = a->pc+2;
|
||||
aop->fail = asmdata->pc+2;
|
||||
} else
|
||||
if (buf[1]>=0xe0 && buf[1]<=0xe7) {
|
||||
aop->type = R_ANAL_AOP_TYPE_UJMP;
|
||||
@ -320,34 +319,34 @@ static int aop(void *user)
|
||||
|
||||
case 0xa1: // mov eax, [addr]
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_EAX] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_EAX] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//radare_read_at((u64)vm_arch_x86_regs[VM_X86_EAX], (unsigned char *)&(vm_arch_x86_regs[VM_X86_EAX]), 4);
|
||||
break;
|
||||
|
||||
// roll to a switch range case
|
||||
case 0xb8: // mov eax, <inmedate>
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_EAX] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_EAX] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
break;
|
||||
case 0xb9: // mov ecx, <inmedate>
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_ECX] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_ECX] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
break;
|
||||
case 0xba: // mov edx, <inmedate>
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_EDX] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_EDX] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
break;
|
||||
case 0xbb: // mov ebx, <inmedate>
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_EBX] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_EBX] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
break;
|
||||
case 0xbc: // mov esp, <inmedate>
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_ESP] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_ESP] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
break;
|
||||
case 0xbd: // mov esp, <inmedate>
|
||||
aop->type = R_ANAL_AOP_TYPE_MOV;
|
||||
//vm_arch_x86_regs[VM_X86_EBP] = a->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
//vm_arch_x86_regs[VM_X86_EBP] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
|
||||
break;
|
||||
#if 0
|
||||
case0xF
|
||||
@ -384,8 +383,8 @@ static int aop(void *user)
|
||||
aop->type = R_ANAL_AOP_TYPE_CJMP;
|
||||
aop->length = 2;
|
||||
// aop->jump = (unsigned long)((buf+2)+6);
|
||||
aop->jump = a->pc+bo+2; //(unsigned long)((buf+1)+5);
|
||||
aop->fail = a->pc+2;
|
||||
aop->jump = asmdata->pc+bo+2; //(unsigned long)((buf+1)+5);
|
||||
aop->fail = asmdata->pc+2;
|
||||
aop->eob = 1;
|
||||
return 2;
|
||||
}
|
||||
@ -394,7 +393,7 @@ static int aop(void *user)
|
||||
//aop->type = R_ANAL_AOP_TYPE_UNK;
|
||||
}
|
||||
|
||||
aop->length = a->inst_len;
|
||||
aop->length = asmdata->inst_len;
|
||||
|
||||
if (!(aop->jump>>33))
|
||||
aop->jump &= 0xFFFFFFFF; // XXX may break on 64 bits here
|
||||
|
@ -347,6 +347,26 @@ static int cmd_anal(void *data, const char *input)
|
||||
r_anal_list(&core->anal);
|
||||
break;
|
||||
case 'o':
|
||||
{
|
||||
/* XXX hardcoded */
|
||||
int ret, idx;
|
||||
u8 *buf = core->block;
|
||||
struct r_asm_t a;// TODO: move to core.h
|
||||
struct r_anal_aop_t aop;
|
||||
r_asm_init(&a);
|
||||
r_asm_set_pc(&a, core->seek);
|
||||
r_anal_set(&core->anal, "anal_x86");
|
||||
|
||||
for(idx=ret=0; idx < len; idx+=ret) {
|
||||
r_asm_set_pc(&a, a.pc + ret);
|
||||
ret = r_asm_disasm(&a, buf+idx, len-idx);
|
||||
r_cons_printf("0x%08llx %14s %s\n",
|
||||
core->seek+idx, a.buf_hex, a.buf_asm);
|
||||
r_anal_aop(&core->anal, &aop, &a);
|
||||
r_cons_printf("JUMP: 0x%08llx\n",
|
||||
aop.jump);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Usage: a[o] [len]\n"
|
||||
|
@ -73,7 +73,7 @@ int __lib_anl_cb(struct r_lib_plugin_t *pl, void *user, void *data)
|
||||
{
|
||||
struct r_anal_handle_t *hand = (struct r_anal_handle_t *)data;
|
||||
struct r_core_t *core = (struct r_core_t *)user;
|
||||
//printf(" * Added language handler\n");
|
||||
//printf(" * Added analysis handler\n");
|
||||
r_anal_add(&core->anal, hand);
|
||||
return R_TRUE;
|
||||
}
|
||||
@ -89,6 +89,7 @@ int r_core_init(struct r_core_t *core)
|
||||
r_lang_init(&core->lang);
|
||||
r_lang_set_user_ptr(&core->lang, core);
|
||||
r_anal_init(&core->anal);
|
||||
r_anal_set_user_ptr(&core->anal, core);
|
||||
r_cons_init();
|
||||
core->search = r_search_new(R_SEARCH_KEYWORD);
|
||||
r_io_init(&core->io);
|
||||
|
@ -89,15 +89,6 @@ struct r_anal_t {
|
||||
struct list_head anals;
|
||||
};
|
||||
|
||||
struct r_anal_handle_t {
|
||||
char *name;
|
||||
char *desc;
|
||||
int (*init)(void *user);
|
||||
int (*fini)(void *user);
|
||||
int (*aop)(void *user);
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
struct r_anal_aop_t {
|
||||
int type; /* type of opcode */
|
||||
int stackop; /* operation on stack? */
|
||||
@ -111,13 +102,22 @@ struct r_anal_aop_t {
|
||||
u64 i_dst,i_src1,i_src2; /* inmediate arguments */
|
||||
};
|
||||
|
||||
struct r_anal_handle_t {
|
||||
char *name;
|
||||
char *desc;
|
||||
int (*init)(void *user);
|
||||
int (*fini)(void *user);
|
||||
int (*aop)(struct r_anal_aop_t *aop, void *data);
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
/* anal.c */
|
||||
int r_anal_init(struct r_anal_t *anal);
|
||||
void r_anal_set_user_ptr(struct r_anal_t *anal, void *user);
|
||||
int r_anal_add(struct r_anal_t *anal, struct r_anal_handle_t *foo);
|
||||
int r_anal_list(struct r_anal_t *anal);
|
||||
int r_anal_set(struct r_anal_t *anal, const char *name);
|
||||
int r_anal_aop(struct r_anal_t *anal);
|
||||
int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data);
|
||||
int r_anal_set_bits(struct r_anal_t *anal, int bits);
|
||||
int r_anal_set_big_endian(struct r_anal_t *anal, int boolean);
|
||||
|
||||
|
@ -14,5 +14,5 @@ test-str:
|
||||
${CC} -g -I ../../include test-str.c ${LDFLAGS} -o test-str
|
||||
|
||||
clean:
|
||||
rm -f test test.o test-str test-str.o
|
||||
rm -f test test.o test-str test-str.o test-regexp
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user