Beispiel #1
0
def pass_remove_junkcode(dgs, graph):

    for block in expgraph.match(graph):

        #connect each predesseccor of MatchGraph to its equivalent successor in AsmGraph
        for pred in graph.predecessors(block[parent]):
            for succ in graph.successors(block[last]):
                #graph.add_edge(pred,succ,graph.edges2constraint[(block[last],succ)])
                graph.add_edge(pred, succ,
                               graph.edges2constraint[(pred, block[parent])])

        #removing junk codes between block[parent] -> block[last]
        for joker, node in block.iteritems():
            graph.del_node(node)


dgs = DiGraphSimplifier()
dgs.enable_passes([pass_remove_junkcode])
#new_graph = dgs.apply_simp(blocks)
new_graph = dgs(blocks)

flag = []

for block in new_graph.walk_depth_first_forward(new_graph.heads()[0]):
    if len(block.lines) == 3 and "XOR" in block.lines[1].name:
        key = block.lines[1].args[1]
        flag.append(key)

print 'flag is: ' + ''.join(chr(i) for i in flag)

#open('JunkRemoved_middle_restrictin_dump2.dot','w').write(new_graph.dot())
Beispiel #2
0
assert len(first_block.bto) == 1
assert list(first_block.bto)[0].c_t == AsmConstraint.c_next

## Simplify the obtained graph to keep only blocks which reach a block
## finishing 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 = AsmBlock(AsmLabel("testlabel"))
Beispiel #3
0
### Check final state
assert len(first_block.bto) == 1
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

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 = AsmBlock(AsmLabel("testlabel"))