在jni中运行的本机C代码和在Android中的shell中运行的区别 [英] Different between native C code run in jni and run in the shell in Android
问题描述
我有一个本机C Android应用程序.首先,我将本机C代码构建到共享库中,jni将使用该库.该库使用一些内核可加载模块.ko,一些已经加载,一些必须通过"insmod"命令加载.
I have a native C Android application. First I build native C code into shared library and jni will use this library. This library uses some kernel loadable module .ko, some already loaded, some must loaded by "insmod" command.
我还构建了一个使用此库的可执行文件,它可以通过命令行正常运行.但是,与可执行文件运行功能相同的jni在调用需要加载内核模块的函数时失败.
I also build an executable that use this library and it run ok by command line. But the jni which do the same work as executable run fail when it calls function that need kernel module to be loaded.
那么它们之间有什么区别?我需要为我的应用授予一些权限吗?
So what is the difference between them? Do I need grant some permission for my app?
推荐答案
我认为您的设备已扎根.
I think your device is rooted.
我还构建了一个使用此库的可执行文件,它可以通过命令行正常运行.
I also build an executable that use this library and it run ok by command line.
也许您可以使用su
运行此命令,并且可以毫无问题地执行它.
Maybe you run this command with su
and can execute it without issue.
但是,如果您通过JNI从App执行二进制文件,则实际上您是在具有普通用户权限的情况下运行命令的,如果您的C代码调用某些内核函数,则可能会出现问题.
But, if you execute your binary from App by JNI, then you are actually running the command with a normal user permission which may have issue if your C code invokes some kernel functions.
您是否尝试过在应用程序中使用以下代码?
Have you tried below code in your app?
Runtime.getRuntime().exec("su").
Here is some reference for you http://muzikant-android.blogspot.com/2011/02/how-to-get-root-access-and-execute.html?_sm_au_=iqsHGF7FqZfPGrJb
这篇关于在jni中运行的本机C代码和在Android中的shell中运行的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!