From 728dd06cb8d2e109a7e604536a1c100f86a930d5 Mon Sep 17 00:00:00 2001 From: lvntky Date: Thu, 20 Jun 2024 14:25:34 +0300 Subject: [PATCH] [feature] to_list added for classfile --- include/cvm/classfile/classfile.hpp | 1 + src/classfile/classfile.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/cvm/classfile/classfile.hpp b/include/cvm/classfile/classfile.hpp index 007bdc1..a2f63b8 100644 --- a/include/cvm/classfile/classfile.hpp +++ b/include/cvm/classfile/classfile.hpp @@ -34,6 +34,7 @@ class Classfile uint64_t readLong(const uint8_t *bytes, size_t &offset); double readDouble(const uint8_t *bytes, size_t &offset); Classfile parseClassfile(const uint8_t *classBytes, size_t fileSize); + std::string to_string(); }; #endif //__CLASSFILE_HPP__ diff --git a/src/classfile/classfile.cpp b/src/classfile/classfile.cpp index 76e9ae7..b6f9c5a 100644 --- a/src/classfile/classfile.cpp +++ b/src/classfile/classfile.cpp @@ -1,5 +1,7 @@ #include "../../include/cvm/classfile/classfile.hpp" +#include + #include #include "../../include/cvm/log.hpp" @@ -47,6 +49,25 @@ double Classfile::readDouble(const uint8_t* bytes, size_t& offset) spdlog::debug("Read double: {}, new offset: {}", value, offset); return value; } + + +std::string Classfile::to_string() +{ + std::ostringstream oss; + oss << "Magic: " << std::hex << magic << std::dec << "\n" + << "Minor Version: " << minor_version << "\n" + << "Major Version: " << major_version << "\n" + << "Constant Pool Count: " << constant_pool_count << "\n" + << "Access Flags: " << access_flags << "\n" + << "This Class: " << this_class << "\n" + << "Super Class: " << super_class << "\n" + << "Interfaces Count: " << interfaces_count << "\n" + << "Fields Count: " << fields_count << "\n" + << "Methods Count: " << methods_count << "\n" + << "Attributes Count: " << attributes_count; + return oss.str(); +} + /** * Helper methods for validating etc. */ @@ -195,5 +216,8 @@ Classfile Classfile::parseClassfile(const uint8_t* classBytes, size_t fileSize) cf.super_class = readShort(classBytes, offset); cf.interfaces_count = readShort(classBytes, offset); + std::string classFileString = cf.to_string(); + spdlog::info("The Parsed Classfile:\n{}", classFileString); + return cf; }