|
1 | 1 | package uwu.narumi.deobfuscator.core.other.impl.skidfuscator; |
2 | 2 |
|
3 | | -import org.objectweb.asm.tree.AbstractInsnNode; |
4 | | -import org.objectweb.asm.tree.LabelNode; |
5 | | -import org.objectweb.asm.tree.MethodNode; |
6 | | -import org.objectweb.asm.tree.TryCatchBlockNode; |
| 3 | +import org.objectweb.asm.tree.*; |
7 | 4 | import uwu.narumi.deobfuscator.api.asm.ClassWrapper; |
8 | 5 | import uwu.narumi.deobfuscator.api.asm.MethodContext; |
9 | 6 | import uwu.narumi.deobfuscator.api.asm.matcher.Match; |
@@ -59,37 +56,40 @@ public void resolveFakeTcb(ClassWrapper classWrapper, MethodNode methodNode) { |
59 | 56 | Set<TryCatchBlockNode> tcbToRemove = new HashSet<>(); |
60 | 57 | Set<AbstractInsnNode> toRemove = new HashSet<>(); |
61 | 58 | methodNode.tryCatchBlocks.forEach(tcb -> { |
62 | | - if (tcb.handler.equals(tcb.end)) { |
63 | | - /* Checking if start block has throw null */ |
64 | | - SequenceMatch.of( |
65 | | - AnyMatch.of(OpcodeMatch.of(ILOAD), OpcodeMatch.of(LDC)).and(Match.of(ctx -> isInsnInLabelRange(methodNode, tcb.start, ctx.insn()))), |
66 | | - MethodMatch.invokeStatic(), |
67 | | - OpcodeMatch.of(LDC), |
68 | | - JumpMatch.of().capture("throw-label"), |
69 | | - OpcodeMatch.of(ACONST_NULL), |
70 | | - OpcodeMatch.of(ATHROW) |
71 | | - ).findAny(methodContext).ifPresent(matchContext -> { |
72 | | - /* Clearing "else" block which throws exception */ |
73 | | - toRemove.addAll(matchContext.collectedInsns()); |
74 | | - LabelNode fakeJump = matchContext.captures().get("throw-label").insn().asJump().label; |
| 59 | + /* Checking if start block has throw null */ |
| 60 | + SequenceMatch.of( |
| 61 | + AnyMatch.of(OpcodeMatch.of(ILOAD), OpcodeMatch.of(LDC)).and(Match.of(ctx -> isInsnInLabelRange(methodNode, tcb.start, ctx.insn()))), |
| 62 | + MethodMatch.invokeStatic(), |
| 63 | + OpcodeMatch.of(LDC), |
| 64 | + JumpMatch.of().capture("throw-label"), |
| 65 | + OpcodeMatch.of(ACONST_NULL), |
| 66 | + OpcodeMatch.of(ATHROW) |
| 67 | + ).or( |
75 | 68 | SequenceMatch.of( |
76 | | - OpcodeMatch.of(NEW).and(Match.of(ctx -> isInsnInLabelRange(methodNode, fakeJump, ctx.insn()))), |
| 69 | + OpcodeMatch.of(NEW).and(Match.of(ctx -> isInsnInLabelRange(methodNode, tcb.start, ctx.insn()))), |
77 | 70 | OpcodeMatch.of(DUP), |
78 | 71 | MethodMatch.invokeSpecial(), |
79 | 72 | OpcodeMatch.of(ATHROW) |
80 | | - ).findAny(methodContext).ifPresent(matchContext1 -> { |
81 | | - toRemove.addAll(matchContext1.collectedInsns()); |
82 | | - }); |
| 73 | + ) |
| 74 | + ).findAny(methodContext).ifPresent(matchContext -> { |
| 75 | + /* Clearing "else" block which throws exception */ |
| 76 | + toRemove.addAll(matchContext.collectedInsns()); |
| 77 | + LabelNode fakeJump; |
| 78 | + if (matchContext.captures().containsKey("throw-label")) { |
| 79 | + fakeJump = matchContext.captures().get("throw-label").insn().asJump().label; |
83 | 80 | toRemove.add(fakeJump); |
84 | | - AbstractInsnNode abstractInsnNode = fakeJump; |
85 | | - while (abstractInsnNode.getNext() != null && abstractInsnNode.getOpcode() != POP) { |
86 | | - abstractInsnNode = abstractInsnNode.getNext(); |
87 | | - } |
88 | | - toRemove.add(abstractInsnNode); |
89 | | - tcbToRemove.add(tcb); |
90 | | - markChange(); |
91 | | - }); |
92 | | - } |
| 81 | + } else { |
| 82 | + fakeJump = tcb.handler; |
| 83 | + } |
| 84 | + AbstractInsnNode abstractInsnNode = fakeJump; |
| 85 | + while (abstractInsnNode.getNext() != null && abstractInsnNode.getOpcode() != POP) { |
| 86 | + abstractInsnNode = abstractInsnNode.getNext(); |
| 87 | + } |
| 88 | + toRemove.add(abstractInsnNode); |
| 89 | + tcbToRemove.add(tcb); |
| 90 | + methodNode.instructions.insert(tcb.start, new JumpInsnNode(GOTO, tcb.handler)); |
| 91 | + markChange(); |
| 92 | + }); |
93 | 93 | }); |
94 | 94 | toRemove.forEach(methodNode.instructions::remove); |
95 | 95 | methodNode.tryCatchBlocks.removeAll(tcbToRemove); |
|
0 commit comments