diff --git a/CHANGELOG.MD b/CHANGELOG.MD index fe4aa5e..d18a427 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,6 +5,7 @@ 更新日志: - [功能] 支持新配置参数忽略 `public` 方法的混淆 @4ra1n +- [功能] 新增 `quiet` 配置参数不打印调试信息 @4ra1n 感谢以下用户的贡献: diff --git a/README.md b/README.md index e9c16f4..ad2550f 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ - 配置大幅简化,仅针对单个 `Class` 文件 - 命令行输出改善,详细展示混淆细节 - 你可以只混淆你项目的核心类替换即可(方便快速) +- 提供了多种方式的 `API` 调用 ## 快速开始 @@ -154,6 +155,8 @@ if (result.getMessage().equals(Result.SUCCESS)) { !!me.n1ar4.clazz.obfuscator.config.BaseConfig # 日志级别 logLevel: info +# 是否使用安静模式(不打印调试信息) +quiet: false # 是否启动 JAVA ASM 的 COMPUTE FRAMES/MAX 自动计算 # 如果遇到 TYPE * NOT PRESENT 报错可以尝试设置该选项为 FALSE asmAutoCompute: true diff --git a/src/main/java/me/n1ar4/clazz/obfuscator/config/BaseConfig.java b/src/main/java/me/n1ar4/clazz/obfuscator/config/BaseConfig.java index 72b5a8a..5a9e753 100644 --- a/src/main/java/me/n1ar4/clazz/obfuscator/config/BaseConfig.java +++ b/src/main/java/me/n1ar4/clazz/obfuscator/config/BaseConfig.java @@ -7,6 +7,8 @@ public class BaseConfig { private String logLevel; + private boolean quiet; + private boolean asmAutoCompute; private boolean enableFieldName; @@ -151,6 +153,14 @@ public void show() { ColorUtil.green(String.valueOf(maxJunkOneClass))); } + public boolean isQuiet() { + return quiet; + } + + public void setQuiet(boolean quiet) { + this.quiet = quiet; + } + public boolean isIgnorePublic() { return ignorePublic; } diff --git a/src/main/java/me/n1ar4/clazz/obfuscator/config/Manager.java b/src/main/java/me/n1ar4/clazz/obfuscator/config/Manager.java index 9e68310..f0938f1 100644 --- a/src/main/java/me/n1ar4/clazz/obfuscator/config/Manager.java +++ b/src/main/java/me/n1ar4/clazz/obfuscator/config/Manager.java @@ -38,6 +38,10 @@ public static boolean initConfig(BaseConfig config) { logger.error("error log level"); return false; } + // 只打印报错信息 + if (config.isQuiet()) { + LogManager.setLevel(LogLevel.ERROR); + } // CHARS if (config.getObfuscateChars() == null || diff --git a/src/main/java/me/n1ar4/clazz/obfuscator/core/Runner.java b/src/main/java/me/n1ar4/clazz/obfuscator/core/Runner.java index d159b27..4ae716a 100644 --- a/src/main/java/me/n1ar4/clazz/obfuscator/core/Runner.java +++ b/src/main/java/me/n1ar4/clazz/obfuscator/core/Runner.java @@ -33,13 +33,15 @@ private static void addClass(Path path) { } public static void run(Path path, BaseConfig config) { - // 输出配置信息 - System.out.println( - ColorUtil.blue("######################## OBFUSCATE CONFIG ########################")); ObfEnv.config = config; - config.show(); - System.out.println( - ColorUtil.blue("##################################################################")); + if (!config.isQuiet()) { + // 输出配置信息 + System.out.println( + ColorUtil.blue("######################## OBFUSCATE CONFIG ########################")); + config.show(); + System.out.println( + ColorUtil.blue("##################################################################")); + } String fileName = FileUtil.getFileNameWithoutExt(path); String newFile = fileName + "_obf.class"; @@ -156,45 +158,45 @@ public static void run(Path path, BaseConfig config) { ArrayList newRes = new ArrayList<>(t); ObfEnv.newStringInClass.put(e.getKey().getName(), newRes); logger.info("build string mapping finish"); - - System.out.println( - ColorUtil.blue("######################### ANALYSIS DATA #########################")); - System.out.println(ColorUtil.green("AnalyzeEnv.classFileList -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.classFileList.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.discoveredClasses -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.discoveredClasses.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.discoveredMethods -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.discoveredMethods.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.methodsInClassMap -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.methodsInClassMap.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.methodCalls -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.methodCalls.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.classMap -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.classMap.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.methodMap -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.methodMap.size()))); - System.out.println(ColorUtil.green("AnalyzeEnv.fieldsInClassMap -> ") + - ColorUtil.red(String.valueOf(AnalyzeEnv.fieldsInClassMap.size()))); - System.out.println( - ColorUtil.blue("#################################################################")); - + if (!config.isQuiet()) { + System.out.println( + ColorUtil.blue("######################### ANALYSIS DATA #########################")); + System.out.println(ColorUtil.green("AnalyzeEnv.classFileList -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.classFileList.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.discoveredClasses -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.discoveredClasses.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.discoveredMethods -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.discoveredMethods.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.methodsInClassMap -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.methodsInClassMap.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.methodCalls -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.methodCalls.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.classMap -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.classMap.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.methodMap -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.methodMap.size()))); + System.out.println(ColorUtil.green("AnalyzeEnv.fieldsInClassMap -> ") + + ColorUtil.red(String.valueOf(AnalyzeEnv.fieldsInClassMap.size()))); + System.out.println( + ColorUtil.blue("#################################################################")); + } logger.info("build obfuscate data finish"); - - System.out.println( - ColorUtil.blue("######################### OBFUSCATE DATA #########################")); - System.out.println(ColorUtil.green("ObfEnv.ADVANCE_STRING_NAME -> ") + - ColorUtil.red(String.valueOf(ObfEnv.ADVANCE_STRING_NAME))); - System.out.println(ColorUtil.green("ObfEnv.methodNameObfMapping -> ") + - ColorUtil.red(String.valueOf(ObfEnv.methodNameObfMapping.size()))); - System.out.println(ColorUtil.green("ObfEnv.fieldNameObfMapping -> ") + - ColorUtil.red(String.valueOf(ObfEnv.fieldNameObfMapping.size()))); - System.out.println(ColorUtil.green("ObfEnv.stringInClass -> ") + - ColorUtil.red(String.valueOf(ObfEnv.stringInClass.size()))); - System.out.println(ColorUtil.green("ObfEnv.newStringInClass -> ") + - ColorUtil.red(String.valueOf(ObfEnv.newStringInClass.size()))); - System.out.println( - ColorUtil.blue("#################################################################")); - + if (!config.isQuiet()) { + System.out.println( + ColorUtil.blue("######################### OBFUSCATE DATA #########################")); + System.out.println(ColorUtil.green("ObfEnv.ADVANCE_STRING_NAME -> ") + + ColorUtil.red(String.valueOf(ObfEnv.ADVANCE_STRING_NAME))); + System.out.println(ColorUtil.green("ObfEnv.methodNameObfMapping -> ") + + ColorUtil.red(String.valueOf(ObfEnv.methodNameObfMapping.size()))); + System.out.println(ColorUtil.green("ObfEnv.fieldNameObfMapping -> ") + + ColorUtil.red(String.valueOf(ObfEnv.fieldNameObfMapping.size()))); + System.out.println(ColorUtil.green("ObfEnv.stringInClass -> ") + + ColorUtil.red(String.valueOf(ObfEnv.stringInClass.size()))); + System.out.println(ColorUtil.green("ObfEnv.newStringInClass -> ") + + ColorUtil.red(String.valueOf(ObfEnv.newStringInClass.size()))); + System.out.println( + ColorUtil.blue("#################################################################")); + } if (config.isEnableDeleteCompileInfo()) { DeleteInfoTransformer.transform(); logger.info("run delete info transformer finish"); @@ -237,9 +239,10 @@ public static void run(Path path, BaseConfig config) { JunkCodeTransformer.transform(config); logger.info("run junk transformer finish"); } - - System.out.println( - ColorUtil.blue("###################### ALL OBFUSCATE FINISH ######################")); + if (!config.isQuiet()) { + System.out.println( + ColorUtil.blue("###################### ALL OBFUSCATE FINISH ######################")); + } try { Files.write(Paths.get(newFile), Files.readAllBytes(Const.TEMP_PATH)); diff --git a/src/main/resources/config.yaml b/src/main/resources/config.yaml index 048956d..738e450 100644 --- a/src/main/resources/config.yaml +++ b/src/main/resources/config.yaml @@ -1,6 +1,8 @@ !!me.n1ar4.clazz.obfuscator.config.BaseConfig # 日志级别 logLevel: info +# 是否使用安静模式(不打印调试信息) +quiet: false # 是否启动 JAVA ASM 的 COMPUTE FRAMES/MAX 自动计算 # 如果遇到 TYPE * NOT PRESENT 报错可以尝试设置该选项为 FALSE asmAutoCompute: true