简体   繁体   English

SU 权限被拒绝,尽管 Android 模拟器上有 ABD Root

[英]SU Permission Denied Despite of ABD Root on Android Emulator

I wanted to write commands to SU like this:我想像这样向 SU 写命令:

Java.Lang.Process process = Java.Lang.Runtime.GetRuntime().Exec("su");

I get the following error unfortunately:不幸的是,我收到以下错误:

'Cannot run program "su": error=13, Permission denied'

I have ran adb root and I have access to shell right now but this error keeps popping up.我已经运行了adb root并且我现在可以访问 shell,但是这个错误不断弹出。 I'm using Xamarin.Android and Visual Studio.我正在使用 Xamarin.Android 和 Visual Studio。

Using adb root is not the same as having a rooted device where you can access the su command.使用adb root与拥有可以访问su命令的 root 设备不同。 There is a reason as to why the command is only available using Android Debug Bridge (adb) on emulators.该命令仅在模拟器上使用 Android Debug Bridge (adb) 时才可用是有原因的。

You can use su on devices that are rooted.您可以在有 root su的设备上使用su I wrote a blog post about how to do this with Xamarin here: https://blog.ostebaronen.dk/2018/07/xamarin-and-java-processes.html我在这里写了一篇关于如何使用 Xamarin 执行此操作的博客文章: https : //blog.ostebaronen.dk/2018/07/xamarin-and-java-processes.html

Instead of using Java.Lang.Runtime.GetRuntime().Exec() to start the process, you can use ProcessBuilder instead, which allows you to build the command nicely like and await the result like:您可以使用ProcessBuilder而不是使用Java.Lang.Runtime.GetRuntime().Exec()来启动进程,它允许您很好地构建命令并等待如下结果:

var builder = new ProcessBuilder("echo", "hello");
var process = builder.Start();
var exitCode = await process.WaitForAsync();

For starting some process as root you can do:要以 root 身份启动某些进程,您可以执行以下操作:

var builder = new ProcessBuilder("su", "-c", "echo hello");

However, doing this does not change the fact that the Emulator you are using is not rooted as devices would be.但是,这样做并不会改变您使用的模拟器不像设备那样扎根的事实。 So none of this will work as you expect.所以这些都不会像你期望的那样工作。

If you are looking to root your emulator, like a device would be rooted.如果您希望为模拟器生根,就像设备会生根一样。 You would need to install something like SuperSU or Magisk on your AVD.你需要在你的 AVD 上安装 SuperSU 或 Magisk 之类的东西。 This is very well described here: https://medium.com/@anthony.f.tannous/android-10-emulation-of-magisk-supersu-on-an-aosp-avd-de93ed080fad这在这里得到了很好的描述: https : //medium.com/@anthony.f.tannous/android-10-emulation-of-magisk-supersu-on-an-aosp-avd-de93ed080fad

This will involve:这将涉及:

  1. Acquiring root using adb root使用adb root获取adb root
  2. Mounting the /system/ partition挂载/system/分区
  3. Pushing some files which override the su and other binaries with patched ones推送一些覆盖su和其他二进制文件的文件
  4. Starting a SU daemon启动 SU 守护进程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM