Remove two unused fields in RAnalOp and some deadcode

This commit is contained in:
pancake 2016-06-17 14:26:24 +02:00
parent 281d79da58
commit 1629dd2b64
19 changed files with 149 additions and 228 deletions

View File

@ -1,5 +1,4 @@
/* radare - LGPL - Copyright 2010-2015 - pancake, nibble */
/* bb.c - basic block analysis */
/* radare - LGPL - Copyright 2010-2016 - pancake, nibble */
#include <r_anal.h>
#include <r_util.h>
@ -15,15 +14,12 @@ R_API RAnalBlock *r_anal_bb_new() {
bb->fail = UT64_MAX;
bb->switch_op = NULL;
bb->type = R_ANAL_BB_TYPE_NULL;
#if R_ANAL_BB_HAS_OPS
bb->ops = r_anal_op_list_new ();
#endif
bb->cond = NULL;
bb->fingerprint = NULL;
bb->diff = r_anal_diff_new ();
bb->label = NULL;
bb->op_pos = R_NEWS0 (ut16, DFLT_NINSTR);
bb->n_op_pos = DFLT_NINSTR;
bb->op_pos_size = DFLT_NINSTR;
return bb;
}
@ -39,10 +35,6 @@ R_API void r_anal_bb_free(RAnalBlock *bb) {
if (bb->switch_op) {
r_anal_switch_op_free (bb->switch_op);
}
#if R_ANAL_BB_HAS_OPS
r_list_free (bb->ops);
bb->ops = NULL;
#endif
bb->fingerprint = NULL;
bb->cond = NULL;
free (bb->label);
@ -80,18 +72,15 @@ R_API int r_anal_bb(RAnal *anal, RAnalBlock *bb, ut64 addr, ut8 *buf, ut64 len,
}
break;
}
if (oplen < 1) goto beach;
r_anal_bb_set_offset (bb, bb->ninstr++, idx); //addr + idx - bb->addr);
if (oplen < 1) {
goto beach;
}
r_anal_bb_set_offset (bb, bb->ninstr++, addr + idx - bb->addr);
idx += oplen;
bb->size += oplen;
#if R_ANAL_BB_HAS_OPS
r_list_append (bb->ops, op);
#endif
if (head) {
bb->type = R_ANAL_BB_TYPE_HEAD;
}
switch (op->type) {
case R_ANAL_OP_TYPE_CMP:
r_anal_cond_free (bb->cond);
@ -167,10 +156,10 @@ R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i) {
R_API void r_anal_bb_set_offset(RAnalBlock *bb, int i, ut16 v) {
// the offset 0 of the instruction 0 is not stored because always 0
if (i > 0 && v > 0) {
if (i >= bb->n_op_pos) {
if (i >= bb->op_pos_size) {
ut16 *tmp_op_pos = realloc (bb->op_pos, (i * 2) * sizeof (*bb->op_pos));
if (!tmp_op_pos) return;
bb->n_op_pos = i * 2;
bb->op_pos_size = i * 2;
bb->op_pos = tmp_op_pos;
}
bb->op_pos[i - 1] = v;

View File

@ -1212,9 +1212,6 @@ R_API int r_anal_fcn_add_bb(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 siz
// bb seems to be ignored
R_API int r_anal_fcn_split_bb(RAnal *anal, RAnalFunction *fcn, RAnalBlock *bb, ut64 addr) {
RAnalBlock *bbi;
#if R_ANAL_BB_HAS_OPS
RAnalOp *opi;
#endif
RListIter *iter;
if (addr == UT64_MAX)
return 0;
@ -1258,19 +1255,6 @@ R_API int r_anal_fcn_split_bb(RAnal *anal, RAnalFunction *fcn, RAnalBlock *bb, u
}
}
bbi->ninstr = new_bbi_instr;
#if R_ANAL_BB_HAS_OPS
if (bbi->ops) {
r_list_foreach (bbi->ops, iter, opi) {
if (opi->addr >= addr) {
/* Remove opi from bbi->ops without free()ing it. */
r_list_split (bbi->ops, opi);
bbi->ninstr--;
r_list_append (bb->ops, opi);
bb->ninstr++;
}
}
}
#endif
return R_ANAL_RET_END;
}
}
@ -1281,10 +1265,6 @@ R_API int r_anal_fcn_split_bb(RAnal *anal, RAnalFunction *fcn, RAnalBlock *bb, u
R_API int r_anal_fcn_bb_overlaps(RAnalFunction *fcn, RAnalBlock *bb) {
RAnalBlock *bbi;
RListIter *iter;
#if R_ANAL_BB_HAS_OPS
RListIter *iter_tmp;
RAnalOp *opi;
#endif
r_list_foreach (fcn->bbs, iter, bbi)
if (bb->addr+bb->size > bbi->addr && bb->addr+bb->size <= bbi->addr+bbi->size) {
bb->size = bbi->addr - bb->addr;
@ -1295,14 +1275,6 @@ R_API int r_anal_fcn_bb_overlaps(RAnalFunction *fcn, RAnalBlock *bb) {
bb->type = R_ANAL_BB_TYPE_HEAD;
bbi->type = bbi->type^R_ANAL_BB_TYPE_HEAD;
} else bb->type = R_ANAL_BB_TYPE_BODY;
#if R_ANAL_BB_HAS_OPS
/* We can reuse iter because we return before the outer loop. */
r_list_foreach_safe (bb->ops, iter, iter_tmp, opi) {
if (opi->addr >= bbi->addr) {
r_list_delete (bb->ops, iter);
}
}
#endif
r_list_append (fcn->bbs, bb);
return R_ANAL_RET_END;
}

View File

@ -26,7 +26,9 @@ R_API RAnalOp *r_anal_op_new () {
R_API RList *r_anal_op_list_new() {
RList *list = r_list_new ();
if (!list) return NULL;
if (!list) {
return NULL;
}
list->free = &r_anal_op_free;
return list;
}
@ -48,14 +50,8 @@ R_API bool r_anal_op_fini(RAnalOp *op) {
r_anal_value_free (op->dst);
r_strbuf_fini (&op->esil);
r_anal_switch_op_free (op->switch_op);
op->src[0] = NULL;
op->src[1] = NULL;
op->src[2] = NULL;
op->dst = NULL;
op->var = NULL;
op->switch_op = NULL;
R_FREE (op->mnemonic);
R_FREE (op->reg);
memset (op, 0, sizeof (RAnalOp));
return true;
}
@ -259,6 +255,7 @@ R_API const char *r_anal_op_to_esil_string(RAnal *anal, RAnalOp *op) {
// TODO: use esil here?
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
RAnalBlock *bb;
RAnalFunction *f;
char ret[128];
char *cstr;
@ -274,13 +271,12 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
snprintf (ret, sizeof (ret), "%s = %s", r0, a0);
break;
case R_ANAL_OP_TYPE_CJMP:
{
RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
if (bb) {
if ((bb = r_anal_bb_from_offset (anal, op->addr))) {
cstr = r_anal_cond_to_string (bb->cond);
snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, cstr, op->jump);
free (cstr);
} else snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, "?", op->jump);
} else {
snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, "?", op->jump);
}
break;
case R_ANAL_OP_TYPE_JMP:
@ -306,9 +302,7 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
break;
case R_ANAL_OP_TYPE_CCALL:
f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL);
{
RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
if (bb) {
if ((bb = r_anal_bb_from_offset (anal, op->addr))) {
cstr = r_anal_cond_to_string (bb->cond);
if (f) snprintf (ret, sizeof (ret), "if (%s) %s()", cstr, f->name);
else snprintf (ret, sizeof (ret), "if (%s) 0x%"PFMT64x"()", cstr, op->jump);
@ -317,42 +311,47 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
if (f) snprintf (ret, sizeof (ret), "if (unk) %s()", f->name);
else snprintf (ret, sizeof (ret), "if (unk) 0x%"PFMT64x"()", op->jump);
}
}
break;
case R_ANAL_OP_TYPE_ADD:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s += %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s + %s", r0, a0, a1);
} else {
snprintf (ret, sizeof (ret), "%s = %s + %s", r0, a0, a1);
}
break;
case R_ANAL_OP_TYPE_SUB:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s -= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s - %s", r0, a0, a1);
} else {
snprintf (ret, sizeof (ret), "%s = %s - %s", r0, a0, a1);
}
break;
case R_ANAL_OP_TYPE_MUL:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s *= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s * %s", r0, a0, a1);
} else {
snprintf (ret, sizeof (ret), "%s = %s * %s", r0, a0, a1);
}
break;
case R_ANAL_OP_TYPE_DIV:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s /= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1);
} else snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1);
break;
case R_ANAL_OP_TYPE_AND:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s &= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1);
} else snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1);
break;
case R_ANAL_OP_TYPE_OR:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s |= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1);
} else snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1);
break;
case R_ANAL_OP_TYPE_XOR:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s ^= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
} else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
break;
case R_ANAL_OP_TYPE_LEA:
snprintf (ret, sizeof (ret), "%s -> %s", r0, a0);
@ -367,27 +366,30 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
memcpy (ret, "ret", 4);
break;
case R_ANAL_OP_TYPE_CRET:
{
RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
if (bb) {
if ((bb = r_anal_bb_from_offset (anal, op->addr))) {
cstr = r_anal_cond_to_string (bb->cond);
snprintf (ret, sizeof (ret), "if (%s) ret", cstr);
free (cstr);
} else memcpy (ret, "if (unk) ret", 13);
} else {
strcpy (ret, "if (unk) ret");
}
break;
case R_ANAL_OP_TYPE_LEAVE:
memcpy (ret, "leave", 6);
break;
case R_ANAL_OP_TYPE_MOD:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s %%= %s", r0, a0);
else snprintf (ret, sizeof (ret), "%s = %s %% %s", r0, a0, a1);
} else {
snprintf (ret, sizeof (ret), "%s = %s %% %s", r0, a0, a1);
}
break;
case R_ANAL_OP_TYPE_XCHG:
if (a1 == NULL || !strcmp (a0, a1))
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "tmp = %s; %s = %s; %s = tmp", r0, r0, a0, a0);
else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
} else {
snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
}
break;
case R_ANAL_OP_TYPE_ROL:
case R_ANAL_OP_TYPE_ROR:

