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.
73 lines
2.5 KiB
73 lines
2.5 KiB
4 years ago
|
package org.openrs2.bundler.transform
|
||
4 years ago
|
|
||
|
import com.github.michaelbull.logging.InlineLogger
|
||
4 years ago
|
import org.objectweb.asm.Opcodes
|
||
4 years ago
|
import org.objectweb.asm.tree.ClassNode
|
||
4 years ago
|
import org.objectweb.asm.tree.JumpInsnNode
|
||
4 years ago
|
import org.objectweb.asm.tree.LdcInsnNode
|
||
|
import org.objectweb.asm.tree.MethodNode
|
||
4 years ago
|
import org.openrs2.asm.InsnMatcher
|
||
|
import org.openrs2.asm.classpath.ClassPath
|
||
|
import org.openrs2.asm.classpath.Library
|
||
|
import org.openrs2.asm.transform.Transformer
|
||
4 years ago
|
import javax.inject.Singleton
|
||
4 years ago
|
|
||
4 years ago
|
@Singleton
|
||
4 years ago
|
public class LoadLibraryTransformer : Transformer() {
|
||
4 years ago
|
private var jnilibs = 0
|
||
|
private var amd64Checks = 0
|
||
4 years ago
|
private var sunOsChecks = 0
|
||
4 years ago
|
|
||
|
override fun preTransform(classPath: ClassPath) {
|
||
|
jnilibs = 0
|
||
|
amd64Checks = 0
|
||
4 years ago
|
sunOsChecks = 0
|
||
4 years ago
|
}
|
||
|
|
||
|
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
|
||
|
val jnilib = method.instructions.find { it is LdcInsnNode && it.cst == "libjaggl.jnilib" } ?: return false
|
||
|
jnilib as LdcInsnNode
|
||
|
jnilib.cst = "libjaggl.dylib"
|
||
|
jnilibs++
|
||
|
|
||
4 years ago
|
for (match in AMD64_CHECK_MATCHER.match(method)) {
|
||
|
val ldc = match[1] as LdcInsnNode
|
||
4 years ago
|
if (ldc.cst == "amd64") {
|
||
4 years ago
|
match.forEach(method.instructions::remove)
|
||
4 years ago
|
amd64Checks++
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
for (match in SUNOS_CHECK_MATCHER.match(method)) {
|
||
|
val ldc = match[1] as LdcInsnNode
|
||
|
if (ldc.cst == "sunos") {
|
||
|
method.instructions.remove(match[0])
|
||
|
method.instructions.remove(match[1])
|
||
|
method.instructions.remove(match[2])
|
||
|
|
||
|
val jump = match[3] as JumpInsnNode
|
||
|
if (jump.opcode == Opcodes.IFEQ) {
|
||
|
method.instructions.set(jump, JumpInsnNode(Opcodes.GOTO, jump.label))
|
||
|
} else {
|
||
|
method.instructions.remove(jump)
|
||
|
}
|
||
|
sunOsChecks++
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
return false
|
||
|
}
|
||
|
|
||
|
override fun postTransform(classPath: ClassPath) {
|
||
4 years ago
|
logger.info { "Replaced $jnilibs jnilibs with dylibs" }
|
||
|
logger.info { "Removed $amd64Checks amd64 jagmisc and $sunOsChecks SunOS checks" }
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
private companion object {
|
||
4 years ago
|
private val logger = InlineLogger()
|
||
|
private val AMD64_CHECK_MATCHER =
|
||
|
InsnMatcher.compile("GETSTATIC LDC INVOKEVIRTUAL IFNE GETSTATIC LDC INVOKEVIRTUAL IFNE")
|
||
4 years ago
|
private val SUNOS_CHECK_MATCHER = InsnMatcher.compile("GETSTATIC LDC INVOKEVIRTUAL (IFNE | IFEQ)")
|
||
4 years ago
|
}
|
||
|
}
|