From 328b122330ee79615f045b65f9a8e25855f84d4f Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 19 Oct 2019 10:43:32 +0100 Subject: [PATCH] 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. --- .../dev/openrs2/deob/ast/AstDeobfuscator.java | 2 ++ .../ast/transform/ValueOfTransformer.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.java diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.java b/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.java index 6e2c983742..b664859657 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.java +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/AstDeobfuscator.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 TRANSFORMERS = ImmutableList.of( @@ -33,6 +34,7 @@ public final class AstDeobfuscator { new BinaryExprOrderTransformer(), new AddSubTransformer(), new BitMaskTransformer(), + new ValueOfTransformer(), new EncloseTransformer() ); diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.java b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.java new file mode 100644 index 0000000000..bed617f515 --- /dev/null +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ValueOfTransformer.java @@ -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())); + }); + } +}