diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2016-04-17 22:16:15 +0200 |
|---|---|---|
| committer | serpilliere <fabrice.desclaux@cea.fr> | 2016-04-18 20:37:22 +0200 |
| commit | 23879d0d8325e5c1ba144923d815cda639903415 (patch) | |
| tree | 253fc7e5ae5ce8f509bc0637d9ae95c8278b014d | |
| parent | 8fff094b010db48e661e926d19536457ca5f86c1 (diff) | |
| download | miasm-23879d0d8325e5c1ba144923d815cda639903415.tar.gz miasm-23879d0d8325e5c1ba144923d815cda639903415.zip | |
X86/sem: fix pusha/popa
| -rw-r--r-- | miasm2/arch/x86/sem.py | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index cc227819..f66570a7 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -1064,51 +1064,45 @@ def popfw(ir, instr): m2_expr.ExprAff(mRSP[instr.mode], mRSP[instr.mode] + m2_expr.ExprInt(2, mRSP[instr.mode].size))) return e, [] +pa_regs = [ + mRAX, mRCX, + mRDX, mRBX, + mRSP, mRBP, + mRSI, mRDI +] -def pushad(ir, instr): +def pusha_gen(ir, instr, size): e = [] - s = instr.v_opmode() - opmode, admode = s, instr.v_admode() - if not s in [16, 32, 64]: - raise ValueError('bad size stacker!') - - regs = [ - mRAX[instr.mode][:s], mRCX[instr.mode][ - :s], mRDX[instr.mode][:s], mRBX[instr.mode][:s], - mRSP[instr.mode][:s], mRBP[instr.mode][:s], - mRSI[instr.mode][:s], mRDI[instr.mode][:s]] - - for i in xrange(len(regs)): - c = mRSP[instr.mode][:s] + m2_expr.ExprInt(-(s / 8) * (i + 1), s) - e.append(m2_expr.ExprAff(m2_expr.ExprMem(c, s), regs[i])) - e.append(m2_expr.ExprAff(mRSP[instr.mode][:s], c)) + for i, reg in enumerate(pa_regs): + stk_ptr = mRSP[instr.mode] + m2_expr.ExprInt(-(reg[size].size / 8) * (i + 1), instr.mode) + e.append(m2_expr.ExprAff(m2_expr.ExprMem(stk_ptr, reg[size].size), reg[size])) + e.append(m2_expr.ExprAff(mRSP[instr.mode], stk_ptr)) return e, [] +def pusha(ir, instr): + return pusha_gen(ir, instr, 16) -def popad(ir, instr): +def pushad(ir, instr): + return pusha_gen(ir, instr, 32) + +def popa_gen(ir, instr, size): e = [] - s = instr.v_opmode() - opmode, admode = s, instr.v_admode() - if not s in [16, 32, 64]: - raise ValueError('bad size stacker!') - regs = [ - mRAX[instr.mode][:s], mRCX[instr.mode][ - :s], mRDX[instr.mode][:s], mRBX[instr.mode][:s], - mRSP[instr.mode][:s], mRBP[instr.mode][:s], - mRSI[instr.mode][:s], mRDI[instr.mode][:s]] - myesp = mRSP[instr.mode][:s] - regs.reverse() - for i in xrange(len(regs)): - if regs[i] == myesp: + for i, reg in enumerate(reversed(pa_regs)): + if reg == mRSP: continue - c = myesp + m2_expr.ExprInt_from(myesp, ((s / 8) * i)) - e.append(m2_expr.ExprAff(regs[i], m2_expr.ExprMem(c, s))) + stk_ptr = mRSP[instr.mode] + m2_expr.ExprInt((reg[size].size / 8) * i, instr.mode) + e.append(m2_expr.ExprAff(reg[size], m2_expr.ExprMem(stk_ptr, instr.mode))) - c = myesp + m2_expr.ExprInt_from(myesp, ((s / 8) * (i + 1))) - e.append(m2_expr.ExprAff(myesp, c)) + stk_ptr = mRSP[instr.mode] + m2_expr.ExprInt((instr.mode / 8) * (i + 1), instr.mode) + e.append(m2_expr.ExprAff(mRSP[instr.mode], stk_ptr)) return e, [] +def popa(ir, instr): + return popa_gen(ir, instr, 16) + +def popad(ir, instr): + return popa_gen(ir, instr, 32) def call(ir, instr, dst): e = [] @@ -4043,10 +4037,10 @@ mnemo_func = {'mov': mov, 'popfd': popfd, 'popfq': popfd, 'popfw': popfw, + 'pusha': pusha, 'pushad': pushad, - 'pusha': pushad, 'popad': popad, - 'popa': popad, + 'popa': popa, 'call': call, 'ret': ret, 'retf': retf, |