Python Script to parse permissions from an AndroidManifest.xml file, and sort them alphabetically.
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
from xml.dom.minidom import parseString | |
# Documentation on Permissions in AndroidManifest.xml | |
# https://developer.android.com/guide/topics/manifest/manifest-intro#perms | |
data = '' # string data from file | |
with open('AndroidManifest.xml', 'r') as f: | |
data = f.read() | |
dom = parseString(data) # parse file contents to xml dom | |
nodes = dom.getElementsByTagName('uses-permission') # xml nodes named "uses-permission" | |
nodes+= dom.getElementsByTagName('uses-permission-sdk-23') # xml nodes named "uses-permission-sdk-23" | |
permissions = [] # holder for all permissions as we gather them | |
# Iterate over all the uses-permission nodes | |
for node in nodes: | |
permissions += [node.getAttribute("android:name")] # save permissionName to our list | |
# Print sorted list | |
for permission in sorted(permissions): # sort permissions and iterate | |
print(permission) # print permission name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment