tweaselORG / appstraction

An abstraction layer for common instrumentation functions (e.g. installing and starting apps, setting preferences, etc.) on Android and iOS.
MIT License
4 stars 1 forks source link

`adb root` fails on vanilla Android with Magisk #92

Closed zner0L closed 1 year ago

zner0L commented 1 year ago

On an Android 11 Google Pixel 3 adb root fails with adbd cannot run as root in production builds, though a current Magisk root is installed.

The workaround using adb shell su does work, however. We should implement that as well, if adb root throws.

zner0L commented 1 year ago

While trying to fix this, I noticed something weird is going on with pipes:

$ adb shell su -c /bin/sh -c "whoami"
root
$ adb shell su -c /bin/sh -c "echo | whoami"
shell

This breaks the wireguard setup since we need to pipe some base64.

zner0L commented 1 year ago

I fixed that by passing the whole command as a string:

adb shell /bin/sh -c 'su -c /bin/sh -c "echo | whoami"'

which doesn‘t work in the shell, but apparently does in execa:

await runAndroidDevTool('adb', ['shell', '/bin/sh', '-c', `'su root -c /bin/sh -c "echo | whoami"'`], {
    stdio: 'inherit',
});
// root
zner0L commented 1 year ago

Another weird error:

$ adb shell su -c mv /sdcard/appstraction-tmp/f71c2061-b77c-4c41-ad3a-f8b78784216d /sdcard/Android/obb/com.pixellabs.pixelstrike3d/main.273.com.pixellabs.pixelstrike3d.obb
mv: bad '/sdcard/appstraction-tmp/f71c2061-b77c-4c41-ad3a-f8b78784216d': No such file or directory

But the file exists:

$ adb shell su -c stat /sdcard/appstraction-tmp/f71c2061-b77c-4c41-ad3a-f8b78784216d 
  File: /sdcard/appstraction-tmp/f71c2061-b77c-4c41-ad3a-f8b78784216d
  Size: 834045431        Blocks: 1630608         IO Blocks: 512  regular file
Device: 5fh/95d  Inode: 13871    Links: 1        Device type: 0,0
Access: (0660/-rw-rw----)       Uid: (    0/    root)   Gid: ( 9997/everybody)
Access: 2023-06-12 14:17:50.000000000 +0200
Modify: 2023-06-12 14:17:50.000000000 +0200
Change: 2023-06-12 14:18:08.207175000 +0200
zner0L commented 1 year ago

That a confusing error message but an easy fix. What mv meant to say was that the destination directory did not exist. I needed to create that.

zner0L commented 1 year ago

Random fun fact: When pushin large files, adb push seems to randomly just give up. Maybe it is related to this: https://forum.xda-developers.com/t/q-adb-hangs-during-push-of-large-files.1184186/

zner0L commented 1 year ago

Sending the intent does not fail using adb shell su -c am broadcast -a com.wireguard.android.action.SET_TUNNEL_UP -n'com.wireguard.android/.model.TunnelManager$IntentReceiver' -e tunnel appstraction, but it does not start the tunnel either. However if I use the shell interactively and log into the root shell using su , I am able to start the tunnel with the same command. I wonder what the difference is…

zner0L commented 1 year ago

Ah, I finally found this was an error with escaping the $. It needs to be escaped like this: \\$\\