From b4d46020aff6aac57b79cfcb64011bdc608854d9 Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 25 Jan 2016 10:47:16 +0100 Subject: Graph: two graphs are equals if they have the same nodes and edges --- test/core/graph.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/core/graph.py b/test/core/graph.py index 86175c91..269b721b 100644 --- a/test/core/graph.py +++ b/test/core/graph.py @@ -192,3 +192,13 @@ assert(sccs == {frozenset({6}), frozenset({7, 8}), frozenset({3}), frozenset({1, 2, 4, 5, 9})}) + +# Equality +graph = DiGraph() +graph.add_edge(1, 2) +graph.add_edge(2, 3) +graph2 = DiGraph() +graph2.add_edge(2, 3) +graph2.add_edge(1, 2) +assert graph == graph2 + -- cgit 1.4.1 From 418d2f1600dd1b7dbe81537f9b24c1d4e2d450cb Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 25 Jan 2016 10:50:59 +0100 Subject: Graph; introduce copy and merge --- miasm2/core/graph.py | 19 +++++++++++++++++++ test/core/graph.py | 15 +++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'test') diff --git a/miasm2/core/graph.py b/miasm2/core/graph.py index f38f71d6..ee5dc418 100644 --- a/miasm2/core/graph.py +++ b/miasm2/core/graph.py @@ -26,6 +26,25 @@ class DiGraph(object): def edges(self): return self._edges + def merge(self, graph): + """Merge the current graph with @graph + @graph: DiGraph instance + """ + for node in graph._nodes: + self.add_node(node) + for edge in graph._edges: + self.add_edge(*edge) + + def __add__(self, graph): + """Wrapper on `.merge`""" + self.merge(graph) + return self + + def copy(self): + """Copy the current graph instance""" + graph = self.__class__() + return graph + self + def __eq__(self, graph): if not isinstance(graph, self.__class__): return False diff --git a/test/core/graph.py b/test/core/graph.py index 269b721b..33a2fc6f 100644 --- a/test/core/graph.py +++ b/test/core/graph.py @@ -202,3 +202,18 @@ graph2.add_edge(2, 3) graph2.add_edge(1, 2) assert graph == graph2 +# Copy +graph4 = graph.copy() +assert graph == graph4 + +# Merge +graph3 = DiGraph() +graph3.add_edge(3, 1) +graph3.add_edge(1, 4) +graph4 += graph3 +for node in graph3.nodes(): + assert node in graph4.nodes() +for edge in graph3.edges(): + assert edge in graph4.edges() +assert graph4.nodes() == graph.nodes().union(graph3.nodes()) +assert sorted(graph4.edges()) == sorted(graph.edges() + graph3.edges()) -- cgit 1.4.1 From 1a49c715e3b60b758e051fd4f30c371d646acadb Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 25 Jan 2016 11:15:36 +0100 Subject: Introduce tests for miasm2.core.asmbloc --- test/core/asmbloc.py | 282 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_all.py | 3 + 2 files changed, 285 insertions(+) create mode 100644 test/core/asmbloc.py (limited to 'test') diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py new file mode 100644 index 00000000..5fe26308 --- /dev/null +++ b/test/core/asmbloc.py @@ -0,0 +1,282 @@ +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, \ + asm_label, asm_block_bad, asm_constraint_to, asm_constraint_next, \ + bbl_simplifier +from miasm2.core.graph import DiGraphSimplifier +from miasm2.expression.expression import ExprId + + +# Initial data: from 'samples/simple_test.bin' +data = "5589e583ec10837d08007509c745fc01100000eb73837d08017709c745fc02100000eb64837d08057709c745fc03100000eb55837d080774138b450801c083f80e7509c745fc04100000eb3c8b450801c083f80e7509c745fc05100000eb298b450883e03085c07409c745fc06100000eb16837d08427509c745fc07100000eb07c745fc081000008b45fcc9c3".decode("hex") +cont = Container.from_string(data) + +# Test Disasm engine +mdis = dis_x86_32(cont.bin_stream) +## Disassembly of one block +first_block = mdis.dis_bloc(0) +assert len(first_block.lines) == 5 +print first_block + +## Disassembly of several block, with cache +blocks = mdis.dis_multibloc(0) +assert len(blocks) == 0 + +## Test cache +mdis.job_done.clear() +blocks = mdis.dis_multibloc(0) +assert len(blocks) == 17 +## Equality between assembly lines is not yet implemented +assert len(blocks.heads()) == 1 +assert len(blocks.heads()[0].lines) == len(first_block.lines) + +# Test BasicBlocks +assert isinstance(blocks, BasicBlocks) +assert len(blocks.pendings) == 0 +assert len(blocks.nodes()) == 17 +assert len(blocks.edges2constraint) == len(blocks.edges()) +assert len(blocks.edges()) == 24 + +## Convert to dot +open("graph.dot", "w").write(blocks.dot()) + +## Modify the structure: link the first and the last block +leaves = blocks.leaves() +assert len(leaves) == 1 +last_block = leaves.pop() + +### Remove first_block for the rest of the graph +first_block = blocks.heads()[0] +assert len(first_block.bto) == 2 +for succ in blocks.successors(first_block): + blocks.del_edge(first_block, succ) + +### Modification must be reported from the graph +assert len(first_block.bto) == 0 +assert last_block in blocks + +### Remove predecessors of last block +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) +### Only one link between two blocks +try: + blocks.add_edge(first_block, last_block, asm_constraint.c_to) + good = False +except AssertionError: + good = True +assert good + +### Check final state +assert len(first_block.bto) == 1 +assert list(first_block.bto)[0].c_t == asm_constraint.c_next + +## Simplify the obtained graph to keep only blocks which reach a block +## finnishing with RET + +def remove_useless_blocks(d_g, graph): + """Remove leaves without a RET""" + for block in graph.leaves(): + if block.lines[-1].name != "RET": + graph.del_node(block) + +### Use a graph simplifier to recursively apply the simplification pass +dg = DiGraphSimplifier() +dg.enable_passes([remove_useless_blocks]) +blocks = dg(blocks) + +### Only two blocks should remain +assert len(blocks) == 2 +assert first_block in blocks +assert last_block in blocks + +## Graph the final output +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")) +blocks.add_node(my_block) +assert len(blocks) == 3 +assert blocks.label2block(first_block.label) == first_block +assert blocks.label2block(my_block.label) == my_block + +## Bad blocks +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")) +blocks.add_node(my_bad_block) +assert list(blocks.get_bad_blocks()) == [my_bad_block] +assert len(list(blocks.get_bad_blocks_predecessors())) == 0 +### Link the bad block and update edges +### Indeed, a sub-element has been modified (bto from a block from blocks) +my_block.bto.add(asm_constraint_to(my_bad_block.label)) +blocks.rebuild_edges() +assert list(blocks.get_bad_blocks_predecessors()) == [my_block] +### Test strict option +my_block.bto.add(asm_constraint_to(my_block.label)) +blocks.rebuild_edges() +assert list(blocks.get_bad_blocks_predecessors(strict=False)) == [my_block] +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.bto.add(asm_constraint_next(my_block_ni.label)) +blocks.add_node(my_block_ni) +error_raised = False +try: + blocks.sanity_check() +except RuntimeError: + error_raised = True +assert error_raised +### Back to a normal state +blocks.del_node(my_block_ni) +blocks.sanity_check() +### Multiple next on the same node +my_block_target = asm_bloc(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.bto.add(asm_constraint_next(my_block_target.label)) +blocks.add_node(my_block_src1) +### OK for now +blocks.sanity_check() +### Add a second next from src2 to target (already src1 -> target) +my_block_src2.bto.add(asm_constraint_next(my_block_target.label)) +blocks.add_node(my_block_src2) +error_raised = False +try: + blocks.sanity_check() +except RuntimeError: + error_raised = True +assert error_raised +blocks.del_node(my_block_src2) +blocks.sanity_check() + +## Guess block size +### Initial state +assert not hasattr(first_block, 'size') +assert not hasattr(first_block, 'max_size') +blocks.guess_blocks_size(mdis.arch) +assert first_block.size == 39 +assert blocks.label2block(my_block_src1.label).size == 0 +assert first_block.max_size == 39 +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.bto.add(asm_constraint_to(my_block_dst.label)) +blocks.add_node(my_block_src) +### Check resulting state +assert len(blocks) == 7 +assert len(blocks.pendings) == 1 +assert my_block_dst.label in blocks.pendings +assert len(blocks.pendings[my_block_dst.label]) == 1 +pending = blocks.pendings[my_block_dst.label][0] +assert isinstance(pending, blocks.BasicBlocksPending) +assert pending.waiter == my_block_src +assert pending.constraint == asm_constraint.c_to +### Sanity check must fail +error_raised = False +try: + blocks.sanity_check() +except RuntimeError: + error_raised = True +assert error_raised +### Pending must disappeared when adding expected block +blocks.add_node(my_block_dst) +assert len(blocks) == 8 +assert len(blocks.pendings) == 0 +blocks.sanity_check() + +# Test block_merge +data2 = "31c0eb0c31c9750c31d2eb0c31ffebf831dbebf031edebfc31f6ebf031e4c3".decode("hex") +cont2 = Container.from_string(data2) +mdis = dis_x86_32(cont2.bin_stream) +## Elements to merge +blocks = mdis.dis_multibloc(0) +## Block alone +blocks.add_node(mdis.dis_bloc(0x1c)) +## Bad block +blocks.add_node(mdis.dis_bloc(len(data2))) +## Dump the graph before merging +open("graph3.dot", "w").write(blocks.dot()) +## Apply merging +blocks = bbl_simplifier(blocks) +## Dump the graph after merging +open("graph4.dot", "w").write(blocks.dot()) +## Check the final state +assert len(blocks) == 5 +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() +entry_blocks.remove(bad_block) +alone_block = (block for block in entry_blocks + if len(blocks.successors(block)) == 0).next() +entry_blocks.remove(alone_block) +assert alone_block.lines[-1].name == "RET" +assert len(alone_block.lines) == 2 +### Check resulting function +entry_block = entry_blocks.pop() +assert len(entry_block.lines) == 4 +assert map(str, entry_block.lines) == ['XOR EAX, EAX', + 'XOR EBX, EBX', + 'XOR ECX, ECX', + 'JNZ loc_0000000000000014:0x00000014'] +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()) +tob = blocks.label2block((cons.label for cons in entry_block.bto + if cons.c_t == asm_constraint.c_to).next()) +assert len(nextb.lines) == 4 +assert map(str, nextb.lines) == ['XOR EDX, EDX', + 'XOR ESI, ESI', + 'XOR EDI, EDI', + 'JMP loc_0000000000000008:0x00000008'] +assert blocks.successors(nextb) == [nextb] +assert len(tob.lines) == 2 +assert map(str, tob.lines) == ['XOR EBP, EBP', + 'JMP loc_0000000000000014:0x00000014'] +assert blocks.successors(tob) == [tob] + +# Check split_block +## Without condition for a split, no change +blocks_bef = blocks.copy() +blocks.apply_splitting(mdis.symbol_pool) +assert blocks_bef == blocks +## Create conditions for a block split +inside_firstbbl = mdis.symbol_pool.getby_offset(4) +tob.bto.add(asm_constraint_to(inside_firstbbl)) +blocks.rebuild_edges() +assert len(blocks.pendings) == 1 +assert inside_firstbbl in blocks.pendings +blocks.apply_splitting(mdis.symbol_pool) +## Check result +assert len(blocks) == 6 +assert len(blocks.pendings) == 0 +assert len(entry_block.lines) == 2 +assert map(str, entry_block.lines) == ['XOR EAX, EAX', + 'XOR EBX, EBX'] +assert len(blocks.successors(entry_block)) == 1 +newb = blocks.successors(entry_block)[0] +assert len(newb.lines) == 2 +assert map(str, newb.lines) == ['XOR ECX, ECX', + 'JNZ loc_0000000000000014:0x00000014'] +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 diff --git a/test/test_all.py b/test/test_all.py index 6b94ad1f..9d7c1256 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -194,6 +194,9 @@ for script in ["interval.py", "test_types.py", ]: testset += RegressionTest([script], base_dir="core") +testset += RegressionTest(["asmbloc.py"], base_dir="core", + products=["graph.dot", "graph2.dot", + "graph3.dot", "graph4.dot"]) ## Expression for script in ["modint.py", "expression.py", -- cgit 1.4.1 From 2a3cca15ca50ae20a56f12fc92f9c8f26909092b Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 25 Jan 2016 13:22:50 +0100 Subject: BasicBlocks.pendings can be a set (creds @serpilliere) --- miasm2/core/asmbloc.py | 10 +++++----- test/core/asmbloc.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py index a929058b..7390536b 100644 --- a/miasm2/core/asmbloc.py +++ b/miasm2/core/asmbloc.py @@ -596,7 +596,7 @@ class BasicBlocks(DiGraph): super(BasicBlocks, self).__init__(*args, **kwargs) # Edges -> constraint self.edges2constraint = {} - # Expected asm_label -> list( (src, dst), constraint ) + # Expected asm_label -> set( (src, dst), constraint ) self._pendings = {} # Label2block built on the fly self._label2block = {} @@ -684,7 +684,7 @@ class BasicBlocks(DiGraph): to_add = self.BasicBlocksPending(waiter=block, constraint=constraint.c_t) self._pendings.setdefault(constraint.label, - list()).append(to_add) + set()).add(to_add) else: # Block is already in known nodes self.add_edge(block, dst, constraint.c_t) @@ -778,7 +778,7 @@ class BasicBlocks(DiGraph): # Helpers @property def pendings(self): - """Dictionnary of label -> list(BasicBlocksPending instance) indicating + """Dictionnary of label -> set(BasicBlocksPending 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, - list()).append(self.BasicBlocksPending(block, - constraint.c_t)) + set()).add(self.BasicBlocksPending(block, + constraint.c_t)) continue edge = (block, dst) edges.append(edge) diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py index 5fe26308..26d935b1 100644 --- a/test/core/asmbloc.py +++ b/test/core/asmbloc.py @@ -181,7 +181,7 @@ assert len(blocks) == 7 assert len(blocks.pendings) == 1 assert my_block_dst.label in blocks.pendings assert len(blocks.pendings[my_block_dst.label]) == 1 -pending = blocks.pendings[my_block_dst.label][0] +pending = list(blocks.pendings[my_block_dst.label])[0] assert isinstance(pending, blocks.BasicBlocksPending) assert pending.waiter == my_block_src assert pending.constraint == asm_constraint.c_to -- cgit 1.4.1 From d6222c4383891c6706ce70ec7750b42ee24e1cfc Mon Sep 17 00:00:00 2001 From: Ajax Date: Tue, 26 Jan 2016 17:15:22 +0100 Subject: Rename BasicBlocks -> AsmCFG, more comprehensible, include "graph" --- example/disasm/full.py | 4 ++-- miasm2/core/asmbloc.py | 38 +++++++++++++++++++------------------- miasm2/core/parse_asm.py | 2 +- test/core/asmbloc.py | 8 ++++---- 4 files changed, 26 insertions(+), 26 deletions(-) (limited to 'test') 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 -- cgit 1.4.1