如何使用超级用户权限打开/dev/diag? [英] How to open /dev/diag with super user permissions?

查看:119
本文介绍了如何使用超级用户权限打开/dev/diag?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一加 6 开发一个应用程序.这个应用程序使用共享库 (lib.so) 来执行一些任务.对于任务,它需要先打开 dev/diag,然后通过代码发送一些命令.下面是打开 dev/diag 的代码:

I am developing an application for One Plus 6. This applications is using a shared library(lib.so) to perform some task. For the task it needs to open dev/diag first and then send some commands through code. Below is the code to open dev/diag:

fd = open("/dev/diag", O_RDWR|O_LARGEFILE|O_NONBLOCK);
if (fd < 0) {
    perror("open diag dev");
    return -8002;
}

我能够使用 include $(BUILD_EXECUTABLE) 编写的 Android.mkndk-build 命令构建可执行文件.我可以通过将可执行文件放在 android 的/system 文件夹中来打开 dev/diag.

I am able to build a executable with include $(BUILD_EXECUTABLE) written in Android.mk and with ndk-build command. I am able to run open the dev/diag with placing the executable in /system folder of android.

失败的原因是对 android 应用程序做同样的事情.我试过以下:

The thing that failing is to do the same with an android application. I have tried following:

  • 扎根一加 6
  • MainActivity::onCreate中调用Runtime.getRuntime().exec("su").
  • 在清单中提供 .
  • 然后调用所需的 jni 函数.

请建议我如何在为我打开 dev/diag 的函数上启用 su 访问?

Please suggest how can I enable su access on a function which is opening dev/diag for me?

我也尝试使用/system 中的 ndk-build 可执行文件运行可执行命令,例如

I have also tried to do the same with running executable commands using ndk-build executable in /system e.g.

阅读:

    // Run the command
    Process process = Runtime.getRuntime().exec("su -c /system/lib get key");

    BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(process.getInputStream()));

    // Grab the results
    StringBuilder log = new StringBuilder();
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        log.append(line).append("\n");
    }

    String allLogs = log.toString();

对于写:

    Process suProcess = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());

    os.writeBytes("/system/lib set key " + value);
    // Close the terminal
    os.writeBytes("exit\n");

    os.flush();

而且它工作正常.我仍然想知道如何对共享库做同样的事情.有什么帮助吗?

and it is working fine. Still I am wondering how to do the same with shared library. Any help?

推荐答案

我能够向 /dev/diag 设备发送命令并激活 Pixel 3a 手机上的 QCDM 消息.我在 开源 Android 应用网络调查 + 中做到了这一点.

I was able to send commands to the the /dev/diag device and activate the QCDM messages on a Pixel 3a phone. I did this in the open source Android app Network Survey+.

具体看一下这行代码,是这样的:

Specifically, take a look at this line of code, which is something like this:

new String[]{"su", "-c", "exec <path_to_shared_library>"};

该行代码构建共享命令,然后由 ProcessBuilder 执行.

That line of code builds the shared command that is then executed by the ProcessBuilder.

共享库的源代码可以在此处.请注意,我没有编写 diag_revealer 代码,而是取自 Mobile Insight 应用程序.

The source code for the shared library can be found here. Note that I did not write the diag_revealer code, instead that was taken from the Mobile Insight app.

我认为您遇到的问题可能是从 /system 执行.相反,请确保共享库位于您应用的私有目录中.我使用的实际代码指向应用程序的文件目录:

I think maybe the problem you ran into is executing from /system. Instead, make sure the shared library is in your app's private directory. The actual code I used pointed to the app's files directory:

return new String[]{"su", "-c", "exec " + diagRevealer + " " + context.getFilesDir() + "/" + context.getResources().getResourceEntryName(R.raw.rrc_filter_diag_edit) + " " + fifoPipeName};

这篇关于如何使用超级用户权限打开/dev/diag?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