View File

@ -108,8 +108,7 @@ static void _6502_anal_esil_get_addr_pattern2(RAnalOp *op, const ut8* data, char
}
/* BIT, JMP, JMP(), STY, LDY, CPY, and CPX share this pattern */
static void _6502_anal_esil_get_addr_pattern3(RAnalOp *op, const ut8* data, char* addrbuf, int addrsize, char reg)
{
static void _6502_anal_esil_get_addr_pattern3(RAnalOp *op, const ut8* data, char* addrbuf, int addrsize, char reg) {
// turn off bits 5, 6 and 7
switch (data[0] & 0x1f) { // 0x1f = b00111111
case 0x00: // op #$ff
@ -718,7 +717,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
break;
// RTS
case 0x60: // rts
op->eob = 1;
op->eob = true;
op->type = R_ANAL_OP_TYPE_RET;
op->cycles = 6;
op->stackop = R_ANAL_STACK_INC;
@ -729,7 +728,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
break;
// RTI
case 0x40: // rti
op->eob = 1;
op->eob = true;
op->type = R_ANAL_OP_TYPE_RET;
op->cycles = 6;
op->stackop = R_ANAL_STACK_INC;

View File

@ -1083,7 +1083,7 @@ static void anop64 (csh handle, RAnalOp *op, cs_insn *insn) {
break;
case ARM64_INS_BR:
op->type = R_ANAL_OP_TYPE_UJMP;
op->eob = 1;
op->eob = true;
break;
case ARM64_INS_B:
// BX LR == RET

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2015 - pancake */
/* radare - LGPL - Copyright 2008-2016 - pancake */
#include <string.h>
#include <r_types.h>
@ -7,24 +7,6 @@
#include <r_anal.h>
#include "../asm/arch/csr/dis.c"
#if 0
static int get_num(int num, int shift) {
int tmp;
char x = (char) ((num >> shift) & 0xff);
tmp = x;
tmp <<= shift;
return tmp;
}
static int get_operand(struct state *s, struct directive *d) {
int total = get_num (d->d_inst.in_operand, 0);
if (s->s_prefix == 2)
total += get_num (s->s_prefix_val, 16);
else total += get_num (s->s_prefix_val, 8);
return total;
}
#endif
static int label_off(struct directive *d) {
int off = d->d_operand;
int lame = off & 0x80;
@ -33,17 +15,21 @@ static int label_off(struct directive *d) {
off = (char) (off & 0xff);
} else if (d->d_prefix == 1) {
off = (short) (off & 0xffff);
if (lame)
if (lame) {
off -= 0x100;
}
} else {
off = (int) (off & 0xffffff);
if (off & 0x800000)
if (off & 0x800000) {
off |= 0xff000000;
if (off & 0x8000)
}
if (off & 0x8000) {
off -= 0x10000;
if (lame)
}
if (lame) {
off -= 0x100;
}
}
return d->d_off + off;
}
@ -57,8 +43,9 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
struct directive d = {{0}};
struct state s = {0};
if (op == NULL)
if (!anal || !op) {
return 2;
}
memcpy (&ins, bytes, sizeof (ins));
memcpy (&lol, bytes, sizeof (ins));
@ -68,7 +55,8 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
s.s_prefix = 0;
memset (&d, '\0', sizeof (struct directive));
memcpy (&d.d_inst, s.s_buf, sizeof (d.d_inst));
d.d_off = (s.s_off+=2);
s.s_off += 2;
d.d_off = s.s_off;
csr_decode (&s, &d);
d.d_operand = get_operand (&s, &d);
@ -144,7 +132,7 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
if (op->jump&1)
op->jump+=3;
op->fail = addr+2;
op->eob = 1;
op->eob = true;
break;
}
break;
@ -164,7 +152,7 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
op->jump = label_off (&d)+4;
if (op->jump&1)
op->jump+=3;
op->eob = 1;
op->eob = true;
break;
case 1:
// BLT
@ -173,7 +161,7 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
if (op->jump&1)
op->jump+=3;
op->fail = addr + 2;
op->eob = 1;
op->eob = true;
break;
case 2:
// BPL
@ -182,7 +170,7 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
if (op->jump&1)
op->jump+=3;
op->fail = addr + 2;
op->eob = 1;
op->eob = true;
break;
case 3:
// BMI
@ -191,7 +179,7 @@ static int csr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
if (op->jump&1)
op->jump+=3;
op->fail = addr + 2;
op->eob = 1;
op->eob = true;
break;
}
break;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010-2015 */
/* radare - LGPL - Copyright 2010-2016 - pancake */
#include <r_types.h>
#include <r_lib.h>
@ -262,7 +262,7 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
//XXX fix this better the check is to avoid an oob
op->jump = addr + (len>3?(short)(data[2]|data[3]<<8)*2 : 0);
op->fail = addr + sz;
op->eob = 1;
op->eob = true;
break;
case 0xec: // breakpoint
case 0x1d: // monitor-enter

View File

@ -1,5 +1,4 @@
/* radare - LGPL - Copyright 2012-2013 - pancake
2013 - Fedor Sakharov <fedor.sakharov@gmail.com> */
/* radare - LGPL - Copyright 2012-2013 - pancake, fedor.sakharov */
#include <string.h>
#include <r_types.h>

View File

@ -1034,7 +1034,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xd8:
gb_anal_cond (anal->reg, op, data[0]);
gb_anal_esil_cret (op, data[0]);
op->eob = 1;
op->eob = true;
op->cycles = 20;
op->failcycles = 8;
op->type = R_ANAL_OP_TYPE_CRET;
@ -1043,7 +1043,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
gb_anal_mov_ime (anal->reg, op, data[0]);
op->type2 = R_ANAL_OP_TYPE_MOV;
case 0xc9:
op->eob = 1;
op->eob = true;
op->cycles = 16;
gb_anal_esil_ret (op);
op->stackop = R_ANAL_STACK_INC;
@ -1101,7 +1101,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
} else {
op->type = R_ANAL_OP_TYPE_UJMP;
}
op->eob = 1;
op->eob = true;
op->cycles = 16;
op->fail = addr+ilen;
break;
@ -1110,7 +1110,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
op->fail = addr + ilen;
gb_anal_esil_jmp (op);
op->cycles = 12;
op->eob = 1;
op->eob = true;
op->type = R_ANAL_OP_TYPE_JMP;
break;
case 0x20:
@ -1123,7 +1123,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
gb_anal_esil_cjmp (op, data[0]);
op->cycles = 12;
op->failcycles = 8;
op->eob = 1;
op->eob = true;
op->type = R_ANAL_OP_TYPE_CJMP;
break;
case 0xc2:
@ -1135,7 +1135,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
} else {
op->type = R_ANAL_OP_TYPE_UCJMP;
}
op->eob = 1;
op->eob = true;
gb_anal_cond (anal->reg, op, data[0]);
gb_anal_esil_cjmp (op, data[0]);
op->cycles = 16;
@ -1144,13 +1144,13 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
break;
case 0xe9:
op->cycles = 4;
op->eob = 1;
op->eob = true;
op->type = R_ANAL_OP_TYPE_UJMP;
gb_anal_jmp_hl (anal->reg, op);
break;
case 0x76:
op->type = R_ANAL_OP_TYPE_CJMP;
op->eob = 1; //halt migth wait for interrupts
op->eob = true; //halt migth wait for interrupts
op->fail = addr + ilen;
if(len > 1)
op->jump = addr + gbOpLength (gb_op[data[1]].type) + ilen;
@ -1160,7 +1160,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
op->type = R_ANAL_OP_TYPE_CALL;
else op->type = R_ANAL_OP_TYPE_UCALL;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 24;
break;
@ -1173,7 +1173,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
op->type = R_ANAL_OP_TYPE_CCALL;
else op->type = R_ANAL_OP_TYPE_UCCALL;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_ccall (op, data[0]);
op->cycles = 24;
op->failcycles = 12;
@ -1181,7 +1181,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xc7: //rst 0
op->jump = 0x00;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1189,7 +1189,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xcf: //rst 8
op->jump = 0x08;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1197,7 +1197,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xd7: //rst 16
op->jump = 0x10;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1205,7 +1205,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xdf: //rst 24
op->jump = 0x18;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1213,7 +1213,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xe7: //rst 32
op->jump = 0x20;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1221,7 +1221,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xef: //rst 40
op->jump = 0x28;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1229,7 +1229,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xf7: //rst 48
op->jump = 0x30;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;
@ -1237,7 +1237,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xff: //rst 56
op->jump = 0x38;
op->fail = addr + ilen;
op->eob = 1;
op->eob = true;
gb_anal_esil_call (op);
op->cycles = 16;
op->type = R_ANAL_OP_TYPE_CALL;

