From 2293d293085c4dbb89b045809302e984bcbc67c3 Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Thu, 24 Sep 2020 12:14:43 +0800 Subject: [PATCH] x86 cmp/sub: Properly generate esil for bitsize of 64 ##anal (#17665) * x86 cmp/sub esil: Support bitsize of 64 * Fix pij tests * Don't shift if bitsize is 0 * Don't esilprint anything if bitsize is invalid * Use %u instead of %d * Check whether bitsize is 0 --- libr/anal/p/anal_x86_cs.c | 18 +++++++++--------- test/db/cmd/cmd_print | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libr/anal/p/anal_x86_cs.c b/libr/anal/p/anal_x86_cs.c index eaa9d1a504..ddf04d7222 100644 --- a/libr/anal/p/anal_x86_cs.c +++ b/libr/anal/p/anal_x86_cs.c @@ -976,17 +976,17 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, src = getarg (&gop, 1, 0, NULL, SRC_AR, NULL); dst = getarg (&gop, 0, 0, NULL, DST_AR, &bitsize); - if (bitsize > 63) { - bitsize = 0; + if (!bitsize || bitsize > 64) { + break; } if (insn->id == X86_INS_TEST) { - esilprintf (op, "0,%s,%s,&,==,$z,zf,:=,$p,pf,:=,%d,$s,sf,:=,0,cf,:=,0,of,:=", + esilprintf (op, "0,%s,%s,&,==,$z,zf,:=,$p,pf,:=,%u,$s,sf,:=,0,cf,:=,0,of,:=", src, dst, bitsize - 1); } else { esilprintf (op, - "%s,%s,==,$z,zf,:=,%d,$b,cf,:=,$p,pf,:=,%d,$s,sf,:=,%s,0x%"PFMT64x",-,!,%d,$o,^,of,:=,3,$b,af,:=", - src, dst, bitsize, bitsize - 1, src, (1ULL << (bitsize - 1)), bitsize - 1); + "%s,%s,==,$z,zf,:=,%u,$b,cf,:=,$p,pf,:=,%u,$s,sf,:=,%s,0x%"PFMT64x",-,!,%u,$o,^,of,:=,3,$b,af,:=", + src, dst, bitsize, bitsize - 1, src, 1ULL << (bitsize - 1), bitsize - 1); } } break; @@ -1476,15 +1476,15 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, src = getarg (&gop, 1, 0, NULL, SRC_AR, NULL); dst = getarg (&gop, 0, 1, "-", DST_AR, &bitsize); - if (bitsize > 63) { - bitsize = 0; + if (!bitsize || bitsize > 64) { + break; } // Set OF, SF, ZF, AF, PF, and CF flags. // We use $b rather than $c here as the carry flag really // represents a "borrow" - esilprintf (op, "%s,%s,%s,0x%"PFMT64x",-,!,%d,$o,^,of,:=,%d,$s,sf,:=,$z,zf,:=,$p,pf,:=,%d,$b,cf,:=,3,$b,af,:=", - src, dst, src, (1ULL << (bitsize - 1)), bitsize - 1, bitsize - 1, bitsize); + esilprintf (op, "%s,%s,%s,0x%"PFMT64x",-,!,%u,$o,^,of,:=,%u,$s,sf,:=,$z,zf,:=,$p,pf,:=,%u,$b,cf,:=,3,$b,af,:=", + src, dst, src, 1ULL << (bitsize - 1), bitsize - 1, bitsize - 1, bitsize); } break; case X86_INS_SBB: diff --git a/test/db/cmd/cmd_print b/test/db/cmd/cmd_print index b13ad8502a..64ac272fea 100644 --- a/test/db/cmd/cmd_print +++ b/test/db/cmd/cmd_print @@ -195,7 +195,7 @@ wx b8010000004839ca7f pij 3 EOF EXPECT=<