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
<clinit> 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 <gpe@openrs2.org>
Graham 10 months ago
parent 293bf83e30
commit 6a7a29c85c
  1. 13
      deob-bytecode/src/main/kotlin/org/openrs2/deob/bytecode/remap/StaticFieldUnscrambler.kt

@ -117,6 +117,19 @@ public class StaticFieldUnscrambler(
}
}
val overlappingInitializers = mutableSetOf<MemberDesc>()
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)
}
}

Loading…
Cancel
Save