2015-03-08 21:09:59 +00:00
|
|
|
/* radare - LGPL - Copyright 2010-2015 - pancake, nibble */
|
2010-03-12 02:05:20 +00:00
|
|
|
|
|
|
|
#include <r_anal.h>
|
|
|
|
#include <r_util.h>
|
|
|
|
#include <r_list.h>
|
|
|
|
|
2014-03-26 13:47:30 +00:00
|
|
|
R_API RAnalOp *r_anal_op_new () {
|
|
|
|
RAnalOp *op = R_NEW0 (RAnalOp);
|
2011-02-24 13:06:49 +00:00
|
|
|
if (op) {
|
|
|
|
op->addr = -1;
|
|
|
|
op->jump = -1;
|
|
|
|
op->fail = -1;
|
2013-06-09 01:25:32 +00:00
|
|
|
op->ptr = -1;
|
|
|
|
op->val = -1;
|
2013-12-10 02:35:59 +00:00
|
|
|
r_strbuf_init (&op->esil);
|
2010-05-20 15:40:58 +00:00
|
|
|
}
|
2011-02-24 13:06:49 +00:00
|
|
|
return op;
|
2010-03-12 02:05:20 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API RList *r_anal_op_list_new() {
|
2010-03-12 02:05:20 +00:00
|
|
|
RList *list = r_list_new ();
|
2011-02-24 13:06:49 +00:00
|
|
|
list->free = &r_anal_op_free;
|
2010-03-12 02:05:20 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2011-11-13 23:21:25 +00:00
|
|
|
R_API void r_anal_op_fini(RAnalOp *op) {
|
2015-03-24 02:23:56 +00:00
|
|
|
if (!op) // || !op->mnemonic)
|
|
|
|
return;
|
|
|
|
if (((ut64)(size_t)op) == UT64_MAX) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (((ut64)(size_t)op->mnemonic) == UT64_MAX) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-01 22:33:07 +00:00
|
|
|
r_anal_value_free (op->src[0]);
|
|
|
|
r_anal_value_free (op->src[1]);
|
|
|
|
r_anal_value_free (op->src[2]);
|
|
|
|
r_anal_value_free (op->dst);
|
2014-03-26 13:47:30 +00:00
|
|
|
r_anal_switch_op_free (op->switch_op);
|
2011-11-13 23:21:25 +00:00
|
|
|
free (op->mnemonic);
|
|
|
|
memset (op, 0, sizeof (RAnalOp));
|
|
|
|
}
|
|
|
|
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API void r_anal_op_free(void *_op) {
|
2011-11-13 23:21:25 +00:00
|
|
|
if (!_op) return;
|
|
|
|
r_anal_op_fini (_op);
|
|
|
|
free (_op);
|
2010-03-12 02:05:20 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
|
2013-07-04 01:34:28 +00:00
|
|
|
int ret = R_FALSE;
|
2014-03-26 13:47:30 +00:00
|
|
|
if (len>0 && anal && memset (op, 0, sizeof (RAnalOp)) &&
|
|
|
|
anal->cur && anal->cur->op) {
|
2013-07-04 01:34:28 +00:00
|
|
|
ret = anal->cur->op (anal, op, addr, data, len);
|
2014-11-06 15:01:00 +00:00
|
|
|
op->addr = addr;
|
2013-07-04 01:34:28 +00:00
|
|
|
if (ret<1) op->type = R_ANAL_OP_TYPE_ILL;
|
|
|
|
}
|
|
|
|
return ret;
|
2010-03-12 02:05:20 +00:00
|
|
|
}
|
2010-06-21 09:55:48 +00:00
|
|
|
|
2011-03-28 08:24:01 +00:00
|
|
|
R_API RAnalOp *r_anal_op_copy (RAnalOp *op) {
|
|
|
|
RAnalOp *nop = R_NEW (RAnalOp);
|
2014-03-26 13:47:30 +00:00
|
|
|
*nop = *op;
|
2011-03-28 08:24:01 +00:00
|
|
|
nop->mnemonic = strdup (op->mnemonic);
|
|
|
|
nop->src[0] = r_anal_value_copy (op->src[0]);
|
|
|
|
nop->src[1] = r_anal_value_copy (op->src[1]);
|
|
|
|
nop->src[2] = r_anal_value_copy (op->src[2]);
|
|
|
|
nop->dst = r_anal_value_copy (op->dst);
|
2013-12-10 02:35:59 +00:00
|
|
|
r_strbuf_init (&nop->esil);
|
|
|
|
r_strbuf_set (&nop->esil, r_strbuf_get (&op->esil));
|
2011-03-28 08:24:01 +00:00
|
|
|
return nop;
|
|
|
|
}
|
|
|
|
|
2011-02-02 23:20:39 +00:00
|
|
|
// TODO: return RAnalException *
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API int r_anal_op_execute (RAnal *anal, RAnalOp *op) {
|
2011-03-28 08:24:01 +00:00
|
|
|
while (op) {
|
|
|
|
if (op->delay>0) {
|
|
|
|
anal->queued = r_anal_op_copy (op);
|
|
|
|
return R_FALSE;
|
|
|
|
}
|
|
|
|
switch (op->type) {
|
|
|
|
case R_ANAL_OP_TYPE_JMP:
|
|
|
|
case R_ANAL_OP_TYPE_UJMP:
|
|
|
|
case R_ANAL_OP_TYPE_CALL:
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_ADD:
|
|
|
|
// dst = src[0] + src[1] + src[2]
|
2012-07-17 08:00:23 +00:00
|
|
|
r_anal_value_set_ut64 (anal, op->dst,
|
2011-03-28 08:24:01 +00:00
|
|
|
r_anal_value_to_ut64 (anal, op->src[0])+
|
|
|
|
r_anal_value_to_ut64 (anal, op->src[1])+
|
|
|
|
r_anal_value_to_ut64 (anal, op->src[2]));
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_SUB:
|
|
|
|
// dst = src[0] + src[1] + src[2]
|
2012-07-17 08:00:23 +00:00
|
|
|
r_anal_value_set_ut64 (anal, op->dst,
|
2011-03-28 08:24:01 +00:00
|
|
|
r_anal_value_to_ut64 (anal, op->src[0])-
|
|
|
|
r_anal_value_to_ut64 (anal, op->src[1])-
|
|
|
|
r_anal_value_to_ut64 (anal, op->src[2]));
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_DIV:
|
|
|
|
{
|
|
|
|
ut64 div = r_anal_value_to_ut64 (anal, op->src[1]);
|
|
|
|
if (div == 0) {
|
|
|
|
eprintf ("r_anal_op_execute: division by zero\n");
|
|
|
|
eprintf ("TODO: throw RAnalException\n");
|
2012-07-17 08:00:23 +00:00
|
|
|
} else r_anal_value_set_ut64 (anal, op->dst,
|
2011-03-28 08:24:01 +00:00
|
|
|
r_anal_value_to_ut64 (anal, op->src[0])/div);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_MUL:
|
2012-07-17 08:00:23 +00:00
|
|
|
r_anal_value_set_ut64 (anal, op->dst,
|
2011-03-28 08:24:01 +00:00
|
|
|
r_anal_value_to_ut64 (anal, op->src[0])*
|
|
|
|
r_anal_value_to_ut64 (anal, op->src[1]));
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_MOV:
|
|
|
|
// dst = src[0]
|
2012-07-17 08:00:23 +00:00
|
|
|
r_anal_value_set_ut64 (anal, op->dst,
|
2011-03-28 08:24:01 +00:00
|
|
|
r_anal_value_to_ut64 (anal, op->src[0]));
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_NOP:
|
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
op = op->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anal->queued) {
|
|
|
|
anal->queued->delay--;
|
|
|
|
if (anal->queued->delay == 0) {
|
|
|
|
r_anal_op_execute (anal, anal->queued);
|
|
|
|
r_anal_op_free (anal->queued);
|
|
|
|
anal->queued = NULL;
|
|
|
|
}
|
2011-02-02 23:20:39 +00:00
|
|
|
}
|
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:46:59 +00:00
|
|
|
R_API const char *r_anal_optype_to_string(int t) {
|
2012-11-08 08:49:27 +00:00
|
|
|
switch (t) {
|
2015-03-03 23:46:59 +00:00
|
|
|
case R_ANAL_OP_TYPE_IO : return "io";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_ACMP : return "acmp";
|
|
|
|
case R_ANAL_OP_TYPE_ADD : return "add";
|
|
|
|
case R_ANAL_OP_TYPE_AND : return "and";
|
2012-11-08 08:49:27 +00:00
|
|
|
case R_ANAL_OP_TYPE_CALL : return "call";
|
2014-02-25 23:03:42 +00:00
|
|
|
case R_ANAL_OP_TYPE_CCALL : return "ccall";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_CJMP : return "cjmp";
|
|
|
|
case R_ANAL_OP_TYPE_CMP : return "cmp";
|
2014-02-25 23:03:42 +00:00
|
|
|
case R_ANAL_OP_TYPE_CRET : return "cret";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_DIV : return "div";
|
2012-11-08 08:49:27 +00:00
|
|
|
case R_ANAL_OP_TYPE_ILL : return "ill";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_JMP : return "jmp";
|
|
|
|
case R_ANAL_OP_TYPE_LEA : return "lea";
|
|
|
|
case R_ANAL_OP_TYPE_LEAVE : return "leave";
|
|
|
|
case R_ANAL_OP_TYPE_LOAD : return "load";
|
|
|
|
case R_ANAL_OP_TYPE_MOD : return "mod";
|
2012-11-08 08:49:27 +00:00
|
|
|
case R_ANAL_OP_TYPE_MOV : return "mov";
|
|
|
|
case R_ANAL_OP_TYPE_MUL : return "mul";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_NOP : return "nop";
|
|
|
|
case R_ANAL_OP_TYPE_NOT : return "not";
|
|
|
|
case R_ANAL_OP_TYPE_NULL : return "null";
|
|
|
|
case R_ANAL_OP_TYPE_OR : return "or";
|
|
|
|
case R_ANAL_OP_TYPE_POP : return "pop";
|
|
|
|
case R_ANAL_OP_TYPE_PUSH : return "push";
|
|
|
|
case R_ANAL_OP_TYPE_REP : return "rep";
|
|
|
|
case R_ANAL_OP_TYPE_RET : return "ret";
|
|
|
|
case R_ANAL_OP_TYPE_ROL : return "rol";
|
|
|
|
case R_ANAL_OP_TYPE_ROR : return "ror";
|
|
|
|
case R_ANAL_OP_TYPE_SAL : return "sal";
|
2014-10-15 23:51:48 +00:00
|
|
|
case R_ANAL_OP_TYPE_SAR : return "sar";
|
2012-11-08 08:49:27 +00:00
|
|
|
case R_ANAL_OP_TYPE_SHL : return "shl";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_SHR : return "shr";
|
2012-11-08 08:49:27 +00:00
|
|
|
case R_ANAL_OP_TYPE_STORE : return "store";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_SUB : return "sub";
|
|
|
|
case R_ANAL_OP_TYPE_SWI : return "swi";
|
2015-03-08 21:09:59 +00:00
|
|
|
case R_ANAL_OP_TYPE_SWITCH: return "switch";
|
2015-01-15 00:31:21 +00:00
|
|
|
case R_ANAL_OP_TYPE_TRAP : return "trap";
|
|
|
|
case R_ANAL_OP_TYPE_UCALL : return "ucall";
|
|
|
|
case R_ANAL_OP_TYPE_UCCALL: return "uccall";
|
|
|
|
case R_ANAL_OP_TYPE_UCJMP : return "ucjmp";
|
|
|
|
case R_ANAL_OP_TYPE_UJMP : return "ujmp";
|
|
|
|
case R_ANAL_OP_TYPE_UNK : return "unk";
|
|
|
|
case R_ANAL_OP_TYPE_UPUSH : return "upush";
|
|
|
|
case R_ANAL_OP_TYPE_XCHG : return "xchg";
|
|
|
|
case R_ANAL_OP_TYPE_XOR : return "xor";
|
2015-03-08 21:09:59 +00:00
|
|
|
case R_ANAL_OP_TYPE_CASE : return "case";
|
2012-11-08 08:49:27 +00:00
|
|
|
}
|
|
|
|
return "undefined";
|
|
|
|
}
|
|
|
|
|
2013-06-09 01:25:32 +00:00
|
|
|
R_API const char *r_anal_op_to_esil_string(RAnal *anal, RAnalOp *op) {
|
2013-12-10 02:35:59 +00:00
|
|
|
return r_strbuf_get (&op->esil);
|
2013-06-09 01:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: use esil here?
|
2011-02-24 13:06:49 +00:00
|
|
|
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
|
2012-07-19 02:54:22 +00:00
|
|
|
RAnalFunction *f;
|
2011-08-18 15:03:45 +00:00
|
|
|
char ret[128];
|
|
|
|
char *cstr;
|
2010-06-21 09:55:48 +00:00
|
|
|
char *r0 = r_anal_value_to_string (op->dst);
|
|
|
|
char *a0 = r_anal_value_to_string (op->src[0]);
|
|
|
|
char *a1 = r_anal_value_to_string (op->src[1]);
|
|
|
|
|
|
|
|
switch (op->type) {
|
|
|
|
case R_ANAL_OP_TYPE_MOV:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s = %s", r0, a0);
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_CJMP:
|
2011-02-28 12:07:41 +00:00
|
|
|
{
|
|
|
|
RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
|
|
|
|
if (bb) {
|
|
|
|
cstr = r_anal_cond_to_string (bb->cond);
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, cstr, op->jump);
|
2011-02-28 12:07:41 +00:00
|
|
|
free (cstr);
|
2011-08-18 15:03:45 +00:00
|
|
|
} else snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, "unk", op->jump);
|
2011-02-28 12:07:41 +00:00
|
|
|
}
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_JMP:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "goto 0x%"PFMT64x, op->jump);
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
2011-03-01 18:16:29 +00:00
|
|
|
case R_ANAL_OP_TYPE_UJMP:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "goto %s", r0);
|
2011-03-01 18:16:29 +00:00
|
|
|
break;
|
2011-02-27 02:39:27 +00:00
|
|
|
case R_ANAL_OP_TYPE_PUSH:
|
|
|
|
case R_ANAL_OP_TYPE_UPUSH:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "push %s", a0);
|
2011-02-27 02:39:27 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_POP:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "pop %s", r0);
|
2011-02-27 02:39:27 +00:00
|
|
|
break;
|
2011-02-28 16:27:08 +00:00
|
|
|
case R_ANAL_OP_TYPE_UCALL:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s()", r0);
|
2011-02-28 16:27:08 +00:00
|
|
|
break;
|
2010-06-21 09:55:48 +00:00
|
|
|
case R_ANAL_OP_TYPE_CALL:
|
2014-09-26 13:40:17 +00:00
|
|
|
f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL);
|
2011-08-18 15:03:45 +00:00
|
|
|
if (f) snprintf (ret, sizeof (ret), "%s()", f->name);
|
|
|
|
else snprintf (ret, sizeof (ret), "0x%"PFMT64x"()", op->jump);
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
2014-02-25 23:03:42 +00:00
|
|
|
case R_ANAL_OP_TYPE_CCALL:
|
2014-09-26 13:40:17 +00:00
|
|
|
f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL);
|
2014-02-25 23:03:42 +00:00
|
|
|
{
|
|
|
|
RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
|
|
|
|
if (bb) {
|
|
|
|
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);
|
|
|
|
free (cstr);
|
|
|
|
} else {
|
|
|
|
if (f) snprintf (ret, sizeof (ret), "if (unk) %s()", f->name);
|
|
|
|
else snprintf (ret, sizeof (ret), "if (unk) 0x%"PFMT64x"()", op->jump);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-02-27 15:17:05 +00:00
|
|
|
case R_ANAL_OP_TYPE_ADD:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s += %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s + %s", r0, a0, a1);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
2010-06-21 09:55:48 +00:00
|
|
|
case R_ANAL_OP_TYPE_SUB:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s -= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s - %s", r0, a0, a1);
|
2010-06-21 09:55:48 +00:00
|
|
|
break;
|
2011-02-27 15:17:05 +00:00
|
|
|
case R_ANAL_OP_TYPE_MUL:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s *= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s * %s", r0, a0, a1);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_DIV:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s /= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_AND:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s &= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_OR:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s |= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_XOR:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s ^= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
2011-03-01 18:16:29 +00:00
|
|
|
case R_ANAL_OP_TYPE_LEA:
|
2011-08-18 15:03:45 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s -> %s", r0, a0);
|
2011-03-01 18:16:29 +00:00
|
|
|
break;
|
2011-02-28 12:07:41 +00:00
|
|
|
case R_ANAL_OP_TYPE_CMP:
|
2011-08-18 15:03:45 +00:00
|
|
|
memcpy (ret, ";", 2);
|
2011-02-28 12:07:41 +00:00
|
|
|
break;
|
2011-02-27 15:17:05 +00:00
|
|
|
case R_ANAL_OP_TYPE_NOP:
|
2011-07-06 07:40:23 +00:00
|
|
|
memcpy (ret, "nop", 4);
|
2011-02-27 15:17:05 +00:00
|
|
|
break;
|
2011-02-28 12:07:41 +00:00
|
|
|
case R_ANAL_OP_TYPE_RET:
|
2011-07-06 07:40:23 +00:00
|
|
|
memcpy (ret, "ret", 4);
|
2011-02-28 12:07:41 +00:00
|
|
|
break;
|
2014-02-25 23:03:42 +00:00
|
|
|
case R_ANAL_OP_TYPE_CRET:
|
|
|
|
{
|
|
|
|
RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
|
|
|
|
if (bb) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
break;
|
2011-03-01 18:16:29 +00:00
|
|
|
case R_ANAL_OP_TYPE_LEAVE:
|
2011-07-06 07:40:23 +00:00
|
|
|
memcpy (ret, "leave", 6);
|
2011-03-01 18:16:29 +00:00
|
|
|
break;
|
2014-01-02 05:09:46 +00:00
|
|
|
case R_ANAL_OP_TYPE_MOD:
|
|
|
|
if (a1 == NULL || !strcmp (a0, a1))
|
2014-03-18 01:21:52 +00:00
|
|
|
snprintf (ret, sizeof (ret), "%s %%= %s", r0, a0);
|
|
|
|
else snprintf (ret, sizeof (ret), "%s = %s %% %s", r0, a0, a1);
|
2014-01-02 05:09:46 +00:00
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_XCHG:
|
|
|
|
if (a1 == NULL || !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);
|
|
|
|
break;
|
|
|
|
case R_ANAL_OP_TYPE_ROL:
|
|
|
|
case R_ANAL_OP_TYPE_ROR:
|
|
|
|
case R_ANAL_OP_TYPE_SWITCH:
|
2014-08-11 02:52:53 +00:00
|
|
|
case R_ANAL_OP_TYPE_CASE:
|
2014-01-02 05:09:46 +00:00
|
|
|
eprintf ("Command not implemented.\n");
|
2014-01-04 04:03:24 +00:00
|
|
|
free (r0);
|
|
|
|
free (a0);
|
|
|
|
free (a1);
|
|
|
|
return NULL;
|
2010-06-21 09:55:48 +00:00
|
|
|
default:
|
2011-08-18 15:03:45 +00:00
|
|
|
free (r0);
|
|
|
|
free (a0);
|
|
|
|
free (a1);
|
|
|
|
return NULL;
|
2010-06-21 09:55:48 +00:00
|
|
|
}
|
|
|
|
free (r0);
|
|
|
|
free (a0);
|
|
|
|
free (a1);
|
2011-08-18 15:03:45 +00:00
|
|
|
return strdup (ret);
|
2010-06-21 09:55:48 +00:00
|
|
|
}
|
2014-09-22 11:45:36 +00:00
|
|
|
|
|
|
|
R_API const char *r_anal_stackop_tostring (int s) {
|
|
|
|
switch (s) {
|
|
|
|
case R_ANAL_STACK_NULL:
|
|
|
|
return "null";
|
|
|
|
case R_ANAL_STACK_NOP:
|
|
|
|
return "nop";
|
|
|
|
case R_ANAL_STACK_INC:
|
|
|
|
return "inc";
|
|
|
|
case R_ANAL_STACK_GET:
|
|
|
|
return "get";
|
|
|
|
case R_ANAL_STACK_SET:
|
|
|
|
return "set";
|
|
|
|
}
|
|
|
|
return "unk";
|
|
|
|
}
|
2014-12-01 23:36:42 +00:00
|
|
|
|
|
|
|
R_API const char *r_anal_op_family_to_string (int n) {
|
|
|
|
static char num[32];
|
|
|
|
switch (n) {
|
|
|
|
case R_ANAL_OP_FAMILY_UNKNOWN: return "unknown";
|
|
|
|
case R_ANAL_OP_FAMILY_CPU: return "cpu";
|
|
|
|
case R_ANAL_OP_FAMILY_FPU: return "fpu";
|
|
|
|
case R_ANAL_OP_FAMILY_MMX: return "mmx";
|
|
|
|
case R_ANAL_OP_FAMILY_PRIV: return "priv";
|
|
|
|
default:
|
2015-03-08 21:44:00 +00:00
|
|
|
snprintf (num, sizeof (num), "%d", n);
|
2014-12-01 23:36:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|