Created
September 3, 2013 23:33
-
-
Save scribu/6431001 to your computer and use it in GitHub Desktop.
Make adb work as if you had true root access.
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
import sys | |
import subprocess | |
# Requirements: | |
# - `adb` command locally | |
# - `su` command on device | |
def use_su(cmd): | |
to_escape = ['*', '|'] | |
for char in to_escape: | |
cmd = cmd.replace(char, '\\' + char) | |
return [ 'shell', 'echo %s | su' % cmd ] | |
def call_adb(): | |
if sys.argv[1] == 'root': | |
return | |
# TODO: 'push' && 'pull' | |
if sys.argv[1] == 'remount': | |
args = use_su('mount -o rw,remount /system') | |
elif sys.argv[1] == 'shell': | |
args = use_su(' '.join(sys.argv[2:])) | |
else: | |
args = sys.argv[1:] | |
args.insert(0, 'adb') | |
# print args | |
subprocess.check_call(args, stdout=sys.stdout, stderr=sys.stderr) | |
if __name__ == '__main__': | |
call_adb() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context: http://pof.eslack.org/2013/07/05/zte-open-firefoxos-phone-root-and-first-impressions/