From 248cad99e3c3a8b55d78087cad1a03645a788ce6 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 5 Feb 2020 09:21:43 +0000 Subject: [PATCH] Improve safety of IFEQ/IFNE check in OpaquePredicateTransformer --- .../transform/OpaquePredicateTransformer.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt index b833b9f1d8..6084d4f817 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt @@ -88,13 +88,17 @@ class OpaquePredicateTransformer : Transformer() { // find and fix opaque predicates for (match in OPAQUE_PREDICATE_MATCHER.match(method).filter { isOpaquePredicate(method, it) }) { val branch = match[1] as JumpInsnNode - if (branch.opcode == Opcodes.IFEQ) { - // branch is always taken - method.instructions.remove(match[0]) - branch.opcode = Opcodes.GOTO - } else { // IFNE - // branch is never taken - match.forEach(method.instructions::remove) + when (branch.opcode) { + Opcodes.IFEQ -> { + // branch is always taken + method.instructions.remove(match[0]) + branch.opcode = Opcodes.GOTO + } + Opcodes.IFNE -> { + // branch is never taken + match.forEach(method.instructions::remove) + } + else -> error("Invalid opcode") } opaquePredicates++