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
相关推荐
白菜欣4 小时前
Linux — 进程控制
android·linux·运维
俩个逗号。。7 小时前
Gradle 踩过的坑
android
土星碎冰机10 小时前
ai自学笔记(3.安卓篇,制作app
android·笔记·ai
随遇丿而安11 小时前
专题:Glide / Coil / Fresco,不是三种写法,而是三套图片加载思路
android
只可远观12 小时前
Android 自动埋点(页面打开 / 关闭 + 点击事件)完整方案
android·kotlin
私人珍藏库13 小时前
【Android】小小最新AI--千变万化扮演任何角色--沉浸式互动
android·app·工具·软件·多功能
zh_xuan13 小时前
Android MVI架构
android·mvi
测试开发-学习笔记14 小时前
Airtest+Poco快速上手
android·其他
李斯维14 小时前
Android Jetpack 简介:由来和演进
android·android studio·android jetpack
阿巴斯甜14 小时前
ARouter 的使用:
android