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
相关推荐
molong9311 小时前
Android 权限模型(前台、后台、特殊权限)
android
怪兽20141 小时前
Looper、MessageQueue、Message及Handler的关系是什么?如何保证MessageQueue的并发访问安全?
android·面试
奥尔特星云大使2 小时前
mysql高可用架构之MHA部署(二)VIP漂移(保姆级)
android·mysql·架构·mha·ip漂移
深海呐3 小时前
Android 编译速度优化:JVM堆内存扩充
android·jvm·jvm内存扩充·android 加快编译速度
心随雨下4 小时前
Flutter中新手需要掌握的几种Widget
android·flutter·ios
叶辞树4 小时前
查看安卓设备的音视频解码器信息
android
f30517095 小时前
Python实现数据可视化用Matplotlib轻松创建专业级图表
android
2501_915918419 小时前
iOS 26 App 性能测试|性能评测|iOS 26 性能对比:实战策略
android·macos·ios·小程序·uni-app·cocoa·iphone
咋吃都不胖lyh12 小时前
SQL-多对多关系
android·mysql·数据分析