diff options
Diffstat (limited to 'miasm2/arch/aarch64/sem.py')
| -rw-r--r-- | miasm2/arch/aarch64/sem.py | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/miasm2/arch/aarch64/sem.py b/miasm2/arch/aarch64/sem.py index 3f70d7a7..1b591f74 100644 --- a/miasm2/arch/aarch64/sem.py +++ b/miasm2/arch/aarch64/sem.py @@ -1,5 +1,5 @@ from miasm2.expression.expression import ExprId, ExprInt, ExprLoc, ExprMem, \ - ExprCond, ExprCompose, ExprOp, ExprAff + ExprCond, ExprCompose, ExprOp, ExprAssign from miasm2.ir.ir import IntermediateRepresentation, IRBlock, AssignBlock from miasm2.arch.aarch64.arch import mn_aarch64, conds_expr, replace_regs from miasm2.arch.aarch64.regs import * @@ -11,16 +11,16 @@ from miasm2.jitter.csts import EXCEPT_DIV_BY_ZERO, EXCEPT_INT_XX def update_flag_zf(a): - return [ExprAff(zf, ExprOp("FLAG_EQ", a))] + return [ExprAssign(zf, ExprOp("FLAG_EQ", a))] def update_flag_zf_eq(a, b): - return [ExprAff(zf, ExprOp("FLAG_EQ_CMP", a, b))] + return [ExprAssign(zf, ExprOp("FLAG_EQ_CMP", a, b))] def update_flag_nf(arg): return [ - ExprAff( + ExprAssign( nf, ExprOp("FLAG_SIGN_SUB", arg, ExprInt(0, arg.size)) ) @@ -41,22 +41,22 @@ def check_ops_msb(a, b, c): def update_flag_add_cf(op1, op2): "Compute cf in @op1 + @op2" - return [ExprAff(cf, ExprOp("FLAG_ADD_CF", op1, op2))] + return [ExprAssign(cf, ExprOp("FLAG_ADD_CF", op1, op2))] def update_flag_add_of(op1, op2): "Compute of in @op1 + @op2" - return [ExprAff(of, ExprOp("FLAG_ADD_OF", op1, op2))] + return [ExprAssign(of, ExprOp("FLAG_ADD_OF", op1, op2))] def update_flag_sub_cf(op1, op2): "Compote CF in @op1 - @op2" - return [ExprAff(cf, ExprOp("FLAG_SUB_CF", op1, op2) ^ ExprInt(1, 1))] + return [ExprAssign(cf, ExprOp("FLAG_SUB_CF", op1, op2) ^ ExprInt(1, 1))] def update_flag_sub_of(op1, op2): "Compote OF in @op1 - @op2" - return [ExprAff(of, ExprOp("FLAG_SUB_OF", op1, op2))] + return [ExprAssign(of, ExprOp("FLAG_SUB_OF", op1, op2))] def update_flag_arith_add_co(arg1, arg2): @@ -72,7 +72,7 @@ def update_flag_arith_add_zn(arg1, arg2): """ e = [] e += update_flag_zf_eq(arg1, -arg2) - e += [ExprAff(nf, ExprOp("FLAG_SIGN_SUB", arg1, -arg2))] + e += [ExprAssign(nf, ExprOp("FLAG_SIGN_SUB", arg1, -arg2))] return e @@ -92,17 +92,17 @@ def update_flag_arith_sub_zn(arg1, arg2): """ e = [] e += update_flag_zf_eq(arg1, arg2) - e += [ExprAff(nf, ExprOp("FLAG_SIGN_SUB", arg1, arg2))] + e += [ExprAssign(nf, ExprOp("FLAG_SIGN_SUB", arg1, arg2))] return e def update_flag_zfaddwc_eq(arg1, arg2, arg3): - return [ExprAff(zf, ExprOp("FLAG_EQ_ADDWC", arg1, arg2, arg3))] + return [ExprAssign(zf, ExprOp("FLAG_EQ_ADDWC", arg1, arg2, arg3))] def update_flag_zfsubwc_eq(arg1, arg2, arg3): - return [ExprAff(zf, ExprOp("FLAG_EQ_SUBWC", arg1, arg2, arg3))] + return [ExprAssign(zf, ExprOp("FLAG_EQ_SUBWC", arg1, arg2, arg3))] def update_flag_arith_addwc_zn(arg1, arg2, arg3): @@ -111,7 +111,7 @@ def update_flag_arith_addwc_zn(arg1, arg2, arg3): """ e = [] e += update_flag_zfaddwc_eq(arg1, arg2, arg3) - e += [ExprAff(nf, ExprOp("FLAG_SIGN_ADDWC", arg1, arg2, arg3))] + e += [ExprAssign(nf, ExprOp("FLAG_SIGN_ADDWC", arg1, arg2, arg3))] return e @@ -121,18 +121,18 @@ def update_flag_arith_subwc_zn(arg1, arg2, arg3): """ e = [] e += update_flag_zfsubwc_eq(arg1, arg2, arg3) - e += [ExprAff(nf, ExprOp("FLAG_SIGN_SUBWC", arg1, arg2, arg3))] + e += [ExprAssign(nf, ExprOp("FLAG_SIGN_SUBWC", arg1, arg2, arg3))] return e def update_flag_addwc_cf(op1, op2, op3): "Compute cf in @res = @op1 + @op2 + @op3" - return [ExprAff(cf, ExprOp("FLAG_ADDWC_CF", op1, op2, op3))] + return [ExprAssign(cf, ExprOp("FLAG_ADDWC_CF", op1, op2, op3))] def update_flag_addwc_of(op1, op2, op3): "Compute of in @res = @op1 + @op2 + @op3" - return [ExprAff(of, ExprOp("FLAG_ADDWC_OF", op1, op2, op3))] + return [ExprAssign(of, ExprOp("FLAG_ADDWC_OF", op1, op2, op3))] def update_flag_arith_addwc_co(arg1, arg2, arg3): @@ -145,12 +145,12 @@ def update_flag_arith_addwc_co(arg1, arg2, arg3): def update_flag_subwc_cf(op1, op2, op3): "Compute cf in @res = @op1 + @op2 + @op3" - return [ExprAff(cf, ExprOp("FLAG_SUBWC_CF", op1, op2, op3) ^ ExprInt(1, 1))] + return [ExprAssign(cf, ExprOp("FLAG_SUBWC_CF", op1, op2, op3) ^ ExprInt(1, 1))] def update_flag_subwc_of(op1, op2, op3): "Compute of in @res = @op1 + @op2 + @op3" - return [ExprAff(of, ExprOp("FLAG_SUBWC_OF", op1, op2, op3))] + return [ExprAssign(of, ExprOp("FLAG_SUBWC_OF", op1, op2, op3))] def update_flag_arith_subwc_co(arg1, arg2, arg3): @@ -290,10 +290,10 @@ def bics(ir, instr, arg1, arg2, arg3): e = [] tmp1, tmp2 = arg2, (~extend_arg(arg2, arg3)) - e += [ExprAff(zf, ExprOp('FLAG_EQ_AND', tmp1, tmp2))] + e += [ExprAssign(zf, ExprOp('FLAG_EQ_AND', tmp1, tmp2))] e += update_flag_nf(res) - e.append(ExprAff(arg1, res)) + e.append(ExprAssign(arg1, res)) e += null_flag_co() return e, [] @@ -312,7 +312,7 @@ def adds(ir, instr, arg1, arg2, arg3): e += update_flag_arith_add_zn(arg2, arg3) e += update_flag_arith_add_co(arg2, arg3) - e.append(ExprAff(arg1, res)) + e.append(ExprAssign(arg1, res)) return e, [] @@ -326,7 +326,7 @@ def subs(ir, instr, arg1, arg2, arg3): e += update_flag_arith_sub_zn(arg2, arg3) e += update_flag_arith_sub_co(arg2, arg3) - e.append(ExprAff(arg1, res)) + e.append(ExprAssign(arg1, res)) return e, [] @@ -355,10 +355,10 @@ def ands(ir, instr, arg1, arg2, arg3): arg3 = extend_arg(arg2, arg3) res = arg2 & arg3 - e += [ExprAff(zf, ExprOp('FLAG_EQ_AND', arg2, arg3))] + e += [ExprAssign(zf, ExprOp('FLAG_EQ_AND', arg2, arg3))] e += update_flag_nf(res) - e.append(ExprAff(arg1, res)) + e.append(ExprAssign(arg1, res)) return e, [] def tst(ir, instr, arg1, arg2): @@ -366,7 +366,7 @@ def tst(ir, instr, arg1, arg2): arg2 = extend_arg(arg1, arg2) res = arg1 & arg2 - e += [ExprAff(zf, ExprOp('FLAG_EQ_AND', arg1, arg2))] + e += [ExprAssign(zf, ExprOp('FLAG_EQ_AND', arg1, arg2))] e += update_flag_nf(res) return e, [] @@ -401,9 +401,9 @@ def movk(ir, instr, arg1, arg2): isinstance(arg2.args[1], ExprInt)) value, shift = int(arg2.args[0].arg), int(arg2.args[1]) e.append( - ExprAff(arg1[shift:shift + 16], ExprInt(value, 16))) + ExprAssign(arg1[shift:shift + 16], ExprInt(value, 16))) else: - e.append(ExprAff(arg1[:16], ExprInt(int(arg2), 16))) + e.append(ExprAssign(arg1[:16], ExprInt(int(arg2), 16))) return e, [] @@ -444,16 +444,16 @@ def ccmp(ir, instr, arg1, arg2, arg3, arg4): new_cf = update_flag_sub_cf(arg1, arg2).src new_of = update_flag_sub_of(arg1, arg2).src - e.append(ExprAff(nf, ExprCond(cond_expr, + e.append(ExprAssign(nf, ExprCond(cond_expr, new_nf, default_nf))) - e.append(ExprAff(zf, ExprCond(cond_expr, + e.append(ExprAssign(zf, ExprCond(cond_expr, new_zf, default_zf))) - e.append(ExprAff(cf, ExprCond(cond_expr, + e.append(ExprAssign(cf, ExprCond(cond_expr, new_cf, default_cf))) - e.append(ExprAff(of, ExprCond(cond_expr, + e.append(ExprAssign(of, ExprCond(cond_expr, new_of, default_of))) return e, [] @@ -463,7 +463,7 @@ def csinc(ir, instr, arg1, arg2, arg3, arg4): e = [] cond_expr = cond2expr[arg4.name] e.append( - ExprAff( + ExprAssign( arg1, ExprCond( cond_expr, @@ -479,7 +479,7 @@ def csinv(ir, instr, arg1, arg2, arg3, arg4): e = [] cond_expr = cond2expr[arg4.name] e.append( - ExprAff( + ExprAssign( arg1, ExprCond( cond_expr, @@ -494,7 +494,7 @@ def csneg(ir, instr, arg1, arg2, arg3, arg4): e = [] cond_expr = cond2expr[arg4.name] e.append( - ExprAff( + ExprAssign( arg1, ExprCond( cond_expr, @@ -509,7 +509,7 @@ def cset(ir, instr, arg1, arg2): e = [] cond_expr = cond2expr[arg2.name] e.append( - ExprAff( + ExprAssign( arg1, ExprCond( cond_expr, @@ -525,7 +525,7 @@ def csetm(ir, instr, arg1, arg2): e = [] cond_expr = cond2expr[arg2.name] e.append( - ExprAff( + ExprAssign( arg1, ExprCond( cond_expr, @@ -562,11 +562,11 @@ def get_mem_access(mem): raise NotImplementedError('bad op') elif mem.op == "postinc": addr, off = mem.args - updt = ExprAff(addr, addr + off) + updt = ExprAssign(addr, addr + off) elif mem.op == "preinc_wb": base, off = mem.args addr = base + off - updt = ExprAff(base, base + off) + updt = ExprAssign(base, base + off) else: raise NotImplementedError('bad op') else: @@ -578,7 +578,7 @@ def get_mem_access(mem): def ldr(ir, instr, arg1, arg2): e = [] addr, updt = get_mem_access(arg2) - e.append(ExprAff(arg1, ExprMem(addr, arg1.size))) + e.append(ExprAssign(arg1, ExprMem(addr, arg1.size))) if updt: e.append(updt) return e, [] @@ -588,7 +588,7 @@ def ldr_size(ir, instr, arg1, arg2, size): e = [] addr, updt = get_mem_access(arg2) e.append( - ExprAff(arg1, ExprMem(addr, size).zeroExtend(arg1.size))) + ExprAssign(arg1, ExprMem(addr, size).zeroExtend(arg1.size))) if updt: e.append(updt) return e, [] @@ -606,7 +606,7 @@ def ldrs_size(ir, instr, arg1, arg2, size): e = [] addr, updt = get_mem_access(arg2) e.append( - ExprAff(arg1, ExprMem(addr, size).signExtend(arg1.size))) + ExprAssign(arg1, ExprMem(addr, size).signExtend(arg1.size))) if updt: e.append(updt) return e, [] @@ -628,7 +628,7 @@ def ldrsw(ir, instr, arg1, arg2): def l_str(ir, instr, arg1, arg2): e = [] addr, updt = get_mem_access(arg2) - e.append(ExprAff(ExprMem(addr, arg1.size), arg1)) + e.append(ExprAssign(ExprMem(addr, arg1.size), arg1)) if updt: e.append(updt) return e, [] @@ -637,7 +637,7 @@ def l_str(ir, instr, arg1, arg2): def strb(ir, instr, arg1, arg2): e = [] addr, updt = get_mem_access(arg2) - e.append(ExprAff(ExprMem(addr, 8), arg1[:8])) + e.append(ExprAssign(ExprMem(addr, 8), arg1[:8])) if updt: e.append(updt) return e, [] @@ -646,7 +646,7 @@ def strb(ir, instr, arg1, arg2): def strh(ir, instr, arg1, arg2): e = [] addr, updt = get_mem_access(arg2) - e.append(ExprAff(ExprMem(addr, 16), arg1[:16])) + e.append(ExprAssign(ExprMem(addr, 16), arg1[:16])) if updt: e.append(updt) return e, [] @@ -655,9 +655,9 @@ def strh(ir, instr, arg1, arg2): def stp(ir, instr, arg1, arg2, arg3): e = [] addr, updt = get_mem_access(arg3) - e.append(ExprAff(ExprMem(addr, arg1.size), arg1)) + e.append(ExprAssign(ExprMem(addr, arg1.size), arg1)) e.append( - ExprAff(ExprMem(addr + ExprInt(arg1.size / 8, addr.size), arg2.size), arg2)) + ExprAssign(ExprMem(addr + ExprInt(arg1.size / 8, addr.size), arg2.size), arg2)) if updt: e.append(updt) return e, [] @@ -666,9 +666,9 @@ def stp(ir, instr, arg1, arg2, arg3): def ldp(ir, instr, arg1, arg2, arg3): e = [] addr, updt = get_mem_access(arg3) - e.append(ExprAff(arg1, ExprMem(addr, arg1.size))) + e.append(ExprAssign(arg1, ExprMem(addr, arg1.size))) e.append( - ExprAff(arg2, ExprMem(addr + ExprInt(arg1.size / 8, addr.size), arg2.size))) + ExprAssign(arg2, ExprMem(addr + ExprInt(arg1.size / 8, addr.size), arg2.size))) if updt: e.append(updt) return e, [] @@ -682,7 +682,7 @@ def sbfm(ir, instr, arg1, arg2, arg3, arg4): else: shift = ExprInt(arg2.size - rim, arg2.size) res = (arg2[:sim].signExtend(arg1.size) << shift) - e.append(ExprAff(arg1, res)) + e.append(ExprAssign(arg1, res)) return e, [] @@ -694,7 +694,7 @@ def ubfm(ir, instr, arg1, arg2, arg3, arg4): else: shift = ExprInt(arg2.size - rim, arg2.size) res = (arg2[:sim].zeroExtend(arg1.size) << shift) - e.append(ExprAff(arg1, res)) + e.append(ExprAssign(arg1, res)) return e, [] def bfm(ir, instr, arg1, arg2, arg3, arg4): @@ -702,12 +702,12 @@ def bfm(ir, instr, arg1, arg2, arg3, arg4): rim, sim = int(arg3.arg), int(arg4) + 1 if sim > rim: res = arg2[rim:sim] - e.append(ExprAff(arg1[:sim-rim], res)) + e.append(ExprAssign(arg1[:sim-rim], res)) else: shift_i = arg2.size - rim shift = ExprInt(shift_i, arg2.size) res = arg2[:sim] - e.append(ExprAff(arg1[shift_i:shift_i+sim], res)) + e.append(ExprAssign(arg1[shift_i:shift_i+sim], res)) return e, [] @@ -721,7 +721,7 @@ def mrs(ir, insr, arg1, arg2, arg3, arg4, arg5): out.append(cf) out.append(zf) out.append(nf) - e.append(ExprAff(arg1, ExprCompose(*out).zeroExtend(arg1.size))) + e.append(ExprAssign(arg1, ExprCompose(*out).zeroExtend(arg1.size))) else: raise NotImplementedError("MRS not implemented") return e, [] @@ -730,10 +730,10 @@ def msr(ir, instr, arg1, arg2, arg3, arg4, arg5): e = [] if arg1.is_int(3) and arg2.is_id("c4") and arg3.is_id("c2") and arg4.is_int(0): - e.append(ExprAff(nf, arg5[31:32])) - e.append(ExprAff(zf, arg5[30:31])) - e.append(ExprAff(cf, arg5[29:30])) - e.append(ExprAff(of, arg5[28:29])) + e.append(ExprAssign(nf, arg5[31:32])) + e.append(ExprAssign(zf, arg5[30:31])) + e.append(ExprAssign(cf, arg5[29:30])) + e.append(ExprAssign(of, arg5[28:29])) else: raise NotImplementedError("MSR not implemented") return e, [] @@ -744,7 +744,7 @@ def adc(ir, instr, arg1, arg2, arg3): arg3 = extend_arg(arg2, arg3) e = [] r = arg2 + arg3 + cf.zeroExtend(arg3.size) - e.append(ExprAff(arg1, r)) + e.append(ExprAssign(arg1, r)) return e, [] @@ -752,7 +752,7 @@ def adcs(ir, instr, arg1, arg2, arg3): arg3 = extend_arg(arg2, arg3) e = [] r = arg2 + arg3 + cf.zeroExtend(arg3.size) - e.append(ExprAff(arg1, r)) + e.append(ExprAssign(arg1, r)) e += update_flag_arith_addwc_zn(arg2, arg3, cf) e += update_flag_arith_addwc_co(arg2, arg3, cf) return e, [] @@ -762,7 +762,7 @@ def sbc(ir, instr, arg1, arg2, arg3): arg3 = extend_arg(arg2, arg3) e = [] r = arg2 - (arg3 + (~cf).zeroExtend(arg3.size)) - e.append(ExprAff(arg1, r)) + e.append(ExprAssign(arg1, r)) return e, [] @@ -770,7 +770,7 @@ def sbcs(ir, instr, arg1, arg2, arg3): arg3 = extend_arg(arg2, arg3) e = [] r = arg2 - (arg3 + (~cf).zeroExtend(arg3.size)) - e.append(ExprAff(arg1, r)) + e.append(ExprAssign(arg1, r)) e += update_flag_arith_subwc_zn(arg2, arg3, ~cf) e += update_flag_arith_subwc_co(arg2, arg3, ~cf) return e, [] @@ -956,7 +956,7 @@ def rev(ir, instr, arg1, arg2): out.reverse() e = [] result = ExprCompose(*out) - e.append(ExprAff(arg1, result)) + e.append(ExprAssign(arg1, result)) return e, [] @@ -1088,7 +1088,7 @@ class ir_aarch64l(IntermediateRepresentation): def expraff_fix_regs_for_mode(self, e): dst = self.expr_fix_regs_for_mode(e.dst) src = self.expr_fix_regs_for_mode(e.src) - return ExprAff(dst, src) + return ExprAssign(dst, src) def irbloc_fix_regs_for_mode(self, irblock, mode=64): irs = [] @@ -1119,7 +1119,7 @@ class ir_aarch64l(IntermediateRepresentation): if dst != self.pc: dst = dst.replace_expr(pc_fixed) src = src.replace_expr(pc_fixed) - instr_ir[i] = ExprAff(dst, src) + instr_ir[i] = ExprAssign(dst, src) for idx, irblock in enumerate(extra_ir): extra_ir[idx] = irblock.modify_exprs(lambda expr: expr.replace_expr(pc_fixed) \ |