Skip to content

Instantly share code, notes, and snippets.

@yannayl
Last active August 17, 2020 22:45
Show Gist options
  • Save yannayl/dcb34db8326446ff18c77827c81ded80 to your computer and use it in GitHub Desktop.
Save yannayl/dcb34db8326446ff18c77827c81ded80 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
@yannayl
Copy link
Author

yannayl commented Jul 31, 2018

updated to account for drefs from the function. tunrs out sark does not provide it... see tmr232/Sark#73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment