Skip to content

Commit

Permalink
[功能] 支持新配置参数忽略 public 方法的混淆
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Dec 19, 2024
1 parent 699bc88 commit b13aa66
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

更新日志:

- todo
- [功能] 支持新配置参数忽略 `public` 方法的混淆 @4ra1n

感谢以下用户的贡献:

- 4ra1n (https://github.com/4ra1n)
- lz520520 (https://github.com/lz520520)

可供下载的文件都由 `Github Actions` 构建,使用 `java -jar class-obf.jar` 启动

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ enableDeleteCompileInfo: true
# 是否开启方法名混淆
# 这里会自动修改方法之间的引用
enableMethodName: true
# 一般 public 方法是被外部调用的
# 可以设置该选项为 true 来跳过 public 方法混淆
ignorePublic: false
# 全局方法黑名单
# 该方法不会进行混淆 引用也不会被修改
methodBlackList:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public class MethodNameChanger extends ClassVisitor {
private String owner;
private final List<MethodReference> ignoreMethods = new ArrayList<>();
private final List<String> ignoreMethodString = new ArrayList<>();

public MethodNameChanger(ClassVisitor classVisitor) {
super(Const.ASMVersion, classVisitor);
Expand Down Expand Up @@ -44,8 +43,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
}
}

for (String method : this.ignoreMethodString) {
if (method.equals(name)) {
// 2024/12/19 允许跳过 public 方法
if ((access & Opcodes.ACC_PUBLIC) != 0) {
if (ObfEnv.config.isIgnorePublic()) {
return super.visitMethod(access, name, desc, signature, exceptions);
}
}
Expand Down
13 changes: 13 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 @@ -26,6 +26,8 @@ public class BaseConfig {
private int junkLevel;
private int maxJunkOneClass;

private boolean ignorePublic;

private String aesKey;
private String aesDecName;
private String aesKeyField;
Expand Down Expand Up @@ -92,6 +94,7 @@ public static BaseConfig Default() {
config.setEnableDeleteCompileInfo(true);
config.setEnableParamName(true);
config.setEnableMethodName(true);
config.setIgnorePublic(false);
// 默认花指令配置
config.setEnableJunk(true);
config.setJunkLevel(3);
Expand All @@ -118,6 +121,8 @@ public void show() {
ColorUtil.green(String.valueOf(enableFieldName)));
System.out.println(ColorUtil.yellow("Enable Method Name Obfuscate -> ") +
ColorUtil.green(String.valueOf(enableMethodName)));
System.out.println(ColorUtil.yellow("Ignore Public Method -> ") +
ColorUtil.green(String.valueOf(ignorePublic)));
System.out.println(ColorUtil.yellow("Enable Param Name Obfuscate -> ") +
ColorUtil.green(String.valueOf(enableParamName)));
System.out.println(ColorUtil.yellow("Enable Hide Method Obfuscate -> ") +
Expand Down Expand Up @@ -146,6 +151,14 @@ public void show() {
ColorUtil.green(String.valueOf(maxJunkOneClass)));
}

public boolean isIgnorePublic() {
return ignorePublic;
}

public void setIgnorePublic(boolean ignorePublic) {
this.ignorePublic = ignorePublic;
}

public String getAesKeyField() {
return aesKeyField;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ enableDeleteCompileInfo: true
# 是否开启方法名混淆
# 这里会自动修改方法之间的引用
enableMethodName: true
# 一般 public 方法是被外部调用的
# 可以设置该选项为 true 来跳过 public 方法混淆
ignorePublic: false
# 全局方法黑名单
# 该方法不会进行混淆 引用也不会被修改
methodBlackList:
Expand Down

0 comments on commit b13aa66

Please sign in to comment.