Add extension method for copying a MethodNode

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent ea755497ee
commit 5c1e630cb8
  1. 12
      asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt
  2. 10
      deob/src/main/java/dev/openrs2/deob/transform/ConstantArgTransformer.kt

@ -133,3 +133,15 @@ fun MethodNode.removeDeadCode(owner: String) {
fun MethodNode.hasCode(): Boolean { fun MethodNode.hasCode(): Boolean {
return access and (Opcodes.ACC_NATIVE or Opcodes.ACC_ABSTRACT) == 0 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
}

@ -4,6 +4,7 @@ import com.github.michaelbull.logging.InlineLogger
import dev.openrs2.asm.MemberRef import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.classpath.ClassPath import dev.openrs2.asm.classpath.ClassPath
import dev.openrs2.asm.classpath.Library import dev.openrs2.asm.classpath.Library
import dev.openrs2.asm.copy
import dev.openrs2.asm.createIntConstant import dev.openrs2.asm.createIntConstant
import dev.openrs2.asm.deleteExpression import dev.openrs2.asm.deleteExpression
import dev.openrs2.asm.hasCode import dev.openrs2.asm.hasCode
@ -105,14 +106,7 @@ class ConstantArgTransformer : Transformer() {
* final pass, as we might discover more routes through the call graph * final pass, as we might discover more routes through the call graph
* later which reduce the number of branches we can simplify. * later which reduce the number of branches we can simplify.
*/ */
val method = MethodNode( val method = originalMethod.copy()
originalMethod.access,
originalMethod.name,
originalMethod.desc,
originalMethod.signature,
originalMethod.exceptions?.toTypedArray()
)
originalMethod.accept(method)
// find existing constant arguments // find existing constant arguments
val args = getArgs(ref) val args = getArgs(ref)

Loading…
Cancel
Save