Last active
October 12, 2021 08:35
-
-
Save WietseWind/0a0d07e7df8e44efa9c8befa55d97b7d to your computer and use it in GitHub Desktop.
Hook in AssemblyScript
This file contains 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
npx asc src/assembly/hook.ts \ | |
-O3 \ | |
--noAssert \ | |
--runtime minimal \ | |
-b build/hook.wasm \ | |
-t build/hook.wat \ | |
-d build/hook.d.ts |
This file contains 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
const fs = require('fs') | |
binary = fs.readFileSync('build/hook.wasm').toString('hex').toUpperCase() | |
console.log(binary) |
This file contains 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
@external("env", "_g") | |
declare function _g(id: i32, maxiter: i32): i32 | |
@external("env", "accept") | |
declare function accept(read_ptr: string, read_len: i32, err: i64): i64 | |
@external("env", "trace") | |
declare function trace(mread_ptr: string, mread_len: i32, dread_ptr: string, dread_len: i32, as_hex: i32): i64 | |
const n = '' | |
export function cbak(reserved: i64): i64 { | |
return 0 | |
} | |
export function hook(reserved: i64): i64 { | |
const t = "test" | |
_g(1, 1) | |
for (let i = 0; _g(10, 10), i < 3; i++) { | |
trace(t, t.length * 2, t, t.length * 2, 0) | |
} | |
accept(t, t.length * 2, 0) | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment