about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2017-02-15 16:01:40 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2017-03-13 14:13:13 +0100
commit9f04c551bddbc7fcab1921a2081a6ee9ea50a2f2 (patch)
tree1dee93cb415b8cc271637e332c09d223655929f2
parent287cb1bb182112ad8b476a9631f0099163041fdc (diff)
downloadmiasm-9f04c551bddbc7fcab1921a2081a6ee9ea50a2f2.tar.gz
miasm-9f04c551bddbc7fcab1921a2081a6ee9ea50a2f2.zip
Asmbloc: rename asm_bloc to AsmBlock
-rw-r--r--miasm2/core/asmbloc.py42
-rw-r--r--miasm2/core/parse_asm.py4
-rw-r--r--miasm2/ir/ir.py4
-rw-r--r--test/core/asmbloc.py16
4 files changed, 37 insertions, 29 deletions
diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py
index ef068a3f..23b16f1b 100644
--- a/miasm2/core/asmbloc.py
+++ b/miasm2/core/asmbloc.py
@@ -2,6 +2,7 @@
 
 import logging
 import inspect
+import warnings
 from collections import namedtuple
 
 import miasm2.expression.expression as m2_expr
@@ -100,7 +101,7 @@ class asm_constraint_to(asm_constraint):
             label, c_t=asm_constraint.c_to)
 
 
-class asm_bloc(object):
+class AsmBlock(object):
 
     def __init__(self, label, alignment=1):
         assert isinstance(label, asm_label)
@@ -142,7 +143,7 @@ class asm_bloc(object):
                 'middle instruction? default middle')
             offsets.sort()
             return None
-        new_bloc = asm_bloc(l)
+        new_bloc = AsmBlock(l)
         i = offsets.index(offset)
 
         self.lines, new_bloc.lines = self.lines[:i], self.lines[i:]
@@ -165,7 +166,7 @@ class asm_bloc(object):
         return new_bloc
 
     def get_range(self):
-        """Returns the offset hull of an asm_bloc"""
+        """Returns the offset hull of an AsmBlock"""
         if len(self.lines):
             return (self.lines[0].offset,
                     self.lines[-1].offset + self.lines[-1].l)
@@ -217,7 +218,7 @@ class asm_bloc(object):
 
     @staticmethod
     def _filter_constraint(constraints):
-        """Sort and filter @constraints for asm_bloc.bto
+        """Sort and filter @constraints for AsmBlock.bto
         @constraints: non-empty set of asm_constraint instance
 
         Always the same type -> one of the constraint
@@ -251,7 +252,14 @@ class asm_bloc(object):
                        for constraints in dests.itervalues())
 
 
-class asm_block_bad(asm_bloc):
+class asm_bloc(object):
+
+    def __init__(self, label, alignment=1):
+        warnings.warn('DEPRECATION WARNING: use "AsmBlock" instead of "asm_bloc"')
+        super(asm_bloc, self).__init__(label, alignment)
+
+
+class asm_block_bad(AsmBlock):
 
     """Stand for a *bad* ASM block (malformed, unreachable,
     not disassembled, ...)"""
@@ -263,8 +271,8 @@ class asm_block_bad(asm_bloc):
                    }
 
     def __init__(self, label=None, alignment=1, errno=-1, *args, **kwargs):
-        """Instanciate an asm_block_bad.
-        @label, @alignement: same as asm_bloc.__init__
+        """Instanciate an AsmBlock_bad.
+        @label, @alignement: same as AsmBlock.__init__
         @errno: (optional) specify a error type associated with the block
         """
         super(asm_block_bad, self).__init__(label, alignment, *args, **kwargs)
@@ -412,8 +420,8 @@ class asm_symbol_pool:
 class AsmCFG(DiGraph):
 
     """Directed graph standing for a ASM Control Flow Graph with:
-     - nodes: asm_bloc
-     - edges: constraints between blocks, synchronized with asm_bloc's "bto"
+     - nodes: AsmBlock
+     - edges: constraints between blocks, synchronized with AsmBlock's "bto"
 
     Specialized the .dot export and force the relation between block to be uniq,
     and associated with a constraint.
@@ -446,7 +454,7 @@ class AsmCFG(DiGraph):
         raise DeprecationWarning("Order of AsmCFG elements is not reliable")
 
     def __iter__(self):
-        """Iterator on asm_bloc composing the current graph"""
+        """Iterator on AsmBlock composing the current graph"""
         return iter(self._nodes)
 
     def __len__(self):
@@ -456,8 +464,8 @@ class AsmCFG(DiGraph):
     # Manage graph with associated constraints
     def add_edge(self, src, dst, constraint):
         """Add an edge to the graph
-        @src: asm_bloc instance, source
-        @dst: asm_block instance, destination
+        @src: AsmBlock instance, source
+        @dst: AsmBlock instance, destination
         @constraint: constraint associated to this edge
         """
         # Sanity check
@@ -491,7 +499,7 @@ class AsmCFG(DiGraph):
 
     def add_node(self, block):
         """Add the block @block to the current instance, if it is not already in
-        @block: asm_bloc instance
+        @block: AsmBlock instance
 
         Edges will be created for @block.bto, if destinations are already in
         this instance. If not, they will be resolved when adding these
@@ -816,7 +824,7 @@ _expgraph = _parent >> _son
 
 
 def _merge_blocks(dg, graph):
-    """Graph simplification merging asm_bloc with one and only one son with this
+    """Graph simplification merging AsmBlock with one and only one son with this
     son if this son has one and only one parent"""
 
     # Blocks to ignore, because they have been removed from the graph
