1 unstable release
0.1.0 | Jan 1, 2025 |
---|
#829 in Web programming
165 downloads per month
15KB
113 lines
Java Decompiler Ollama
This Rust library provides functionality to disassemble Java class files using javap
and translate the bytecode to equivalent Java source code using the Ollama API.
Requirements
- Ollama: Ensure that the Ollama API is accessible. By default, the library uses the
qwen2.5-coder
model, but you can change this by setting theOLLAMA_MODEL
environment variable. - Java Development Kit (JDK): Ensure that
javap
is available in your environment, as it is used to disassemble the.class
files.
Installation
Add the following dependency to your Cargo.toml
:
[dependencies]
java_decompiler_ollama = "0.1.0"
Usage
Example: Fibonacci Class
Create a Java class file: Save the following Java code in a file named Fibonacci.java:
public class Fibonacci {
public static void main(String[] args) {
int n = 30;
System.out.println("Fibonacci(" + n + ") = " + fibonacci(n));
}
public static int fibonacci(int n) {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
Compile the Java class:
javac Fibonacci.java
This will generate a Fibonacci.class file.
Place the Fibonacci.class file in the test/dataset/ directory of your Rust project.
Run the Rust example:
cargo run --example basic -- test/dataset/Fibonacci.class
This command will disassemble the Fibonacci.class file and print the equivalent Java source code.
Environment Variables
You can customize the behavior of the library by setting the following environment variables:
OLLAMA_MODEL: The Ollama model to use for translation (default: qwen2.5-coder).
OLLAMA_URL: The URL of the Ollama API (default: http://localhost:11434/api/generate).
License
This project is licensed under the MIT License. See the LICENSE file for details.
Dependencies
~7–19MB
~258K SLoC