about summary refs log tree commit diff stats
path: root/test/expression/expression.py
blob: b998d4a563c18506c62e6e2d026f4fb589bb70c9 (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
#
# Expression regression tests  #
#
from pdb import pm
from miasm2.expression.expression import *
from miasm2.expression.expression_helper import *

# Expression comparison
assert(ExprInt(-1, 64) != ExprInt(-2, 64))
assert(ExprInt(1, 64) != ExprInt(1, 32))

# Expression size
big_cst = ExprInt(1, size=0x1000)
assert big_cst.size == 0x1000

# Possible values
#- Common constants
A = ExprId("A", 32)
cond1 = ExprId("cond1", 1)
cond2 = ExprId("cond2", 16)
cst1 = ExprInt(1, 32)
cst2 = ExprInt(2, 32)
cst3 = ExprInt(3, 32)
cst4 = ExprInt(4, 32)

#- Launch tests
for expr in [
        cst1,
        A,
        ExprMem(cst1, 32),
        ExprCond(cond1, cst1, cst2),
        ExprMem(ExprCond(cond1, cst1, cst2), 16),
        ExprCond(cond1,
                 ExprCond(cond2, cst3, cst4),
                 cst2),
        A + cst1,
        A + ExprCond(cond1, cst1, cst2),
        ExprCond(cond1, cst1, cst2) + ExprCond(cond2, cst3, cst4),
        ExprCompose(A, cst1),
        ExprCompose(ExprCond(cond1, cst1, cst2), A),
        ExprCompose(ExprCond(cond1, cst1, cst2),
                    ExprCond(cond2, cst3, cst4)),
        ExprCond(ExprCond(cond1, cst1, cst2), cst3, cst4),
]:
    print "*" * 80
    print expr
    sol = possible_values(expr)
    print sol
    print "Resulting constraints:"
    for consval in sol:
        print "For value %s" % consval.value
        for constraint in consval.constraints:
            print "\t%s" % constraint.to_constraint()

# Repr
for expr in [
        cst1,
        A,
        ExprMem(cst1, 32),
        ExprCond(cond1, cst1, cst2),
        A + cst1,
        ExprCompose(A, cst1),
        A.msb(),
        ExprAff(A, cst1),
]:
    print repr(expr)
    assert expr == eval(repr(expr))


aff = ExprAff(A[0:32], cst1)

assert aff.dst == A and aff.src == cst1