Created
December 24, 2014 13:34
-
-
Save geekman/71c076725776112d93da to your computer and use it in GitHub Desktop.
mass-extract permissions & features from Android manifest
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
#!/usr/bin/env python | |
# | |
# extract permissions and features from Android manifest | |
# put this script into the androguard directory | |
# | |
import os | |
import sys | |
import csv | |
import traceback | |
from androguard.core.bytecodes import apk | |
def process_apk(filename): | |
results = {'_file': os.path.basename(filename)} | |
try: | |
a = apk.APK(filename) | |
features = a.get_elements('uses-feature', 'name') | |
perms = a.get_permissions() | |
# if uses-feature describes a GL version, there will be no name | |
if '' in features: | |
features.remove('') | |
results.update(dict(('p_' + p, 1) for p in perms)) | |
results.update(dict(('f_' + f, 1) for f in features)) | |
except: | |
traceback.print_exc() | |
results['_error'] = 1 | |
return results | |
if __name__ == '__main__': | |
output_file = sys.argv[1] | |
assert not os.path.exists(output_file), 'output file %s already exists!' % output_file | |
files = [] | |
for f in sys.argv[2:]: | |
if os.path.isfile(f): | |
files.append(f) | |
elif os.path.isdir(f): | |
files.extend(os.listdir(f)) | |
results = [] | |
columns = set() | |
for f in files: | |
print >> sys.stderr, 'processing %s...' % f | |
r = process_apk(f) | |
results.append(r) | |
columns.update(r.keys()) | |
columns = sorted(list(columns)) | |
# write data into output file | |
outf = open(output_file, 'wb') | |
outf_csv = csv.writer(outf) | |
outf_csv.writerow(columns) | |
for row in results: | |
outf_csv.writerow([row.get(k, '') for k in columns]) | |
outf.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment