Skip to content

Instantly share code, notes, and snippets.

@Areizen
Last active July 23, 2020 18:40
Show Gist options
  • Save Areizen/9d53b37bd2da08be053f978e75ee2c1c to your computer and use it in GitHub Desktop.
Save Areizen/9d53b37bd2da08be053f978e75ee2c1c to your computer and use it in GitHub Desktop.
Uninstall Device administrator applications
#!/usr/bin/python3
import frida
import subprocess
import sys
if len(sys.argv) !=2:
print(f"[-] Usage : python3 {sys.argv[0]} <package_to_uninstall>")
sys.exit(-1)
def message(message, data):
print(message)
device = frida.get_usb_device()
session_system_server = device.attach("system_server")
# see : https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java?q=DELETE_FAILED_DEVICE_POLICY_MANAGER&ss=android%2Fplatform%2Fsuperproject
script_system_server = session_system_server.create_script("""
Java.perform(function(){
const PackageManager = Java.use("com.android.server.pm.PackageManagerService")
PackageManager.isPackageDeviceAdmin.implementation = function(packageName, userId){
console.log("isPackageDeviceAdmin called !");
return false;
}
})
""")
script_system_server.on("message", message)
script_system_server.load()
pid = subprocess.Popen(["adb","uninstall", sys.argv[1]])
pid.wait()
@Areizen
Copy link
Author

Areizen commented Jul 22, 2020

adb shell pm list packages -3 | cut -d':' -f2 | tr '\r' ' ' | xargs -r -n1 -t python scripts/uninstall.py to uninstall all packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment