Last active
December 11, 2018 09:52
-
-
Save kalonw/b0258ef68b7b029ce8a4 to your computer and use it in GitHub Desktop.
A simple python script for stripping out READ_PHONE_STATE in Unity 5.1 Android apps. Run from whereever your UNSIGNED built apk is as build.py <infile> <keystore file> <keystore password> <keystore alias>. Assumes that apktool, jarsigner, and zipalign are available from command. Tested on windows but should work on other platforms.
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 | |
"""A simple python script for stripping out READ_PHONE_STATE in Unity 5.1 Android apps. | |
""" | |
import os | |
import sys | |
import argparse | |
import subprocess | |
import shutil | |
def main(arguments): | |
parser = argparse.ArgumentParser(description=__doc__, | |
formatter_class=argparse.RawDescriptionHelpFormatter) | |
parser.add_argument('infile', help="Input file") | |
parser.add_argument('keystore', help="keystore file") | |
parser.add_argument('kpw', help="keystore password") | |
parser.add_argument('alias', help="keystore alias") | |
args = vars(parser.parse_args(arguments)) | |
infile = args["infile"] | |
processPath = os.path.splitext(args["infile"])[0] | |
keystore = args["keystore"] | |
kpw = args["kpw"] | |
alias = args["alias"] | |
if os.path.exists(processPath): | |
shutil.rmtree(processPath) | |
os.system("apktool d %s" % (infile)) | |
with open(("%s/AndroidManifest.xml" % processPath), 'r+') as content_file: | |
content = content_file.read() | |
content = content.replace('<uses-permission android:name="android.permission.READ_PHONE_STATE"/>', "\n") | |
content_file.seek(0) | |
content_file.write(content) | |
content_file.truncate() | |
tmpfile1 = "%s.tmp" % infile | |
if os.path.exists(tmpfile1): | |
os.remove(tmpfile1) | |
os.system("apktool b %s -o %s" % (processPath, tmpfile1)) | |
shutil.rmtree(processPath) | |
success = os.system("jarsigner -strict -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore %s -storepass %s %s %s" % (keystore, kpw, tmpfile1, alias)) | |
if success != 0: | |
sys.exit("signing error") | |
outfile = "%s_signed.apk" % processPath | |
if os.path.exists(outfile): | |
os.remove(outfile) | |
os.system("zipalign -v 4 %s %s" % (tmpfile1, outfile)) | |
os.remove(tmpfile1) | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment