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.
35 lines
1.0 KiB
35 lines
1.0 KiB
package dev.openrs2.asm.io
|
|
|
|
import dev.openrs2.asm.classpath.JsrInliner
|
|
import dev.openrs2.asm.classpath.Library
|
|
import org.objectweb.asm.ClassReader
|
|
import org.objectweb.asm.tree.ClassNode
|
|
import java.util.jar.JarEntry
|
|
import java.util.jar.JarInputStream
|
|
|
|
class JarLibraryReader(private val input: JarInputStream) : LibraryReader {
|
|
|
|
override fun read(): Library {
|
|
val classes = generateSequence { input.nextJarEntry }
|
|
.filter(::isClass)
|
|
.map { input.readClass() }
|
|
.associateBy(ClassNode::name)
|
|
|
|
return Library(classes)
|
|
}
|
|
|
|
private fun isClass(entry: JarEntry): Boolean {
|
|
return entry.name.endsWith(CLASS_SUFFIX)
|
|
}
|
|
|
|
private fun JarInputStream.readClass(): ClassNode {
|
|
val clazz = ClassNode()
|
|
val reader = ClassReader(this)
|
|
reader.accept(JsrInliner(clazz), ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES)
|
|
return clazz
|
|
}
|
|
|
|
private companion object {
|
|
private const val CLASS_SUFFIX = ".class"
|
|
}
|
|
}
|
|
|