#include "Attributes.h" #include #include #include #include #include #include #include #include #include #include #include #include void Methods::MethodParser(method_info &p, JavaClassFormat &jc) { p.access_flags = Utils::ReadFromStartIntoVal(Globals::buffer()); p.name_index = Utils::ReadFromStartIntoVal(Globals::buffer()); p.descriptor_index = Utils::ReadFromStartIntoVal(Globals::buffer()); p.attributes_count = Utils::ReadFromStartIntoVal(Globals::buffer()); // std::cout << p.attributes_count.ToHostFormat() << std::endl; // FIXME: Implement attributes[] for (int i = 0; i < p.attributes_count.ToHostFormat(); i++) { Attributes::CODE_Attribute a; a.attribute_name_index = Utils::ReadFromStartIntoVal(Globals::buffer()); auto v = jc.constant_pool[a.attribute_name_index.ToHostFormat() - 1]; ASSERT(VEC_ELEM_TYPE(v) == TYPE(ConstantPoolTags::ConstantUtf8Info)); ConstantPoolTags::ConstantUtf8Info str = std::any_cast(v); ASSERT(strcmp(str.bytes.c_str(), "Code") == 0); u4 attribute_length = Utils::ReadFromStartIntoVal(Globals::buffer()); std::cout << "(attr)" << a.attribute_name_index.ToHostFormat() << std::endl; a.max_stack = Utils::ReadFromStartIntoVal(Globals::buffer()); a.max_locals = Utils::ReadFromStartIntoVal(Globals::buffer()); a.code_length = Utils::ReadFromStartIntoVal(Globals::buffer()); for (int i = 0; i < a.code_length.ToHostFormat(); i++) { a.code.push_back(Utils::ReadFromStartIntoVal(Globals::buffer())); } a.exception_table_length = Utils::ReadFromStartIntoVal(Globals::buffer()); for (int i = 0; i < a.exception_table_length.ToHostFormat(); i++) { a.exceptions.push_back({.start_pc = Utils::ReadFromStartIntoVal(Globals::buffer()), .end_pc = Utils::ReadFromStartIntoVal(Globals::buffer()), .handler_pc = Utils::ReadFromStartIntoVal(Globals::buffer()), .catch_type = Utils::ReadFromStartIntoVal(Globals::buffer())}); } a.attributes_count = Utils::ReadFromStartIntoVal(Globals::buffer()); for (int i = 0; i < a.attributes_count.ToHostFormat(); i++) { u2 attribute_name_index = Utils::ReadFromStartIntoVal(Globals::buffer()); u4 attribute_length = Utils::ReadFromStartIntoVal(Globals::buffer()); for (int i = 0; i < attribute_length.ToHostFormat(); i++) { Utils::ReadFromStartIntoVal(Globals::buffer()); } // std::cout << attribute_name_index.ToHostFormat() << std::endl; } // for (int j = 0; j < attribute_length.ToHostFormat() - 8; j++) // { // uint8_t data = Utils::ReadFromStartIntoVal(Globals::buffer()); // std::cout << std::dec << std::to_string(data) << std::endl; // // a.info.push_back(Utils::ReadFromStartIntoVal(Globals::buffer())); // } std::cout << a.attribute_name_index.ToHostFormat() << std::endl; // std::cout << info.size() << std::endl; std::cout << std::endl; } // if ((p.access_flags.ToHostFormat() & (int)Method::ACCESS_FLAGS::ACC_NATIVE) == 0 && // (p.access_flags.ToHostFormat() & (int)Method::ACCESS_FLAGS::ACC_ABSTRACT) == 0) // { // std::cout << "Not Set" << std::endl; // } jc.methods.push_back(p); }