diff options
| author | Camille Mougey <commial@gmail.com> | 2015-06-11 18:05:42 +0200 |
|---|---|---|
| committer | Camille Mougey <commial@gmail.com> | 2015-06-11 18:05:42 +0200 |
| commit | 15b777061e96f55f2bfd2f7233d67f12b8f9f575 (patch) | |
| tree | 602a54119897928445fd88ea5706a0ec35cb8fc8 /miasm2/expression/simplifications_common.py | |
| parent | e4557a93d4bafb3ae86a0fc5280592ee98c1fb9f (diff) | |
| parent | 89f0c6718384557e9a1e9341310f0770eec5e0a2 (diff) | |
| download | miasm-15b777061e96f55f2bfd2f7233d67f12b8f9f575.tar.gz miasm-15b777061e96f55f2bfd2f7233d67f12b8f9f575.zip | |
Merge pull request #175 from serpilliere/add_simp_slice
Add simp slice
Diffstat (limited to 'miasm2/expression/simplifications_common.py')
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index ab3e2e82..b8c78692 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -416,12 +416,43 @@ def simp_slice(e_s, e): new_e = ExprSlice(e.arg.arg, e.start + e.arg.start, e.start + e.arg.start + (e.stop - e.start)) return new_e - # Slice(Compose(A), x) => Slice(A, y) elif isinstance(e.arg, ExprCompose): + # Slice(Compose(A), x) => Slice(A, y) for a in e.arg.args: if a[1] <= e.start and a[2] >= e.stop: new_e = a[0][e.start - a[1]:e.stop - a[1]] return new_e + # Slice(Compose(A, B, C), x) => Compose(A, B, C) with truncated A/B/C + out = [] + for arg, s_start, s_stop in e.arg.args: + # arg is before slice start + if e.start >= s_stop: + continue + # arg is after slice stop + elif e.stop <= s_start: + continue + # arg is fully included in slice + elif e.start <= s_start and s_stop <= e.stop: + out.append((arg, s_start, s_stop)) + continue + # arg is truncated at start + if e.start > s_start: + slice_start = e.start - s_start + a_start = 0 + else: + # arg is not truncated at start + slice_start = 0 + a_start = s_start - e.start + # a is truncated at stop + if e.stop < s_stop: + slice_stop = arg.size + e.stop - s_stop - slice_start + a_stop = e.stop - e.start + else: + slice_stop = arg.size + a_stop = s_stop - e.start + out.append((arg[slice_start:slice_stop], a_start, a_stop)) + return ExprCompose(out) + # ExprMem(x, size)[:A] => ExprMem(x, a) # XXXX todo hum, is it safe? elif (isinstance(e.arg, ExprMem) and |