From 47df11608368537677c02c649e6d526d9893a88e Mon Sep 17 00:00:00 2001 From: calcium Date: Sat, 24 Aug 2024 23:38:54 -0400 Subject: [PATCH] Swapped to using std::string from unsigned char* for ConstantUtf8Info.bytes --- include/ConstantPoolTags/Tags.h | 4 ++-- src/Main.cpp | 3 ++- src/Method/MethodParser.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ConstantPoolTags/Tags.h b/include/ConstantPoolTags/Tags.h index 83a708d..aafa2a2 100644 --- a/include/ConstantPoolTags/Tags.h +++ b/include/ConstantPoolTags/Tags.h @@ -4,7 +4,7 @@ #include #include #include - +#include struct JavaClassFormat; @@ -47,7 +47,7 @@ struct ConstantUtf8Info : ConstantPoolInfo { ConstantPoolTags::Tags tag; u2 length; - unsigned char *bytes; + std::string bytes; // std::vector bytes; }; diff --git a/src/Main.cpp b/src/Main.cpp index 0347966..725e389 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -163,7 +163,8 @@ int main(int argc, char **argv) if (x == TYPE(ConstantPoolTags::ConstantUtf8Info)) { - std::cout << "utf8:\t" << std::any_cast(jc.constant_pool[i]).bytes << std::endl; + ConstantPoolTags::ConstantUtf8Info ref = std::any_cast(jc.constant_pool[i]); + std::cout << "utf8:\t" << "(length): " << ref.length.ToHostFormat() << ",\t(str): " << ref.bytes << std::endl; } else if (x == TYPE(ConstantPoolTags::ConstantClassInfo)) { diff --git a/src/Method/MethodParser.cpp b/src/Method/MethodParser.cpp index 0820eeb..815eef2 100644 --- a/src/Method/MethodParser.cpp +++ b/src/Method/MethodParser.cpp @@ -32,7 +32,7 @@ void Methods::MethodParser(method_info &p, JavaClassFormat &jc) ASSERT(VEC_ELEM_TYPE(v) == TYPE(ConstantPoolTags::ConstantUtf8Info)); ConstantPoolTags::ConstantUtf8Info str = std::any_cast(v); - ASSERT(strcmp(reinterpret_cast(str.bytes), "Code") == 0); + ASSERT(strcmp(str.bytes.c_str(), "Code") == 0); u4 attribute_length = Utils::ReadFromStartIntoVal(Globals::buffer());