about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/arch/mips32/arch.py2
-rw-r--r--miasm2/core/bin_stream.py9
2 files changed, 4 insertions, 7 deletions
diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py
index 146dfc67..9d452e68 100644
--- a/miasm2/arch/mips32/arch.py
+++ b/miasm2/arch/mips32/arch.py
@@ -210,8 +210,6 @@ class mn_mips32b(cls_mn):
         if not n:
             return 0
         o = 0
-        if n > bs.getlen() * 8:
-            raise ValueError('not enought bits %r %r' % (n, len(bs.bin) * 8))
         while n:
             offset = start / 8
             n_offset = cls.endian_offset(offset)
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):