Created
March 28, 2023 15:10
-
-
Save scratchadams/43607661cbd86137cbcf9e540e2a73ec to your computer and use it in GitHub Desktop.
WASM sanitizer for acropalypse
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
(module | |
(import "js" "mem" (memory 1)) | |
(import "console" "log" (func $log (param i32))) | |
(func $getbyte (param $pos i32) (result i32) | |
local.get $pos | |
i32.const 255 | |
i32.and | |
) | |
(func (export "memtest") (param $size i32) (result i32) | |
(local $hdr i32) (local $ftr i32) (local $hdridx i32) | |
(local $ftridx i32) (local $idx i32) | |
i32.const 0 | |
local.set $hdr | |
i32.const 0 | |
local.set $ftr | |
i32.const 4 | |
local.set $idx | |
local.get $idx | |
i32.load | |
i32.const 0x474E5089 | |
i32.eq | |
if | |
local.get $idx | |
i32.const 4 | |
i32.add | |
local.set $idx | |
else | |
i32.const 1 | |
return | |
end | |
(loop $locate_iend | |
local.get $idx | |
i32.load | |
i32.const 0x444E4549 | |
i32.eq | |
if | |
local.get $idx | |
local.set $ftr | |
local.get $idx | |
i32.const 8 | |
i32.add | |
local.set $idx | |
else | |
local.get $idx | |
i32.const 1 | |
i32.add | |
local.set $idx | |
br $locate_iend | |
end | |
) | |
local.get $ftr | |
i32.const 0 | |
i32.gt_s | |
if | |
local.get $idx | |
local.get $size | |
i32.lt_s | |
if | |
(loop $null_bytes | |
local.get $idx | |
i32.const 0 | |
i32.store | |
local.get $idx | |
i32.const 1 | |
i32.add | |
local.set $idx | |
local.get $idx | |
local.get $size | |
i32.lt_s | |
if | |
br $null_bytes | |
end | |
) | |
end | |
end | |
i32.const 1 | |
return) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment