From 586b2912bed9c4303d62ea62fdc845734be490f9 Mon Sep 17 00:00:00 2001 From: calcium Date: Sat, 24 Aug 2024 23:43:47 -0400 Subject: [PATCH] Fixed incorrect string length being stored --- src/ConstantPoolTags/PoolParser.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/ConstantPoolTags/PoolParser.cpp b/src/ConstantPoolTags/PoolParser.cpp index 3c85d87..c0b4181 100644 --- a/src/ConstantPoolTags/PoolParser.cpp +++ b/src/ConstantPoolTags/PoolParser.cpp @@ -14,31 +14,34 @@ void ConstantPoolTags::ConstantPoolParser(ConstantPoolTags::Tags t, JavaClassFor case Tags::Utf8: { // std::cout << "FIXME: Implement Utf8 Constant Pool Tag" << std::endl; ConstantUtf8Info ref; - std::vector length = Utils::ReadFromStart(Globals::buffer(), 2); + ref.length = Utils::ReadFromStartIntoVal(Globals::buffer(), 2); + // std::vector length = Utils::ReadFromStart(Globals::buffer(), 2); ref.tag = t; - ref.length = Utils::vecToVal(length); + // ref.length = Utils::vecToVal(length); unsigned char x = Utils::ReadFromStartIntoVal(Globals::buffer(), 1); bool valid = true; - ref.bytes = new unsigned char[ref.length.ToHostFormat()]; + unsigned char* bytes = new unsigned char[ref.length.ToHostFormat()]; + + int len = 0; for (int i = 0; i < ref.length.ToHostFormat(); i++) { if ((x & 0x80) == 0) { - ref.bytes[i] = x; + bytes[i] = x; } else if ((x & 0x800) == 0) { unsigned char y = Utils::ReadFromStartIntoVal(Globals::buffer(), 1); - ref.bytes[i] = ((x & 0x1f) << 6) + (y & 0x3f); + bytes[i] = ((x & 0x1f) << 6) + (y & 0x3f); } else if ((x & 0x10000) == 0) { unsigned char y = Utils::ReadFromStartIntoVal(Globals::buffer(), 1); unsigned char z = Utils::ReadFromStartIntoVal(Globals::buffer(), 1); - ref.bytes[i] = ((x & 0xf) << 12) + ((y & 0x3f) << 6) + (z & 0x3f); + bytes[i] = ((x & 0xf) << 12) + ((y & 0x3f) << 6) + (z & 0x3f); } else { @@ -46,11 +49,20 @@ void ConstantPoolTags::ConstantPoolParser(ConstantPoolTags::Tags t, JavaClassFor exit(1); } - if (i != ref.length.ToHostFormat() - 1) + if (i < ref.length.ToHostFormat() - 1) x = Utils::ReadFromStartIntoVal(Globals::buffer(), 1); + + len += 1; } + + std::string bytes1; + + bytes1.append(reinterpret_cast(bytes), 0, len); + + ref.bytes = bytes1; jc.constant_pool.push_back(ref); + ref.length = len; break; } case Tags::Integer: