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

Public Member Functions

def __init__
 
def __str__
 
def addline
 
def addto
 
def split
 
def get_range
 
def get_offsets
 
def add_cst
 
def get_flow_instr
 
def get_subcall_instr
 
def get_next
 

Public Attributes

 bto
 
 lines
 
 label
 
 alignment
 

Detailed Description

Definition at line 109 of file asmbloc.py.

Constructor & Destructor Documentation

def miasm2.core.asmbloc.asm_bloc.__init__ (   self,
  label = None,
  alignment = 1 
)

Definition at line 111 of file asmbloc.py.

112  def __init__(self, label=None, alignment=1):
113  self.bto = set()
114  self.lines = []
115  self.label = label
116  self.alignment = alignment

Member Function Documentation

def miasm2.core.asmbloc.asm_bloc.__str__ (   self)

Definition at line 117 of file asmbloc.py.

118  def __str__(self):
119  out = []
120  out.append(str(self.label))
121  for l in self.lines:
122  out.append(str(l))
123  if self.bto:
124  lbls = ["->"]
125  for l in self.bto:
126  if l is None:
127  lbls.append("Unknown? ")
128  else:
129  lbls.append(str(l) + " ")
130  lbls = '\t'.join(lbls)
131  out.append(lbls)
132  return '\n'.join(out)
def miasm2.core.asmbloc.asm_bloc.add_cst (   self,
  offset,
  c_t,
  symbol_pool 
)

Definition at line 181 of file asmbloc.py.

182  def add_cst(self, offset, c_t, symbol_pool):
183  if type(offset) in [int, long]:
184  l = symbol_pool.getby_offset_create(offset)
185  elif type(offset) is str:
186  l = symbol_pool.getby_name_create(offset)
187  elif isinstance(offset, asm_label):
188  l = offset
189  else:
190  raise ValueError('unknown offset type %r' % offset)
191  c = asm_constraint(l, c_t)
192  self.bto.add(c)
def miasm2.core.asmbloc.asm_bloc.addline (   self,
  l 
)

Definition at line 133 of file asmbloc.py.

134  def addline(self, l):
135  self.lines.append(l)
def miasm2.core.asmbloc.asm_bloc.addto (   self,
  c 
)

Definition at line 136 of file asmbloc.py.

137  def addto(self, c):
138  assert type(self.bto) is set
139  self.bto.add(c)
def miasm2.core.asmbloc.asm_bloc.get_flow_instr (   self)

Definition at line 193 of file asmbloc.py.

194  def get_flow_instr(self):
195  if not self.lines:
196  return None
197  for i in xrange(-1, -1 - self.lines[0].delayslot - 1, -1):
198  if not 0 <= i < len(self.lines):
199  return None
200  l = self.lines[i]
201  if l.splitflow() or l.breakflow():
202  raise NotImplementedError('not fully functional')

+ Here is the caller graph for this function:

def miasm2.core.asmbloc.asm_bloc.get_next (   self)

Definition at line 215 of file asmbloc.py.

216  def get_next(self):
217  for x in self.bto:
218  if x.c_t == asm_constraint.c_next:
219  return x.label
220  return None
221 
def miasm2.core.asmbloc.asm_bloc.get_offsets (   self)

Definition at line 178 of file asmbloc.py.

179  def get_offsets(self):
180  return [x.offset for x in self.lines]
def miasm2.core.asmbloc.asm_bloc.get_range (   self)

Definition at line 172 of file asmbloc.py.

173  def get_range(self):
174  if len(self.lines):
175  return self.lines[0].offset, self.lines[-1].offset
176  else:
177  return 0, 0
def miasm2.core.asmbloc.asm_bloc.get_subcall_instr (   self)

Definition at line 203 of file asmbloc.py.

204  def get_subcall_instr(self):
205  if not self.lines:
206  return None
207  delayslot = self.lines[0].delayslot
208  end_index = len(self.lines) - 1
209  ds_max_index = max(end_index - delayslot, 0)
210  for i in xrange(end_index, ds_max_index - 1, -1):
211  l = self.lines[i]
212  if l.is_subcall():
213  return l
214  return None
def miasm2.core.asmbloc.asm_bloc.split (   self,
  offset,
  l 
)

Definition at line 140 of file asmbloc.py.

141  def split(self, offset, l):
142  log_asmbloc.debug('split at %x', offset)
143  i = -1
144  offsets = [x.offset for x in self.lines]
145  if not l.offset in offsets:
146  log_asmbloc.warning(
147  'cannot split bloc at %X ' % offset +
148  'middle instruction? default middle')
149  offsets.sort()
150  return None
151  new_bloc = asm_bloc(l)
152  i = offsets.index(offset)
153 
154  self.lines, new_bloc.lines = self.lines[:i], self.lines[i:]
155  flow_mod_instr = self.get_flow_instr()
156  log_asmbloc.debug('flow mod %r', flow_mod_instr)
157  c = asm_constraint(l, asm_constraint.c_next)
158  # move dst if flowgraph modifier was in original bloc
159  # (usecase: split delayslot bloc)
160  if flow_mod_instr:
161  for xx in self.bto:
162  log_asmbloc.debug('lbl %s', xx)
163  c_next = set(
164  [x for x in self.bto if x.c_t == asm_constraint.c_next])
165  c_to = [x for x in self.bto if x.c_t != asm_constraint.c_next]
166  self.bto = set([c] + c_to)
167  new_bloc.bto = c_next
168  else:
169  new_bloc.bto = self.bto
170  self.bto = set([c])
171  return new_bloc

+ Here is the call graph for this function:

Member Data Documentation

miasm2.core.asmbloc.asm_bloc.alignment

Definition at line 115 of file asmbloc.py.

miasm2.core.asmbloc.asm_bloc.bto

Definition at line 112 of file asmbloc.py.

miasm2.core.asmbloc.asm_bloc.label

Definition at line 114 of file asmbloc.py.

miasm2.core.asmbloc.asm_bloc.lines

Definition at line 113 of file asmbloc.py.


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