|
|
方案一:彻底重写字符串加密
核心思路:不再直接修改 DEX 二进制中的 string_data ,而是在运行时通过 JNI Native 层 提供字符串解密服务。
1. 修改 HardeningConfig.java —— 区分
// HardeningConfig.java
/** 代码混淆(R8/ProGuard)— 只混淆类/方法/字段名,不修改 DEX 结构 */
public boolean obfuscation = true;
/** 字符串加密 — 改为 Native 层实现,不再直接修改 DEX 二进制 */
public boolean stringEncryption = false; // 默认关闭,直到 Native 实现完成
2. 修改 HardeningTask.java —— 生成正确的 ProGuard 规则
// 在 generateProguardRules() 中,移除破坏性的字符串加密规则
// 删除以下内容:
// if (config.stringEncryption) {
// sb.append("-assumenosideeffects class java.lang.String {...}\n");
// }
3. 修改 ShellEngine.java —— 禁用有缺陷的 DEX 字符串加密
// ShellEngine.java - encryptDex() 方法
private void encryptDex(File dex, File outDir) throws Exception {
byte[] raw = readAllBytes(dex);
// 禁用有缺陷的字符串加密,仅保留 AES 加密
// if (enableStringEncryption) {
// byte[] strKey = DexStringEncryptor.deriveKey(encryptionKey);
// DexStringEncryptor.encryptInMemory(raw, strKey);
// }
// AES-256-GCM 加密(保持不变)
byte[] iv = new byte[GCM_IV_LENGTH];
new SecureRandom().nextBytes(iv);
// ...
}
4. 修改 ShellApplication.java —— 移除有缺陷的字符串解密
// ShellApplication.java - attachBaseContext() 中
// 删除以下代码块:
// boolean strEncEnabled = false;
// try {
// InputStream flagStream = base.getAssets().open("apkprotector_strenc");
// flagStream.close();
// strEncEnabled = true;
// } catch (Exception ignored) {}
// if (strEncEnabled) {
// int strCount = decryptDexStrings(raw, key);
// ...
// }
立即禁用 DEX 级字符串加密功能,改用 Native 层字符串保护方案。 |
|