Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Dec 17, 2024
1 parent bfc756a commit e606933
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

- [BUG] 修复之前版本参数混淆功能实际没有生效
- [优化] 优化 `AES KEY` 提到全局变量并支持配置
- [优化] 允许混淆 `main` 方法但默认在方法黑名单中
- [优化] 配置文件支持关闭某些 `ASM` 选项提高兼容性
- [优化] 启动前检查各种配置参数是否合法有错误退出

感谢以下用户的贡献:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ enableMethodName: true
# 全局方法黑名单
# 该方法不会进行混淆 引用也不会被修改
methodBlackList:
- "test"
- "main"

# 是否开启字段混淆
enableFieldName: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
}
}

if ("main".equals(name) && desc.equals("([Ljava/lang/String;)V") && access == 9) {
mv = super.visitMethod(access, name, desc, signature, exceptions);
} else if (name.equals("<init>") || name.equals("<clinit>")) {
if (name.equals("<init>") || name.equals("<clinit>")) {
mv = super.visitMethod(access, name, desc, signature, exceptions);
} else {
MethodReference.Handle m = ObfEnv.methodNameObfMapping.get(new MethodReference.Handle(
Expand Down
42 changes: 42 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 @@ -32,6 +32,48 @@ public class BaseConfig {
private String[] obfuscateChars;
private String[] methodBlackList;

/**
* 如果配置没问题可以启动就返回 true
*
* @return true/false
*/
public boolean isValid() {
if (logLevel == null || logLevel.trim().isEmpty()) {
System.out.println(ColorUtil.red("[ERROR] log level is null"));
return false;
}
if (advanceStringName == null || advanceStringName.trim().isEmpty()) {
System.out.println(ColorUtil.red("[ERROR] advance string name is null"));
return false;
}
if (aesKey == null || aesKey.trim().isEmpty()) {
System.out.println(ColorUtil.red("[ERROR] aes key is null"));
return false;
}
if (aesDecName == null || aesDecName.trim().isEmpty()) {
System.out.println(ColorUtil.red("[ERROR] aes dec name is null"));
return false;
}
if (aesKeyField == null || aesKeyField.trim().isEmpty()) {
System.out.println(ColorUtil.red("[ERROR] aes key field is null"));
return false;
}
if (obfuscateChars == null || obfuscateChars.length == 0) {
System.out.println(ColorUtil.red("[ERROR] obfuscate chars is null"));
return false;
}
// methodBlackList 允许是空
if (junkLevel < 1 || junkLevel > 5) {
System.out.println(ColorUtil.red("[ERROR] junk level must be between 1 and 5"));
return false;
}
if (maxJunkOneClass < 1 || maxJunkOneClass > 10000) {
System.out.println(ColorUtil.red("[ERROR] max junk must be between 1 and 10000"));
return false;
}
return true;
}

public static BaseConfig Default() {
BaseConfig config = new BaseConfig();
config.setAsmAutoCompute(true);
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 @@ -15,6 +15,10 @@ public static boolean initConfig(BaseConfig config) {
JRandom random = new JRandom();
JRandom.setInstance(random);

if (!config.isValid()) {
return false;
}

// LOG LEVEL
String logLevel = config.getLogLevel();
switch (logLevel) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enableMethodName: true
# 全局方法黑名单
# 该方法不会进行混淆 引用也不会被修改
methodBlackList:
- "test"
- "main"

# 是否开启字段混淆
enableFieldName: true
Expand Down

0 comments on commit e606933

Please sign in to comment.