def extract_intra_function_cfg(name):
for seg in Segments():
if SegName(seg) == ".text":
#functions = Functions(seg)
#for func_ea in functions:
func_ea = here()
cfg = nx.DiGraph()
tmp_bbs = []
#flag FC_PREDS is to get the backward info
for bb in FlowChart(get_func(func_ea), flags=FC_PREDS):
#check if we have already met this bb
flag = True
for tmp_bb in tmp_bbs:
if tmp_bb.startEA == bb.startEA:
bb = tmp_bb
flag = False
if flag:
tmp_bbs.append(bb)
cfg.add_node(bb.startEA)
preds = bb.preds()
succs = bb.succs()
if preds:
for preds_block in preds:
#check if we have already met this bb
flag = True
for tmp_bb in tmp_bbs:
if tmp_bb.startEA == preds_block.startEA:
preds_block = tmp_bb
flag = False
if flag:
tmp_bbs.append(preds_block)
cfg.add_edge(preds_block.startEA, bb.startEA)
if succs:
for succs_block in preds:
#check if we have already met this bb
flag = True
for tmp_bb in tmp_bbs:
if tmp_bb.startEA == succs_block.startEA:
succs_block = tmp_bb
flag = False
if flag:
tmp_bbs.append(succs_block)
cfg.add_edge(bb.startEA, succs_block.startEA)
nx.write_gml(cfg, "C:\\Users\\Xu Zhengzi\\Desktop\\tt\\second.gml")
return cfg
评论列表
文章目录