From bc5f9668e92dee2b8fcd9bd9f8aa511f1de783a9 Mon Sep 17 00:00:00 2001 From: silur Date: Mon, 29 Nov 2021 23:11:47 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 ++ Cargo.toml | 10 ++++++++++ src/lib.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3695f7e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "wasmfuzz" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +wasmi = "0.9.1" +wabt = "0.10.0" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b5d74d8 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,57 @@ +use wasmi::{ModuleInstance, ImportsBuilder, NopExternals, RuntimeValue}; + +fn init_population() -> Vec { + unimplemented!(); +} + +fn mutate() -> Vec { + unimplemented!(); +} + +fn asd() { + // Parse WAT (WebAssembly Text format) into wasm bytecode. + let wasm_binary: Vec = + wabt::wat2wasm( + r#" + (module + (func (export "test") (result i32) + i32.const 1337 + ) + ) + "#, + ) + .expect("failed to parse wat"); + + // Load wasm binary and prepare it for instantiation. + let module = wasmi::Module::from_buffer(&wasm_binary) + .expect("failed to load wasm"); + + // Instantiate a module with empty imports and + // assert that there is no `start` function. + let instance = + ModuleInstance::new( + &module, + &ImportsBuilder::default() + ) + .expect("failed to instantiate wasm module") + .assert_no_start(); + + // Finally, invoke the exported function "test" with no parameters + // and empty external function executor. + assert_eq!( + instance.invoke_export( + "test", + &[], + &mut NopExternals, + ).expect("failed to execute export"), + Some(RuntimeValue::I32(1337)), + ); +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + super::asd(); + } +}