diff options
| author | Ajax <commial@gmail.com> | 2017-03-30 15:55:35 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2017-03-30 16:25:41 +0200 |
| commit | 19af18b7bd57c37c6bdb3ef1a98b8111a9b74259 (patch) | |
| tree | a857208380d8e7e25943753817fba18599e60060 | |
| parent | b26958a1d4fde09c40359fb8fb30e2ec3b56b06d (diff) | |
| download | miasm-19af18b7bd57c37c6bdb3ef1a98b8111a9b74259.tar.gz miasm-19af18b7bd57c37c6bdb3ef1a98b8111a9b74259.zip | |
ModularIntervals: naive support for * operation
| -rw-r--r-- | miasm2/analysis/expression_range.py | 1 | ||||
| -rw-r--r-- | miasm2/analysis/modularintervals.py | 24 |
2 files changed, 24 insertions, 1 deletions
diff --git a/miasm2/analysis/expression_range.py b/miasm2/analysis/expression_range.py index ca63588c..a2c4a8df 100644 --- a/miasm2/analysis/expression_range.py +++ b/miasm2/analysis/expression_range.py @@ -7,6 +7,7 @@ _op_range_handler = { "&": lambda x, y: x & y, "|": lambda x, y: x | y, "^": lambda x, y: x ^ y, + "*": lambda x, y: x * y, ">>": lambda x, y: x >> y, "a>>": lambda x, y: x.arithmetic_shift_right(y), "<<": lambda x, y: x << y, diff --git a/miasm2/analysis/modularintervals.py b/miasm2/analysis/modularintervals.py index 2554339d..650dbc21 100644 --- a/miasm2/analysis/modularintervals.py +++ b/miasm2/analysis/modularintervals.py @@ -261,6 +261,21 @@ class ModularIntervals(object): _interval_xor = _range2interval(_range_xor) + def _range_mul(self, x_min, x_max, y_min, y_max): + """Interval bounds for x * y, with + - x, y of size self.size + - @x_min <= x <= @x_max + - @y_min <= y <= @y_max + - operations are considered unsigned + This is a naive version, going to TOP on overflow""" + max_bound = self.mask + if y_max * x_max > max_bound: + return interval([(0, max_bound)]) + else: + return interval([(x_min * y_min, x_max * y_max)]) + + _interval_mul = _range2interval(_range_mul) + def _range_mod_uniq(self, x_min, x_max, mod): """Interval bounds for x % @mod, with - x, @mod of size self.size @@ -390,11 +405,18 @@ class ModularIntervals(object): @_promote def __xor__(self, to_xor): """Bitwise XOR @to_xor to the current intervals - @to_or: ModularInstances or integer + @to_xor: ModularInstances or integer """ return self._interval_xor(to_xor) @_promote + def __mul__(self, to_mul): + """Multiply @to_mul to the current intervals + @to_mul: ModularInstances or integer + """ + return self._interval_mul(to_mul) + + @_promote def __rshift__(self, to_shift): """Logical shift right the current intervals of @to_shift @to_shift: ModularInstances or integer |