feat: support auto decompiling with cfr

This commit is contained in:
ReaJason
2026-08-30 21:19:42 +08:00
parent b74c8f6155
commit 305bc0e12c
19 changed files with 692 additions and 29 deletions
+10
View File
@@ -0,0 +1,10 @@
declare module "@run-slicer/cfr" {
export type Options = Record<string, string>;
export interface Config {
source?: (name: string) => Uint8Array | null;
options?: Options;
}
export function decompile(name: string, config?: Config): Promise<string>;
}
+19
View File
@@ -0,0 +1,19 @@
const isNode =
typeof process !== "undefined" &&
process?.versions?.node != null;
const wasmPath = async () => {
const url = new URL("./cfr.wasm", import.meta.url).href;
return isNode ? await import("node:url").then((mod) => mod.fileURLToPath(url)) : url;
};
let decompileFunc = null;
export const decompile = async (name, options) => {
if (!decompileFunc) {
const { load } = await import("./cfr.wasm-runtime.js");
const { exports } = await load(await wasmPath(), { noAutoImports: true });
decompileFunc = exports.decompile;
}
return decompileFunc(name, options);
};
BIN
View File
Binary file not shown.
File diff suppressed because one or more lines are too long
+24
View File
@@ -0,0 +1,24 @@
{
"name": "@run-slicer/cfr",
"version": "0.1.6-0.152",
"description": "A JavaScript port of the CFR decompiler (https://github.com/leibnitz27/cfr).",
"type": "module",
"main": "cfr.js",
"module": "cfr.js",
"exports": {
".": {
"types": "./cfr.d.ts",
"import": "./cfr.js",
"default": "./cfr.js"
}
},
"types": "cfr.d.ts",
"keywords": [
"decompiler",
"java",
"decompilation",
"cfr"
],
"author": "run-slicer",
"license": "MIT"
}