Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
package dev.openrs2.deob.transform
|
|
|
|
import com.github.michaelbull.logging.InlineLogger
|
|
import dev.openrs2.asm.InsnMatcher
|
|
import dev.openrs2.asm.classpath.ClassPath
|
|
import dev.openrs2.asm.classpath.Library
|
|
import dev.openrs2.asm.createIntConstant
|
|
import dev.openrs2.asm.intConstant
|
|
import dev.openrs2.asm.transform.Transformer
|
|
import org.objectweb.asm.Opcodes
|
|
import org.objectweb.asm.tree.ClassNode
|
|
import org.objectweb.asm.tree.MethodNode
|
|
|
|
class BitShiftTransformer : Transformer() {
|
|
private var simplified = 0
|
|
|
|
override fun preTransform(classPath: ClassPath) {
|
|
simplified = 0
|
|
}
|
|
|
|
override fun transformCode(
|
|
classPath: ClassPath,
|
|
library: Library,
|
|
clazz: ClassNode,
|
|
method: MethodNode
|
|
): Boolean {
|
|
CONST_SHIFT_MATCHER.match(method).forEach {
|
|
val push = it[0]
|
|
val bits = push.intConstant!!
|
|
|
|
val opcode = it[1].opcode
|
|
val mask = if (LONG_SHIFTS.contains(opcode)) 63 else 31
|
|
|
|
val simplifiedBits = bits and mask
|
|
|
|
if (bits != simplifiedBits) {
|
|
method.instructions[push] = createIntConstant(simplifiedBits)
|
|
simplified++
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
override fun postTransform(classPath: ClassPath) {
|
|
logger.info { "Simplified $simplified bit shifts" }
|
|
}
|
|
|
|
companion object {
|
|
private val logger = InlineLogger()
|
|
private val CONST_SHIFT_MATCHER =
|
|
InsnMatcher.compile("(ICONST | BIPUSH | SIPUSH | LDC) (ISHL | ISHR | IUSHR | LSHL | LSHR | LUSHR)")
|
|
private val LONG_SHIFTS = setOf(Opcodes.LSHL, Opcodes.LSHR, Opcodes.LUSHR)
|
|
}
|
|
}
|
|
|