about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2017-02-15 16:12:59 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2017-03-13 14:13:13 +0100
commite1fc2de7e4d8662d5b97ceb7d7a9b9ba24acddaa (patch)
tree2dc3a42c36de4dab3ff964967e48224806f21612
parent9f04c551bddbc7fcab1921a2081a6ee9ea50a2f2 (diff)
downloadmiasm-e1fc2de7e4d8662d5b97ceb7d7a9b9ba24acddaa.tar.gz
miasm-e1fc2de7e4d8662d5b97ceb7d7a9b9ba24acddaa.zip
Asmbloc: rename asm_block_bad to AsmBlockBad
-rw-r--r--miasm2/core/asmbloc.py37
-rw-r--r--miasm2/jitter/codegen.py4
-rw-r--r--miasm2/jitter/jitcore.py2
-rw-r--r--miasm2/jitter/llvmconvert.py2
-rw-r--r--test/core/asmbloc.py6
5 files changed, 29 insertions, 22 deletions
diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py
index 23b16f1b..a0dd64f0 100644
--- a/miasm2/core/asmbloc.py
+++ b/miasm2/core/asmbloc.py
@@ -259,7 +259,7 @@ class asm_bloc(object):
         super(asm_bloc, self).__init__(label, alignment)
 
 
-class asm_block_bad(AsmBlock):
+class AsmBlockBad(AsmBlock):
 
     """Stand for a *bad* ASM block (malformed, unreachable,
     not disassembled, ...)"""
@@ -275,7 +275,7 @@ class asm_block_bad(AsmBlock):
         @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)
+        super(AsmBlockBad, self).__init__(label, alignment, *args, **kwargs)
         self._errno = errno
 
     def __str__(self):
@@ -284,13 +284,20 @@ class asm_block_bad(AsmBlock):
                           "\tBad block: %s" % error_txt])
 
     def addline(self, *args, **kwargs):
-        raise RuntimeError("An asm_block_bad cannot have line")
+        raise RuntimeError("An AsmBlockBad cannot have line")
 
     def addto(self, *args, **kwargs):
-        raise RuntimeError("An asm_block_bad cannot have bto")
+        raise RuntimeError("An AsmBlockBad cannot have bto")
 
     def split(self, *args, **kwargs):
-        raise RuntimeError("An asm_block_bad cannot be splitted")
+        raise RuntimeError("An AsmBlockBad cannot be splitted")
+
+
+class asm_block_bad(AsmBlockBad):
+
+    def __init__(self, label=None, alignment=1, errno=-1, *args, **kwargs):
+        warnings.warn('DEPRECATION WARNING: use "AsmBlockBad" instead of "asm_block_bad"')
+        super(asm_block_bad, self).__init__(label, alignment, *args, **kwargs)
 
 
 class asm_symbol_pool:
@@ -552,7 +559,7 @@ class AsmCFG(DiGraph):
                                             'colspan': 2,
                                             'bgcolor': 'grey'})
 
