Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit 9c73543

Browse files
committed
[优化] 不应该对接口和枚举等类型进行花指令
1 parent 54fd6a3 commit 9c73543

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [功能] 花指令数添加简单的控制流
88
- [功能] 花指令从单 `int` 类型拓展到更多
99
- [功能] 花指令支持添加无意义的垃圾方法
10+
- [优化] 不应该对接口和枚举等类型进行花指令
1011
- [优化] 优化命令行输出的信息
1112
- [其他]`CI` 增加 `Gitleaks` 检查
1213
- [其他] 提供 `Dockerfile` 和构建脚本

src/main/java/me/n1ar4/jar/obfuscator/asm/JunkCodeChanger.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,34 @@ public class JunkCodeChanger extends ClassVisitor {
1515
public static int MAX_JUNK_NUM = 1000;
1616
public static int JUNK_NUM = 0;
1717
private final BaseConfig config;
18+
private boolean shouldSkip;
1819

1920
public JunkCodeChanger(ClassVisitor classVisitor, BaseConfig config) {
2021
super(Const.ASMVersion, classVisitor);
2122
JUNK_NUM = 0;
2223
this.config = config;
24+
this.shouldSkip = false;
2325
}
2426

2527
@Override
2628
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
2729
super.visit(version, access, name, signature, superName, interfaces);
30+
boolean isAbstract = (access & Opcodes.ACC_ABSTRACT) != 0;
31+
boolean isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
32+
boolean isEnum = (access & Opcodes.ACC_ENUM) != 0;
33+
if (isAbstract || isInterface || isEnum) {
34+
shouldSkip = true;
35+
}
2836
}
2937

3038
@Override
3139
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
3240
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
33-
return new JunkChangerMethodAdapter(mv, this.config);
41+
if (shouldSkip) {
42+
return mv;
43+
} else {
44+
return new JunkChangerMethodAdapter(mv, this.config);
45+
}
3446
}
3547

3648
@Override
@@ -66,7 +78,7 @@ public void visitAttribute(Attribute attribute) {
6678
@Override
6779
public void visitEnd() {
6880
// 添加无意义的代码
69-
if (config.getJunkLevel() > 2) {
81+
if (!shouldSkip && config.getJunkLevel() > 2) {
7082
JunkUtil.addHttpCode(cv);
7183
JunkUtil.addPrintMethod(cv);
7284
}

0 commit comments

Comments
 (0)