Forked from yannayl/ida_sarlk_function_strings_ref.py
Created
August 17, 2020 22:45
-
-
Save iddoeldor/67de892af4f689ac8050eb885b13fdc6 to your computer and use it in GitHub Desktop.
A function which returns all the strings referenced from function
This file contains hidden or 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