about summary refs log tree commit diff stats
path: root/miasm2/core/bin_stream.py
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2014-08-21 09:03:46 +0200
committerserpilliere <devnull@localhost>2014-08-21 09:03:46 +0200
commit495970a6c5665ec6a9ed8773601c6c11cb8ec041 (patch)
treeb1da62daaae8adddd6a892c4b154147d01601483 /miasm2/core/bin_stream.py
parent03d65f485435899bb30e2f8c777f2ea3de765f6c (diff)
downloadmiasm-495970a6c5665ec6a9ed8773601c6c11cb8ec041.tar.gz
miasm-495970a6c5665ec6a9ed8773601c6c11cb8ec041.zip
bin_stream: fix bin_stream len test
Diffstat (limited to 'miasm2/core/bin_stream.py')
-rw-r--r--miasm2/core/bin_stream.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/miasm2/core/bin_stream.py b/miasm2/core/bin_stream.py
index a15ffa8e..6dafecfd 100644
--- a/miasm2/core/bin_stream.py
+++ b/miasm2/core/bin_stream.py
@@ -70,16 +70,15 @@ class bin_stream_str(bin_stream):
         self.l = len(bin)
 
     def getbytes(self, start, l=1):
-        if start + l > self.l:
+        if start + l + self.shift > self.l:
             raise IOError
 
         return super(bin_stream_str, self).getbytes(start + self.shift, l)
 
     def readbs(self, l=1):
-        if self.offset + l > self.l:
+        if self.offset + l + self.shift > self.l:
             raise IOError
         self.offset += l
-        print hex(self.offset + self.shift)
         return self.bin[self.offset - l + self.shift:self.offset + self.shift]
 
     def writebs(self, l=1):
@@ -93,10 +92,10 @@ class bin_stream_str(bin_stream):
         self.offset = val
 
     def __len__(self):
-        return len(self.bin) - self.offset + self.shift
+        return len(self.bin) - (self.offset + self.shift)
 
     def getlen(self):
-        return len(self.bin) - self.offset + self.shift
+        return len(self.bin) - (self.offset + self.shift)
 
 
 class bin_stream_file(bin_stream):