SoFunction
Updated on 2025-03-01

Android programming to prevent decompilation

This article describes the implementation method of Android programming to prevent decompilation. Share it for your reference, as follows:

1. Determine whether the program is running on the simulator

boolean isRunningInEmualtor() {
  boolean qemuKernel = false;
  Process process = null;
  DataOutputStream os = null;
  try{ 
   process = ().exec("getprop "); 
   os = new DataOutputStream(());
   BufferedReader in = new BufferedReader(new InputStreamReader((),"GBK"));
   ("exit\n"); 
   ();
   ();
   // getprop == 1 in the emulator   // getprop == "sdk" in the emulator   // getprop == "test-keys" in the emulator   qemuKernel = ((()) == 1);
   ("", "Simulator detected:" + qemuKernel);
  } catch (Exception e){ 
   qemuKernel = false;
   ("", "run failed" + ()); 
  } finally {
   try{ 
    if (os != null) { 
     (); 
    } 
    (); 
   } catch (Exception e) {
   } 
   ("", "run finally"); 
  }
  return qemuKernel;
}

2. Check the keystore signature and then compare it with the previous one

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

3. Detect the package name, version name and version number, and then make a judgment:

private String getAppInfo() {
   try {
    String pkName = ();
    String versionName = ().getPackageInfo(
      pkName, 0).versionName;
    int versionCode = ()
      .getPackageInfo(pkName, 0).versionCode;
    return pkName + " " + versionName + " " + versionCode;
   } catch (Exception e) {
   }
   return null;
}

4. Write jpg images into png format, but the latest version of apktool has been fixed

5. Spend instructions to affect jd-gui, but the latest version of jd-gui has been fixed

private static final char[] wJ = "0123456789abcdef".toCharArray();
public static String imsi = "204046330839890";
public static String p = "0";
public static String keyword = "Telephone";
public static String tranlateKeyword = "%E7%94%B5%E8%AF%9D";

Add the above field to each class. . . .

https://***/  A third party needs "Ai Encryption" website. 1. You need to use the official packaging key tool to package it and upload it to the "Ai Encryption" website for processing, and then download it on the website. After downloading, you need to use the "Ai Encryption" packaging tool to package it again.

I hope this article will be helpful to everyone's Android programming design.