我有一个Android应用程序,它通过jni调用本机共享库。这个共享库调用了一些可加载的内核模块.ko
当jni调用共享库中调用内核模块的函数时,我的应用程序运行失败。但是,当我使用此共享库编写可执行文件时,调用上面的函数可以正常工作。
我发现我的应用程序以用户名“ u0_axx”运行,而我的可执行文件以root用户身份通过命令行运行。因此,也许它没有调用内核模块的权限。
我的问题是,本机代码如何在具有root权限的情况下运行?还是一些解决此类问题的解决方案?
Ps:我还尝试使用Runtime.getRuntime().exec("su")
并将<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
添加到清单中,但是它无济于事,并获得了权限被拒绝的异常。我的设备已扎根,我的应用程序已构建为系统应用程序。
答案 0 :(得分:1)
您可以将您的应用设置为以系统身份运行,
error: borrowed data cannot be stored outside of its closure
--> src/main.rs:14:33
|
13 | let mut y = std::cell::RefCell::new(&0);
| ----- -- cannot infer an appropriate lifetime...
| |
| ...so that variable is valid at time of its declaration
14 | foo(&mut x, |a| { y.replace(&a); a }, |a| a);
| --- ^^ cannot be stored outside of its closure
| |
| borrowed data cannot outlive this closure
这需要一些额外的步骤,但不会使您的JNI代码访问内核模块。
为此,您需要一些中介程序(以 root 运行),该进程可以接收来自Java或本机代码的请求,并为您调用内核函数。您可以使用
foo
但是从 init.rc 作为服务启动此中介程序可能会更容易。像https://github.com/SpazeDog/rootfw这样的专用库也可能有帮助。
您可以在https://boundarydevices.com/android-security-part-1-application-signatures-permissions/上找到更多说明。