Skip to content

Commit

Permalink
Merge pull request #72 from EpicPlayerA10/chore/rewrite-number-transf…
Browse files Browse the repository at this point in the history
…ormer

Rewrite UniversalNumberTransformer
  • Loading branch information
narumii authored Aug 24, 2024
2 parents f1a2b47 + 9b65c6b commit 7e0ec6f
Show file tree
Hide file tree
Showing 17 changed files with 570 additions and 507 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
> - Porting old transformers to new code base
> - Testing InstructionMatcher
> - Implementing/Improving transformers
> - Variable inlining (UniversalNumberTransformer)
> - Safety checks on putstatic in FieldInlineTransformers (overriding values)
> - Feedback on how the new api presents itself (mainly InstructionMatcher)
> <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.analysis.Frame;
import org.objectweb.asm.tree.analysis.OriginalSourceValue;

@FunctionalInterface
public interface Match {
Expand All @@ -24,7 +26,20 @@ default Match not() {
return (node) -> !test(node);
}

default boolean invoke(MethodNode methodNode, AbstractInsnNode node) {
return false;
default Transformation transformation() {
return ((methodNode, insn, frame) -> false);
}

@FunctionalInterface
interface Transformation {
/**
* Executes given action
*
* @param methodNode Method node
* @param insn Instruction
* @param frame Current frame. Useful when you need to get some values from the stack.
* @return If changed
*/
boolean transform(MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package uwu.narumi.deobfuscator.api.asm.matcher.rule.impl;

import java.util.function.BiFunction;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.MethodNode;
import uwu.narumi.deobfuscator.api.asm.matcher.rule.Match;

public class FieldMatch implements Match {
Expand All @@ -14,7 +12,7 @@ public class FieldMatch implements Match {
private String name;
private String desc;

private BiFunction<MethodNode, AbstractInsnNode, Boolean> action;
private Transformation transformation;

private FieldMatch(int opcode) {
this.opcode = opcode;
Expand Down Expand Up @@ -44,14 +42,14 @@ public static FieldMatch getField() {
return new FieldMatch(Opcodes.GETFIELD);
}

public Match invokeAction(BiFunction<MethodNode, AbstractInsnNode, Boolean> function) {
this.action = function;
public Match transformation(Transformation transformation) {
this.transformation = transformation;
return this;
}

@Override
public boolean invoke(MethodNode methodNode, AbstractInsnNode node) {
return action.apply(methodNode, node);
public Transformation transformation() {
return this.transformation;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package uwu.narumi.deobfuscator.api.asm.matcher.rule.impl;

import java.util.function.BiFunction;
import java.util.function.Predicate;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodNode;
import uwu.narumi.deobfuscator.api.asm.matcher.rule.Match;

public class InvokeDynamicMatch implements Match {
Expand All @@ -18,22 +16,22 @@ public class InvokeDynamicMatch implements Match {

private Predicate<Object[]> bsmArgsPredicate;

private BiFunction<MethodNode, AbstractInsnNode, Boolean> action;
private Transformation transformation;

private InvokeDynamicMatch() {}

public static InvokeDynamicMatch create() {
return new InvokeDynamicMatch();
}

public Match invokeAction(BiFunction<MethodNode, AbstractInsnNode, Boolean> function) {
this.action = function;
public Match defineTransformation(Transformation transformation) {
this.transformation = transformation;
return this;
}

@Override
public boolean invoke(MethodNode methodNode, AbstractInsnNode node) {
return action.apply(methodNode, node);
public Transformation transformation() {
return this.transformation;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package uwu.narumi.deobfuscator.api.asm.matcher.rule.impl;

import java.util.Arrays;
import java.util.function.BiFunction;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import uwu.narumi.deobfuscator.api.asm.matcher.rule.Match;

public class MethodMatch implements Match {
Expand All @@ -15,7 +14,7 @@ public class MethodMatch implements Match {
private String[] name;
private String desc;

private BiFunction<MethodNode, AbstractInsnNode, Boolean> action;
private Transformation transformation;

private MethodMatch(int opcode) {
this.opcode = opcode;
Expand Down Expand Up @@ -45,14 +44,14 @@ public static MethodMatch invokeInterface() {
return new MethodMatch(Opcodes.INVOKEINTERFACE);
}

public Match invokeAction(BiFunction<MethodNode, AbstractInsnNode, Boolean> function) {
this.action = function;
public Match defineTransformation(Transformation transformation) {
this.transformation = transformation;
return this;
}

@Override
public boolean invoke(MethodNode methodNode, AbstractInsnNode node) {
return action.apply(methodNode, node);
public Transformation transformation() {
return this.transformation;
}

@Override
Expand Down
Loading

0 comments on commit 7e0ec6f

Please sign in to comment.