Add CabLibraryReader

Signed-off-by: Graham <gpe@openrs2.org>
Graham 1 year ago
parent 2b086a1f8c
commit db07c93471
  1. 1
      asm/build.gradle.kts
  2. 45
      asm/src/main/kotlin/org/openrs2/asm/io/CabLibraryReader.kt
  3. 1
      gradle/libs.versions.toml

@ -14,6 +14,7 @@ dependencies {
implementation(projects.cache)
implementation(projects.compress)
implementation(projects.crypto)
implementation(libs.cabParser)
}
publishing {

@ -0,0 +1,45 @@
package org.openrs2.asm.io
import dorkbox.cabParser.CabParser
import dorkbox.cabParser.CabStreamSaver
import dorkbox.cabParser.structure.CabFileEntry
import org.objectweb.asm.ClassReader
import org.objectweb.asm.tree.ClassNode
import org.openrs2.asm.classpath.JsrInliner
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
public object CabLibraryReader : LibraryReader {
private const val CLASS_SUFFIX = ".class"
override fun read(input: InputStream): Iterable<ClassNode> {
val classes = mutableListOf<ClassNode>()
ByteArrayOutputStream().use { tempOutput ->
CabParser(input, object : CabStreamSaver {
override fun closeOutputStream(outputStream: OutputStream, entry: CabFileEntry) {
if (entry.name.endsWith(CLASS_SUFFIX)) {
val clazz = ClassNode()
val reader = ClassReader(tempOutput.toByteArray())
reader.accept(JsrInliner(clazz), ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES)
classes += clazz
}
tempOutput.reset()
}
override fun openOutputStream(entry: CabFileEntry): OutputStream {
return tempOutput
}
override fun saveReservedAreaData(data: ByteArray?, dataLength: Int): Boolean {
return false
}
}).extractStream()
}
return classes
}
}

@ -29,6 +29,7 @@ bootstrapTable = { module = "org.webjars.npm:bootstrap-table", version = "1.22.1
bouncyCastle-pkix = { module = "org.bouncycastle:bcpkix-jdk15on", version = "1.70" }
bouncyCastle-provider = { module = "org.bouncycastle:bcprov-jdk15on", version = "1.70" }
byteUnits = { module = "com.jakewharton.byteunits:byteunits", version = "0.9.1" }
cabParser = { module = "com.dorkbox:CabParser", version = "3.4" }
clikt = { module = "com.github.ajalt.clikt:clikt", version = "4.2.0" }
commons-compress = { module = "org.apache.commons:commons-compress", version.ref = "commons-compress" }
fastutil = { module = "it.unimi.dsi:fastutil", version = "8.5.12" }

Loading…
Cancel
Save