保护根手机上的Android应用程序
我将创建应用程序,并希望在越狱的情况下进行保护。 是否有任何过程来检测设备是否为根设备,以便在检测到设备为根设备时使应用程序停止工作 任何帮助都将不胜感激保护根手机上的Android应用程序,android,rooted-device,Android,Rooted Device,我将创建应用程序,并希望在越狱的情况下进行保护。 是否有任何过程来检测设备是否为根设备,以便在检测到设备为根设备时使应用程序停止工作 任何帮助都将不胜感激 提前感谢。首先,Android中没有“越狱”。如果要检查设备是否已根目录,可以使用来获得合适的解决方案。“越狱意味着根目录” 下面是一个类,它将通过以下三种方式之一检查根目录 public class Root { private static String LOG_TAG = Root.class.getName();
提前感谢。首先,Android中没有“越狱”。如果要检查设备是否已根目录,可以使用来获得合适的解决方案。“越狱意味着根目录” 下面是一个类,它将通过以下三种方式之一检查根目录
public class Root {
private static String LOG_TAG = Root.class.getName();
public boolean isDeviceRooted() {
if (checkRootMethod1()){return true;}
if (checkRootMethod2()){return true;}
if (checkRootMethod3()){return true;}
return false;
}
public boolean checkRootMethod1(){
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
return false;
}
public boolean checkRootMethod2(){
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e) { }
return false;
}
public boolean checkRootMethod3() {
if (new ExecShell().executeCommand(SHELL_CMD.check_su_binary) != null){
return true;
}else{
return false;
}
}
}
public class ExecShell {
private static String LOG_TAG = ExecShell.class.getName();
public static enum SHELL_CMD {
check_su_binary(new String[] {"/system/xbin/which","su"}),
;
String[] command;
SHELL_CMD(String[] command){
this.command = command;
}
}
public ArrayList<String> executeCommand(SHELL_CMD shellCmd){
String line = null;
ArrayList<String> fullResponse = new ArrayList<String>();
Process localProcess = null;
try {
localProcess = Runtime.getRuntime().exec(shellCmd.command);
} catch (Exception e) {
return null;
//e.printStackTrace();
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(localProcess.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
try {
while ((line = in.readLine()) != null) {
Log.d(LOG_TAG, "--> Line received: " + line);
fullResponse.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d(LOG_TAG, "--> Full response was: " + fullResponse);
return fullResponse;
}
}
公共类根目录{
私有静态字符串LOG_TAG=Root.class.getName();
公共布尔值isDeviceRooted(){
if(checkRootMethod1()){return true;}
if(checkRootMethod2()){return true;}
if(checkRootMethod3()){return true;}
返回false;
}
公共布尔checkRootMethod1(){
String buildTags=android.os.Build.TAGS;
if(buildTags!=null&&buildTags.contains(“测试键”)){
返回true;
}
返回false;
}
公共布尔checkRootMethod2(){
试一试{
File File=新文件(“/system/app/Superuser.apk”);
if(file.exists()){
返回true;
}
}捕获(例外e){}
返回false;
}
公共布尔checkRootMethod3(){
if(new ExecShell().executeCommand(SHELL命令检查二进制)!=null){
返回true;
}否则{
返回false;
}
}
}
公共类ExecShell{
私有静态字符串LOG_TAG=ExecShell.class.getName();
公共静态枚举SHELL_CMD{
检查_su_二进制(新字符串[]{“/system/xbin/which”,“su”}),
;
字符串[]命令;
SHELL命令(字符串[]命令){
this.command=命令;
}
}
公共ArrayList executeCommand(SHELL\u CMD shellCmd){
字符串行=null;
ArrayList fullResponse=新的ArrayList();
processlocalprocess=null;
试一试{
localProcess=Runtime.getRuntime().exec(shellCmd.command);
}捕获(例外e){
返回null;
//e、 printStackTrace();
}
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(localProcess.getOutputStream());
BufferedReader in=新的BufferedReader(新的InputStreamReader(localProcess.getInputStream());
试一试{
而((line=in.readLine())!=null){
Log.d(Log_标签,“-->”行接收:“+行);
fullResponse.add(行);
}
}捕获(例外e){
e、 printStackTrace();
}
Log.d(Log_标签,“-->Full response为:“+fullResponse”);
返回完整响应;
}
}
但我已经读到“根设备可能会以任何方式被修改”,所以您认为此代码的结果总是正确的吗。请检查“Longpoke”给出的答案,以供参考。您能解释一下checkRootMethod1()实际上在做什么吗?“测试密钥”构建标记是什么,它与root有什么关系?警告!checkRootMethod3是错误的。您必须在输出中检查/su。在S7上,输出1,返回为真