about summary refs log tree commit diff stats
path: root/miasm2/core/bin_stream.py
diff options
context:
space:
mode:
authorCamille Mougey <camille.mougey@cea.fr>2014-12-03 20:49:50 +0100
committerCamille Mougey <camille.mougey@cea.fr>2014-12-03 22:29:33 +0100
commit8ba608cba23060502e600445108cdb46cd678df2 (patch)
treea3c44f4828977a54ad162270ac3973a6d31c0415 /miasm2/core/bin_stream.py
parent7c07c648f1ea895b8868435f17232fbdbb8bd0f7 (diff)
downloadmiasm-8ba608cba23060502e600445108cdb46cd678df2.tar.gz
miasm-8ba608cba23060502e600445108cdb46cd678df2.zip
BinStream: Unify BinStreams location
Diffstat (limited to 'miasm2/core/bin_stream.py')
-rw-r--r--miasm2/core/bin_stream.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/miasm2/core/bin_stream.py b/miasm2/core/bin_stream.py
index 6dafecfd..48471b2f 100644
--- a/miasm2/core/bin_stream.py
+++ b/miasm2/core/bin_stream.py
@@ -171,3 +171,35 @@ class bin_stream_pe(bin_stream):
 
 class bin_stream_elf(bin_stream_pe):
     pass
+
+
+class bin_stream_vm(bin_stream):
+
+    def __init__(self, vm, offset=0L, base_offset=0L):
+        self.offset = offset
+        self.base_offset = base_offset
+        self.vm = vm
+
+    def getlen(self):
+        return 0xFFFFFFFFFFFFFFFF
+
+    def getbytes(self, start, l=1):
+        try:
+            s = self.vm.get_mem(start + self.base_offset, l)
+        except:
+            raise IOError('cannot get mem ad', hex(start))
+        return s
+
+    def readbs(self, l=1):
+        try:
+            s = self.vm.get_mem(self.offset + self.base_offset, l)
+        except:
+            raise IOError('cannot get mem ad', hex(self.offset))
+        self.offset += l
+        return s
+
+    def writebs(self, l=1):
+        raise ValueError('writebs unsupported')
+
+    def setoffset(self, val):
+        self.offset = val