A Java library for reverse engineering Java class files and jars. It contains a class file parser for accurate class file representation and a modern and fast bytecode decompiler. It is currently under development.
Note: Currently only capable of parsing Java 8 files
- Full support of the Java 8 classfile format and the Java 8 instruction set
- Fast loading time and accurate representation of the classfile
- Easy to use API
git clone https://github.com/mrsalwater/Kapteyn.git
cd Kapteyn
./gradlew build
public static String decompile(byte[] bytes) throws ClassFileException {
ClassFileParser classFileParser = new ClassFileParser(bytes);
ClassFile classFile = classFileParser.parse();
ByteCodeParser byteCodeParser = new ByteCodeParser(classFile);
ByteCodeFile byteCodeFile = byteCodeParser.parse();
return byteCodeFile.getSource();
}
ClassFileParser classFileParser = new ClassFileParser(bytes);
ClassFile classFile = classFileParser.parse();
if (ClassFileVersion.match(classFile.getMajorVersion()) == ClassFileVersion.JAVA_8) {
/* ... */
}
ConstantPool constantPool = classFile.getConstantPool();
String thisClassName = constantPool.getUTF8(classFile.getThisClass()).getValue();
String superClassName = constantPool.getUTF8(classFile.getSuperClass()).getValue();
AccessFlags accessFlags = new AccessFlags(classFile.getAccessFlags());
if (accessFlags.isPublic() && accessFlags.isStatic()) {
/* ... */
}
for (int index : classFile.getInterfaces()) {
String interfaceName = constantPool.getUTF8(constantPool.getClass(index).getNameIndex()).getValue();
/* ... */
}
for (Field field : classFile.getFields()) {
String fieldName = constantPool.getUTF8(field.getNameIndex()).getValue();
String fieldDescriptor = constantPool.getUTF8(field.getDescriptorIndex()).getValue();
/* ... */
}
for (Method method : classFile.getMethods()) {
String methodName = constantPool.getUTF8(method.getNameIndex()).getValue();
String methodDescriptor = constantPool.getUTF8(method.getDescriptorIndex()).getValue();
/* ... */
}
Attributes classAttributes = classFile.getAttributes();
if (classAttributes.has(AttributeRuntimeVisibleAnnotations.class)) {
AttributeRuntimeVisibleAnnotations annotations = classAttributes.get(AttributeRuntimeVisibleAnnotations.class);
/* ... */
}
- Java documentation
The official defining document of the Java Virtual Machine
Authors: Tim Lindholm, Frank Yellin, Gilad Bracha, Alex Buckley (2015-02-13) - Fernflower
"Fernflower is the first actually working analytical decompiler for Java and probably for a high-level programming language in general"
Author: JetBrains - Procyon
"Procyon is a suite of Java metaprogramming tools focused on code generation and analysis"
Author: Stefan Steiger - JD-Core
"JD-Core is a Java decompiler written in Java"
Author: Emmanuel Dupuy
This software is licensed under the MIT License
Copyright 2020 mrsalwater