* Some changes in r_anal

* Fixed build
This commit is contained in:
Nibble 2009-03-31 22:05:18 +02:00
parent ae84fb0695
commit c4421c3c7f
5 changed files with 36 additions and 53 deletions

View File

@ -4,7 +4,7 @@ PFX=${DESTDIR}${PREFIX}
#PREFIX=${PFX}
# Libraries
LIBLIST=io util lib meta lang flags bin macro hash line cons line print config syscall range socket cmd asm anal parse search diff debug reg core var sign trace bininfo
LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons line print config syscall range socket cmd asm anal parse search diff debug reg core var sign trace
# Under development
#LIBLIST+=print

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
#include <r_anal.h>
#include <r_util.h>
@ -61,13 +61,6 @@ int r_anal_set(struct r_anal_t *anal, const char *name)
return R_FALSE;
}
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, aop, data);
return R_FALSE;
}
int r_anal_set_bits(struct r_anal_t *anal, int bits)
{
switch (bits) {
@ -92,3 +85,10 @@ int r_anal_set_pc(struct r_anal_t *a, u64 pc)
a->pc = pc;
return R_TRUE;
}
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, aop, data);
return R_FALSE;
}

View File

@ -1,4 +1,6 @@
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009 */
/* pancake<nopcode.org> */
/* nibble<.ds@gmail.com> */
#include <string.h>
@ -25,11 +27,11 @@
// XXX addr should be off_t for 64 love
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
{
#if 0
struct r_asm_aop_t *asmdata = (struct r_asm_t*)data;
struct r_asm_aop_t *asmdata = (struct r_asm_aop_t*)data;
u8 *buf = asmdata->buf;
memset(aop, '\0', sizeof(struct r_anal_aop_t));
aop->length = asmdata->inst_len;
aop->type = R_ANAL_AOP_TYPE_UNK;
switch(buf[0]) {
@ -78,18 +80,15 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
break;
}
aop->type = R_ANAL_AOP_TYPE_MOV;
aop->length = 2;
break;
case 0xf4: // hlt
aop->type = R_ANAL_AOP_TYPE_RET;
aop->length = 1;
break;
case 0xc3: // ret
case 0xc2: // ret + 2 buf
case 0xcb: // lret
case 0xcf: // iret
aop->type = R_ANAL_AOP_TYPE_RET;
// aop->length = 1;
aop->eob = 1;
break;
//case 0xea: // far jmp
@ -102,11 +101,9 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
case 0x3d:
case 0x85:
aop->type = R_ANAL_AOP_TYPE_CMP;
aop->length = 2;
break;
case 0x90:
aop->type = R_ANAL_AOP_TYPE_NOP;
aop->length = 1;
break;
case 0x0f: // 3 byte nop
//0fbe55ff movsx edx, byte [ebp-0x1]
@ -120,47 +117,40 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
} else
if (buf[1]>=0x18 && buf[1]<=0x1f) {
aop->type = R_ANAL_AOP_TYPE_NOP;
aop->length = 3;
} else
if (buf[1]>=0x80 && buf[1]<=0x8f) {
aop->type = R_ANAL_AOP_TYPE_CJMP;
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->jump = anal->pc+6+buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24);//((unsigned long)((buf+2))+6);
aop->fail = anal->pc+6;
//aop->eob = 1;
}
break;
case 0xcc: // int3
aop->eob = 1;
case 0xf1: // int1
aop->length = 1;
aop->type = R_ANAL_AOP_TYPE_SWI;
break;
case 0xcd:
aop->length = 2;
aop->type = R_ANAL_AOP_TYPE_SWI;
break;
case 0xe8: // call
aop->type = R_ANAL_AOP_TYPE_CALL;
aop->length = 5;
//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->jump = anal->pc+*ptr+5; //(unsigned long)((buf+1)+5);
aop->jump = anal->pc+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
aop->fail = anal->pc+5;
//printf("anal->pc: %08llx\n call %08llx \n ret %08llx\n", anal->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 = asmdata->pc+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
aop->jump = anal->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 = asmdata->pc+((unsigned long)((char)buf[1])+2);
aop->jump = anal->pc+((unsigned long)((char)buf[1])+2);
aop->fail = 0L;
aop->eob = 1;
break;
@ -188,14 +178,12 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
} else
if (buf[1]>=0xd0 && buf[1]<=0xd7) {
aop->type = R_ANAL_AOP_TYPE_CALL;
aop->length = 2;
aop->eob = 1;
//aop->jump = vm_arch_x86_regs[VM_X86_EAX+buf[1]-0xd0];
aop->fail = asmdata->pc+2;
aop->fail = anal->pc+2;
} else
if (buf[1]>=0xe0 && buf[1]<=0xe7) {
aop->type = R_ANAL_AOP_TYPE_UJMP;
aop->length = 2;
//aop->jump = vm_arch_x86_regs[VM_X86_EAX+buf[1]-0xd0];
aop->eob = 1;
}
@ -220,7 +208,6 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
case 0x5e:
case 0x5f:
aop->type = R_ANAL_AOP_TYPE_POP;
aop->length = 1;
break;
case 0x68:
aop->type = R_ANAL_AOP_TYPE_PUSH;
@ -320,41 +307,40 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
case 0xa1: // mov eax, [addr]
aop->type = R_ANAL_AOP_TYPE_MOV;
//vm_arch_x86_regs[VM_X86_EAX] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_EAX] = anal->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] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_EAX] = anal->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] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_ECX] = anal->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] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_EDX] = anal->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] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_EBX] = anal->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] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_ESP] = anal->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] = asmdata->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//vm_arch_x86_regs[VM_X86_EBP] = anal->pc+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
break;
#if 0
case0xF
/* conditional jump */
if (buf[1]>=0x80&&buf[1]<=0x8F) {
aop->type = R_ANAL_AOP_TYPE_CJMP;
aop->length = 6;
aop->jump = (unsigned long)((buf+2)+6);
aop->fail = addr+6;
aop->eob = 1;
@ -382,10 +368,9 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
/* conditional jump */
//if (buf[1]>=0x80&&buf[1]<=0x8F) {
aop->type = R_ANAL_AOP_TYPE_CJMP;
aop->length = 2;
// aop->jump = (unsigned long)((buf+2)+6);
aop->jump = asmdata->pc+bo+2; //(unsigned long)((buf+1)+5);
aop->fail = asmdata->pc+2;
aop->jump = anal->pc+bo+2; //(unsigned long)((buf+1)+5);
aop->fail = anal->pc+2;
aop->eob = 1;
return 2;
}
@ -394,14 +379,10 @@ static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
//aop->type = R_ANAL_AOP_TYPE_UNK;
}
aop->length = asmdata->inst_len;
if (!(aop->jump>>33))
aop->jump &= 0xFFFFFFFF; // XXX may break on 64 bits here
return aop->length;
#endif
return R_FALSE;
}
static struct r_anal_handle_t r_anal_plugin_x86 = {

View File

@ -1,4 +1,4 @@
/* radare - GPL3 - Copyright 2009 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009 - nibble<.ds@gmail.com> */
#include <stdio.h>
#include <string.h>

View File

@ -1,4 +1,6 @@
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009 */
/* nibble<.ds@gmail.com> */
/* pancake<nopcode.org> */
#ifndef _INCLUDE_R_ANAL_H_
#define _INCLUDE_R_ANAL_H_