Add ValueOfTransformer

Might need to move to the bytecode deobfuscator if public boxed type
constructors are removed from future JDKs, but for now it's easier to do
this on the AST level.
master
Graham 5 years ago
parent 08caea8289
commit 328b122330
  1. 2
      deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.java
  2. 21
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.java

@ -22,6 +22,7 @@ import dev.openrs2.deob.ast.transform.NegativeLiteralTransformer;
import dev.openrs2.deob.ast.transform.TernaryTransformer;
import dev.openrs2.deob.ast.transform.Transformer;
import dev.openrs2.deob.ast.transform.UnencloseTransformer;
import dev.openrs2.deob.ast.transform.ValueOfTransformer;
public final class AstDeobfuscator {
private static final ImmutableList<Transformer> TRANSFORMERS = ImmutableList.of(
@ -33,6 +34,7 @@ public final class AstDeobfuscator {
new BinaryExprOrderTransformer(),
new AddSubTransformer(),
new BitMaskTransformer(),
new ValueOfTransformer(),
new EncloseTransformer()
);

@ -0,0 +1,21 @@
package dev.openrs2.deob.ast.transform;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.ObjectCreationExpr;
import com.github.javaparser.ast.expr.TypeExpr;
import dev.openrs2.deob.ast.util.NodeUtils;
public final class ValueOfTransformer extends Transformer {
@Override
public void transform(CompilationUnit unit) {
NodeUtils.walk(unit, Node.TreeTraversal.POSTORDER, ObjectCreationExpr.class, expr -> {
if (!expr.getType().isBoxedType()) {
return;
}
expr.replace(new MethodCallExpr(new TypeExpr(expr.getType()), "valueOf", expr.getArguments()));
});
}
}
Loading…
Cancel
Save