Convert packclass try/catch count to an unsigned short smart

This fixes compatibility with very modern packclass files.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 3 years ago
parent 211041ab6d
commit adc1138ca4
  1. 19
      asm/src/main/kotlin/org/openrs2/asm/packclass/PackClass.kt

@ -376,7 +376,7 @@ public object PackClass {
// read method metadata // read method metadata
val exceptionCounts = readExceptionCounts(buf, methodAttributes) val exceptionCounts = readExceptionCounts(buf, methodAttributes)
val tryCatchCounts = readMaxs(buf, methodAttributes) val tryCatchCounts = readTryCatchCounts(buf, methodAttributes)
val maxStacks = readMaxs(buf, methodAttributes) val maxStacks = readMaxs(buf, methodAttributes)
val maxLocals = readMaxs(buf, methodAttributes) val maxLocals = readMaxs(buf, methodAttributes)
val lineStartPcs = readLinePcs(buf, methodAttributes) val lineStartPcs = readLinePcs(buf, methodAttributes)
@ -815,6 +815,21 @@ public object PackClass {
} }
} }
private fun readTryCatchCounts(buf: ByteBuf, attributes: Array<Array<String>>): IntArray {
return IntArray(attributes.size) { i ->
if (attributes[i].contains(ConstantPool.CODE)) {
/*
* XXX(gpe): in older versions of packclass this is an unsigned
* byte. Are there any class files using the older format with
* 128 or more try/catch blocks per method?
*/
buf.readUnsignedShortSmart()
} else {
0
}
}
}
private fun readMaxs(buf: ByteBuf, attributes: Array<Array<String>>): IntArray { private fun readMaxs(buf: ByteBuf, attributes: Array<Array<String>>): IntArray {
return IntArray(attributes.size) { i -> return IntArray(attributes.size) { i ->
if (attributes[i].contains(ConstantPool.CODE)) { if (attributes[i].contains(ConstantPool.CODE)) {
@ -1399,7 +1414,7 @@ public object PackClass {
private fun writeTryCatchCounts(buf: ByteBuf, clazz: ClassNode) { private fun writeTryCatchCounts(buf: ByteBuf, clazz: ClassNode) {
for (method in clazz.methods) { for (method in clazz.methods) {
if (method.instructions.size() != 0) { if (method.instructions.size() != 0) {
buf.writeByte(method.tryCatchBlocks.size) buf.writeUnsignedShortSmart(method.tryCatchBlocks.size)
} }
} }
} }

Loading…
Cancel
Save