import os
import subprocess
import time
import lief

os.system('wget https://github.com/frida/frida/releases/download/15.1.17/frida-gadget-15.1.17-android-arm64.so.xz')
os.system("unxz -d frida-gadget-15.1.17-android-arm64.so.xz")

"""Uses APKTool to disassemble an APK"""
cmd = "apktool d myapk.apk"
print(cmd)
output = subprocess.getoutput(cmd)

time.sleep(2)
if 'Exception in' in output:
    print('[-] An error occurred when disassembling the APK.')
    print(output)
    exit(0)

os.system("cp frida-gadget-15.1.17-android-arm64.so myapk/lib/arm64-v8a/libfrida-gadget.so")

input("Press any button once you inserted the smali code into a suitable MainActivity function")

os.system("apktool b myapk")

os.system("wget https://github.com/patrickfav/uber-apk-signer/releases/download/v1.2.1/uber-apk-signer-1.2.1.jar")
os.system("java -jar uber-apk-signer-1.2.1.jar -a ./myapk/dist/myapk.apk")
os.system("adb install -r myapk/dist/myapk-aligned-debugSigned.apk")
