def get_callers(ea,maxlen=None):
'''
Walk through the callers recursively starting at address ea.
maxlen is the maximum number of node the graph can contain.
Return a dictionary of list of caller addresses.
Return empty dictionary when number of node > maxlen.
'''
xtree = {}
visited = []
towalk = [ea]
while towalk:
curr = towalk.pop()
if curr not in xtree: # the start point also will record in the tree
xtree[curr] = []
if curr not in visited:
visited.append(curr)
for x in idautils.XrefsTo(curr):
caller = idaapi.get_func(x.frm)
if caller:
caller = caller.startEA
if caller not in visited:
towalk.append(caller)
# else: #not very clear, if this is not a function, still record it??
# caller = x.frm
# xtree[caller] = []
xtree[curr].append(caller)
if maxlen and len(tree) > maxlen:
return {}
return xtree
评论列表
文章目录