@@ -1326,7 +1334,7 @@ class disasmEngine(object):
 
     def _dis_bloc(self, offset):
         """Disassemble the block at offset @offset
-        Return the created asm_bloc and future offsets to disassemble
+        Return the created AsmBlock and future offsets to disassemble
         """
 
         lines_cpt = 0
@@ -1335,7 +1343,7 @@ class disasmEngine(object):
         offsets_to_dis = set()
         add_next_offset = False
         label = self.symbol_pool.getby_offset_create(offset)
-        cur_block = asm_bloc(label)
+        cur_block = AsmBlock(label)
         log_asmbloc.debug("dis at %X", int(offset))
         while not in_delayslot or delayslot_count > 0:
             if in_delayslot:
@@ -1459,7 +1467,7 @@ class disasmEngine(object):
 
     def dis_bloc(self, offset):
         """Disassemble the block at offset @offset and return the created
-        asm_bloc
+        AsmBlock
         @offset: targeted offset to disassemble
         """
         current_block, _ = self._dis_bloc(offset)
diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py
index 11fa4040..ce982b48 100644
--- a/miasm2/core/parse_asm.py
+++ b/miasm2/core/parse_asm.py
@@ -254,9 +254,9 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None):
                 # First line must be a label. If it's not the case, generate
                 # it.
                 label = guess_next_new_label(symbol_pool)
-                cur_block = asmbloc.asm_bloc(label, alignment=mnemo.alignment)
+                cur_block = asmbloc.AsmBlock(label, alignment=mnemo.alignment)
             else:
-                cur_block = asmbloc.asm_bloc(line, alignment=mnemo.alignment)
+                cur_block = asmbloc.AsmBlock(line, alignment=mnemo.alignment)
                 i += 1
             # Generate the current bloc
             blocks.add_node(cur_block)
diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py
index 7f1b00d6..c2e63132 100644
--- a/miasm2/ir/ir.py
+++ b/miasm2/ir/ir.py
@@ -25,7 +25,7 @@ import miasm2.expression.expression as m2_expr
 from miasm2.expression.expression_helper import get_missing_interval
 from miasm2.expression.simplifications import expr_simp
 from miasm2.core.asmbloc import asm_symbol_pool, expr_is_label, asm_label, \
-    asm_bloc
+    AsmBlock
 from miasm2.core.graph import DiGraph
 
 
@@ -377,7 +377,7 @@ class IntermediateRepresentation(object):
         return self.blocks.get(label, None)
 
     def add_instr(self, l, ad=0, gen_pc_updt=False):
-        b = asm_bloc(self.gen_label())
+        b = AsmBlock(self.gen_label())
         b.lines = [l]
         self.add_bloc(b, gen_pc_updt)
 
diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py
index 5fbdca3e..e2f9631e 100644
--- a/test/core/asmbloc.py
+++ b/test/core/asmbloc.py
@@ -2,7 +2,7 @@ from pdb import pm
 
 from miasm2.arch.x86.disasm import dis_x86_32
 from miasm2.analysis.binary import Container
-from miasm2.core.asmbloc import AsmCFG, asm_constraint, asm_bloc, \
+from miasm2.core.asmbloc import AsmCFG, asm_constraint, AsmBlock, \
     asm_label, asm_block_bad, asm_constraint_to, asm_constraint_next, \
     bbl_simplifier
 from miasm2.core.graph import DiGraphSimplifier, MatchGraphJoker
@@ -98,7 +98,7 @@ open("graph2.dot", "w").write(blocks.dot())
 # Test helper methods
 ## Label2block should always be updated
 assert blocks.label2block(first_block.label) == first_block
-my_block = asm_bloc(asm_label("testlabel"))
+my_block = AsmBlock(asm_label("testlabel"))
 blocks.add_node(my_block)
 assert len(blocks) == 3
 assert blocks.label2block(first_block.label) == first_block
@@ -126,7 +126,7 @@ assert len(list(blocks.get_bad_blocks_predecessors(strict=True))) == 0
 ## Sanity check
 blocks.sanity_check()
 ### Next on itself
-my_block_ni = asm_bloc(asm_label("testlabel_nextitself"))
+my_block_ni = AsmBlock(asm_label("testlabel_nextitself"))
 my_block_ni.bto.add(asm_constraint_next(my_block_ni.label))
 blocks.add_node(my_block_ni)
 error_raised = False
@@ -139,10 +139,10 @@ assert error_raised
 blocks.del_node(my_block_ni)
 blocks.sanity_check()
 ### Multiple next on the same node
-my_block_target = asm_bloc(asm_label("testlabel_target"))
+my_block_target = AsmBlock(asm_label("testlabel_target"))
 blocks.add_node(my_block_target)
-my_block_src1 = asm_bloc(asm_label("testlabel_src1"))
-my_block_src2 = asm_bloc(asm_label("testlabel_src2"))
+my_block_src1 = AsmBlock(asm_label("testlabel_src1"))
+my_block_src2 = AsmBlock(asm_label("testlabel_src2"))
 my_block_src1.bto.add(asm_constraint_next(my_block_target.label))
 blocks.add_node(my_block_src1)
 ### OK for now
@@ -171,8 +171,8 @@ assert blocks.label2block(my_block_src1.label).max_size == 0
 
 ## Check pendings
 ### Create a pending element
-my_block_src = asm_bloc(asm_label("testlabel_pend_src"))
-my_block_dst = asm_bloc(asm_label("testlabel_pend_dst"))
+my_block_src = AsmBlock(asm_label("testlabel_pend_src"))
+my_block_dst = AsmBlock(asm_label("testlabel_pend_dst"))
 my_block_src.bto.add(asm_constraint_to(my_block_dst.label))
 blocks.add_node(my_block_src)
 ### Check resulting state