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

Public Member Functions

def __init__
 
def pinned
 
def place
 
def merge
 
def fix_blocks
 

Public Attributes

 symbol_pool
 
 blocks
 
 pinned_block_idx
 
 max_size
 
 offset_min
 
 offset_max
 

Private Member Functions

def _set_pinned_block_idx
 

Detailed Description

Manage blocks linked with an asm_constraint_next

Definition at line 693 of file asmbloc.py.

Constructor & Destructor Documentation

def miasm2.core.asmbloc.BlockChain.__init__ (   self,
  symbol_pool,
  blocks 
)

Definition at line 697 of file asmbloc.py.

698  def __init__(self, symbol_pool, blocks):
699  self.symbol_pool = symbol_pool
700  self.blocks = blocks
701  self.place()

Member Function Documentation

def miasm2.core.asmbloc.BlockChain._set_pinned_block_idx (   self)
private

Definition at line 707 of file asmbloc.py.

709  self.pinned_block_idx = None
710  for i, block in enumerate(self.blocks):
711  if is_int(block.label.offset):
712  if self.pinned_block_idx is not None:
713  raise ValueError("Multiples pinned block detected")
714  self.pinned_block_idx = i

+ Here is the caller graph for this function:

def miasm2.core.asmbloc.BlockChain.fix_blocks (   self,
  modified_labels 
)
Propagate a pinned to its blocks' neighbour
@modified_labels: store new pinned labels

Definition at line 748 of file asmbloc.py.

749  def fix_blocks(self, modified_labels):
750  """Propagate a pinned to its blocks' neighbour
751  @modified_labels: store new pinned labels"""
752 
753  if not self.pinned:
754  raise ValueError('Trying to fix unpinned block')
755 
756  # Propagate offset to blocks before pinned block
757  pinned_block = self.blocks[self.pinned_block_idx]
758  offset = pinned_block.label.offset
759  if offset % pinned_block.alignment != 0:
760  raise RuntimeError('Bad alignment')
761 
762  for block in self.blocks[:self.pinned_block_idx - 1:-1]:
763  new_offset = offset - block.size
764  new_offset = new_offset - new_offset % pinned_block.alignment
766  block.label,
767  new_offset,
768  modified_labels)
769 
770  # Propagate offset to blocks after pinned block
771  offset = pinned_block.label.offset + pinned_block.size
772 
773  last_block = pinned_block
774  for block in self.blocks[self.pinned_block_idx + 1:]:
775  offset += (- offset) % last_block.alignment
777  block.label,
778  offset,
779  modified_labels)
780  offset += block.size
781  last_block = block
782  return modified_labels
783 

+ Here is the call graph for this function:

def miasm2.core.asmbloc.BlockChain.merge (   self,
  chain 
)
Best effort merge two block chains
Return the list of resulting blockchains

Definition at line 741 of file asmbloc.py.

742  def merge(self, chain):
743  """Best effort merge two block chains
744  Return the list of resulting blockchains"""
745  self.blocks += chain.blocks
746  self.place()
747  return [self]

+ Here is the call graph for this function:

def miasm2.core.asmbloc.BlockChain.pinned (   self)
Return True iff at least one block is pinned

Definition at line 703 of file asmbloc.py.

704  def pinned(self):
705  """Return True iff at least one block is pinned"""
706  return self.pinned_block_idx is not None

+ Here is the caller graph for this function:

def miasm2.core.asmbloc.BlockChain.place (   self)
Compute BlockChain min_offset and max_offset using pinned block and
blocks' size

Definition at line 715 of file asmbloc.py.

716  def place(self):
717  """Compute BlockChain min_offset and max_offset using pinned block and
718  blocks' size
719  """
721  self.max_size = 0
722  for block in self.blocks:
723  self.max_size += block.max_size + block.alignment - 1
724 
725  # Check if chain has one block pinned
726  if not self.pinned:
727  return
728 
729  offset_base = self.blocks[self.pinned_block_idx].label.offset
730  assert(offset_base % self.blocks[self.pinned_block_idx].alignment == 0)
732  self.offset_min = offset_base
733  for block in self.blocks[:self.pinned_block_idx - 1:-1]:
734  self.offset_min -= block.max_size + \
735  (block.alignment - block.max_size) % block.alignment
737  self.offset_max = offset_base
738  for block in self.blocks[self.pinned_block_idx:]:
739  self.offset_max += block.max_size + \
740  (block.alignment - block.max_size) % block.alignment

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

miasm2.core.asmbloc.BlockChain.blocks

Definition at line 699 of file asmbloc.py.

miasm2.core.asmbloc.BlockChain.max_size

Definition at line 720 of file asmbloc.py.

miasm2.core.asmbloc.BlockChain.offset_max

Definition at line 736 of file asmbloc.py.

miasm2.core.asmbloc.BlockChain.offset_min

Definition at line 731 of file asmbloc.py.

miasm2.core.asmbloc.BlockChain.pinned_block_idx

Definition at line 708 of file asmbloc.py.

miasm2.core.asmbloc.BlockChain.symbol_pool

Definition at line 698 of file asmbloc.py.


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