-        if isinstance(node, asm_block_bad):
+        if isinstance(node, AsmBlockBad):
             yield [self.DotCellDescription(
                 text=node.ERROR_TYPES.get(node._errno,
                                           node._errno),
@@ -567,7 +574,7 @@ class AsmCFG(DiGraph):
                 yield self.DotCellDescription(text=str(line), attr={})
 
     def node_attr(self, node):
-        if isinstance(node, asm_block_bad):
+        if isinstance(node, AsmBlockBad):
             return {'style': 'filled', 'fillcolor': 'red'}
         return {}
 
@@ -648,14 +655,14 @@ class AsmCFG(DiGraph):
                     self.del_edge(*edge)
 
     def get_bad_blocks(self):
-        """Iterator on asm_block_bad elements"""
+        """Iterator on AsmBlockBad elements"""
         # A bad asm block is always a leaf
         for block in self.leaves():
-            if isinstance(block, asm_block_bad):
+            if isinstance(block, AsmBlockBad):
                 yield block
 
     def get_bad_blocks_predecessors(self, strict=False):
-        """Iterator on block with an asm_block_bad destination
+        """Iterator on block with an AsmBlockBad destination
         @strict: (optional) if set, return block with only bad
         successors
         """
@@ -665,7 +672,7 @@ class AsmCFG(DiGraph):
             for predecessor in self.predecessors_iter(badblock):
                 if predecessor not in done:
                     if (strict and
-                        not all(isinstance(block, asm_block_bad)
+                        not all(isinstance(block, AsmBlockBad)
                                 for block in self.successors_iter(predecessor))):
                         continue
                     yield predecessor
@@ -816,7 +823,7 @@ class AsmCFG(DiGraph):
         return "<%s %s>" % (self.__class__.__name__, hex(id(self)))
 
 # Out of _merge_blocks to be computed only once
-_acceptable_block = lambda block: (not isinstance(block, asm_block_bad) and
+_acceptable_block = lambda block: (not isinstance(block, AsmBlockBad) and
                                    len(block.lines) > 0)
 _parent = MatchGraphJoker(restrict_in=False, filt=_acceptable_block)
 _son = MatchGraphJoker(restrict_out=False, filt=_acceptable_block)
@@ -1353,7 +1360,7 @@ class disasmEngine(object):
                 if not cur_block.lines:
                     self.job_done.add(offset)
                     # Block is empty -> bad block
-                    cur_block = asm_block_bad(label, errno=2)
+                    cur_block = AsmBlockBad(label, errno=2)
                 else:
                     # Block is not empty, stop the desassembly pass and add a
                     # constraint to the next block
@@ -1389,7 +1396,7 @@ class disasmEngine(object):
                 if not cur_block.lines:
                     self.job_done.add(offset)
                     # Block is empty -> bad block
-                    cur_block = asm_block_bad(label, errno=0)
+                    cur_block = AsmBlockBad(label, errno=0)
                 else:
                     # Block is not empty, stop the desassembly pass and add a
                     # constraint to the next block
@@ -1402,7 +1409,7 @@ class disasmEngine(object):
                 log_asmbloc.warning("reach nul instr at %X", int(off_i))
                 if not cur_block.lines:
                     # Block is empty -> bad block
-                    cur_block = asm_block_bad(label, errno=1)
+                    cur_block = AsmBlockBad(label, errno=1)
                 else:
                     # Block is not empty, stop the desassembly pass and add a
                     # constraint to the next block
diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py
index d5d8204f..e9907071 100644
--- a/miasm2/jitter/codegen.py
+++ b/miasm2/jitter/codegen.py
@@ -1,7 +1,7 @@
 import miasm2.expression.expression as m2_expr
 from miasm2.ir.ir import IRBlock
 from miasm2.ir.translators import Translator
-from miasm2.core.asmbloc import expr_is_label, asm_block_bad, asm_label
+from miasm2.core.asmbloc import expr_is_label, AsmBlockBad, asm_label
 
 # Miasm to C translator
 translator = Translator.to_language("C")
@@ -545,7 +545,7 @@ class CGen(object):
         @log_regs: log registers
         """
 
-        if isinstance(block, asm_block_bad):
+        if isinstance(block, AsmBlockBad):
             return self.gen_bad_block()
         irblocks_list = self.block2assignblks(block)
 
diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py
index 60fb3f2c..ecf55bd5 100644
--- a/miasm2/jitter/jitcore.py
+++ b/miasm2/jitter/jitcore.py
@@ -147,7 +147,7 @@ class JitCore(object):
         except IOError:
             # vm_exception_flag is set
             label = self.ir_arch.symbol_pool.getby_offset_create(addr)
-            cur_block = asmbloc.asm_block_bad(label)
+            cur_block = asmbloc.AsmBlockBad(label)
 
         # Logging
         if self.log_newbloc:
diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py
index 527dc733..6d8cdc18 100644
--- a/miasm2/jitter/llvmconvert.py
+++ b/miasm2/jitter/llvmconvert.py
@@ -1276,7 +1276,7 @@ class LLVMFunction():
         self.init_fc()
         self.local_vars_pointers["status"] = self.local_vars["status"]
 
-        if isinstance(asmblock, m2_asmbloc.asm_block_bad):
+        if isinstance(asmblock, m2_asmbloc.AsmBlockBad):
             self.gen_bad_block(asmblock)
             return
 
diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py
index e2f9631e..ef68b5db 100644
--- a/test/core/asmbloc.py
+++ b/test/core/asmbloc.py
@@ -3,7 +3,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, AsmBlock, \
-    asm_label, asm_block_bad, asm_constraint_to, asm_constraint_next, \
+    asm_label, AsmBlockBad, asm_constraint_to, asm_constraint_next, \
     bbl_simplifier
 from miasm2.core.graph import DiGraphSimplifier, MatchGraphJoker
 from miasm2.expression.expression import ExprId
@@ -108,7 +108,7 @@ assert blocks.label2block(my_block.label) == my_block
 assert len(list(blocks.get_bad_blocks())) == 0
 assert len(list(blocks.get_bad_blocks_predecessors())) == 0
 ### Add a bad block, not linked
-my_bad_block = asm_block_bad(asm_label("testlabel_bad"))
+my_bad_block = AsmBlockBad(asm_label("testlabel_bad"))
 blocks.add_node(my_bad_block)
 assert list(blocks.get_bad_blocks()) == [my_bad_block]
 assert len(list(blocks.get_bad_blocks_predecessors())) == 0
@@ -219,7 +219,7 @@ assert len(list(blocks.get_bad_blocks())) == 1
 ### Check "special" blocks
 entry_blocks = blocks.heads()
 bad_block = (block for block in entry_blocks
-             if isinstance(block, asm_block_bad)).next()
+             if isinstance(block, AsmBlockBad)).next()
 entry_blocks.remove(bad_block)
 alone_block = (block for block in entry_blocks
                if len(blocks.successors(block)) == 0).next()