Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iddoeldor/67de892af4f689ac8050eb885b13fdc6 to your computer and use it in GitHub Desktop.
Save iddoeldor/67de892af4f689ac8050eb885b13fdc6 to your computer and use it in GitHub Desktop.
A function which returns all the strings referenced from function
def strs(f=None, visited=None, level=0, maxlevel=-1):
if maxlevel >= 0 and level > maxlevel:
return [], set()
if not f:
f = sark.Function()
if not visited:
visited = set()
root = True
else:
root = False
print 'f: ' + f.name
visited.add(f)
ret = []
for ln in f.lines:
for x in ln.xrefs_from:
if x.iscode:
to = sark.Function(x.to)
if to in visited:
continue
ret_str, ret_set = strs(to, visited, level+1, maxlevel)
ret.extend(ret_str)
visited = visited.union(ret_set)
else:
l = sark.Line(x.to)
print 'x: ' + repr(l)
if l.type != 'string':
continue
ret.append(l.bytes)
if root:
return sorted(list(set(ret)))
return ret, visited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment