diff --git a/build.gradle.kts b/build.gradle.kts index 02c7bcb..2b8e187 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { alias(libs.plugins.teavm) // order matters? } -val thisVersion = "0.1.0" +val thisVersion = "0.2.0" group = "run.slicer" version = "$thisVersion-${libs.versions.jasm.get()}" diff --git a/docs/index.html b/docs/index.html index 7ba2a45..5203703 100644 --- a/docs/index.html +++ b/docs/index.html @@ -64,11 +64,11 @@ const file = e.target.files[0]; if (file) { const reader = new FileReader(); - reader.onload = (evt) => { + reader.onload = async (evt) => { const start = Date.now(); console.log(`Disassembling ${file.name}...`); - document.getElementById("file-content").textContent = disassemble(new Uint8Array(evt.target.result)); + document.getElementById("file-content").textContent = await disassemble(new Uint8Array(evt.target.result)); console.log(`Disassembled ${file.name} in ${Date.now() - start}ms.`); }; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ee3c1db..7315c2b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -jasm = "2.5.0" +jasm = "2.6.0" teavm = "0.10.0" [libraries] diff --git a/jasm.d.ts b/jasm.d.ts index 8efe84c..8c9c99f 100644 --- a/jasm.d.ts +++ b/jasm.d.ts @@ -3,5 +3,5 @@ declare module "@run-slicer/jasm" { indent?: string; } - export function disassemble(b: Uint8Array, config?: DisassemblyConfig): string; + export function disassemble(b: Uint8Array, config?: DisassemblyConfig): Promise; } diff --git a/src/main/java/run/slicer/jasm/Main.java b/src/main/java/run/slicer/jasm/Main.java index 4d6ddc9..2fe41e6 100644 --- a/src/main/java/run/slicer/jasm/Main.java +++ b/src/main/java/run/slicer/jasm/Main.java @@ -5,25 +5,35 @@ import org.teavm.jso.JSByRef; import org.teavm.jso.JSExport; import org.teavm.jso.core.JSObjects; +import org.teavm.jso.core.JSPromise; +import org.teavm.jso.core.JSString; import java.io.IOException; import java.io.UncheckedIOException; public class Main { @JSExport - public static String disassemble(@JSByRef byte[] b, DisassemblyOptions options) { + public static JSPromise disassemble(@JSByRef byte[] b, DisassemblyOptions options) { return disassemble0(b, options == null || JSObjects.isUndefined(options) ? JSObjects.create() : options); } - private static String disassemble0(byte[] b, DisassemblyOptions options) { - final var ctx = new PrintContext<>(options.indent()); + private static JSPromise disassemble0(byte[] b, DisassemblyOptions options) { + return new JSPromise<>((resolve, reject) -> { + new Thread(() -> { + try { + final var ctx = new PrintContext<>(options.indent()); - try { - new JvmClassPrinter(b).print(ctx); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + try { + new JvmClassPrinter(b).print(ctx); + } catch (IOException e) { + throw new UncheckedIOException(e); + } - return ctx.toString(); + resolve.accept(JSString.valueOf(ctx.toString())); + } catch (Throwable e) { + reject.accept(e); + } + }).start(); + }); } }