Last active
October 29, 2018 14:16
-
-
Save havron/bb5706e82697ceae65db6a5e2a5b068a to your computer and use it in GitHub Desktop.
Get full human-readable labels for Android permissions. Run `adb shell pm list permissions -g -f > permissions_dump.txt` on an Android device, then run this Gist to convert to pandas-friendly CSV.
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
''' | |
Get full human-readable labels for Android permissions. | |
Run `adb shell pm list permissions -g -f > permissions_dump.txt` on an Android device, | |
then run this Gist to convert to pandas-friendly CSV. | |
''' | |
from rsonlite import simpleparse | |
import pandas as pd | |
OUTFILE = 'android_permissions.csv' | |
def permission_labels(permissions_dumpfile): | |
print('Parsing permissions dumpfile...') | |
groupcols = ['group','group_package','group_label','group_description'] | |
pcols = ['permission','package','label','description','protectionLevel'] | |
sp = simpleparse(open(permissions_dumpfile,'r').read()) | |
df = pd.DataFrame(columns=groupcols+pcols) | |
record = {} | |
ungrouped_d = dict.fromkeys(groupcols, 'ungrouped') | |
for group in sp[1]: | |
record['group'] = group.split(':')[1] | |
if record['group'] == '': | |
for permission in sp[1][group]: | |
record['permission'] = permission.split(':')[1] | |
for permission_attr in sp[1][group][permission]: | |
label, val = permission_attr.split(':') | |
record[label.replace('+ ','')] = val | |
df.loc[df.shape[0]] = {**record, **ungrouped_d} | |
else: | |
for group_attr in sp[1][group]: | |
if isinstance(group_attr, str): | |
label, val = group_attr.split(':') | |
record['group_'+label.replace('+ ','')] = val | |
else: | |
for permission in group_attr: | |
record['permission'] = permission.split(':')[1] | |
for permission_attr in group_attr[permission]: | |
label, val = permission_attr.split(':') | |
record[label.replace('+ ','')] = val | |
df.loc[df.shape[0]] = record | |
print("Parsed. Saving to '{}'...".format(OUTFILE)) | |
df.to_csv(OUTFILE) | |
print('Saved.') | |
if __name__ == "__main__": | |
permission_labels('permissions_dump.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment