Skip to content

Commit 0f04b22

Browse files
committed
Better Try-Catch handling for aggresive nested FlowException
1 parent c6264ca commit 0f04b22

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

deobfuscator-transformers/src/main/java/uwu/narumi/deobfuscator/core/other/impl/skidfuscator/SkidTryCatchRemoveTransformer.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package uwu.narumi.deobfuscator.core.other.impl.skidfuscator;
22

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.*;
74
import uwu.narumi.deobfuscator.api.asm.ClassWrapper;
85
import uwu.narumi.deobfuscator.api.asm.MethodContext;
96
import uwu.narumi.deobfuscator.api.asm.matcher.Match;
@@ -59,37 +56,40 @@ public void resolveFakeTcb(ClassWrapper classWrapper, MethodNode methodNode) {
5956
Set<TryCatchBlockNode> tcbToRemove = new HashSet<>();
6057
Set<AbstractInsnNode> toRemove = new HashSet<>();
6158
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(
7568
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()))),
7770
OpcodeMatch.of(DUP),
7871
MethodMatch.invokeSpecial(),
7972
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;
8380
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+
});
9393
});
9494
toRemove.forEach(methodNode.instructions::remove);
9595
methodNode.tryCatchBlocks.removeAll(tcbToRemove);

0 commit comments

Comments
 (0)