Skip to content

Commit 92ccbe8

Browse files
committed
fix: Remove more exception obfuscation
1 parent 25ba8d2 commit 92ccbe8

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/main/java/rs/lostcity/deob/bytecode/transform/openrs2/ExceptionObfuscationTransformer.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import rs.lostcity.asm.transform.Transformer;
88

99
import java.util.List;
10+
import java.util.Objects;
1011

1112
/**
1213
* A [Transformer] responsible for removing [ZKM](http://www.zelix.com/klassmaster/)'s
@@ -26,19 +27,25 @@ public void preTransform(List<ClassNode> classes) {
2627
@Override
2728
public boolean transformCode(List<ClassNode> classes, ClassNode clazz, MethodNode method) {
2829
for (var insn : method.instructions) {
29-
if (insn.getOpcode() != Opcodes.ATHROW) {
30-
continue;
31-
}
32-
33-
var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch ->
34-
InsnNodeUtil.getNextReal(tryCatch.handler).equals(insn));
35-
36-
if (foundTryCatch) {
37-
method.instructions.remove(insn);
38-
handlers++;
30+
if (insn.getOpcode() == Opcodes.ATHROW) {
31+
// redundant throw
32+
var foundTryCatch = method.tryCatchBlocks.removeIf(tryCatch ->
33+
InsnNodeUtil.getNextReal(tryCatch.handler).equals(insn));
34+
35+
if (foundTryCatch) {
36+
method.instructions.remove(insn);
37+
handlers++;
38+
}
3939
}
4040
}
4141

42+
int before = method.tryCatchBlocks.size();
43+
// todo: this may result in synchronized blocks going unused
44+
method.tryCatchBlocks.removeIf(tryCatch -> tryCatch.type == null);
45+
// todo: confirm this is fine, early clients don't need throwable for any legitimate use
46+
method.tryCatchBlocks.removeIf(tryCatch -> Objects.equals(tryCatch.type, "java/lang/Throwable"));
47+
handlers += before - method.tryCatchBlocks.size();
48+
4249
return false;
4350
}
4451

0 commit comments

Comments
 (0)