From 711cd0c85fbf92f203ecb3554042c8ad8af9727c Mon Sep 17 00:00:00 2001 From: Tyler Bochard Date: Tue, 16 Apr 2024 14:03:15 -0400 Subject: [PATCH] remove PatchManager --- .../ExamplePrintInstructionClassVisitor.kt | 16 ---- .../main/java/hotlite/patch/PatchManager.kt | 82 ----------------- .../hotlite/patch/PrintingMethodVisitor.kt | 91 ------------------- .../net/runelite/client/rs/ClientLoader.java | 4 - 4 files changed, 193 deletions(-) delete mode 100644 runelite-client/src/main/java/hotlite/patch/ExamplePrintInstructionClassVisitor.kt delete mode 100644 runelite-client/src/main/java/hotlite/patch/PatchManager.kt delete mode 100644 runelite-client/src/main/java/hotlite/patch/PrintingMethodVisitor.kt diff --git a/runelite-client/src/main/java/hotlite/patch/ExamplePrintInstructionClassVisitor.kt b/runelite-client/src/main/java/hotlite/patch/ExamplePrintInstructionClassVisitor.kt deleted file mode 100644 index 456ab10fd..000000000 --- a/runelite-client/src/main/java/hotlite/patch/ExamplePrintInstructionClassVisitor.kt +++ /dev/null @@ -1,16 +0,0 @@ -package hotlite.patch - -import org.objectweb.asm.ClassVisitor -import org.objectweb.asm.ClassWriter -import org.objectweb.asm.MethodVisitor - -//TODO: methodDesc is inconsistent atm -class ExamplePrintInstructionClassVisitor(api: Int, private val methodName: String, private val methodDesc: String, classWriter: ClassWriter) : ClassVisitor(api, classWriter) { - override fun visitMethod(access: Int, name: String, descriptor: String, signature: String?, exceptions: Array?): MethodVisitor { - if (methodName == name) { - val originalMethodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions) - return PrintingMethodVisitor(api, originalMethodVisitor) - } - return super.visitMethod(access, name, descriptor, signature, exceptions) - } - } \ No newline at end of file diff --git a/runelite-client/src/main/java/hotlite/patch/PatchManager.kt b/runelite-client/src/main/java/hotlite/patch/PatchManager.kt deleted file mode 100644 index 3f74ba6d4..000000000 --- a/runelite-client/src/main/java/hotlite/patch/PatchManager.kt +++ /dev/null @@ -1,82 +0,0 @@ -package hotlite.patch - -import ext.java.JarFileExt.getBytes -import org.objectweb.asm.ClassReader -import org.objectweb.asm.ClassWriter -import org.objectweb.asm.Opcodes -import java.io.IOException -import java.util.jar.JarFile -import kotlin.reflect.KClass -import kotlin.reflect.KFunction -import kotlin.reflect.full.memberFunctions -import kotlin.reflect.jvm.javaMethod - - -object PatchManager { - lateinit var PATCHED_JAR: String - lateinit var CLASSLOADER: ClassLoader - val classNames = HashSet() - val classes = HashMap, ByteArray>() - - fun init(pathToJar: String, classLoader: ClassLoader) { - PATCHED_JAR = pathToJar - CLASSLOADER = classLoader - - loadPatch(PATCHED_JAR, CLASSLOADER) - - println("Loaded ${classes.size} patch classes") - - printChangeWorldInstructions() - } - - fun loadPatch(pathToPatch: String, classLoader: ClassLoader) { - try { - val jarFile = JarFile(pathToPatch) - val entries = jarFile.entries() - - while (entries.hasMoreElements()) { - val entry = entries.nextElement() - if (entry.name.endsWith(".class")) { - val className = entry.name.replace('/', '.').substring(0, entry.name.length - 6) - classNames.add(className) - classes[classLoader.loadClass(className).kotlin] = - jarFile.getBytes(entry) - } - } - } catch (e: IOException) { - e.printStackTrace() - } - } - - fun printChangeWorldInstructions() { - for (c in classes.keys) { - for (m in c.memberFunctions) { - if (m.name == "changeWorld") { - m.javaMethod?.let { - try { - val classBytes = classes[c] - val reader = ClassReader(classBytes) - val classWriter = ClassWriter(ClassWriter.COMPUTE_MAXS) - val visitor = ExamplePrintInstructionClassVisitor(Opcodes.ASM9, m.name, getMethodDescriptor(m), classWriter) - reader.accept(visitor, 0) - } catch (e: IOException) { - e.printStackTrace() - } - } - } - } - } - } - - //FIXME - fun getMethodDescriptor(kFunction: KFunction<*>): String { - val javaMethod = kFunction.javaMethod ?: error("Java method not found for the provided Kotlin function") - val methodDescriptor = javaMethod.toGenericString() - - // If you specifically want just the method descriptor, you can extract it from the generic string - val descriptorStart = methodDescriptor.indexOf('(') - val descriptorEnd = methodDescriptor.indexOf(')') + 1 - return methodDescriptor.substring(descriptorStart, descriptorEnd) - } -} - diff --git a/runelite-client/src/main/java/hotlite/patch/PrintingMethodVisitor.kt b/runelite-client/src/main/java/hotlite/patch/PrintingMethodVisitor.kt deleted file mode 100644 index 2b32c55db..000000000 --- a/runelite-client/src/main/java/hotlite/patch/PrintingMethodVisitor.kt +++ /dev/null @@ -1,91 +0,0 @@ -package hotlite.patch - -import org.objectweb.asm.Label -import org.objectweb.asm.MethodVisitor -import org.objectweb.asm.util.Printer - -class PrintingMethodVisitor(api: Int, mv: MethodVisitor?) : MethodVisitor(api, mv) { - override fun visitCode() { - println("Method Instructions:") - super.visitCode() - } - - override fun visitInsn(opcode: Int) { - println(getOpcodeName(opcode)) - super.visitInsn(opcode) - } - - override fun visitIntInsn(opcode: Int, operand: Int) { - println(getOpcodeName(opcode) + " " + operand) - super.visitIntInsn(opcode, operand) - } - - override fun visitVarInsn(opcode: Int, `var`: Int) { - println(getOpcodeName(opcode) + " " + `var`) - super.visitVarInsn(opcode, `var`) - } - - override fun visitTypeInsn(opcode: Int, type: String) { - println(getOpcodeName(opcode) + " " + type) - super.visitTypeInsn(opcode, type) - } - - override fun visitFieldInsn(opcode: Int, owner: String, name: String, descriptor: String) { - println(getOpcodeName(opcode) + " " + owner + " " + name + " " + descriptor) - super.visitFieldInsn(opcode, owner, name, descriptor) - } - - override fun visitMethodInsn(opcode: Int, owner: String, name: String, descriptor: String, isInterface: Boolean) { - println(getOpcodeName(opcode) + " " + owner + " " + name + " " + descriptor + " " + isInterface) - super.visitMethodInsn(opcode, owner, name, descriptor, isInterface) - } - - override fun visitJumpInsn(opcode: Int, label: Label) { - println(getOpcodeName(opcode) + " " + label) - super.visitJumpInsn(opcode, label) - } - - override fun visitLabel(label: Label) { - println("Label: $label") - super.visitLabel(label) - } - - override fun visitLdcInsn(value: Any) { - println("LDC: $value") - super.visitLdcInsn(value) - } - - override fun visitIincInsn(`var`: Int, increment: Int) { - println("IINC: $`var` $increment") - super.visitIincInsn(`var`, increment) - } - - override fun visitTableSwitchInsn(min: Int, max: Int, dflt: Label, vararg labels: Label) { - println("TABLESWITCH: " + min + " " + max + " " + dflt + " " + labels.contentToString()) - super.visitTableSwitchInsn(min, max, dflt, *labels) - } - - override fun visitLookupSwitchInsn(dflt: Label, keys: IntArray, labels: Array