5 #include <capstone/capstone.h>
10 #define REG64(x) rz_str_get_null(cs_reg_name(*handle, insn->detail->arm64.operands[x].reg))
11 #define MEMBASE64(x) rz_str_get_null(cs_reg_name(*handle, insn->detail->arm64.operands[x].mem.base))
12 #define MEMINDEX64(x) rz_str_get_null(cs_reg_name(*handle, insn->detail->arm64.operands[x].mem.index))
77 #define EXT64(x) decode_sign_ext(insn->detail->arm64.operands[x].ext)
80 const char *E_OP_SR =
">>";
81 const char *E_OP_SL =
"<<";
82 const char *E_OP_RR =
">>>";
83 const char *E_OP_VOID =
"";
103 #define DECODE_SHIFT64(x) decode_shift_64(insn->detail->arm64.operands[x].shift.type)
106 unsigned int reg = insn->detail->arm64.operands[
n].reg;
124 #define REGSIZE64(x) regsize64(insn, x)
126 #define SHIFTED_REG64_APPEND(sb, n) shifted_reg64_append(sb, handle, insn, n)
140 if (insn->detail->arm64.operands[
n].shift.type !=
ARM64_SFT_ASR) {
154 rz_strbuf_appendf(
sb,
"%d,%d,%s,~,%s,1,%d,%s,~,<<<,1,&,?{,%" PFMT64u ",}{,0,},|",
157 rz_strbuf_appendf(
sb,
"%d,%s,%s,1,%s,<<<,1,&,?{,%" PFMT64u ",}{,0,},|",
161 }
else if (signext) {
168 #define OPCALL(opchar) arm64math(a, op, addr, buf, len, handle, insn, opchar, 0)
169 #define OPCALL_NEG(opchar) arm64math(a, op, addr, buf, len, handle, insn, opchar, 1)
187 rz_strbuf_setf(&
op->esil,
"%s,-1,^,%s,%s,%s,=",
r2,
r1, opchar,
r0);
195 rz_strbuf_setf(&
op->esil,
"%" PFMT64d ",-1,^,%s,%s,%s,=",
i2,
r1, opchar,
r0);
203 const char *postfix =
NULL;
224 "DUP,0xff,<<,%s,&,>>,"
232 "56,0xff,%s,&,<<,tmp,=,"
233 "48,0xff,8,%s,>>,&,<<,tmp,|=,"
234 "40,0xff,16,%s,>>,&,<<,tmp,|=,"
235 "32,0xff,24,%s,>>,&,<<,tmp,|=,"
236 "24,0xff,32,%s,>>,&,<<,tmp,|=,"
237 "16,0xff,40,%s,>>,&,<<,tmp,|=,"
238 "8,0xff,48,%s,>>,&,<<,tmp,|=,"
239 "0xff,56,%s,>>,&,tmp,|=,tmp,%s,=",
244 "24,0xff,%s,&,<<,tmp,=,"
245 "16,0xff,8,%s,>>,&,<<,tmp,|=,"
246 "8,0xff,16,%s,>>,&,<<,tmp,|=,"
247 "0xff,24,%s,>>,&,tmp,|=,tmp,%s,=",
256 "24,0x000000ff000000ff,%s,&,<<,tmp,=,"
257 "16,0x000000ff000000ff,8,%s,>>,&,<<,tmp,|=,"
258 "8,0x000000ff000000ff,16,%s,>>,&,<<,tmp,|=,"
259 "0x000000ff000000ff,24,%s,>>,&,tmp,|=,tmp,%s,=",
267 "8,0xff00ff00ff00ff00,%s,&,>>,tmp,=,"
268 "8,0x00ff00ff00ff00ff,%s,&,<<,tmp,|=,tmp,%s,=",
279 rz_strbuf_setf(&
op->esil,
"%d,%s,~,%d,%s,~,*,%s,+,%s,=",
312 rz_strbuf_setf(&
op->esil,
"%d,%s,~,%d,%s,~,*,%s,=",
342 rz_strbuf_appendf(&
op->esil,
",%d,%%,%s,>>,%s,=",
size,
r1,
r0);
345 rz_strbuf_setf(&
op->esil,
"%d,%s,%%,%s,>>,%s,=",
size,
r2,
r1,
r0);
361 rz_strbuf_appendf(&
op->esil,
",%d,%%,%s,<<,%s,=",
size,
r1,
r0);
364 rz_strbuf_setf(&
op->esil,
"%d,%s,%%,%s,<<,%s,=",
size,
r2,
r1,
r0);
384 rz_strbuf_setf(&
op->esil,
"%d,%s,~,%d,%s,~,~/,%s,=",
size,
REG64(2),
size,
REG64(1),
REG64(0));
386 rz_strbuf_setf(&
op->esil,
"%d,%s,~,%d,%s,~,~/,%s,=",
size,
REG64(1),
size,
REG64(0),
REG64(0));
437 "tmp,0xffff0000,&,!,?{,16,tmp,<<=,16,+,},"
438 "tmp,0xff000000,&,!,?{,8,tmp,<<=,8,+,},"
439 "tmp,0xf0000000,&,!,?{,4,tmp,<<=,4,+,},"
440 "tmp,0xc0000000,&,!,?{,2,tmp,<<=,2,+,},"
441 "tmp,0x80000000,&,!,?{,1,+,},"
442 "%s,!,?{,32,%s,=,}{,%s,=,}",
447 "tmp,0xffffffff00000000,&,!,?{,32,tmp,<<=,32,+,},"
448 "tmp,0xffff000000000000,&,!,?{,16,tmp,<<=,16,+,},"
449 "tmp,0xff00000000000000,&,!,?{,8,tmp,<<=,8,+,},"
450 "tmp,0xf000000000000000,&,!,?{,4,tmp,<<=,4,+,},"
451 "tmp,0xc000000000000000,&,!,?{,2,tmp,<<=,2,+,},"
452 "tmp,0x8000000000000000,&,!,?{,1,+,},"
453 "%s,!,?{,64,%s,=,}{,%s,=,}",
670 rz_strbuf_setf(&
op->esil,
"%" PFMT64d ",%s,==,$z,zf,:=,%d,$s,nf,:=,%d,$b,!,cf,:=,%d,$o,vf,:=",
IMM64(1) <<
LSHIFT2_64(1),
REG64(0),
bits - 1,
bits,
bits - 1);
674 rz_strbuf_appendf(&
op->esil,
",%s,==,$z,zf,:=,%d,$s,nf,:=,%d,$b,!,cf,:=,%d,$o,vf,:=",
REG64(0),
bits - 1,
bits,
bits - 1);
688 rz_strbuf_appendf(&
op->esil,
"1,%s,+,}{,%s,},%s,=",
REG64(1),
REG64(1),
REG64(0));
692 rz_strbuf_appendf(&
op->esil,
"%s,}{,1,%s,+,},%s,=",
REG64(1),
REG64(2),
REG64(0));
797 rz_strbuf_appendf(&
op->esil,
"%s,0xffffffff,^,%s,&,%s,=",
REG64(2),
REG64(1),
REG64(0));
799 rz_strbuf_appendf(&
op->esil,
"%s,0xffffffffffffffff,^,%s,&,%s,=",
REG64(2),
REG64(1),
REG64(0));
814 rz_strbuf_setf(&
op->esil,
"%" PFMT64d ",1,<<,%s,&,!,?{,%" PFMT64d ",pc,=,}",
820 rz_strbuf_setf(&
op->esil,
"%" PFMT64d ",1,<<,%s,&,?{,%" PFMT64d ",pc,=,}",
827 char sign = disp >= 0 ?
'+' :
'-';
835 "%" PFMT64d ",%s,%c=,%s,%s,=[%d],%s,%s,%d,+,=[%d]",
842 sign =
val >= 0 ?
'+' :
'-';
847 "%s,%s,=[%d],%s,%s,%d,+,=[%d],%" PFMT64d ",%s,%c=",
855 "%s,%s,%" PFMT64d ",%c,%d,+,=[%d]",
863 char sign = disp >= 0 ?
'+' :
'-';
881 sign =
val >= 0 ?
'+' :
'-';
894 "%" PFMT64d ",%s,%c,[%d],%s,=,"
895 "%d,%" PFMT64d ",%s,%c,+,[%d],%s,=",
921 rz_strbuf_setf(&
op->esil,
"%" PFMT64d ",%s,>>,%" PFMT64d ",%s,<<,|,%s,=",
927 rz_strbuf_setf(&
op->esil,
"0xffffffff00000000,0x20,0xffff0000ffff0000,0x10,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1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buf_setf(&
op->esil,
"%d,%" PFMT64d ",<<,-1,^,%s,=",
LSHIFT2_64(1),
IMM64(1),
REG64(0));
943 }
else if (
shift > 48) {
972 rz_strbuf_appendf(&
op->esil,
",%d,%%,%s,>>>>,%s,=",
size,
r1,
r0);
975 rz_strbuf_setf(&
op->esil,
"%d,%s,%%,%s,>>>>,%s,=",
size,
r2,
r1,
r0);
985 rz_strbuf_setf(&
op->esil,
"0xffffffff,8,0xff,%s,&,~,&,%s,=",
994 rz_strbuf_setf(&
op->esil,
"0xffffffff,16,0xffff,%s,&,~,&,%s,=",
1027 rz_strbuf_setf(&
op->esil,
"%" PFMT64u ",%s,&,%" PFMT64u ",%" PFMT64u ",%s,&,<<,|,%s,=",
1034 rz_strbuf_appendf(&
op->esil,
"%" PFMT64d ",%" PFMT64d ",%s,%" PFMT64u ",&,~,<<,%s,=",
1046 rz_strbuf_appendf(&
op->esil,
"%" PFMT64d ",%" PFMT64d ",%s,%" PFMT64d ",%" PFMT64u ",<<,&,>>,~,%s,=",
1052 rz_strbuf_appendf(&
op->esil,
"%" PFMT64d ",%s,%" PFMT64d ",%" PFMT64u ",<<,&,>>,%s,=",
1057 #if CS_API_MAJOR > 3
RZ_IPI const char * rz_arm_cs_esil_prefix_cond(RzAnalysisOp *op, int cond_type)
static int decode_sign_ext(arm64_extender extender)
#define OPCALL_NEG(opchar)
static void shifted_reg64_append(RzStrBuf *sb, csh *handle, cs_insn *insn, int n)
static void arm64math(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, const char *opchar, int negate)
static int regsize64(cs_insn *insn, int n)
#define DECODE_SHIFT64(x)
static const char * decode_shift_64(arm64_shifter shift)
#define SHIFTED_REG64_APPEND(sb, n)
RZ_IPI int rz_arm_cs_analysis_op_64_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn)
static int arm64_reg_width(int reg)
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
static mcore_handle handle
int bits(struct state *s, int need)
arm64_shifter
ARM64 shift type.
arm64_extender
ARM64 extender type.
static ut64 rz_num_bitmask(ut8 width)
Get the 64-bit value that has exactly its width lowest bits set to 1. e.g. rz_num_bitmask(2) == 0b11 ...
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()