diff options
| author | Ajax <commial@gmail.com> | 2016-12-14 18:08:02 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2016-12-14 18:08:02 +0100 |
| commit | 952255aac561a1c7c72ae7c61f59d7e9b1602936 (patch) | |
| tree | b0bbb8627a421fe9f13d29f3ecd5278303df977f | |
| parent | 84ace5ec556c260bd01d7ac26129577ea1d78c0f (diff) | |
| download | miasm-952255aac561a1c7c72ae7c61f59d7e9b1602936.tar.gz miasm-952255aac561a1c7c72ae7c61f59d7e9b1602936.zip | |
Introduce ExprInt of any size (like others Expr)
| -rw-r--r-- | miasm2/expression/expression.py | 2 | ||||
| -rw-r--r-- | miasm2/expression/modint.py | 35 |
2 files changed, 25 insertions, 12 deletions
diff --git a/miasm2/expression/expression.py b/miasm2/expression/expression.py index 581dc8dc..f8af52d9 100644 --- a/miasm2/expression/expression.py +++ b/miasm2/expression/expression.py @@ -380,6 +380,8 @@ class ExprInt(Expr): if size is not None and num.size != size: raise RuntimeError("size must match modint size") elif size is not None: + if size not in mod_size2uint: + define_uint(size) self.__arg = mod_size2uint[size](num) self.__size = self.arg.size else: diff --git a/miasm2/expression/modint.py b/miasm2/expression/modint.py index 76896eb9..a801c948 100644 --- a/miasm2/expression/modint.py +++ b/miasm2/expression/modint.py @@ -198,25 +198,36 @@ mod_size2int = {} mod_uint2size = {} mod_int2size = {} +def define_int(size): + """Build the 'modint' instance corresponding to size @size""" + global mod_size2int, mod_int2size + + name = 'int%d' % size + cls = type(name, (modint,), {"size": size, "limit": 1 << size}) + globals()[name] = cls + mod_size2int[size] = cls + mod_int2size[cls] = size + return cls + +def define_uint(size): + """Build the 'moduint' instance corresponding to size @size""" + global mod_size2uint, mod_uint2size + + name = 'uint%d' % size + cls = type(name, (moduint,), {"size": size, "limit": 1 << size}) + globals()[name] = cls + mod_size2uint[size] = cls + mod_uint2size[cls] = size + return cls def define_common_int(): "Define common int: ExprInt1, ExprInt2, .." - global mod_size2int, mod_int2size, mod_size2uint, mod_uint2size - common_int = xrange(1, 257) for i in common_int: - name = 'uint%d' % i - c = type(name, (moduint,), {"size": i, "limit": 1 << i}) - globals()[name] = c - mod_size2uint[i] = c - mod_uint2size[c] = i + define_int(i) for i in common_int: - name = 'int%d' % i - c = type(name, (modint,), {"size": i, "limit": 1 << i}) - globals()[name] = c - mod_size2int[i] = c - mod_int2size[c] = i + define_uint(i) define_common_int() |