Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Last active October 12, 2021 08:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WietseWind/0a0d07e7df8e44efa9c8befa55d97b7d to your computer and use it in GitHub Desktop.
Save WietseWind/0a0d07e7df8e44efa9c8befa55d97b7d to your computer and use it in GitHub Desktop.
Hook in AssemblyScript
npx asc src/assembly/hook.ts \
-O3 \
--noAssert \
--runtime minimal \
-b build/hook.wasm \
-t build/hook.wat \
-d build/hook.d.ts
const fs = require('fs')
binary = fs.readFileSync('build/hook.wasm').toString('hex').toUpperCase()
console.log(binary)
@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