//非Debug 编译,反调试检测

if(!BuildConfig.DEBUG) {

if(isDebuggable()) {

exit(0);

}

Thread t = new Thread(new Runnable() {

@Override

public void run() {

while(true) {

try {

sleep(100);

if(Debug.isDebuggerConnected()) {

exit(0);

}

if(isUnderTraced()) {

exit(0);

}

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}, "SafeGuardThread");

t.start();

}

if(isUnderTraced()) {

System.exit(0);

}

CrashReport.initCrashReport(getApplicationContext(), "4abcbaaf23", BuildConfig.DEBUG);

}

private boolean isUnderTraced() {

String processStatusFilePath = String.format(Locale.US, "/proc/%d/status", android.os.Process.myPid());

File procInfoFile = new File(processStatusFilePath);

try {

BufferedReader b = new BufferedReader(new FileReader(procInfoFile));

String readLine;

while ((readLine = b.readLine()) != null) {

if(readLine.contains("TracerPid")) {

String[] arrays = readLine.split(":");

if(arrays.length == 2) {

int tracerPid = Integer.parseInt(arrays[1].trim());

if(tracerPid != 0) {

return true;

}

}

}

}

b.close();

} catch (Exception e) {

e.printStackTrace();

}

return false;

}

public boolean isDebuggable() {

return 0 != ( getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE );

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