反破解

/**
     * 检测软件是否被调试连接的方法
     *
     */
    public static boolean isDebuggerConnected() {
        return android.os.Debug.isDebuggerConnected();
    }
    /**
     * 检测软件是否运行在模拟器中的方法
     *
     */
    public static boolean isRunningInEmualtor() {
        boolean qemuKernel = false;
        Process process = null;
        DataOutputStream os = null;
        try {
            process = Runtime.getRuntime().exec("getprop ro.kernel.qemu");
            //执行getprop
            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); //判断ro.kernel.qemu属性值是否为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){
                e.printStackTrace();
            }
            Log.d("com.droider.checkqemu","run finally");
        }
        return qemuKernel;
    }
    /**
     * 获得软件发布时签名的hash值的方法
     * sig=1696108939
     *
     */
    public static Long getSignature(Context context,String packageName){
        PackageManager pm=context.getPackageManager();
        PackageInfo pi=null;
        long sig=0;
        try {
            pi=pm.getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
            android.content.pm.Signature[] s = pi.signatures;
            sig = s[0].hashCode();
        } catch (PackageManager.NameNotFoundException e) {
            sig=0;
            e.printStackTrace();
        }
        return sig;
    }
    /**
     * classes.dex文件CRC检验
     *
     */
    public static boolean checkCRC(Context context){
        boolean beModified = false;
//    long crc = Long.parseLong(context.getResources().getString(R.string.crc));
        long crc = Constant.crc;
        ZipFile zf;
        try {
            zf=new ZipFile(context.getApplicationContext().getPackageCodePath());
            //获取apk安装后的路径
            ZipEntry ze = zf.getEntry("classes.dex");//获取apk文件中的classes.dex
            Log.d("com.droider.checkcrc",String.valueOf(ze.getCrc()));
            if (ze.getCrc() == crc){//检查CRC
                beModified = true;
            }
        } catch (IOException e) {
            beModified = false;
            e.printStackTrace();
        }
        return beModified;
    }

    /**
     * 分别进行判断是否被破解
     * @param context
     * @param packageName
     */
    public static void isKillProcess(Context context,String packageName){
        if(AntiCrackUtils.isDebuggerConnected()
                ||AntiCrackUtils.getSignature(context,packageName) != 1696108939
                ||!AntiCrackUtils.checkCRC(context)
                ||isRunningInEmualtor()){
            SPUtils.put(context, Constant.SPKeys.SHAREDPREF_TIME.name(),System.currentTimeMillis());
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    }

    /**
     * 修改crc值
     */
    public static void setCRC(Context context){
        ZipFile zf;
        try {
            zf = new ZipFile(context.getApplicationContext().getPackageCodePath());
            //获取apk安装后的路径
            ZipEntry ze = zf.getEntry("classes.dex");//获取apk文件中的classes.dex
//            long crc=ze.getCrc();
//            String data = getResources().getString(R.string.crc);
//            data=String.format(data,String.valueOf(crc));
            Constant.crc=ze.getCrc();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
 
 
 
 
 
 
//修改crc值
if(TimeUtils.isToday((Long) SPUtils.get(this, Constant.SPKeys.SHAREDPREF_TIME.name(), 0L))) {
    AntiCrackUtils.setCRC(this);
}
if(TimeUtils.isToday((Long)SPUtils.get(this,Constant.SPKeys.SHAREDPREF_TIME.name(),0L))){
   AntiCrackUtils.isKillProcess(this,getPackageName());
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值