about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--example/disasm/callback.py4
-rw-r--r--miasm2/arch/aarch64/disasm.py2
-rw-r--r--miasm2/arch/arm/disasm.py4
-rw-r--r--miasm2/core/asmbloc.py51
-rw-r--r--miasm2/core/parse_asm.py12
-rw-r--r--test/core/asmbloc.py18
6 files changed, 49 insertions, 42 deletions
diff --git a/example/disasm/callback.py b/example/disasm/callback.py
index f1b2d3c8..20ffe962 100644
--- a/example/disasm/callback.py
+++ b/example/disasm/callback.py
@@ -1,5 +1,5 @@
 from miasm2.core.bin_stream import bin_stream_str
-from miasm2.core.asmbloc import AsmLabel, asm_constraint, expr_is_label
+from miasm2.core.asmbloc import AsmLabel, AsmConstraint, expr_is_label
 from miasm2.arch.x86.disasm import dis_x86_32, cb_x86_funcs
 
 
@@ -34,7 +34,7 @@ def cb_x86_callpop(cur_bloc, symbol_pool, *args, **kwargs):
 
     # Update next blocks to process in the disassembly engine
     cur_bloc.bto.clear()
-    cur_bloc.add_cst(dst.name.offset, asm_constraint.c_next, symbol_pool)
+    cur_bloc.add_cst(dst.name.offset, AsmConstraint.c_next, symbol_pool)
 
 
 # Prepare a tiny shellcode
diff --git a/miasm2/arch/aarch64/disasm.py b/miasm2/arch/aarch64/disasm.py
index d31ce3fd..a15ce306 100644
--- a/miasm2/arch/aarch64/disasm.py
+++ b/miasm2/arch/aarch64/disasm.py
@@ -1,4 +1,4 @@
-from miasm2.core.asmbloc import asm_constraint, disasmEngine
+from miasm2.core.asmbloc import disasmEngine
 from miasm2.arch.aarch64.arch import mn_aarch64
 
 cb_aarch64_funcs = []
diff --git a/miasm2/arch/arm/disasm.py b/miasm2/arch/arm/disasm.py
index 6209be5e..4d300f11 100644
--- a/miasm2/arch/arm/disasm.py
+++ b/miasm2/arch/arm/disasm.py
@@ -1,4 +1,4 @@
-from miasm2.core.asmbloc import asm_constraint, disasmEngine
+from miasm2.core.asmbloc import AsmConstraint, disasmEngine
 from miasm2.arch.arm.arch import mn_arm, mn_armt
 
 
@@ -24,7 +24,7 @@ def cb_arm_fix_call(mn, cur_bloc, symbol_pool, offsets_to_dis, *args, **kwargs):
         return
     if not l2.args[1] in values:
         return
-    cur_bloc.add_cst(l1.offset + 4, asm_constraint.c_next, symbol_pool)
+    cur_bloc.add_cst(l1.offset + 4, AsmConstraint.c_next, symbol_pool)
     offsets_to_dis.add(l1.offset + 4)
 
 cb_arm_funcs = [cb_arm_fix_call]
diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py
index 7db08e2f..28f1fe12 100644
--- a/miasm2/core/asmbloc.py
+++ b/miasm2/core/asmbloc.py
@@ -85,7 +85,7 @@ class asm_raw(AsmRaw):
         super(asm_label, self).__init__(raw)
 
 
-class asm_constraint(object):
+class AsmConstraint(object):
     c_to = "c_to"
     c_next = "c_next"
 
@@ -100,18 +100,25 @@ class asm_constraint(object):
         return "%s:%s" % (str(self.c_t), str(self.label))
 
 
-class asm_constraint_next(asm_constraint):
+class asm_constraint(AsmConstraint):
+
+    def __init__(self, label, c_t=c_to):
+        warnings.warn('DEPRECATION WARNING: use "AsmConstraint" instead of "asm_constraint"')
+        super(asm_constraint, self).__init__(label, c_t)
+
+
+class asm_constraint_next(AsmConstraint):
 
     def __init__(self, label):
         super(asm_constraint_next, self).__init__(
-            label, c_t=asm_constraint.c_next)
+            label, c_t=AsmConstraint.c_next)
 
 
-class asm_constraint_to(asm_constraint):
+class asm_constraint_to(AsmConstraint):
 
     def __init__(self, label):
         super(asm_constraint_to, self).__init__(
-            label, c_t=asm_constraint.c_to)
+            label, c_t=AsmConstraint.c_to)
 
 
 class AsmBlock(object):
@@ -162,15 +169,15 @@ class AsmBlock(object):
         self.lines, new_bloc.lines = self.lines[:i], self.lines[i:]
         flow_mod_instr = self.get_flow_instr()
         log_asmbloc.debug('flow mod %r', flow_mod_instr)
