Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
bin_stream_ida.py
Go to the documentation of this file.
1 from idc import Byte, SegEnd
2 from idautils import Segments
3 
4 from miasm2.core.bin_stream import bin_stream_str
5 
6 
8  """
9  bin_stream implementation for IDA
10 
11  Don't generate xrange using address computation:
12  It can raise error on overflow 7FFFFFFF with 32 bit python
13  """
14  def getbytes(self, start, l=1):
15  o = ""
16  for ad in xrange(l):
17  o += chr(Byte(ad + start - self.shift))
18  return o
19 
20  def readbs(self, l=1):
21  if self.offset + l > self.l:
22  raise IOError("not enough bytes")
23  o = self.getbytes(self.offset)
24  self.offset += l
25  return p
26 
27  def __str__(self):
28  raise NotImplementedError('Not fully functional')
29 
30  def setoffset(self, val):
31  self.offset = val
32 
33  def getlen(self):
34  # Lazy version
35  if hasattr(self, "_getlen"):
36  return self._getlen
37  max_addr = SegEnd(list(Segments())[-1] - (self.offset + self.shift))
38  self._getlen = max_addr
39  return max_addr