about summary refs log tree commit diff stats
path: root/miasm/arch/x86/lifter_model_call.py
blob: e75f8c698596b0a17661f39b4ba13c086d2de577 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#-*- coding:utf-8 -*-

from miasm.expression.expression import ExprAssign, ExprOp
from miasm.ir.ir import AssignBlock
from miasm.ir.analysis import LifterModelCall
from miasm.arch.x86.sem import Lifter_X86_16, Lifter_X86_32, Lifter_X86_64


class LifterModelCall_x86_16(Lifter_X86_16, LifterModelCall):

    def __init__(self, loc_db):
        Lifter_X86_16.__init__(self, loc_db)
        self.ret_reg = self.arch.regs.AX

    def get_out_regs(self, _):
        return set([self.ret_reg, self.sp])

class LifterModelCall_x86_32(Lifter_X86_32, LifterModelCall_x86_16):

    def __init__(self, loc_db):
        Lifter_X86_32.__init__(self, loc_db)
        self.ret_reg = self.arch.regs.EAX

    def sizeof_char(self):
        return 8

    def sizeof_short(self):
        return 16

    def sizeof_int(self):
        return 32

    def sizeof_long(self):
        return 32

    def sizeof_pointer(self):
        return 32


class LifterModelCall_x86_64(Lifter_X86_64, LifterModelCall_x86_16):

    def __init__(self, loc_db):
        Lifter_X86_64.__init__(self, loc_db)
        self.ret_reg = self.arch.regs.RAX

    def call_effects(self, ad, instr):
        call_assignblk = AssignBlock(
            [
                ExprAssign(
                    self.ret_reg,
                    ExprOp(
                        'call_func_ret',
                        ad,
                        self.sp,
                        self.arch.regs.RCX,
                        self.arch.regs.RDX,
                        self.arch.regs.R8,
                        self.arch.regs.R9,
                    )
                ),
                ExprAssign(self.sp, ExprOp('call_func_stack', ad, self.sp)),
            ],
            instr
        )
        return [call_assignblk], []

    def sizeof_char(self):
        return 8

    def sizeof_short(self):
        return 16

    def sizeof_int(self):
        return 32

    def sizeof_long(self):
        return 64

    def sizeof_pointer(self):
        return 64