-        c = asm_constraint(l, asm_constraint.c_next)
+        c = AsmConstraint(l, AsmConstraint.c_next)
         # move dst if flowgraph modifier was in original bloc
         # (usecase: split delayslot bloc)
         if flow_mod_instr:
             for xx in self.bto:
                 log_asmbloc.debug('lbl %s', xx)
             c_next = set(
-                [x for x in self.bto if x.c_t == asm_constraint.c_next])
-            c_to = [x for x in self.bto if x.c_t != asm_constraint.c_next]
+                [x for x in self.bto if x.c_t == AsmConstraint.c_next])
+            c_to = [x for x in self.bto if x.c_t != AsmConstraint.c_next]
             self.bto = set([c] + c_to)
             new_bloc.bto = c_next
         else:
@@ -198,7 +205,7 @@ class AsmBlock(object):
             l = offset
         else:
             raise ValueError('unknown offset type %r' % offset)
-        c = asm_constraint(l, c_t)
+        c = AsmConstraint(l, c_t)
         self.bto.add(c)
 
     def get_flow_instr(self):
@@ -225,14 +232,14 @@ class AsmBlock(object):
 
     def get_next(self):
         for x in self.bto:
-            if x.c_t == asm_constraint.c_next:
+            if x.c_t == AsmConstraint.c_next:
                 return x.label
         return None
 
     @staticmethod
     def _filter_constraint(constraints):
         """Sort and filter @constraints for AsmBlock.bto
-        @constraints: non-empty set of asm_constraint instance
+        @constraints: non-empty set of AsmConstraint instance
 
         Always the same type -> one of the constraint
         c_next and c_to -> c_next
@@ -252,7 +259,7 @@ class AsmBlock(object):
 
         # At least 2 types -> types = {c_next, c_to}
         # c_to is included in c_next
-        return next(iter(cbytype[asm_constraint.c_next]))
+        return next(iter(cbytype[AsmConstraint.c_next]))
 
     def fix_constraints(self):
         """Fix next block constraints"""
@@ -500,7 +507,7 @@ class AsmCFG(DiGraph):
 
         # Add the edge to src.bto if needed
         if dst.label not in [cons.label for cons in src.bto]:
-            src.bto.add(asm_constraint(dst.label, constraint))
+            src.bto.add(AsmConstraint(dst.label, constraint))
 
         # Add edge
         self.edges2constraint[(src, dst)] = constraint
@@ -603,7 +610,7 @@ class AsmCFG(DiGraph):
         edge_color = "blue"
 
         if len(self.successors(src)) > 1:
-            if cst == asm_constraint.c_next:
+            if cst == AsmConstraint.c_next:
                 edge_color = "red"
             else:
                 edge_color = "limegreen"
@@ -711,7 +718,7 @@ class AsmCFG(DiGraph):
 
         next_edges = {edge: constraint
                       for edge, constraint in self.edges2constraint.iteritems()
-                      if constraint == asm_constraint.c_next}
+                      if constraint == AsmConstraint.c_next}
 
         for block in self._nodes:
             # No next constraint to self
@@ -1384,12 +1391,12 @@ class disasmEngine(object):
                 else:
                     # Block is not empty, stop the desassembly pass and add a
                     # constraint to the next block
-                    cur_block.add_cst(offset, asm_constraint.c_next,
+                    cur_block.add_cst(offset, AsmConstraint.c_next,
                                       self.symbol_pool)
                 break
 
             if lines_cpt > 0 and offset in self.split_dis:
-                cur_block.add_cst(offset, asm_constraint.c_next,
+                cur_block.add_cst(offset, AsmConstraint.c_next,
                                   self.symbol_pool)
                 offsets_to_dis.add(offset)
                 break
@@ -1400,7 +1407,7 @@ class disasmEngine(object):
                 break
 
             if offset in self.job_done:
-                cur_block.add_cst(offset, asm_constraint.c_next,
+                cur_block.add_cst(offset, AsmConstraint.c_next,
                                   self.symbol_pool)
                 break
 
@@ -1420,7 +1427,7 @@ class disasmEngine(object):
                 else:
                     # Block is not empty, stop the desassembly pass and add a
                     # constraint to the next block
-                    cur_block.add_cst(off_i, asm_constraint.c_next,
+                    cur_block.add_cst(off_i, AsmConstraint.c_next,
                                       self.symbol_pool)
                 break
 
@@ -1433,7 +1440,7 @@ class disasmEngine(object):
                 else:
                     # Block is not empty, stop the desassembly pass and add a
                     # constraint to the next block
-                    cur_block.add_cst(off_i, asm_constraint.c_next,
+                    cur_block.add_cst(off_i, AsmConstraint.c_next,
                                       self.symbol_pool)
                 break
 
@@ -1469,7 +1476,7 @@ class disasmEngine(object):
                 dst = dstn
                 if (not instr.is_subcall()) or self.follow_call:
                     cur_block.bto.update(
-                        [asm_constraint(x, asm_constraint.c_to) for x in dst])
+                        [AsmConstraint(x, AsmConstraint.c_to) for x in dst])
 
             # get in delayslot mode
             in_delayslot = True
@@ -1479,7 +1486,7 @@ class disasmEngine(object):
             offsets_to_dis.add(c.label.offset)
 
         if add_next_offset:
-            cur_block.add_cst(offset, asm_constraint.c_next, self.symbol_pool)
+            cur_block.add_cst(offset, AsmConstraint.c_next, self.symbol_pool)
             offsets_to_dis.add(offset)
 
         # Fix multiple constraints
diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py
index bceab949..514fee3b 100644
--- a/miasm2/core/parse_asm.py
+++ b/miasm2/core/parse_asm.py
@@ -116,8 +116,8 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None):
     if symbol_pool is None:
         symbol_pool = asmbloc.AsmSymbolPool()
 
-    C_NEXT = asmbloc.asm_constraint.c_next
-    C_TO = asmbloc.asm_constraint.c_to
+    C_NEXT = asmbloc.AsmConstraint.c_next
+    C_TO = asmbloc.AsmConstraint.c_to
 
     lines = []
     # parse each line
@@ -263,8 +263,8 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None):
             state = STATE_IN_BLOC
             if block_to_nlink:
                 block_to_nlink.addto(
-                    asmbloc.asm_constraint(cur_block.label,
-                                           C_NEXT))
+                    asmbloc.AsmConstraint(cur_block.label,
+                                          C_NEXT))
             block_to_nlink = None
             continue
 
@@ -284,7 +284,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None):
             elif isinstance(line, asmbloc.AsmLabel):
                 if block_to_nlink:
                     cur_block.addto(
-                        asmbloc.asm_constraint(line, C_NEXT))
+                        asmbloc.AsmConstraint(line, C_NEXT))
                     block_to_nlink = None
                 state = STATE_NO_BLOC
                 continue
@@ -303,7 +303,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None):
                             continue
                         if dst in mnemo.regs.all_regs_ids:
                             continue
-                        cur_block.addto(asmbloc.asm_constraint(dst.name, C_TO))
+                        cur_block.addto(asmbloc.AsmConstraint(dst.name, C_TO))
 
                 if not line.splitflow():
                     block_to_nlink = None
diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py
index 4b6947d6..f9cebb4e 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, AsmBlock, \
+from miasm2.core.asmbloc import AsmCFG, AsmConstraint, AsmBlock, \
     AsmLabel, AsmBlockBad, asm_constraint_to, asm_constraint_next, \
     bbl_simplifier
 from miasm2.core.graph import DiGraphSimplifier, MatchGraphJoker
@@ -60,10 +60,10 @@ assert last_block in blocks
 for pred in blocks.predecessors(last_block):
     blocks.del_edge(pred, last_block)
 ### Link first and last block
-blocks.add_edge(first_block, last_block, asm_constraint.c_next)
+blocks.add_edge(first_block, last_block, AsmConstraint.c_next)
 ### Only one link between two blocks
 try:
-    blocks.add_edge(first_block, last_block, asm_constraint.c_to)
+    blocks.add_edge(first_block, last_block, AsmConstraint.c_to)
     good = False
 except AssertionError:
     good = True
@@ -71,7 +71,7 @@ assert good
 
 ### Check final state
 assert len(first_block.bto) == 1
-assert list(first_block.bto)[0].c_t == asm_constraint.c_next
+assert list(first_block.bto)[0].c_t == AsmConstraint.c_next
 
 ## Simplify the obtained graph to keep only blocks which reach a block
 ## finnishing with RET
@@ -183,7 +183,7 @@ assert len(blocks.pendings[my_block_dst.label]) == 1
 pending = list(blocks.pendings[my_block_dst.label])[0]
 assert isinstance(pending, blocks.AsmCFGPending)
 assert pending.waiter == my_block_src
-assert pending.constraint == asm_constraint.c_to
+assert pending.constraint == AsmConstraint.c_to
 ### Sanity check must fail
 error_raised = False
 try:
@@ -236,9 +236,9 @@ assert map(str, entry_block.lines) == ['XOR        EAX, EAX',
 assert len(blocks.successors(entry_block)) == 2
 assert len(entry_block.bto) == 2
 nextb = blocks.label2block((cons.label for cons in entry_block.bto
-                            if cons.c_t == asm_constraint.c_next).next())
+                            if cons.c_t == AsmConstraint.c_next).next())
 tob = blocks.label2block((cons.label for cons in entry_block.bto
-                          if cons.c_t == asm_constraint.c_to).next())
+                          if cons.c_t == AsmConstraint.c_to).next())
 assert len(nextb.lines) == 4
 assert map(str, nextb.lines) == ['XOR        EDX, EDX',
                                  'XOR        ESI, ESI',
@@ -277,8 +277,8 @@ preds = blocks.predecessors(newb)
 assert len(preds) == 2
 assert entry_block in preds
 assert tob in preds
-assert blocks.edges2constraint[(entry_block, newb)] == asm_constraint.c_next
-assert blocks.edges2constraint[(tob, newb)] == asm_constraint.c_to
+assert blocks.edges2constraint[(entry_block, newb)] == AsmConstraint.c_next
+assert blocks.edges2constraint[(tob, newb)] == AsmConstraint.c_to
 
 
 # Check double block split