Improve safety of IFEQ/IFNE check in OpaquePredicateTransformer

master
Graham 5 years ago
parent c4e08242aa
commit 248cad99e3
  1. 18
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt

@ -88,13 +88,17 @@ class OpaquePredicateTransformer : Transformer() {
// find and fix opaque predicates // find and fix opaque predicates
for (match in OPAQUE_PREDICATE_MATCHER.match(method).filter { isOpaquePredicate(method, it) }) { for (match in OPAQUE_PREDICATE_MATCHER.match(method).filter { isOpaquePredicate(method, it) }) {
val branch = match[1] as JumpInsnNode val branch = match[1] as JumpInsnNode
if (branch.opcode == Opcodes.IFEQ) { when (branch.opcode) {
// branch is always taken Opcodes.IFEQ -> {
method.instructions.remove(match[0]) // branch is always taken
branch.opcode = Opcodes.GOTO method.instructions.remove(match[0])
} else { // IFNE branch.opcode = Opcodes.GOTO
// branch is never taken }
match.forEach(method.instructions::remove) Opcodes.IFNE -> {
// branch is never taken
match.forEach(method.instructions::remove)
}
else -> error("Invalid opcode")
} }
opaquePredicates++ opaquePredicates++

Loading…
Cancel
Save