def graph_function_llil_instructions (function) :
'''
Returns a graph where each LLIL instruction is a vertex in the graph
'''
graph = Graph(0)
# Get the low_level_il basic blocks
basic_blocks = function.low_level_il.basic_blocks
# Add all the low_level_il instructions as their own vertices
for basic_block in basic_blocks :
for ins in basic_block :
graph.add_vertex(ins.instr_index, ins)
# Go back through and add edges
for basic_block in basic_blocks :
# Add edges between instructions in block
previous_ins = None
for ins in basic_block :
if previous_ins == None :
previous_ins = ins.instr_index
continue
graph.add_edge_by_indices(previous_ins, ins.instr_index)
previous_ins = ins.instr_index
# Add edges between basic blocks
for outgoing_edge in basic_block.outgoing_edges :
target = outgoing_edge.target.start
graph.add_edge_by_indices(previous_ins, target)
return graph
评论列表
文章目录