// ==UserScript==
// @name localhost wasm
// @namespace http://tampermonkey.net/
// @version 0.1
// @description learn webpack wasm compiling from rust
// @author Your Name
// @match http://localhost/*
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @require http://localhost:8080/index.js
// @run-at document-start
// ==/UserScript==
(function(){
unsafeWindow.WebAssembly.instantiateStreaming_ = unsafeWindow.WebAssembly.instantiateStreaming;
unsafeWindow.WebAssembly.instantiateStreaming = function(bufferSource, importObject){
return unsafeWindow.WebAssembly.instantiateStreaming_(bufferSource, importObject).then(
results => {
// Modify the greet function once the WebAssembly instance is created
const instance = results.instance;
debugger;
// Hook the greet function
const originalGreet = instance.exports.greet;
// debugger;
instance.exports.greet = function(...args) {
// args 是一个包含所有传入参数的数组
console.log('Hooked greet function called with arguments:', args);
// 调用原始 greet 函数,使用 apply 方法传递所有参数
return originalGreet.apply(instance, args); // args 会自动展开为多个参数传递给原始函数
};
// Expose instance globally if needed
unsafeWindow.greet = instance.exports.greet;
console.log('WebAssembly instance created and greet hooked');
return results; // Return the original results
});
}
})();
这里greet明明被调用了,但是hook不到,是因为greet是只读不可修改属性的原因吗,要怎么用proxy或者defineproporty来修改属性然后hook到greet函数呀(比如修改参数显示"哥哥牛逼")