1 extern crate parity_wasm; 2 3 use std::env; 4 main()5fn main() { 6 let args = env::args().collect::<Vec<_>>(); 7 if args.len() != 3 { 8 println!("Usage: {} <wasm file> <index of function>", args[0]); 9 return; 10 } 11 12 let module = parity_wasm::deserialize_file(&args[1]).expect("Failed to load module"); 13 let function_index = args[2].parse::<usize>().expect("Failed to parse function index"); 14 15 if module.code_section().is_none() { 16 println!("no code in module!"); 17 std::process::exit(1); 18 } 19 20 let sig = match module.function_section().unwrap().entries().get(function_index) { 21 Some(s) => s, 22 None => { 23 println!("no such function in module!"); 24 std::process::exit(1) 25 } 26 }; 27 28 let sig_type = &module.type_section().expect("No type section: module malformed").types()[sig.type_ref() as usize]; 29 let code = &module.code_section().expect("Already checked, impossible").bodies()[function_index]; 30 31 println!("signature: {:?}", sig_type); 32 println!("code: "); 33 for instruction in code.code().elements() { 34 println!("{}", instruction); 35 } 36 }