Added improved support for the .class file spec

This commit is contained in:
calcium 2024-08-19 20:10:15 -04:00
parent 1749594952
commit 65e88b7f76

View File

@ -1,13 +1,16 @@
#include "ConstantPoolTags/Tags.h"
#include <Globals.h>
#include <Utils/Utils.h>
#include "Attributes.h"
#include <ClassFormat.h>
#include <SpecTypes.h>
#include <ConstantPoolTags/Tags.h>
#include <Globals.h>
#include <Methods.h>
#include <SpecTypes.h>
#include <Utils/Utils.h>
#include <any>
#include <cassert>
#include <cstdint>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
void Methods::MethodParser(method_info &p, JavaClassFormat &jc)
{
@ -22,17 +25,63 @@ void Methods::MethodParser(method_info &p, JavaClassFormat &jc)
for (int i = 0; i < p.attributes_count.ToHostFormat(); i++)
{
attribute_info a;
Attributes::CODE_Attribute a;
a.attribute_name_index = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
a.attribute_length = Utils::ReadFromStartIntoVal<uint32_t>(Globals::buffer());
for (int j = 0; j < a.attribute_length.ToHostFormat(); j++)
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<ConstantPoolTags::ConstantUtf8Info>(v);
ASSERT(strcmp(reinterpret_cast<const char *>(str.bytes), "Code") == 0);
u4 attribute_length = Utils::ReadFromStartIntoVal<uint32_t>(Globals::buffer());
std::cout << "(attr)" << a.attribute_name_index.ToHostFormat() << std::endl;
a.max_stack = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
a.max_locals = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
a.code_length = Utils::ReadFromStartIntoVal<uint32_t>(Globals::buffer());
for (int i = 0; i < a.code_length.ToHostFormat(); i++)
{
a.info.push_back(Utils::ReadFromStartIntoVal<uint8_t>(Globals::buffer()));
a.code.push_back(Utils::ReadFromStartIntoVal<uint8_t>(Globals::buffer()));
}
a.exception_table_length = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
for (int i = 0; i < a.exception_table_length.ToHostFormat(); i++)
{
a.exceptions.push_back({.start_pc = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer()),
.end_pc = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer()),
.handler_pc = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer()),
.catch_type = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer())});
}
a.attributes_count = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
for (int i = 0; i < a.attributes_count.ToHostFormat(); i++)
{
u2 attribute_name_index = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
u4 attribute_length = Utils::ReadFromStartIntoVal<uint32_t>(Globals::buffer());
for (int i = 0; i < attribute_length.ToHostFormat(); i++)
{
Utils::ReadFromStartIntoVal<uint8_t>(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<uint8_t>(Globals::buffer());
// std::cout << std::dec << std::to_string(data) << std::endl;
// // a.info.push_back(Utils::ReadFromStartIntoVal<uint8_t>(Globals::buffer()));
// }
std::cout << a.attribute_name_index.ToHostFormat() << std::endl;
// std::cout << a.info.size() << std::endl;
// std::cout << info.size() << std::endl;
std::cout << std::endl;
}
// if ((p.access_flags.ToHostFormat() & (int)Method::ACCESS_FLAGS::ACC_NATIVE) == 0 &&