Android 系统获取 Root 权限以后,会存在一个 su 文件,对其作适当判断来得知设备是否已 ROOT
#include <sys/stat.h>
#include <jni.h>
jboolean Java_com_glorevo_RootState_getRootState( JNIEnv* env, jobject thiz )
{
char *path[] = {
"/system/bin/su",
"/system/xbin/su"
};
struct stat sb;
if (stat(path[0], &sb) == -1)
if (stat(path[1], &sb) == -1)
return JNI_FALSE;
//-rwxr-xr-x/-rwsr-sr-x, root, root/shell
if(
((unsigned long)sb.st_mode == 0100755 /*|| (unsigned long)sb.st_mode == 0106755*/ )
&& ((unsigned long)sb.st_uid == 0)
&& ((unsigned long)sb.st_gid == 0 || sb.st_gid == 2000)
)
return JNI_TRUE;
else
return JNI_FALSE;
}