add esil_mod and esil_modeq (%,%=)

This commit is contained in:
condret 2015-04-03 02:03:19 +02:00
parent b553f607b7
commit 54fe5e8589

View File

@ -828,6 +828,61 @@ static int esil_pop(RAnalEsil *esil) {
return 1;
}
static int esil_mod(RAnalEsil *esil) {
int ret = 0;
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && r_anal_esil_get_parm (esil, src, &s)) {
if (dst && r_anal_esil_get_parm (esil, dst, &d)) {
if (s == 0) {
eprintf ("esil_mod: Division by zero!\n");
esil->trap = R_ANAL_TRAP_DIVBYZERO;
esil->trap_code = 0;
} else {
r_anal_esil_pushnum (esil, d%s);
}
ret = 1;
}
} else {
eprintf ("esil_mod: invalid parameters");
}
free (dst);
free (src);
return ret;
}
static int esil_modeq(RAnalEsil *esil) {
int ret = 0;
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && r_anal_esil_get_parm (esil, src, &s)) {
if (dst && r_anal_esil_reg_read (esil, dst, &d)) {
if (s==0) {
eprintf ("esil_modeq: Division by zero!\n");
esil->trap = R_ANAL_TRAP_DIVBYZERO;
esil->trap_code = 0;
} else {
if (r_anal_esil_get_parm_type (esil, src) != R_ANAL_ESIL_PARM_INTERNAL) {
esil->old = d;
esil->cur = d%s;
esil->lastsz = esil_internal_sizeof_reg (esil, dst);
}
r_anal_esil_reg_write (esil, dst, d%s);
}
ret = 1;
} else {
eprintf ("esil_modeq: empty stack\n");
}
} else {
eprintf ("esil_modeq: invalid parameters");
}
free (src);
free (dst);
return ret;
}
static int esil_div(RAnalEsil *esil) {
int ret = 0;
ut64 s, d;
@ -2498,6 +2553,8 @@ R_API int r_anal_esil_setup (RAnalEsil *esil, RAnal *anal, int romem, int stats)
r_anal_esil_set_op (esil, "--=", esil_deceq);
r_anal_esil_set_op (esil, "/", esil_div);
r_anal_esil_set_op (esil, "/=", esil_diveq);
r_anal_esil_set_op (esil, "%", esil_mod);
r_anal_esil_set_op (esil, "%=", esil_modeq);
r_anal_esil_set_op (esil, "=[]", esil_poke);
r_anal_esil_set_op (esil, "=[1]", esil_poke1);
r_anal_esil_set_op (esil, "=[2]", esil_poke2);
@ -2558,4 +2615,4 @@ R_API int r_anal_esil_setup (RAnalEsil *esil, RAnal *anal, int romem, int stats)
if (anal->cur && anal->cur->esil_init && anal->cur->esil_fini)
return anal->cur->esil_init (esil);
return R_TRUE;
}
}