diff options
| author | Ajax <commial@gmail.com> | 2016-01-26 17:15:22 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2016-01-26 17:15:22 +0100 |
| commit | d6222c4383891c6706ce70ec7750b42ee24e1cfc (patch) | |
| tree | 1ca51aab9e0908e3f11b0cccc7ad7f50be349f67 | |
| parent | 2a3cca15ca50ae20a56f12fc92f9c8f26909092b (diff) | |
| download | miasm-d6222c4383891c6706ce70ec7750b42ee24e1cfc.tar.gz miasm-d6222c4383891c6706ce70ec7750b42ee24e1cfc.zip | |
Rename BasicBlocks -> AsmCFG, more comprehensible, include "graph"
| -rw-r--r-- | example/disasm/full.py | 4 | ||||
| -rw-r--r-- | miasm2/core/asmbloc.py | 38 | ||||
| -rw-r--r-- | miasm2/core/parse_asm.py | 2 | ||||
| -rw-r--r-- | test/core/asmbloc.py | 8 |
4 files changed, 26 insertions, 26 deletions
diff --git a/example/disasm/full.py b/example/disasm/full.py index 25e3a018..0b0069c6 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -4,7 +4,7 @@ from argparse import ArgumentParser from pdb import pm from miasm2.analysis.binary import Container -from miasm2.core.asmbloc import log_asmbloc, asm_label, BasicBlocks +from miasm2.core.asmbloc import log_asmbloc, asm_label, AsmCFG from miasm2.expression.expression import ExprId from miasm2.core.interval import interval from miasm2.analysis.machine import Machine @@ -142,7 +142,7 @@ while not finish and todo: # Generate dotty graph -all_blocs = BasicBlocks() +all_blocs = AsmCFG() for blocs in all_funcs_blocs.values(): all_blocs += blocs diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py index 7390536b..9553d14d 100644 --- a/miasm2/core/asmbloc.py +++ b/miasm2/core/asmbloc.py @@ -532,7 +532,7 @@ def dis_bloc_all(mnemo, pool_bin, offset, job_done, symbol_pool, dont_dis=[], attrib={}): log_asmbloc.info("dis bloc all") if blocs is None: - blocs = BasicBlocks() + blocs = AsmCFG() todo = [offset] bloc_cpt = 0 @@ -576,7 +576,7 @@ def dis_bloc_all(mnemo, pool_bin, offset, job_done, symbol_pool, dont_dis=[], return blocs -class BasicBlocks(DiGraph): +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" @@ -584,16 +584,16 @@ class BasicBlocks(DiGraph): Specialized the .dot export and force the relation between block to be uniq, and associated with a constraint. - Offer helpers on BasicBlocks management, such as research by label, sanity + Offer helpers on AsmCFG management, such as research by label, sanity checking and mnemonic size guessing. """ # Internal structure for pending management - BasicBlocksPending = namedtuple("BasicBlocksPending", - ["waiter", "constraint"]) + AsmCFGPending = namedtuple("AsmCFGPending", + ["waiter", "constraint"]) def __init__(self, *args, **kwargs): - super(BasicBlocks, self).__init__(*args, **kwargs) + super(AsmCFG, self).__init__(*args, **kwargs) # Edges -> constraint self.edges2constraint = {} # Expected asm_label -> set( (src, dst), constraint ) @@ -603,20 +603,20 @@ class BasicBlocks(DiGraph): # Compatibility with old list API def append(self, *args, **kwargs): - raise DeprecationWarning("BasicBlocks is a graph, use add_node") + raise DeprecationWarning("AsmCFG is a graph, use add_node") def remove(self, *args, **kwargs): - raise DeprecationWarning("BasicBlocks is a graph, use del_node") + raise DeprecationWarning("AsmCFG is a graph, use del_node") def __getitem__(self, *args, **kwargs): - raise DeprecationWarning("Order of BasicBlocks elements is not reliable") + raise DeprecationWarning("Order of AsmCFG elements is not reliable") def __iter__(self): """Iterator on asm_bloc composing the current graph""" return iter(self._nodes) def __len__(self): - """Return the number of blocks in BasicBlocks""" + """Return the number of blocks in AsmCFG""" return len(self._nodes) # Manage graph with associated constraints @@ -635,7 +635,7 @@ class BasicBlocks(DiGraph): # Add edge self.edges2constraint[(src, dst)] = constraint - super(BasicBlocks, self).add_edge(src, dst) + super(AsmCFG, self).add_edge(src, dst) def add_uniq_edge(self, src, dst, constraint): """Add an edge from @src to @dst if it doesn't already exist""" @@ -653,7 +653,7 @@ class BasicBlocks(DiGraph): # Del edge del self.edges2constraint[(src, dst)] - super(BasicBlocks, self).del_edge(src, dst) + super(AsmCFG, self).del_edge(src, dst) def add_node(self, block): """Add the block @block to the current instance, if it is not already in @@ -664,7 +664,7 @@ class BasicBlocks(DiGraph): aforementionned destinations. `self.pendings` indicates which blocks are not yet resolved. """ - status = super(BasicBlocks, self).add_node(block) + status = super(AsmCFG, self).add_node(block) if not status: return status @@ -681,8 +681,8 @@ class BasicBlocks(DiGraph): None) if dst is None: # Block is yet unknown, add it to pendings - to_add = self.BasicBlocksPending(waiter=block, - constraint=constraint.c_t) + to_add = self.AsmCFGPending(waiter=block, + constraint=constraint.c_t) self._pendings.setdefault(constraint.label, set()).add(to_add) else: @@ -692,7 +692,7 @@ class BasicBlocks(DiGraph): return status def del_node(self, block): - super(BasicBlocks, self).del_node(block) + super(AsmCFG, self).del_node(block) del self._label2block[block.label] def merge(self, graph): @@ -778,7 +778,7 @@ class BasicBlocks(DiGraph): # Helpers @property def pendings(self): - """Dictionnary of label -> set(BasicBlocksPending instance) indicating + """Dictionnary of label -> set(AsmCFGPending instance) indicating which label are missing in the current instance. A label is missing if a block which is already in nodes has constraints with him (thanks to its .bto) and the corresponding block is not yet in @@ -814,8 +814,8 @@ class BasicBlocks(DiGraph): if dst is None: # Missing destination, add to pendings self._pendings.setdefault(constraint.label, - set()).add(self.BasicBlocksPending(block, - constraint.c_t)) + set()).add(self.AsmCFGPending(block, + constraint.c_t)) continue edge = (block, dst) edges.append(edge) diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py index 304d0673..aefa6df9 100644 --- a/miasm2/core/parse_asm.py +++ b/miasm2/core/parse_asm.py @@ -232,7 +232,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None): cur_block = None state = STATE_NO_BLOC i = 0 - blocks = asmbloc.BasicBlocks() + blocks = asmbloc.AsmCFG() block_to_nlink = None block_may_link = False delayslot = 0 diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py index 26d935b1..45f7f27f 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 BasicBlocks, asm_constraint, asm_bloc, \ +from miasm2.core.asmbloc import AsmCFG, asm_constraint, asm_bloc, \ asm_label, asm_block_bad, asm_constraint_to, asm_constraint_next, \ bbl_simplifier from miasm2.core.graph import DiGraphSimplifier @@ -32,8 +32,8 @@ assert len(blocks) == 17 assert len(blocks.heads()) == 1 assert len(blocks.heads()[0].lines) == len(first_block.lines) -# Test BasicBlocks -assert isinstance(blocks, BasicBlocks) +# Test AsmCFG +assert isinstance(blocks, AsmCFG) assert len(blocks.pendings) == 0 assert len(blocks.nodes()) == 17 assert len(blocks.edges2constraint) == len(blocks.edges()) @@ -182,7 +182,7 @@ assert len(blocks.pendings) == 1 assert my_block_dst.label in blocks.pendings assert len(blocks.pendings[my_block_dst.label]) == 1 pending = list(blocks.pendings[my_block_dst.label])[0] -assert isinstance(pending, blocks.BasicBlocksPending) +assert isinstance(pending, blocks.AsmCFGPending) assert pending.waiter == my_block_src assert pending.constraint == asm_constraint.c_to ### Sanity check must fail |