Skip to content

Instantly share code, notes, and snippets.

@iGio90
Created May 27, 2020 16:26
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 iGio90/fd7689af7db54554cf5a0aba7b43061b to your computer and use it in GitHub Desktop.
Save iGio90/fd7689af7db54554cf5a0aba7b43061b to your computer and use it in GitHub Desktop.
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