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
相关推荐
繁依Fanyi1 小时前
Animaster:一次由 CodeBuddy 主导的 CSS 动画编辑器诞生记
android·前端·css·编辑器·codebuddy首席试玩官
奔跑吧 android3 小时前
【android bluetooth 框架分析 02】【Module详解 6】【StorageModule 模块介绍】
android·bluetooth·bt·aosp13·storagemodule
田一一一7 小时前
Android framework 中间件开发(三)
android·中间件·framework·jni
androidwork12 小时前
掌握 Kotlin Android 单元测试:MockK 框架深度实践指南
android·kotlin
田一一一12 小时前
Android framework 中间件开发(二)
android·中间件·framework
追随远方12 小时前
FFmpeg在Android开发中的核心价值是什么?
android·ffmpeg
神探阿航13 小时前
HNUST湖南科技大学-安卓Android期中复习
android·安卓·hnust
千里马-horse15 小时前
android vlc播放rtsp
android·media·rtsp·mediaplayer·vlc
難釋懷15 小时前
Android开发-文本输入
android·gitee
志存高远6617 小时前
(面试)Android各版本新特性
android