diff options
| author | Florent <florent.monjalet@gmail.com> | 2015-10-29 15:47:55 +0100 |
|---|---|---|
| committer | Florent <florent.monjalet@gmail.com> | 2015-10-29 15:47:55 +0100 |
| commit | fefb609f7ed8267815e3ab4b7467a8fada7040b8 (patch) | |
| tree | 03b82bcf93d36fa36f7cdee28b36eba3c7d59d40 /miasm2/expression/expression.py | |
| parent | 967be0c4e0f8d32f6bf3e8aa9f85d0abc9ab95da (diff) | |
| parent | c4e4273c2d4e459eddc96c8ef0af0e5eff9c3f7e (diff) | |
| download | miasm-fefb609f7ed8267815e3ab4b7467a8fada7040b8.tar.gz miasm-fefb609f7ed8267815e3ab4b7467a8fada7040b8.zip | |
Merge pull request #250 from serpilliere/ExprInt_api
Expression: normalize ExprInt api
Diffstat (limited to 'miasm2/expression/expression.py')
| -rw-r--r-- | miasm2/expression/expression.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index 1b9e0a91..46b7737e 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -288,7 +288,7 @@ class Expr(object): if self.size == size: return self ad_size = size - self.size - n = ExprInt_fromsize(ad_size, 0) + n = ExprInt(0, ad_size) return ExprCompose([(self, 0, self.size), (n, self.size, size)]) @@ -302,9 +302,8 @@ class Expr(object): ad_size = size - self.size c = ExprCompose([(self, 0, self.size), (ExprCond(self.msb(), - ExprInt_fromsize( - ad_size, size2mask(ad_size)), - ExprInt_fromsize(ad_size, 0)), + ExprInt(size2mask(ad_size), ad_size), + ExprInt(0, ad_size)), self.size, size) ]) return c @@ -331,7 +330,7 @@ class Expr(object): def set_mask(self, value): raise ValueError('mask is not mutable') - mask = property(lambda self: ExprInt_fromsize(self.size, -1)) + mask = property(lambda self: ExprInt(-1, self.size)) class ExprInt(Expr): @@ -344,15 +343,21 @@ class ExprInt(Expr): - Constant 0x12345678 on 32bits """ - def __init__(self, arg): - """Create an ExprInt from a numpy int - @arg: numpy int""" - - if not is_modint(arg): - raise ValueError('arg must by numpy int! %s' % arg) - - self._arg = arg - self._size = self.arg.size + def __init__(self, num, size=None): + """Create an ExprInt from a modint or num/size + @arg: modint or num + @size: (optionnal) int size""" + + if is_modint(num): + self._arg = num + self._size = self.arg.size + if size is not None and num.size != size: + raise RuntimeError("size must match modint size") + elif size is not None: + self._arg = mod_size2uint[size](num) + self._size = self.arg.size + else: + raise ValueError('arg must by modint or (int,size)! %s' % num) arg = property(lambda self: self._arg) @@ -1162,11 +1167,6 @@ def ExprInt_from(e, i): return ExprInt(mod_size2uint[e.size](i)) -def ExprInt_fromsize(size, i): - "Generate ExprInt with a given size" - return ExprInt(mod_size2uint[size](i)) - - def get_expr_ids_visit(e, ids): if isinstance(e, ExprId): ids.add(e) |