Skip to content

Commit

Permalink
[功能] 新增 quiet 配置参数不打印调试信息 @4ra1n
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Dec 19, 2024
1 parent 9fd5ff5 commit 7b05ac1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
更新日志:

- [功能] 支持新配置参数忽略 `public` 方法的混淆 @4ra1n
- [功能] 新增 `quiet` 配置参数不打印调试信息 @4ra1n

感谢以下用户的贡献:

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- 配置大幅简化,仅针对单个 `Class` 文件
- 命令行输出改善,详细展示混淆细节
- 你可以只混淆你项目的核心类替换即可(方便快速)
- 提供了多种方式的 `API` 调用

## 快速开始

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/n1ar4/clazz/obfuscator/config/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
public class BaseConfig {
private String logLevel;

private boolean quiet;

private boolean asmAutoCompute;

private boolean enableFieldName;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/n1ar4/clazz/obfuscator/config/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
97 changes: 50 additions & 47 deletions src/main/java/me/n1ar4/clazz/obfuscator/core/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -156,45 +158,45 @@ public static void run(Path path, BaseConfig config) {
ArrayList<String> 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");
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7b05ac1

Please sign in to comment.