diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-04-25 22:53:29 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-05-01 23:39:09 +0200 |
| commit | af875f2a6ea80bba2e7306d24929a18d85d451ed (patch) | |
| tree | 23cb1017768b53bc843bbce1a7dd411cffbf13b5 /miasm2/expression/expression.py | |
| parent | 968e8fff0b9caef2441d005787897d44efaf860a (diff) | |
| download | miasm-af875f2a6ea80bba2e7306d24929a18d85d451ed.tar.gz miasm-af875f2a6ea80bba2e7306d24929a18d85d451ed.zip | |
Expression: Forbid mix between Expr and int/long
A classic error in Miasm is to confuse ExprInt with int, for example:
ExprId('a') + 3
We could return ExprOp('+', ExprId('a') + ExprInt(3, 32)), but this
may (and often) mask a problem in the source, so we forbid such a
construction (and assert this to clarify the error)
Diffstat (limited to 'miasm2/expression/expression.py')
| -rw-r--r-- | miasm2/expression/expression.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index 8ea855b5..c9255cca 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -560,7 +560,9 @@ class ExprAff(Expr): @dst: Expr, affectation destination @src: Expr, affectation source """ - + # dst & src must be Expr + assert isinstance(dst, Expr) + assert isinstance(src, Expr) super(ExprAff, self).__init__() if dst.size != src.size: @@ -664,6 +666,11 @@ class ExprCond(Expr): @src2: Expr, value if condition is evaled zero """ + # cond, src1, src2 must be Expr + assert isinstance(cond, Expr) + assert isinstance(src1, Expr) + assert isinstance(src2, Expr) + super(ExprCond, self).__init__() self.__cond, self.__src1, self.__src2 = cond, src1, src2 @@ -754,6 +761,10 @@ class ExprMem(Expr): @size: int, memory access size """ + # arg must be Expr + assert isinstance(arg, Expr) + assert isinstance(size, (int, long)) + super(ExprMem, self).__init__() if not isinstance(arg, Expr): @@ -839,6 +850,9 @@ class ExprOp(Expr): @*args: Expr, operand list """ + # args must be Expr + assert all(isinstance(arg, Expr) for arg in args) + super(ExprOp, self).__init__() sizes = set([arg.size for arg in args]) @@ -998,6 +1012,12 @@ class ExprSlice(Expr): __slots__ = Expr.__slots__ + ["__arg", "__start", "__stop"] def __init__(self, arg, start, stop): + + # arg must be Expr + assert isinstance(arg, Expr) + assert isinstance(start, (int, long)) + assert isinstance(stop, (int, long)) + super(ExprSlice, self).__init__() assert start < stop @@ -1097,6 +1117,9 @@ class ExprCompose(Expr): @args: [(Expr, int, int), (Expr, int, int), ...] """ + # args must be Expr + assert all(isinstance(arg, Expr) for arg in args) + super(ExprCompose, self).__init__() assert isinstance(args, tuple) self.__args = args |