about summary refs log tree commit diff stats
path: root/miasm2/arch/x86/disasm.py
blob: 6d144944fd4f96f947ffdad7254c63533f5234f0 (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
from miasm2.core.asmbloc import asm_constraint, asm_label, disasmEngine
from miasm2.expression.expression import ExprId
from miasm2.arch.x86.arch import mn_x86


def cb_x86_callpop(cur_bloc, *args, **kwargs):
    """
    1000: call 1005
    1005: pop

    Will give:

    1000: push 1005
    1005: pop

    """
    if len(cur_bloc.lines) < 1:
        return
    l = cur_bloc.lines[-1]
    if l.name != 'CALL':
        return
    dst = l.args[0]
    if not (isinstance(dst, ExprId) and isinstance(dst.name, asm_label)):
        return
    if dst.name.offset != l.offset + l.l:
        return
    l.name = 'PUSH'
    cur_bloc.bto = set()
    cur_bloc.add_cst(dst.name.offset, asm_constraint.c_next, symbol_pool)


cb_x86_funcs = [cb_x86_callpop]


def cb_x86_disasm(*args, **kwargs):
    for func in cb_x86_funcs:
        func(*args, **kwargs)


class dis_x86(disasmEngine):
    attrib = None

    def __init__(self, bs=None, **kwargs):
        super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
        self.dis_bloc_callback = cb_x86_disasm


class dis_x86_16(dis_x86):
    attrib = 16


class dis_x86_32(dis_x86):
    attrib = 32


class dis_x86_64(dis_x86):
    attrib = 64