diff options
| author | Ajax <commial@gmail.com> | 2017-02-13 17:27:12 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2017-02-13 17:27:12 +0100 |
| commit | a89ff77f5efeb33c2006eac06036b80c3999e401 (patch) | |
| tree | 0dcfce60592a9e9d3cad19a4ea9334427a664b12 | |
| parent | d30ea3788133fffc294602ee6cce88b407caaf4a (diff) | |
| download | miasm-a89ff77f5efeb33c2006eac06036b80c3999e401.tar.gz miasm-a89ff77f5efeb33c2006eac06036b80c3999e401.zip | |
Interval: add .length computation
| -rw-r--r-- | miasm2/core/interval.py | 8 | ||||
| -rwxr-xr-x | test/core/interval.py | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/miasm2/core/interval.py b/miasm2/core/interval.py index 66445674..019764d4 100644 --- a/miasm2/core/interval.py +++ b/miasm2/core/interval.py @@ -244,3 +244,11 @@ class interval(object): if dry_run is False: img.show() + + @property + def length(self): + """ + Return the cumulated length of intervals + """ + # Do not use __len__ because we may return a value > 32 bits + return sum((stop - start + 1) for start, stop in self.intervals) diff --git a/test/core/interval.py b/test/core/interval.py index ab18e567..97d45a39 100755 --- a/test/core/interval.py +++ b/test/core/interval.py @@ -90,6 +90,10 @@ assert(i14 & i15 == i14) assert(i15 & i14 == i14) assert(i14 & i16 == interval([(3, 5), (7, 8)])) +assert(i5.length == 5) +assert(i6.length == 7) +assert((i1 - i1).length == 0) + x1 = [(7, 87), (76, 143), (94, 129), (79, 89), (46, 100)] assert(interval(x1) == interval([(7, 143)])) x2 = [(11, 16), (35, 74), (18, 114), (91, 188), (3, 75)] |