From 256b7117409be41abd8477f13a6e53ec0bdca3f4 Mon Sep 17 00:00:00 2001 From: Doehyun Baek Date: Wed, 6 Dec 2023 17:21:02 +0900 Subject: [PATCH] handle WebAssembly.Instance and Module --- src/runtime.js | 27 +++++++++++++++++++++++++++ wasabi | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/runtime.js b/src/runtime.js index 1519ec07..5517680b 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -54,6 +54,7 @@ function setup() { initSync(buffer) let original_instantiate = WebAssembly.instantiate WebAssembly.instantiate = function (buffer, importObject) { + buffer = (buffer.byte) ? buffer.byte : buffer // self.performanceList.push(p_timeToFirstInstantiate.stop()) const this_i = i i += 1 @@ -85,5 +86,31 @@ function setup() { let body = await response.arrayBuffer(); return WebAssembly.instantiate(body, obj); } + const original_module = WebAssembly.Module + WebAssembly.Module = function (byte) { + console.log('WebAssembly.Module') + const module = new original_module(byte) + module.byte = byte + return module + } + const original_instance = WebAssembly.Instance + WebAssembly.Instance = function (module, importObject) { + console.log('WebAssembly.Instance') + let buffer = module.byte + const this_i = i + i += 1 + printWelcome() + self.originalWasmBuffer.push(Array.from(new Uint8Array(buffer))) + const { instrumented, js } = instrument_wasm(new Uint8Array(buffer)); + wasabis.push(eval(js + '\nWasabi')) + buffer = new Uint8Array(instrumented) + importObject = importObjectWithHooks(importObject, this_i) + self.analysis.push(setupAnalysis(wasabis[this_i])) + let result + module = new WebAssembly.Module(buffer) + const instance = new original_instance(module, importObject) + result = wireInstanceExports(instance, this_i) + return instance + } } setup() diff --git a/wasabi b/wasabi index bb715211..cceef12d 160000 --- a/wasabi +++ b/wasabi @@ -1 +1 @@ -Subproject commit bb71521154c4aaa272cd7c506cfaecd6d8e3a0a7 +Subproject commit cceef12d0ab5c7d0abc69a0d3cd90542ac0fda59