From 5c1e630cb806656d440168f6cf3e57e2474dcb12 Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 10 Apr 2020 16:21:24 +0100 Subject: [PATCH] Add extension method for copying a MethodNode Signed-off-by: Graham --- asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt | 12 ++++++++++++ .../openrs2/deob/transform/ConstantArgTransformer.kt | 10 ++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt index f690d80c..89b99aeb 100644 --- a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt @@ -133,3 +133,15 @@ fun MethodNode.removeDeadCode(owner: String) { fun MethodNode.hasCode(): Boolean { return access and (Opcodes.ACC_NATIVE or Opcodes.ACC_ABSTRACT) == 0 } + +fun MethodNode.copy(): MethodNode { + val copy = MethodNode( + access, + name, + desc, + signature, + exceptions?.toTypedArray() + ) + accept(copy) + return copy +} diff --git a/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt index 8cfb9983..6cd222cd 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt @@ -4,6 +4,7 @@ import com.github.michaelbull.logging.InlineLogger import dev.openrs2.asm.MemberRef import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.Library +import dev.openrs2.asm.copy import dev.openrs2.asm.createIntConstant import dev.openrs2.asm.deleteExpression import dev.openrs2.asm.hasCode @@ -105,14 +106,7 @@ class ConstantArgTransformer : Transformer() { * final pass, as we might discover more routes through the call graph * later which reduce the number of branches we can simplify. */ - val method = MethodNode( - originalMethod.access, - originalMethod.name, - originalMethod.desc, - originalMethod.signature, - originalMethod.exceptions?.toTypedArray() - ) - originalMethod.accept(method) + val method = originalMethod.copy() // find existing constant arguments val args = getArgs(ref)