Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
[功能] 类黑名单新增正则配置 classBlackRegexList
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Jun 26, 2024
1 parent 9a97ae3 commit 23a4426
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
更新日志:

- [功能] 支持配置随机数来源为 `CPU``RDRAND` 指令
- [功能] 类黑名单新增正则配置 `classBlackRegexList`
- [功能] 对于错误和默认的 `AES KEY` 配置自动生成随机的
- [BUG] 不应该对 `JNI` 类进行混淆
- [BUG] 处理错误配置文件可能导致的异常

感谢以下用户的贡献:

Expand Down
19 changes: 14 additions & 5 deletions src/main/java/me/n1ar4/jar/obfuscator/config/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class BaseConfig {
private String[] obfuscateChars;
private String[] methodBlackList;
private String[] classBlackList;
private String[] classBlackRegexList;
private String[] rootPackages;
private String mainClass;
private boolean modifyManifest;
Expand All @@ -45,6 +46,14 @@ public class BaseConfig {

private boolean useCpuRDRAND;

public String[] getClassBlackRegexList() {
return classBlackRegexList != null ? classBlackRegexList : new String[0];
}

public void setClassBlackRegexList(String[] classBlackRegexList) {
this.classBlackRegexList = classBlackRegexList;
}

public boolean isUseCpuRDRAND() {
return useCpuRDRAND;
}
Expand Down Expand Up @@ -94,15 +103,15 @@ public void setDecryptMethodName(String decryptMethodName) {
}

public String[] getRootPackages() {
return rootPackages;
return rootPackages!=null ? rootPackages : new String[0];
}

public void setRootPackages(String[] rootPackages) {
this.rootPackages = rootPackages;
}

public String[] getClassBlackList() {
return classBlackList;
return classBlackList != null ? classBlackList : new String[0];
}

public void setClassBlackList(String[] classBlackList) {
Expand All @@ -126,7 +135,7 @@ public void setStringAesKey(String stringAesKey) {
}

public String[] getMethodBlackList() {
return methodBlackList;
return methodBlackList!=null ? methodBlackList : new String[0];
}

public void setMethodBlackList(String[] methodBlackList) {
Expand Down Expand Up @@ -288,15 +297,15 @@ public void setMaxJunkOneClass(int maxJunkOneClass) {
}

public String[] getObfuscatePackage() {
return obfuscatePackage;
return obfuscatePackage!=null ? obfuscatePackage : new String[0];
}

public void setObfuscatePackage(String[] obfuscatePackage) {
this.obfuscatePackage = obfuscatePackage;
}

public String[] getObfuscateChars() {
return obfuscateChars;
return obfuscateChars!=null ? obfuscateChars : new String[0];
}

public void setObfuscateChars(String[] obfuscateChars) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/n1ar4/jar/obfuscator/utils/PackageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PackageUtil {
private static final List<String> internalList = new ArrayList<>();
Expand Down Expand Up @@ -48,6 +50,14 @@ public static boolean inBlackClass(String className, BaseConfig config) {
return true;
}
}
for (String s : config.getClassBlackRegexList()) {
className = className.replace(".", "/");
Pattern pattern = Pattern.compile(s, Pattern.DOTALL);
Matcher matcher = pattern.matcher(className);
if (matcher.matches()) {
return true;
}
}
for (String s : internalList) {
s = s.replace(".", "/");
if (className.equals(s)) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ rootPackages: [ me.n1ar4, org.n1ar4 ]
# 不对某些类做混淆(不混淆其中的所有内容)
# 例如反射调用/JAVAFX FXML绑定等情况
classBlackList: [ javafx.controller.DemoController ]
# 不对指定正则的类进行混淆
# 注意这里的类名匹配是 java/lang/String 而不是 java.lang.String
# 该配置和 classBlackList 同时生效
classBlackRegexList: [ java/.*, com/intellij/.* ]
# 不对某些 method 名做混淆 正则
# visit.* 忽略 JAVA ASM 的 visitCode visitMethod 等方法
# start.* 忽略 JAVAFX 因为启动基于 start 方法
Expand Down

0 comments on commit 23a4426

Please sign in to comment.