-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more improvements to zelix deobfuscation
- Loading branch information
1 parent
68b85b8
commit b2891c8
Showing
11 changed files
with
492 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/asm/MethodRef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package uwu.narumi.deobfuscator.api.asm; | ||
|
||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
/** | ||
* @param owner Class that owns this method | ||
* @param name Method's name | ||
* @param desc Method's descriptor | ||
*/ | ||
public record MethodRef(String owner, String name, String desc) { | ||
public static MethodRef of(ClassNode classNode, MethodNode methodNode) { | ||
return new MethodRef(classNode.name, methodNode.name, methodNode.desc); | ||
} | ||
|
||
public static MethodRef of(MethodInsnNode methodInsn) { | ||
return new MethodRef(methodInsn.owner, methodInsn.name, methodInsn.desc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...a/uwu/narumi/deobfuscator/core/other/impl/zkm/ZelixUselessTryCatchRemoverTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package uwu.narumi.deobfuscator.core.other.impl.zkm; | ||
|
||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import uwu.narumi.deobfuscator.api.asm.ClassWrapper; | ||
import uwu.narumi.deobfuscator.api.asm.InstructionContext; | ||
import uwu.narumi.deobfuscator.api.asm.MethodContext; | ||
import uwu.narumi.deobfuscator.api.asm.MethodRef; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.Match; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.group.SequenceMatch; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.impl.MethodMatch; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.impl.OpcodeMatch; | ||
import uwu.narumi.deobfuscator.api.context.Context; | ||
import uwu.narumi.deobfuscator.api.transformer.Transformer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Removes useless try catches | ||
* <pre> | ||
* {@code | ||
* try { | ||
* ... | ||
* } catch (PacketEventsLoadFailureException packetEventsLoadFailureException) { | ||
* throw PacketEvents.a(packetEventsLoadFailureException); | ||
* } | ||
* | ||
* // Self return | ||
* private static Exception a(Exception exception) { | ||
* return exception; | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public class ZelixUselessTryCatchRemoverTransformer extends Transformer { | ||
private static final Match INSTANT_RETURN_EXCEPTION = | ||
SequenceMatch.of( | ||
OpcodeMatch.of(ALOAD), | ||
OpcodeMatch.of(ARETURN) | ||
); | ||
|
||
@Override | ||
protected void transform(ClassWrapper scope, Context context) throws Exception { | ||
context.classes(scope).forEach(classWrapper -> { | ||
List<MethodRef> instantReturnExceptionMethods = new ArrayList<>(); | ||
|
||
// Find methods that instantly returns an exception | ||
classWrapper.methods().forEach(methodNode -> { | ||
MethodContext framelessContext = MethodContext.frameless(classWrapper, methodNode); | ||
|
||
// Check instructions | ||
if (methodNode.instructions.size() == 2 && INSTANT_RETURN_EXCEPTION.matches(framelessContext.newInsnContext(methodNode.instructions.getFirst()))) { | ||
// Add it to list | ||
instantReturnExceptionMethods.add(MethodRef.of(classWrapper.getClassNode(), methodNode)); | ||
} | ||
}); | ||
|
||
Match invokeAndReturnMatch = | ||
SequenceMatch.of( | ||
MethodMatch.invokeStatic().and(Match.predicate(ctx -> { | ||
MethodRef methodRef = MethodRef.of((MethodInsnNode) ctx.insn()); | ||
return instantReturnExceptionMethods.contains(methodRef); | ||
})), | ||
OpcodeMatch.of(ATHROW) | ||
); | ||
|
||
// Remove try-catches with these instant return exception methods | ||
classWrapper.methods().forEach(methodNode -> { | ||
MethodContext framelessContext = MethodContext.frameless(classWrapper, methodNode); | ||
|
||
methodNode.tryCatchBlocks.removeIf(tryBlock -> { | ||
InstructionContext start = framelessContext.newInsnContext(tryBlock.handler.getNext()); | ||
if (invokeAndReturnMatch.matches(start)) { | ||
markChange(); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.