@@ -70,19 +70,32 @@ class DeobfuscatorGenerator(
70
70
71
71
private fun ClassVisitor.generateStaticInitializer () {
72
72
newMethod(Opcodes .ACC_STATIC , METHOD_STATIC_INITIALIZER ) {
73
- val chunks = stringRegistry.getAllChunks ()
74
- push(chunks.size )
73
+ val chunkCount = stringRegistry.getChunkCount ()
74
+ push(chunkCount )
75
75
newArray(CHUNKS_ELEMENT_TYPE )
76
+ // Store the new array into the static field
76
77
putStatic(deobfuscator.type.toAsmType(), CHUNKS_FIELD_NAME , CHUNKS_FIELD_TYPE )
77
78
78
- getStatic(deobfuscator.type.toAsmType(), CHUNKS_FIELD_NAME , CHUNKS_FIELD_TYPE )
79
- chunks.forEachIndexed { index, chunk ->
80
- dup()
81
- push(index)
82
- push(chunk)
83
- arrayStore(CHUNKS_ELEMENT_TYPE )
79
+ // If there are chunks to add, load the field back onto the stack
80
+ if (chunkCount > 0 ) {
81
+ getStatic(deobfuscator.type.toAsmType(), CHUNKS_FIELD_NAME , CHUNKS_FIELD_TYPE )
82
+ var index = 0
83
+ stringRegistry.streamChunks { chunk ->
84
+ dup() // Duplicate the array reference
85
+ push(index) // Push the index
86
+ push(chunk) // Push the chunk string
87
+ arrayStore(CHUNKS_ELEMENT_TYPE ) // Store the chunk in the array
88
+ index++
89
+ }
90
+ // Pop the array reference that was loaded by getStatic (if chunkCount > 0)
91
+ // and duplicated in the loop. The original putStatic already stored it.
92
+ // If streamChunks did nothing (e.g. 0 chunks), this pop is not needed as getStatic wasn't called.
93
+ // However, the structure with index ensures it's balanced if chunks were processed.
94
+ // If chunkCount > 0, one array reference remains on stack after loop.
95
+ pop()
84
96
}
85
- pop()
97
+ // Ensure stack is balanced: if chunkCount was 0, no putStatic/getStatic/pop happened here.
98
+ // If chunkCount > 0, array was putStatic, then getStatic, then loop, then pop. Correct.
86
99
}
87
100
}
88
101
0 commit comments