Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Public Attributes | Properties | List of all members
miasm2.core.bin_stream.bin_stream_file Class Reference
+ Inheritance diagram for miasm2.core.bin_stream.bin_stream_file:
+ Collaboration diagram for miasm2.core.bin_stream.bin_stream_file:

Public Member Functions

def __init__
 
def getoffset
 
def setoffset
 
def readbs
 
def __str__
 
def getlen
 
def __repr__
 
def hexdump
 
def getbytes
 
def getbits
 

Public Attributes

 bin
 
 shift
 
 l
 

Properties

 offset = property(getoffset, setoffset)
 

Detailed Description

Definition at line 97 of file bin_stream.py.

Constructor & Destructor Documentation

def miasm2.core.bin_stream.bin_stream_file.__init__ (   self,
  binary,
  offset = 0L,
  shift = 0 
)

Definition at line 99 of file bin_stream.py.

99 
100  def __init__(self, binary, offset=0L, shift=0):
101  bin_stream.__init__(self)
102  self.bin = binary
103  self.bin.seek(0, 2)
104  self.shift = shift
105  self.l = self.bin.tell()
106  self.offset = offset

Member Function Documentation

def miasm2.core.bin_stream.bin_stream.__repr__ (   self)
inherited

Definition at line 25 of file bin_stream.py.

25 
26  def __repr__(self):
27  return "<%s !!>" % self.__class__.__name__
def miasm2.core.bin_stream.bin_stream_file.__str__ (   self)

Definition at line 119 of file bin_stream.py.

120  def __str__(self):
121  return str(self.bin)
def miasm2.core.bin_stream.bin_stream.getbits (   self,
  start,
  n 
)
inherited
Return the bits from the bit stream
@start: the offset in bits
@n: number of bits to read

Definition at line 34 of file bin_stream.py.

34 
35  def getbits(self, start, n):
36  """Return the bits from the bit stream
37  @start: the offset in bits
38  @n: number of bits to read
39  """
40  if not n:
41  return 0
42  o = 0
43  if n > self.getlen() * 8:
44  raise IOError('not enough bits %r %r' % (n, len(self.bin) * 8))
45  while n:
46  # print 'xxx', n, start
47  i = start / 8
48  c = self.getbytes(i)
49  if not c:
50  raise IOError('cannot get bytes')
51  c = ord(c)
52  # print 'o', hex(c)
53  r = 8 - start % 8
54  c &= (1 << r) - 1
55  # print 'm', hex(c)
56  l = min(r, n)
57  # print 'd', r-l
58  c >>= (r - l)
59  o <<= l
60  o |= c
61  n -= l
62  start += l
63  return o
64 

+ Here is the call graph for this function:

def miasm2.core.bin_stream.bin_stream.getbytes (   self,
  start,
  l = 1 
)
inherited

Definition at line 31 of file bin_stream.py.

31 
32  def getbytes(self, start, l=1):
33  return self.bin[start:start + l]

+ Here is the caller graph for this function:

def miasm2.core.bin_stream.bin_stream_file.getlen (   self)

Definition at line 122 of file bin_stream.py.

123  def getlen(self):
124  return self.l - (self.offset + self.shift)
125 
126 

+ Here is the caller graph for this function:

def miasm2.core.bin_stream.bin_stream_file.getoffset (   self)

Definition at line 107 of file bin_stream.py.

108  def getoffset(self):
109  return self.bin.tell() - self.shift
def miasm2.core.bin_stream.bin_stream.hexdump (   self,
  offset,
  l 
)
inherited

Definition at line 28 of file bin_stream.py.

28 
29  def hexdump(self, offset, l):
30  return
def miasm2.core.bin_stream.bin_stream_file.readbs (   self,
  l = 1 
)

Definition at line 114 of file bin_stream.py.

115  def readbs(self, l=1):
116  if self.offset + l + self.shift > self.l:
117  raise IOError("not enough bytes in file")
118  return self.bin.read(l)
def miasm2.core.bin_stream.bin_stream_file.setoffset (   self,
  val 
)

Definition at line 110 of file bin_stream.py.

111  def setoffset(self, val):
self.bin.seek(val + self.shift)

Member Data Documentation

miasm2.core.bin_stream.bin_stream_file.bin

Definition at line 101 of file bin_stream.py.

miasm2.core.bin_stream.bin_stream_file.l

Definition at line 104 of file bin_stream.py.

miasm2.core.bin_stream.bin_stream_file.shift

Definition at line 103 of file bin_stream.py.

Property Documentation

miasm2.core.bin_stream.bin_stream_file.offset = property(getoffset, setoffset)
static

Definition at line 112 of file bin_stream.py.


The documentation for this class was generated from the following file: