From 6c26fb8b9ce707e9b699492010c6bde37ecb76eb Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 6 Jun 2020 16:09:46 +0100 Subject: [PATCH] Fix incorrect marking of fields as final if no constructor existed Signed-off-by: Graham --- .../deob/transform/FinalFieldTransformer.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/deob/src/main/java/dev/openrs2/deob/transform/FinalFieldTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/FinalFieldTransformer.kt index 1e3df671..f7dbe316 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/FinalFieldTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/FinalFieldTransformer.kt @@ -98,6 +98,24 @@ class FinalFieldTransformer : Transformer() { return false } + override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean { + // if a class has no constructor all its fields must be non-final + + val hasInstanceConstructor = clazz.methods.any { it.name == "" } + val hasStaticConstructor = clazz.methods.any { it.name == "" } + + for (field in clazz.fields) { + val fieldStatic = (field.access and Opcodes.ACC_STATIC) != 0 + + if ((!hasInstanceConstructor && !fieldStatic) || (!hasStaticConstructor && fieldStatic)) { + val partition = inheritedFieldSets[MemberRef(clazz, field)]!! + nonFinalFields += partition + } + } + + return false + } + override fun transformField(classPath: ClassPath, library: Library, clazz: ClassNode, field: FieldNode): Boolean { if ((field.access and Opcodes.ACC_VOLATILE) != 0) { val partition = inheritedFieldSets[MemberRef(clazz, field)]!!