forked from openrs2/openrs2
parent
26348b8a2e
commit
6e877b52ce
@ -0,0 +1,32 @@ |
|||||||
|
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.JarInputStream |
||||||
|
|
||||||
|
class JarLibraryReader(private val input: JarInputStream) : LibraryReader { |
||||||
|
override fun read(): Library { |
||||||
|
val library = Library() |
||||||
|
|
||||||
|
while (true) { |
||||||
|
val entry = input.nextJarEntry ?: break |
||||||
|
if (!entry.name.endsWith(CLASS_SUFFIX)) { |
||||||
|
continue |
||||||
|
} |
||||||
|
|
||||||
|
val clazz = ClassNode() |
||||||
|
val reader = ClassReader(input) |
||||||
|
reader.accept(JsrInliner(clazz), ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES) |
||||||
|
|
||||||
|
library.add(clazz) |
||||||
|
} |
||||||
|
|
||||||
|
return library |
||||||
|
} |
||||||
|
|
||||||
|
private companion object { |
||||||
|
private const val CLASS_SUFFIX = ".class" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
package dev.openrs2.asm.io |
||||||
|
|
||||||
|
import dev.openrs2.asm.classpath.Library |
||||||
|
|
||||||
|
interface LibraryReader { |
||||||
|
fun read(): Library |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package dev.openrs2.asm.io |
||||||
|
|
||||||
|
import dev.openrs2.asm.classpath.Library |
||||||
|
import dev.openrs2.compress.gzip.Gzip |
||||||
|
import java.io.InputStream |
||||||
|
import java.nio.file.Files |
||||||
|
import java.util.jar.JarInputStream |
||||||
|
import java.util.jar.JarOutputStream |
||||||
|
import java.util.jar.Pack200 |
||||||
|
|
||||||
|
class Pack200LibraryReader(private val input: InputStream) : LibraryReader { |
||||||
|
override fun read(): Library { |
||||||
|
val temp = Files.createTempFile(TEMP_PREFIX, JAR_SUFFIX) |
||||||
|
try { |
||||||
|
Gzip.createHeaderlessInputStream(input).use { gzipInput -> |
||||||
|
JarOutputStream(Files.newOutputStream(temp)).use { output -> |
||||||
|
Pack200.newUnpacker().unpack(gzipInput, output) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return JarInputStream(Files.newInputStream(temp)).use { tempInput -> |
||||||
|
JarLibraryReader(tempInput).read() |
||||||
|
} |
||||||
|
} finally { |
||||||
|
Files.deleteIfExists(temp) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private companion object { |
||||||
|
private const val TEMP_PREFIX = "tmp" |
||||||
|
private const val JAR_SUFFIX = ".jar" |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue