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

Commit

Permalink
CODE FORMAT
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Jun 26, 2024
1 parent 59d6539 commit 9a97ae3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> methodBlackList;
private final List<MethodReference> ignoreMethods = new ArrayList<>();
private final List<String> ignoreMethodString = new ArrayList<>();

public MethodNameChanger(ClassVisitor classVisitor) {
super(Const.ASMVersion, classVisitor);
this.methodBlackList = Arrays.asList(ObfEnv.config.getMethodBlackList());
}

@Override
Expand Down
61 changes: 30 additions & 31 deletions src/main/java/me/n1ar4/jar/obfuscator/core/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/n1ar4/jar/obfuscator/utils/NameUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public static String genPackage() {
public static String genWithSet(HashSet<String> 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;
Expand All @@ -50,10 +50,10 @@ public static String genWithSet(HashSet<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class PackageUtil {
private static final List<String> internalList = new ArrayList<>();

public static void buildInternalBlackList() {
// JNI 的 CLASS 默认加到黑名单里面
for (Map.Entry<ClassReference.Handle, List<MethodReference>> entry :
Expand Down

0 comments on commit 9a97ae3

Please sign in to comment.