From adc1138ca4f158b3e7571d907fb3a159bb9b728a Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 17 Dec 2021 20:59:23 +0000 Subject: [PATCH] Convert packclass try/catch count to an unsigned short smart This fixes compatibility with very modern packclass files. Signed-off-by: Graham --- .../org/openrs2/asm/packclass/PackClass.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/asm/src/main/kotlin/org/openrs2/asm/packclass/PackClass.kt b/asm/src/main/kotlin/org/openrs2/asm/packclass/PackClass.kt index 9efe9608..81bafc6a 100644 --- a/asm/src/main/kotlin/org/openrs2/asm/packclass/PackClass.kt +++ b/asm/src/main/kotlin/org/openrs2/asm/packclass/PackClass.kt @@ -376,7 +376,7 @@ public object PackClass { // read method metadata val exceptionCounts = readExceptionCounts(buf, methodAttributes) - val tryCatchCounts = readMaxs(buf, methodAttributes) + val tryCatchCounts = readTryCatchCounts(buf, methodAttributes) val maxStacks = readMaxs(buf, methodAttributes) val maxLocals = readMaxs(buf, methodAttributes) val lineStartPcs = readLinePcs(buf, methodAttributes) @@ -815,6 +815,21 @@ public object PackClass { } } + private fun readTryCatchCounts(buf: ByteBuf, attributes: Array>): 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>): IntArray { return IntArray(attributes.size) { i -> if (attributes[i].contains(ConstantPool.CODE)) { @@ -1399,7 +1414,7 @@ public object PackClass { private fun writeTryCatchCounts(buf: ByteBuf, clazz: ClassNode) { for (method in clazz.methods) { if (method.instructions.size() != 0) { - buf.writeByte(method.tryCatchBlocks.size) + buf.writeUnsignedShortSmart(method.tryCatchBlocks.size) } } }