Skip to content

Instantly share code, notes, and snippets.

@matandobr
Created June 29, 2018 12:20
Show Gist options
  • Save matandobr/0235422a733a0b4f84bd18a2392d5f55 to your computer and use it in GitHub Desktop.
Save matandobr/0235422a733a0b4f84bd18a2392d5f55 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# @0xGr00t, 2018
# This is a simple shell script that does exactly what SuperSU guided in their code.
# Tested on AVD android 7 arm64 emulator (sdk25) with macOS host
# Before you run this, make sure you have downloaded SuperSu flashable zip from their site, and cd into it
# To this to work properly, run the emulator with -no-snapshot -writable-system flags
# For example: MacBook-Pro-2:tools matandobr$ ./emulator -no-snapshot -writable-system @Nexus5API25
# There is one issue I faced - when starting the emulator it won't boot until you disable SELinux (adb shell setenforce 0)
# After the boot completes you can turn it back on.
# Make sure you restart the emulator after running the script so the system app will installed properly
# GoodLuck <3
#
ADB_COMMAND="adb "
# echo "Clean up"
# TODO
echo "Getting emulator ready"
$ADB_COMMAND root
$ADB_COMMAND remount
$ADB_COMMAND shell setenforce 0
echo "Backing up files"
$ADB_COMMAND shell cp /system/bin/app_process /system/bin/app_process_original
$ADB_COMMAND shell cp /system/bin/app_process64 /system/bin/app_process64_original
$ADB_COMMAND shell cp /system/bin/app_process /system/bin/app_process_init
echo "Pushing & chmoding SuperSu.apk"
$ADB_COMMAND push common/Superuser.apk /system/app/SuperSU/SuperSU.apk
$ADB_COMMAND shell chmod 0644 /system/app/SuperSU/SuperSU.apk
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/app/SuperSU/SuperSU.apk
echo "Pushing & chmoding install-recovery"
$ADB_COMMAND push common/install-recovery.sh /system/etc/install-recovery.sh
$ADB_COMMAND shell chmod 0755 /system/etc/install-recovery.sh
$ADB_COMMAND shell chcon u:object_r:toolbox_exec:s0 /system/etc/install-recovery.sh
$ADB_COMMAND shell ln -s /system/etc/install-recovery.sh /system/bin/install-recovery.sh
echo "Pushing & chmoding su"
$ADB_COMMAND push arm64/su /system/xbin/su
$ADB_COMMAND push arm64/su /system/bin/.ext/.su
$ADB_COMMAND push arm64/su /system/xbin/daemonsu
$ADB_COMMAND shell chmod 0755 /system/xbin/su
$ADB_COMMAND shell chmod 0755 /system/bin/.ext/.su
$ADB_COMMAND shell chmod 0755 /system/xbin/daemonsu
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/xbin/su
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/bin/.ext/.su
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/xbin/daemonsu
echo "Pushing & chmoding supolicy & libsupol.so"
$ADB_COMMAND push arm64/supolicy /system/xbin/supolicy
$ADB_COMMAND push arm64/libsupol.so /system/lib/libsupol.so
$ADB_COMMAND shell chmod 0755 /system/xbin/supolicy
$ADB_COMMAND shell chmod 0644 /system/lib/libsupol.so
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/xbin/supolicy
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/lib/libsupol.so
echo "Symlinking app_process to supersu"
$ADB_COMMAND shell rm /system/bin/app_process
$ADB_COMMAND shell rm /system/bin/app_process64
$ADB_COMMAND shell ln -s /system/xbin/daemonsu /system/bin/app_process
$ADB_COMMAND shell ln -s /system/xbin/daemonsu /system/bin/app_process64
echo "Finising"
$ADB_COMMAND shell touch /system/etc/.installed_su_daemon
$ADB_COMMAND shell chmod 0644 /system/etc/.installed_su_daemon
$ADB_COMMAND shell chcon u:object_r:system_file:s0 /system/etc/.installed_su_daemon
$ADB_COMMAND shell /system/xbin/su --install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment