about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2012-07-27 16:11:00 +0200
committerserpilliere <devnull@localhost>2012-07-27 16:11:00 +0200
commita4bcc8527720f476c30981ec94603a7012281d7a (patch)
tree1854c8f8e0729c02ba6427ec6f359cd7cabd5165
parentd2d28c982402e57bfeaf9c4b9683b61d374b9031 (diff)
downloadmiasm-a4bcc8527720f476c30981ec94603a7012281d7a.tar.gz
miasm-a4bcc8527720f476c30981ec94603a7012281d7a.zip
bin_stream: add getitem
-rw-r--r--miasm/core/bin_stream.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/miasm/core/bin_stream.py b/miasm/core/bin_stream.py
index 5db15bcc..9236e037 100644
--- a/miasm/core/bin_stream.py
+++ b/miasm/core/bin_stream.py
@@ -39,6 +39,17 @@ class bin_stream(object):
     def hexdump(self, offset, l):
         return
 
+    def __getitem__(self, item):
+        if not type(item) is slice: # integer
+            self.offset = item
+            return self.readbs(1)
+        start = item.start
+        stop  = item.stop
+        step  = item.step
+        self.offset = start
+        s = self.readbs(stop-start)
+        return s[::step]
+
 class bin_stream_str(bin_stream):
     def __init__(self, bin ="", offset = 0L):
         if offset>len(bin):