fuck java
This commit is contained in:
@@ -7,9 +7,9 @@ import java.nio.file.Path
|
|||||||
class Knot(private val jar: Path) : ClassFileTransformer {
|
class Knot(private val jar: Path) : ClassFileTransformer {
|
||||||
private val knot = "net.fabricmc.loader.impl.launch.knot"
|
private val knot = "net.fabricmc.loader.impl.launch.knot"
|
||||||
private var registry = mutableSetOf<Instrumentation>()
|
private var registry = mutableSetOf<Instrumentation>()
|
||||||
override fun transform(classLoader: ClassLoader, className: String,
|
override fun transform(classLoader: ClassLoader?, className: String?,
|
||||||
redefined: Class<*>, domain: ProtectionDomain, bytes: ByteArray
|
redefined: Class<*>?, domain: ProtectionDomain?, bytes: ByteArray?
|
||||||
): ByteArray? = null.also { load(classLoader) }
|
): ByteArray? = null.also { classLoader?.let { load(it) } }
|
||||||
|
|
||||||
fun register(inst: Instrumentation) {
|
fun register(inst: Instrumentation) {
|
||||||
val result = runCatching { expose(jar) }
|
val result = runCatching { expose(jar) }
|
||||||
@@ -18,7 +18,7 @@ class Knot(private val jar: Path) : ClassFileTransformer {
|
|||||||
registry.add(inst)
|
registry.add(inst)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun delegate() = run {
|
private fun delegate(): Any = run {
|
||||||
val base = Class.forName("$knot.KnotClassLoader")
|
val base = Class.forName("$knot.KnotClassLoader")
|
||||||
val delegate = base.getDeclaredField("delegate")
|
val delegate = base.getDeclaredField("delegate")
|
||||||
val threads = Thread.getAllStackTraces().keys
|
val threads = Thread.getAllStackTraces().keys
|
||||||
@@ -27,7 +27,7 @@ class Knot(private val jar: Path) : ClassFileTransformer {
|
|||||||
delegate.apply { isAccessible = true }.get(knot)
|
delegate.apply { isAccessible = true }.get(knot)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun expose(jar: Path) = delegate().let {
|
private fun expose(jar: Path): Unit = delegate().let {
|
||||||
val base = Class.forName("$knot.KnotClassDelegate")
|
val base = Class.forName("$knot.KnotClassDelegate")
|
||||||
val source = base.getMethod("addCodeSource", Path::class.java)
|
val source = base.getMethod("addCodeSource", Path::class.java)
|
||||||
source.apply { isAccessible = true }.invoke(it, jar)
|
source.apply { isAccessible = true }.invoke(it, jar)
|
||||||
|
|||||||
Reference in New Issue
Block a user