Android 自定义混淆字典

添加下面的代码,用新的混淆字典,随机大小写字母组合

c 复制代码
package com.jiuhong.mbtirgtest.util;

import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class ObfuscationDictionaryGeneratorUtil {

    public static void generateObfuscationDictionary(String filePath, int count) {
        Set<String> uniqueWords = new HashSet<>();  // 使用 Set 确保唯一性

        while (uniqueWords.size() < count) {
            uniqueWords.add(generateRandomWord(3, 10));
        }

        try (FileWriter writer = new FileWriter(filePath)) {
            for (String word : uniqueWords) {
                writer.write(word + "\n");
            }
            System.out.println("混淆字典已生成: " + filePath);
        } catch (IOException e) {
            System.err.println("生成混淆字典失败: " + e.getMessage());
        }
    }

    private static String generateRandomWord(int minLength, int maxLength) {
        Random random = new Random();
        int wordLength = random.nextInt(maxLength - minLength + 1) + minLength;
        StringBuilder word = new StringBuilder(wordLength);
        for (int i = 0; i < wordLength; i++) {
            char randomChar = (char) (random.nextBoolean() ? 'A' + random.nextInt(26) : 'a' + random.nextInt(26));
            word.append(randomChar);
        }
        return word.toString();
    }
}

生成字典文件

c 复制代码
        // 调用方法生成混淆字典
        String filePath = this.getFilesDir().getAbsolutePath() + "/obfuscation_dictionary.txt";
        
        int count = 10000; // 生成 10000 条记录
        ObfuscationDictionaryGeneratorUtil.generateObfuscationDictionary(filePath, count);

在Device Explorer找到这个文件

c 复制代码
/data/user/0/com.j.mt/files/obfuscation_dictionary.txt

拖到APP目录下

在混淆文件中添加规则

c 复制代码
#用于字段名和方法名混淆。
-obfuscationdictionary obfuscation_dictionary.txt
#用于类名混淆。
-classobfuscationdictionary obfuscation_dictionary.txt
#用于包名混淆。
-packageobfuscationdictionary obfuscation_dictionary.txt
相关推荐
waiting9711183 小时前
Ubuntu 26.04 + Android14安装与编译教程
android·linux·ubuntu
hunterandroid3 小时前
Android 测试全景:从单元测试到 UI 自动化的完整实践
android·前端
蜡台3 小时前
Kotlin 五大作用域函数详解|let/run/apply/also/with 选型指南+实战避坑
android·java·kotlin
2401_833269304 小时前
Android registerForActivityResult详解
android
Carson带你学Android4 小时前
9月 Android Drop:Gemini 终于不只是聊天助手了
android·ai编程
Sagittarius_A*4 小时前
【LitCTF2026】lit_ezsql
android·java·数据库
hai_android5 小时前
Messenger:Android 最轻量的 IPC 方式
android·kotlin
gxgldyh6 小时前
Android Framework源码解析(十):Service启动全流程——从startService到Service执行的源码深度解析
android
换元不配限6 小时前
Android Studio Dolphin 新版Logcat 使用指南:告别混乱日志,高效定位问题
android·android studio·logcat
Android-Flutter7 小时前
android Binder 应用层开发 详解
android·binder