Created
May 27, 2020 16:26
-
-
Save iGio90/fd7689af7db54554cf5a0aba7b43061b to your computer and use it in GitHub Desktop.
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
import os | |
import sys | |
if len(sys.argv) < 2: | |
print('usage: python3', sys.argv[0], ' /path/to/file_smali') | |
exit(2) | |
path = sys.argv[1] | |
if not os.path.exists(path): | |
print(path, 'not existing') | |
exit(2) | |
if not os.path.isfile(path): | |
print(path, 'is not a smali file') | |
exit(2) | |
with open(path, 'r') as f: | |
data = f.read() | |
if not data.startswith('.class'): | |
print(path, 'is not a smali file') | |
exit(2) | |
lines = data.split('\n') | |
def get_class(line: str, index=0): | |
try: | |
index = start = line.index('L', index) + 1 | |
index = line.index(';', index) | |
return line[start:index].replace('/', '.'), index | |
except: | |
return None, 0 | |
ret = [] | |
for line in lines: | |
clazz, index = get_class(line) | |
while clazz is not None: | |
ret.append(clazz) | |
clazz, index = get_class(line, index) | |
ret = list(dict.fromkeys(ret)) | |
print(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment