diff options
| author | Ajax <commial@gmail.com> | 2016-01-08 15:12:00 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2016-01-08 15:12:00 +0100 |
| commit | 9c99f574aa28cbb601f6894536cf7e1f9ddb7d7b (patch) | |
| tree | b958016799a51189661c7feaed444c8e97a6b2b4 /miasm2/core/bin_stream.py | |
| parent | ee96ee5e19f6c6712a871a19c07eb89c35e3dce5 (diff) | |
| download | miasm-9c99f574aa28cbb601f6894536cf7e1f9ddb7d7b.tar.gz miasm-9c99f574aa28cbb601f6894536cf7e1f9ddb7d7b.zip | |
BinStream: merge getbits calls to getbytes
Diffstat (limited to 'miasm2/core/bin_stream.py')
| -rw-r--r-- | miasm2/core/bin_stream.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/miasm2/core/bin_stream.py b/miasm2/core/bin_stream.py index f7b160f9..638cfd0e 100644 --- a/miasm2/core/bin_stream.py +++ b/miasm2/core/bin_stream.py @@ -15,6 +15,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # +import math class bin_stream(object): @@ -36,18 +37,19 @@ class bin_stream(object): @start: the offset in bits @n: number of bits to read """ - if not n: + if n == 0: return 0 o = 0 if n > self.getlen() * 8: raise IOError('not enough bits %r %r' % (n, len(self.bin) * 8)) + temp = self.getbytes(start / 8, int(math.ceil(n / 8.))) + if not temp: + raise IOError('cannot get bytes') + start = start % 8 while n: # print 'xxx', n, start i = start / 8 - c = self.getbytes(i) - if not c: - raise IOError('cannot get bytes') - c = ord(c) + c = ord(temp[i]) # print 'o', hex(c) r = 8 - start % 8 c &= (1 << r) - 1 |