对Dex进行完整性的检查,可通过CRC,或者Hash值。可将校验值放到String资源文件里,或者放到服务器中。

  1. 在代码中完成校验值对比逻辑,此部分代码后续不能再改变,否则CRC值会发生变化;
  2. 从生成的APK文件中提取出classes.dex文件,计算CRC值,或Hash值,
  3. 将计算出的值放入strings.xml文件中
string apkPath=this.getPackageCodePath();

Long dexCRC=Long.parseLong(this.getString(R.string.dex_crc));

try{
     ZipFile zipfile=new ZipFile(apkPath);

     ZipEntry dexentry=zipfile.getEntry("classes.dex");
         
     if(dexentry.getCrc()!=dexCRC){//代码逻辑中,进行校验
          System.out.println("Dex has been modified!");
     }else
     ...
破解方法:逻辑判断的true/false容易更改



对APK的完整性校验:Hash值放在服务端比较合适。

MessageDigest msgDigest=null;

try{
     msgDigest= MessageDigest.getInstance("md5");
     byte[] bytes=new byte[8192];
     int byteCount;

     FileInputStream fis=null;
     fis =new FileInputStream(new File(apkpath));
     
     while((byteCount=fis.read(bytes))>0){
          msgDigest.update(bytes,0,byteCount);
          BinInteger bi=new BigInteger(1,msgDigest.digest());
          String md5 =bi.toString(16);
          fis.close();
     
     ...
}






相关文章:

  • 2022-02-01
  • 2021-12-06
  • 2021-12-02
  • 2021-09-16
  • 2021-10-19
  • 2021-06-07
  • 2022-01-13
猜你喜欢
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-01-29
  • 2021-11-17
相关资源
相似解决方案