View File

@ -69,7 +69,7 @@ static int m68k_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = addr + 2 + off;
op->fail = addr + op->size;
op->eob = 1;
op->eob = true;
} break;
case 0x30:
op->type = R_ANAL_OP_TYPE_MOV;
@ -80,7 +80,7 @@ static int m68k_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
case 0x4e:
if (b[1]==0x75){
op->type = R_ANAL_OP_TYPE_RET;
op->eob = 1;
op->eob = true;
break;
}
if (b[1]==0x71){
@ -98,7 +98,7 @@ static int m68k_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
op->jump += off;
op->fail = addr + op->size;
op->eob = 1;
op->eob = true;
break;
}
break;

View File

@ -1,3 +1,5 @@
/* radare - LGPL - Copyright 2015 - condret */
#include <r_anal.h>
#include <r_types.h>
#include <r_lib.h>

View File

@ -78,16 +78,19 @@ static bool is_xmm_reg(cs_x86_op op) {
* @return char* with the esil operand
*/
static char *getarg(struct Getarg* gop, int n, int set, char *setop) {
csh handle = gop->handle;
cs_insn *insn = gop->insn;
char buf[64];
char *setarg = setop ? setop : "";
cs_insn *insn = gop->insn;
csh handle = gop->handle;
char buf[64];
cs_x86_op op;
if (!insn->detail)
if (!insn->detail) {
return NULL;
}
buf[0] = 0;
if (n < 0 || n >= INSOPS)
if (n < 0 || n >= INSOPS) {
return NULL;
}
op = INSOP (n);
switch (op.type) {
case X86_OP_INVALID:
@ -181,7 +184,7 @@ static char *getarg(struct Getarg* gop, int n, int set, char *setop) {
}
return strdup (buf);
}
return strdup ("PoP");
return NULL;
}
static csh handle = 0;
@ -1907,9 +1910,7 @@ static void anop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh
break;
case X86_OP_REG:
{
op->reg = getarg (&gop, 0, 0, NULL);
op->src[0] = r_anal_value_new ();
op->src[0]->reg = r_reg_get (a->reg, op->reg, R_REG_TYPE_GPR);
op->reg = cs_reg_name (gop.handle, INSOP(0).reg);
op->type = R_ANAL_OP_TYPE_UJMP;
op->ptr = UT64_MAX;
}

View File

@ -53,11 +53,12 @@ static ut64 baddr(RBinFile *arch) {
}
static char *flagname (const char *class, const char *method) {
int s_len;
char *p, *str, *s;
if (class && method) {
if (method) {
if (class) {
return r_str_newf ("static.%s.%s", class, method);
}
return r_str_newf ("static.method.%s", method);
}
return NULL;
}

View File

@ -1814,25 +1814,30 @@ static RList *recurse(RCore *core, RAnalBlock *from, RAnalBlock *dest) {
}
R_API void fcn_callconv (RCore *core, RAnalFunction *fcn) {
if (!core || !fcn || core->anal->opt.bb_max_size < 1) {
return;
}
ut8 *buf = calloc(1,core->anal->opt.bb_max_size);
ut8 *tbuf, *buf;
RListIter *tmp = NULL;
RAnalBlock *bb = NULL;
int i;
if (!core || !core->anal || !fcn || core->anal->opt.bb_max_size < 1) {
return;
}
buf = calloc (1, core->anal->opt.bb_max_size);
if(!buf) {
return;
}
r_list_foreach (fcn->bbs, tmp, bb) {
if (bb->size < 1) continue;
buf = realloc (buf, bb->size);
tbuf = realloc (buf, bb->size);
if (!tbuf) {
break;
}
buf = tbuf;
if (r_io_read_at (core->io, bb->addr, buf, bb->size) != bb->size) {
eprintf ("read error\n");
free(buf);
return;
break;
}
for (i = 0 ; i < bb->n_op_pos ; i++) {
for (i = 0 ; i < bb->op_pos_size; i++) {
RAnalOp op = { 0 };
r_anal_op (core->anal, &op, 0, buf + bb->op_pos[i], bb->size - bb->op_pos[i]);
op.addr = bb->addr + bb->op_pos[i];

View File

@ -13,8 +13,9 @@ static RCorePlugin *cmd_static_plugins[] = { R_CORE_STATIC_PLUGINS };
R_API int r_core_plugin_deinit(RCmd *cmd) {
RListIter *iter;
RCorePlugin *plugin;
if (!cmd->plist)
if (!cmd->plist) {
return false;
}
r_list_foreach (cmd->plist, iter, plugin) {
if (plugin && plugin->deinit) {
plugin->deinit (cmd, NULL);
@ -27,8 +28,9 @@ R_API int r_core_plugin_deinit(RCmd *cmd) {
}
R_API int r_core_plugin_add(RCmd *cmd, RCorePlugin *plugin) {
if (plugin->init && !plugin->init (cmd, NULL))
if (plugin->init && !plugin->init (cmd, NULL)) {
return false;
}
r_list_append (cmd->plist, plugin);
return true;
}
@ -49,8 +51,9 @@ R_API int r_core_plugin_check(RCmd *cmd, const char *a0) {
RListIter *iter;
RCorePlugin *cp;
r_list_foreach (cmd->plist, iter, cp) {
if (cp->call (NULL, a0))
if (cp->call (NULL, a0)) {
return true;
}
}
return false;
}

View File

@ -33,8 +33,6 @@ R_LIB_VERSION_HEADER(r_anal);
bb_has_ops=1 -> 600M
bb_has_ops=0 -> 350MB
*/
#define R_ANAL_BB_HAS_OPS 0
/* TODO: work in progress */
#define USE_NEW_FCN_STORE 0
@ -310,9 +308,6 @@ typedef struct r_anal_type_function_t {
int depth;
bool folded;
RAnalType *args; // list of arguments
#if USE_VARSUBS
RAnalVarSub varsubs[R_ANAL_VARSUBS];
#endif
ut8 *fingerprint; // TODO: make is fuzzy and smarter
RAnalDiff *diff;
RList *locs; // list of local variables
@ -661,8 +656,6 @@ typedef struct r_anal_t {
#if DEPRECATE
Sdb *sdb_args; //
Sdb *sdb_vars; // globals?
//Sdb *sdb_locals;
// Sdb *sdb_ret; // UNUSED
#endif
Sdb *sdb_hints; // OK
Sdb *sdb_fcnsign; // OK
@ -735,16 +728,16 @@ typedef struct r_anal_op_t {
int stackop; /* operation on stack? */
int cond; /* condition type */
int size; /* size in bytes of opcode */
int nopcode; /* number of bytes representing the opcode (not the arguments) */
int nopcode; /* number of bytes representing the opcode (not the arguments) TODO: find better name */
int cycles; /* cpu-cycles taken by instruction */
int failcycles; /* conditional cpu-cycles */
int family; /* family of opcode */
int eob; /* end of block (boolean) */
bool eob; /* end of block (boolean) */
/* Run N instructions before executing the current one */
int delay; /* delay N slots (mips, ..)*/
ut64 jump; /* true jmp */
ut64 fail; /* false jmp */
ut32 selector; /* segment selector */
//ut32 selector; /* segment selector */
st64 ptr; /* reference to memory */ /* XXX signed? */
ut64 val; /* reference to value */ /* XXX signed? */
int ptrsize; /* f.ex: zero extends for 8, 16 or 32 bits only */
@ -753,9 +746,9 @@ typedef struct r_anal_op_t {
RAnalVar *var; /* local var/arg used by this instruction */
RAnalValue *src[3];
RAnalValue *dst;
struct r_anal_op_t *next; // XXX deprecate
struct r_anal_op_t *next; // TODO deprecate
RStrBuf esil;
char *reg; /* destination register */
const char *reg; /* destination register */
RAnalSwitchOp *switch_op;
} RAnalOp;
@ -782,18 +775,14 @@ typedef struct r_anal_bb_t {
char *label;
ut8 *fingerprint;
RAnalDiff *diff;
#if R_ANAL_BB_HAS_OPS
RList *ops;
#endif
RAnalCond *cond;
RAnalSwitchOp *switch_op;
// offsets of instructions in this block
ut16 *op_pos;
// size of the op_pos array
int n_op_pos; // XXX. isnt this the same as ninstr ?
int op_pos_size;
ut8 *op_bytes;
ut8 op_sz;
ut64 eflags;
/* deprecate ??? where is this used? */
/* iirc only java. we must use r_anal_bb_from_offset(); instead */
struct r_anal_bb_t *head;

View File

@ -34,22 +34,8 @@ static int assemble(RParse *p, char *data, char *str) {
}
static bool varsub(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) {
#if USE_VARSUBS
char *ptr, *ptr2;
int i;
strncpy (str, data, len);
for (i = 0; i < R_ANAL_VARSUBS; i++)
if (f->varsubs[i].pat[0] != '\0' && f->varsubs[i].sub[0] != '\0' &&
(ptr = strstr (data, f->varsubs[i].pat))) {
*ptr = '\0';
ptr2 = ptr + strlen (f->varsubs[i].pat);
snprintf (str, len, "%s%s%s", data, f->varsubs[i].sub, ptr2);
}
return true;
#else
strncpy (str, data, len);
return false;
#endif
}
RParsePlugin r_parse_plugin_mreplace = {

View File

@ -210,20 +210,6 @@ static inline int issegoff (const char *w) {
#endif
static bool varsub (RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) {
#if USE_VARSUBS
int i;
char *ptr, *ptr2;
for (i = 0; i < R_ANAL_VARSUBS; i++)
if (f->varsubs[i].pat[0] != '\0' && \
f->varsubs[i].sub[0] != '\0' && \
(ptr = strstr (data, f->varsubs[i].pat))) {
*ptr = '\0';
ptr2 = ptr + strlen (f->varsubs[i].pat);
snprintf (str, len, "%s%s%s", data,
f->varsubs[i].sub, ptr2);
}
return true;
#else
RAnalVar *reg, *bparg, *sparg;
RListIter *regiter, *bpargiter, *spiter;
char oldstr[64], newstr[64];
@ -354,7 +340,6 @@ static bool varsub (RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *dat
r_list_free (bpargs);
r_list_free (regs);
return ret;
#endif
}
RParsePlugin r_parse_plugin_x86_pseudo = {