Last active
November 27, 2024 22:11
-
-
Save yurydelendik/2061007fc0f8736d30f554bdeba10df0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script> | |
var memory; | |
var env = { | |
sys: { | |
print(ptr) { | |
let p = ptr; | |
while (memory[p]) p++; | |
console.log(String.fromCharCode(...memory.subarray(ptr, p))); | |
} | |
} | |
}; | |
fetch('helloworld2.wasm') | |
.then(req => req.arrayBuffer()) | |
.then(buf => WebAssembly.instantiate(buf, env)) | |
.then(({instance}) => { | |
memory = new Uint8Array(instance.exports.memory.buffer); | |
instance.exports.main(); | |
}); | |
</script> | |
<h1>base64 helloworld2.wasm</h1> | |
<p>AGFzbQ0AAAABiICAgAACYAF/AGAAAAKNgICAAAEDc3lzBXByaW50AAADgoCAgAABAQWGgICAAAEByAHIAQeRgICAAAIGbWVtb3J5AgAEbWFpbgABCoyAgIAAAYaAgIAAAEEAEAALC5OAgIAAAQBBAAsNSGVsbG8sIHdvcmxkAA==</p> | |
<h1>wasm-dis helloworld2.wasm | tee helloworld2.wast</h1> | |
<pre> | |
(module | |
(memory (export "memory") 200 200) | |
(data (i32.const 0) "Hello, world\00") | |
(import $print "sys" "print" (param i32)) | |
(func (export "main") | |
(call $print | |
(i32.const 0) | |
) | |
) | |
) | |
</pre> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing. good wasm guide is very rare