Home
What is it?
Platform independent C++ (only STL) implementation of JVM class files parser and disassembler.
Features
- Powerful JVM class file parser and disassembler C++ library.
- Full support of JVM 8.0 specification.
- Fast disassembler.
- Name demangler API.
- Platform independent C++ code (based on STL).
- Fast implementation of file read for Windows and Linux.
- Can read directly from .class file or from memory buffer (e.g. from decompressed .jar file).
- An intuitive interface API.
How to use it?
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):
- version - MSVC/gcc
- version-1 MinGW/gcc
- version-2 clang-cl/clang++
Example: 0.5-2 - CLang build variant of the library.
Documentation
Code example
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;
}
Project Members:
- Alexander Kornilov (admin)