您的位置:首页 > 移动开发 > Android开发

Android应用保护

2016-05-23 19:44 337 查看
if ((getApplicationInfo().flags &=
ApplicationInfo.FLAG_DEBUGGABLE) != 0){
Log.e("com.droider.antidebug", "程序被修改为可调试状态");
android.os.Process.killProcess(android.os.Process.myPid());
}
if (android.os.Debug.isDebuggerConnected()) {   //检测调试器
Log.e("com.droider.antidebug", "检测到测试器");
android.os.Process.killProcess(android.os.Process.myPid());
}


boolean isRunningInEmualtor() {
boolean qemuKernel = false;
Process process = null;
DataOutputStream os = null;
try{
process = Runtime.getRuntime().exec("getprop ro.kernel.qemu");
os = new DataOutputStream(process.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
os.writeBytes("exit\n");
os.flush();
process.waitFor();
qemuKernel = (Integer.valueOf(in.readLine()) == 1);
Log.d("com.droider.checkqemu", "检测到模拟器:" + qemuKernel);
} catch (Exception e){
qemuKernel = false;
Log.d("com.droider.checkqemu", "run failed" + e.getMessage());
} finally {
try{
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {

}
Log.d("com.droider.checkqemu", "run finally");
}
return qemuKernel;
}

public static String getProp(Context context, String property) {
try {
ClassLoader cl = context.getClassLoader();
Class SystemProperties = cl.loadClass("android.os.SystemProperties");
Method method = SystemProperties.getMethod("get", String.class);
Object[] params = new Object[1];
params[0] = new String(property);
return (String)method.invoke(SystemProperties, params);
} catch (Exception e) {
return null;
}
}


public int getSignature(String packageName) {
PackageManager pm = this.getPackageManager();
PackageInfo pi = null;
int sig = 0;
try {
pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
Signature[] s = pi.signatures;
sig = s[0].hashCode();
} catch (Exception e1) {
sig = 0;
e1.printStackTrace();
}
return sig;
}


private boolean checkCRC() {
boolean beModified = false;
long crc = Long.parseLong(getString(R.string.crc));
ZipFile zf;
try {
zf = new ZipFile(getApplicationContext().getPackageCodePath());
ZipEntry ze = zf.getEntry("classes.dex");
Log.d("com.droider.checkcrc", String.valueOf(ze.getCrc()));
if (ze.getCrc() == crc) {
beModified = true;
}
} catch (IOException e) {
e.printStackTrace();
beModified = false;
}
return beModified;
}


转自:
http://blog.csdn.net/allenwells/article/details/47019605 http://blog.csdn.net/allenwells/article/details/47019615
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: