Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/java-decompiler/jd-core
JD-Core is a JAVA decompiler written in JAVA.
https://github.com/java-decompiler/jd-core
Last synced: 30 days ago
JSON representation
JD-Core is a JAVA decompiler written in JAVA.
- Host: GitHub
- URL: https://github.com/java-decompiler/jd-core
- Owner: java-decompiler
- License: gpl-3.0
- Created: 2019-05-13T19:54:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-19T08:02:04.000Z (8 months ago)
- Last Synced: 2024-11-09T10:39:01.694Z (about 1 month ago)
- Language: Java
- Homepage:
- Size: 2.29 MB
- Stars: 530
- Watchers: 28
- Forks: 135
- Open Issues: 56
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rainmana - java-decompiler/jd-core - JD-Core is a JAVA decompiler written in JAVA. (Java)
README
# JD-Core
JD-Core is a JAVA decompiler written in JAVA.
- Java Decompiler project home page:
[http://java-decompiler.github.io](https://java-decompiler.github.io)
- JD-Core source code:
[https://github.com/java-decompiler/jd-core](https://github.com/java-decompiler/jd-core)
- JCenter Maven repository:
[https://jcenter.bintray.com/](https://bintray.com/java-decompiler/maven/org.jd%3Ajd-core/_latestVersion)## Description
JD-Core is a standalone JAVA library containing the JAVA decompiler of
"Java Decompiler project". It support Java 1.1.8 to Java 12.0,
including Lambda expressions, method references and default methods.
JD-Core is the engine of JD-GUI.## How to build JD-Core ?
```
> git clone https://github.com/java-decompiler/jd-core.git
> cd jd-core
> ./gradlew build
```
generate _"build/libs/jd-core-x.y.z.jar"_## How to use JD-Core ?
1. Implement the
_[org.jd.core.loader.Loader](https://github.com/java-decompiler/jd-core/blob/master/src/main/java/org/jd/core/v1/api/loader/Loader.java)_
interface,
2. Implement the
_[org.jd.core.printer.Printer](https://github.com/java-decompiler/jd-core/blob/master/src/main/java/org/jd/core/v1/api/printer/Printer.java)_
interface,
3. And call the method _"decompile(loader, printer, internalTypeName);"_## Example
1. Implement the _Loader_ interface:
```java
Loader loader = new Loader() {
@Override
public byte[] load(String internalName) throws LoaderException {
InputStream is = this.getClass().getResourceAsStream("/" + internalName + ".class");if (is == null) {
return null;
} else {
try (InputStream in=is; ByteArrayOutputStream out=new ByteArrayOutputStream()) {
byte[] buffer = new byte[1024];
int read = in.read(buffer);while (read > 0) {
out.write(buffer, 0, read);
read = in.read(buffer);
}return out.toByteArray();
} catch (IOException e) {
throw new LoaderException(e);
}
}
}@Override
public boolean canLoad(String internalName) {
return this.getClass().getResource("/" + internalName + ".class") != null;
}
};
```2. Implement the _Printer_ interface
```java
Printer printer = new Printer() {
protected static final String TAB = " ";
protected static final String NEWLINE = "\n";protected int indentationCount = 0;
protected StringBuilder sb = new StringBuilder();@Override public String toString() { return sb.toString(); }
@Override public void start(int maxLineNumber, int majorVersion, int minorVersion) {}
@Override public void end() {}@Override public void printText(String text) { sb.append(text); }
@Override public void printNumericConstant(String constant) { sb.append(constant); }
@Override public void printStringConstant(String constant, String ownerInternalName) { sb.append(constant); }
@Override public void printKeyword(String keyword) { sb.append(keyword); }
@Override public void printDeclaration(int type, String internalTypeName, String name, String descriptor) { sb.append(name); }
@Override public void printReference(int type, String internalTypeName, String name, String descriptor, String ownerInternalName) { sb.append(name); }@Override public void indent() { this.indentationCount++; }
@Override public void unindent() { this.indentationCount--; }@Override public void startLine(int lineNumber) { for (int i=0; i 0) sb.append(NEWLINE); }
@Override public void startMarker(int type) {}
@Override public void endMarker(int type) {}
};
```3. And call the method _"decompile(loader, printer, internalTypeName);"_
```java
ClassFileToJavaSourceDecompiler decompiler = new ClassFileToJavaSourceDecompiler();decompiler.decompile(loader, printer, "path/to/YourClass");
String source = printer.toString();
```## License
Released under the [GNU GPL v3](LICENSE).