about summary refs log tree commit diff stats
path: root/example/expression/get_read_write.py
blob: 0c8bb3dd1c59fc04756c87af3fdcf9a746d889c5 (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
from __future__ import print_function

from future.utils import viewitems

from miasm2.arch.x86.arch import mn_x86
from miasm2.expression.expression import get_rw
from miasm2.arch.x86.ira import ir_a_x86_32
from miasm2.core.locationdb import LocationDB

loc_db = LocationDB()


print("""
Simple expression manipulation demo.
Get read/written registers for a given instruction
""")

arch = mn_x86
ir_arch = ir_a_x86_32(loc_db)
ircfg = ir_arch.new_ircfg()
instr = arch.fromstring('LODSB', loc_db, 32)
instr.offset, instr.l = 0, 15
ir_arch.add_instr_to_ircfg(instr, ircfg)

print('*' * 80)
for lbl, irblock in viewitems(ircfg.blocks):
    print(irblock)
    for assignblk in irblock:
        rw = assignblk.get_rw()
        for dst, reads in viewitems(rw):
            print('read:   ', [str(x) for x in reads])
            print('written:', dst)
            print()

open('graph_instr.dot', 'w').write(ircfg.dot())