Merge #1080 esil comparators commit. It requires more discussion

This commit is contained in:
pancake 2014-07-21 04:27:42 +02:00
parent 338fa079cd
commit fd803510c8
1 changed files with 87 additions and 0 deletions

View File

@ -931,6 +931,89 @@ static int esil_peek(RAnalEsil *esil) {
return 0;
}
static int esil_smaller(RAnalEsil *esil) { // 'src < dst' => 'src,dst,<'
int ret = 0;
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && isregornum (esil, src, &s)) {
if (dst && isregornum (esil, dst, &d)) {
r_anal_esil_pushnum(esil, (s < d));
ret = 1;
} else {
eprintf ("esil_smaller: dst is broken\n");
}
} else {
eprintf ("esil_smaller: src is broken\n");
}
free (src);
free (dst);
return ret;
}
// TODO:
// sign is not handled
// ESIL flags not updated?
static int esil_bigger(RAnalEsil *esil) { // 'src > dst' => 'src,dst,>'
int ret = 0;
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && isregornum (esil, src, &s)) {
if (dst && isregornum (esil, dst, &d)) {
r_anal_esil_pushnum(esil, (s > d));
ret = 1;
} else {
eprintf ("esil_bigger: dst is broken\n");
}
} else {
eprintf ("esil_bigger: src is broken\n");
}
free (src);
free (dst);
return ret;
}
static int esil_smaller_equal(RAnalEsil *esil) { // 'src <= dst' => 'src,dst,<='
int ret = 0;
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && isregornum (esil, src, &s)) {
if (dst && isregornum (esil, dst, &d)) {
r_anal_esil_pushnum(esil, (s <= d));
ret = 1;
} else {
eprintf ("esil_smaller_equal: dst is broken\n");
}
} else {
eprintf ("esil_smaller_equal: src is broken\n");
}
free (src);
free (dst);
return ret;
}
static int esil_bigger_equal(RAnalEsil *esil) { // 'src >= dst' => 'src,dst,>='
int ret = 0;
ut64 s, d;
char *dst = r_anal_esil_pop (esil);
char *src = r_anal_esil_pop (esil);
if (src && isregornum (esil, src, &s)) {
if (dst && isregornum (esil, dst, &d)) {
r_anal_esil_pushnum(esil, (s >= d));
ret = 1;
} else {
eprintf ("esil_bigger_equal: dst is broken\n");
}
} else {
eprintf ("esil_bigger_equal: src is broken\n");
}
free (src);
free (dst);
return ret;
}
typedef int RAnalEsilCmd(RAnalEsil *esil);
static int iscommand (RAnalEsil *esil, const char *word, RAnalEsilCmd **cmd) {
@ -938,6 +1021,10 @@ static int iscommand (RAnalEsil *esil, const char *word, RAnalEsilCmd **cmd) {
// TODO: Implement rotate >>>= and <<<=
if (!strcmp (word, "$")) { *cmd = &esil_syscall; return 1; } else
if (!strcmp (word, "==")) { *cmd = &esil_cmp; return 1; } else
if (!strcmp (word, "<")) { *cmd = &esil_smaller; return 1; } else
if (!strcmp (word, ">")) { *cmd = &esil_bigger; return 1; } else
if (!strcmp (word, "<=")) { *cmd = &esil_smaller_equal; return 1; } else
if (!strcmp (word, ">=")) { *cmd = &esil_bigger_equal; return 1; } else
if (!strcmp (word, "?=")) { *cmd = &esil_ifset; return 1; } else
if (!strcmp (word, "?{")) { *cmd = &esil_if; return 1; } else
//if (!strcmp (word, "!?{")) { *cmd = &esil_ask; return 1; } else