Skip to content

katana-project/vf

Repository files navigation

vf

A JavaScript port of the Vineflower decompiler.

Example

const fs = require("fs");
const { decompile } = require("./vf.js"); // get it from the dist/ directory or jsDelivr

const data = fs.readFileSync("./your/package/HelloWorld.class"); // read a class file
const result = await decompile(["your/package/HelloWorld", /* you can decompile multiple classes at once */], {
    source: async (name) => {
        /* provide classes for analysis here, including the one you want to decompile */

        console.log(name); /* internal name, e.g. java/lang/Object */
        return name === "your/package/HelloWorld" ? data : null /* class not available */;
    },
    resources: [
        /* class names of supporting resources (libraries), which `source` can load */
        // "java/lang/Object",
    ],
    options: {
        /* see https://github.com/Vineflower/vineflower/blob/master/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java#L11 */
        "banner": "// Decompiled with Vineflower in TeaVM!\n", /* testing option - comment on top of the decompiled code */
    },
    tokenCollector: {
        /* exposes the text tokens generated by the decompiler */
        /* useful for gathering info about placement of element references/declarations in the output */
        /* see the vf.d.ts file for the API */
    },
    logger: {
        /* exposes the logger, defaults to writing to the console if not present */
        /* see the vf.d.ts file for the API */
    },
}); // {"your/package/HelloWorld": "decompiled source code here..."}
console.log(result["your/package/HelloWorld"]);

Or see the browser-based proof-of-concept in the docs directory.

Notes

This project leverages a dependency analyzer to determine which classes are needed for decompilation and pre-fetch them before decompilation begins. This is needed to prevent the decompiler from having to make asynchronous calls to fetch classes during decompilation, which would require a costly coroutine transformation of the decompiler code.

The aforementioned analyzer does not create a complete, transitive dependency graph, as that would require way more classes to be loaded into memory than necessary. This approach is sufficient for the decompiler to work, but it may worsen the quality of the decompiled code in some cases, notably:

  • generic type casts and intersection type resolution
  • enhanced for loop and try-with-resources resugaring
  • and possibly more

Licensing

The supporting code for this project is licensed under the MIT License. The Vineflower decompiler is licensed under the Apache License 2.0.

This project is not affiliated with, maintained or endorsed by the Vineflower project in any way. Do NOT report issues with this project to the Vineflower issue tracker.

About

A JavaScript port of the Vineflower decompiler.

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE-VF

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors