From 6a7a29c85c49513d441df5bc6d50c34b228b238e Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 12 Jan 2024 23:16:16 +0000 Subject: [PATCH] Exclude overlapping initializers in StaticFieldUnscrambler 667 has an initializer like `a = b = new X()`. This broke the previous version of the unscrambler, as it treated it as two separate initializers: `a = b = new X()` and `b = new X()`. When the fields were moved, the overlapping instructions were removed twice from the original method, making its size negative. Even if this were fixed, it is still not safe to move the initializers, as `new X()` would end up being executed twice, not once. This commit fixes the problem by treating any simple initializer that overlaps with any other simple initializer as a complex initializer. Signed-off-by: Graham --- .../deob/bytecode/remap/StaticFieldUnscrambler.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt index a5c58f0d..df226d7e 100644 --- a/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt +++ b/deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt @@ -117,6 +117,19 @@ public class StaticFieldUnscrambler( } } + val overlappingInitializers = mutableSetOf() + + for ((field1, initializer1) in simpleInitializers) { + for ((field2, initializer2) in simpleInitializers) { + if (field1 != field2 && initializer1.any { it in initializer2 }) { + overlappingInitializers += field1 + } + } + } + + simpleInitializers -= overlappingInitializers + complexInitializers += overlappingInitializers + return Pair(simpleInitializers, complexInitializers) } }