Last active
August 17, 2020 22:45
-
-
Save yannayl/dcb34db8326446ff18c77827c81ded80 to your computer and use it in GitHub Desktop.
A function which returns all the strings referenced from function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
updated to account for drefs from the function. tunrs out sark does not provide it... see tmr232/Sark#73