From 9a97ae3c81e93722e2be9d4fc1f700ea5850c20a Mon Sep 17 00:00:00 2001 From: 4ra1n <2023503307@qq.com> Date: Thu, 27 Jun 2024 01:19:37 +0800 Subject: [PATCH] CODE FORMAT --- .../jar/obfuscator/asm/MethodNameChanger.java | 3 - .../me/n1ar4/jar/obfuscator/core/Runner.java | 61 +++++++++---------- .../n1ar4/jar/obfuscator/utils/NameUtil.java | 8 +-- .../jar/obfuscator/utils/PackageUtil.java | 1 + 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/main/java/me/n1ar4/jar/obfuscator/asm/MethodNameChanger.java b/src/main/java/me/n1ar4/jar/obfuscator/asm/MethodNameChanger.java index e791d9e..9d44b78 100644 --- a/src/main/java/me/n1ar4/jar/obfuscator/asm/MethodNameChanger.java +++ b/src/main/java/me/n1ar4/jar/obfuscator/asm/MethodNameChanger.java @@ -8,20 +8,17 @@ import org.objectweb.asm.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @SuppressWarnings("all") public class MethodNameChanger extends ClassVisitor { private String owner; - private final List methodBlackList; private final List ignoreMethods = new ArrayList<>(); private final List ignoreMethodString = new ArrayList<>(); public MethodNameChanger(ClassVisitor classVisitor) { super(Const.ASMVersion, classVisitor); - this.methodBlackList = Arrays.asList(ObfEnv.config.getMethodBlackList()); } @Override diff --git a/src/main/java/me/n1ar4/jar/obfuscator/core/Runner.java b/src/main/java/me/n1ar4/jar/obfuscator/core/Runner.java index 4ee5f53..63782d7 100644 --- a/src/main/java/me/n1ar4/jar/obfuscator/core/Runner.java +++ b/src/main/java/me/n1ar4/jar/obfuscator/core/Runner.java @@ -14,7 +14,6 @@ import me.n1ar4.jar.obfuscator.utils.*; import me.n1ar4.log.LogManager; import me.n1ar4.log.Logger; -import me.n1ar4.log.LoggingStream; import java.io.File; import java.io.IOException; @@ -133,44 +132,44 @@ public static void run(Path path, BaseConfig config) { } else { newPackageNameS = packageNameS; } - + // 修复 enableClassName: false & enablePackageName: true 时混淆未正确生效 BUG String originalName = c.getName(); String finalName = originalName; - + boolean notInWhiteList = PackageUtil.notInWhiteList(packageNameS, config); boolean inBlackClass = PackageUtil.inBlackClass(originalName, config); boolean inRootPackage = PackageUtil.inRootPackage(originalName, config); if (!(notInWhiteList || inBlackClass) || inRootPackage) { - String result = ObfEnv.classNameObfMapping.putIfAbsent(originalName, originalName); - if (result == null) { - boolean isEnablePackageName = config.isEnablePackageName(); - boolean isEnableClassName = config.isEnableClassName(); - if (!inBlackClass && (isEnablePackageName || isEnableClassName)) { - String finalPackageName = packageNameS; - if (isEnablePackageName) { - finalPackageName = newPackageNameS; - } - if (isEnableClassName) { - if (className.contains("$")) { - String outerClassName = originalName.split("\\$")[0]; - String exist = ObfEnv.classNameObfMapping.get(outerClassName); - if (exist == null) { - exist = finalPackageName + "/" + NameUtil.genNewName(); - ObfEnv.classNameObfMapping.put(outerClassName, exist); - } - finalName = exist + "$" + NameUtil.genNewName(); - } else { - finalName = finalPackageName + "/" + NameUtil.genNewName(); - } - } else { - finalName = finalPackageName + "/" + className; - } - ObfEnv.classNameObfMapping.put(originalName, finalName); - } - } + String result = ObfEnv.classNameObfMapping.putIfAbsent(originalName, originalName); + if (result == null) { + boolean isEnablePackageName = config.isEnablePackageName(); + boolean isEnableClassName = config.isEnableClassName(); + if (!inBlackClass && (isEnablePackageName || isEnableClassName)) { + String finalPackageName = packageNameS; + if (isEnablePackageName) { + finalPackageName = newPackageNameS; + } + if (isEnableClassName) { + if (className.contains("$")) { + String outerClassName = originalName.split("\\$")[0]; + String exist = ObfEnv.classNameObfMapping.get(outerClassName); + if (exist == null) { + exist = finalPackageName + "/" + NameUtil.genNewName(); + ObfEnv.classNameObfMapping.put(outerClassName, exist); + } + finalName = exist + "$" + NameUtil.genNewName(); + } else { + finalName = finalPackageName + "/" + NameUtil.genNewName(); + } + } else { + finalName = finalPackageName + "/" + className; + } + ObfEnv.classNameObfMapping.put(originalName, finalName); + } + } } - + if (originalName.equals(ObfEnv.MAIN_CLASS)) { ObfEnv.NEW_MAIN_CLASS = finalName.replace("/", "."); logger.info("new main: {}", ObfEnv.NEW_MAIN_CLASS); diff --git a/src/main/java/me/n1ar4/jar/obfuscator/utils/NameUtil.java b/src/main/java/me/n1ar4/jar/obfuscator/utils/NameUtil.java index 42c0f84..2f02149 100644 --- a/src/main/java/me/n1ar4/jar/obfuscator/utils/NameUtil.java +++ b/src/main/java/me/n1ar4/jar/obfuscator/utils/NameUtil.java @@ -31,10 +31,10 @@ public static String genPackage() { public static String genWithSet(HashSet exists) { JRandom random = JRandom.getInstance(); while (true) { - int length = 10 + random.getInt(0,3); + int length = 10 + random.getInt(0, 3); StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { - sb.append(CHAR_POOL[random.getInt(0,CHAR_POOL.length)]); + sb.append(CHAR_POOL[random.getInt(0, CHAR_POOL.length)]); } if (sb.charAt(0) == '~' || sb.charAt(0) == '1') { continue; @@ -50,10 +50,10 @@ public static String genWithSet(HashSet exists) { private static String genBase(int op) { JRandom random = JRandom.getInstance(); while (true) { - int length = 10 + random.getInt(0,3); + int length = 10 + random.getInt(0, 3); StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { - sb.append(CHAR_POOL[random.getInt(0,CHAR_POOL.length)]); + sb.append(CHAR_POOL[random.getInt(0, CHAR_POOL.length)]); } if (sb.charAt(0) == '~' || sb.charAt(0) == '1') { continue; diff --git a/src/main/java/me/n1ar4/jar/obfuscator/utils/PackageUtil.java b/src/main/java/me/n1ar4/jar/obfuscator/utils/PackageUtil.java index a37435a..a1524d2 100644 --- a/src/main/java/me/n1ar4/jar/obfuscator/utils/PackageUtil.java +++ b/src/main/java/me/n1ar4/jar/obfuscator/utils/PackageUtil.java @@ -12,6 +12,7 @@ public class PackageUtil { private static final List internalList = new ArrayList<>(); + public static void buildInternalBlackList() { // JNI 的 CLASS 默认加到黑名单里面 for (Map.Entry> entry :