Platform independent C++ (only STL) implementation of JVM class files parser and disassembler.
Build from sources by Gradle or just put class-reader artifact as a dependency in your Gradle build script and enjoy :)
Example of build.gradle for application:
plugins {
id 'cpp-application'
}
repositories {
maven {
url = 'https://cpp-mate.sourceforge.io/maven'
}
maven {
url = 'https://class-reader.sourceforge.io/maven'
}
}
application {
dependencies {
implementation 'loggersoft:cpp-mate:0.5'
implementation 'loggersoft.jvm:class-reader:0.9'
}
}
At moment Gradle Artifactory has only Windows and Linux x86-64 binaries.
Versions variants for different toolchains (Windows/Linux):
Example: 0.5-2 - CLang build variant of the library.
Dump all public methods of the class to console:
#include <ClassReader/ClassFile.hpp>
#include <iostream>
#include <fstream>
using namespace ClassReader;
int main(int argc, char* argv[])
{
if (argc <= 1) {
std::cout << "Please specify .class file name." << std::endl;
return 0;
}
try {
const auto file = ClassFile::load(argv[1]);
for (const auto& method: file->getMethods()) {
if (method.hasAccessFlag(Method::AccessFlags::Public)) {
std::cout << method.getName() << std::endl;
}
}
} catch(const std::ifstream::failure& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
} catch(const std::bad_alloc& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 2;
} catch(const std::system_error& e) {
std::cerr << "Error: Failed to open class file '" << argv[1] << "' with reason: " << e.code().message() << std::endl;
return 3;
}
return 0;
}