use std::io; use std::io::Write; use std::process; use std::process::{Command, Stdio}; use std::env; fn run_process(iterp: &String, prog: &String, args: &Vec) { let prog = format!("{}", prog.to_owned()); //println!("{}", prog); let opt = if iterp == "ruby" { "-e" } else { "-c" }; let output = Command::new(iterp) .arg(opt) .arg(prog) .args(args) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output() .expect("failed to execute process"); //println!("status: {}", output.status.code().unwrap()); std::process::exit(output.status.code().unwrap()); } fn main() { let prog = vec![99, 100, 32, 101, 120, 97, 109, 112, 108, 101, 115, 59, 32, 102, 111, 114, 32, 102, 105, 108, 101, 32, 105, 110, 32, 42, 46, 110, 101, 119, 95, 111, 117, 116, 59, 32, 100, 111, 32, 99, 112, 32, 34, 36, 102, 105, 108, 101, 34, 32, 34, 36, 123, 102, 105, 108, 101, 47, 110, 101, 119, 95, 111, 117, 116, 47, 103, 101, 110, 95, 111, 117, 116, 125, 34, 59, 100, 111, 110, 101, 10]; let pass = ""; let iterp = "bash"; if pass.len() != 0 { let mut input = String::new(); print!("Password: "); io::stdout().flush().ok(); io::stdin() .read_line(&mut input) .ok() .expect("Couldn't read password"); if input.trim() != pass { println!("Invalid password!"); process::exit(1); } } let prog_str = String::from_utf8(prog).unwrap(); //println!("running ...:\n {}", prog_str); let mut args = env::args().collect::>(); args.drain(0..1); run_process(&iterp.to_string(), &prog_str, &args); }