From 2c320c84716545628eaf85e10dabaa1cdcd466e7 Mon Sep 17 00:00:00 2001 From: Hulto <7121375+hulto@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:10:18 -0500 Subject: [PATCH] Re-add newline (#613) * Re-add newline * Add newline to eprint * Fix tests --------- Co-authored-by: KCarretto --- implants/golem/src/main.rs | 2 +- implants/lib/eldritch/src/assets/copy_impl.rs | 2 +- .../lib/eldritch/src/runtime/environment.rs | 4 ++-- .../lib/eldritch/src/runtime/eprint_impl.rs | 4 ++-- implants/lib/eldritch/src/runtime/mod.rs | 24 +++++++++---------- tavern/tomes/hostname/main.eldritch | 3 --- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/implants/golem/src/main.rs b/implants/golem/src/main.rs index 80ae18c95..4ad98eddd 100644 --- a/implants/golem/src/main.rs +++ b/implants/golem/src/main.rs @@ -156,7 +156,7 @@ mod tests { }]); let out = run_tomes(parsed_tomes).await?; - assert_eq!("hello world".to_string(), out.join("")); + assert_eq!("hello world\n".to_string(), out.join("")); Ok(()) } } diff --git a/implants/lib/eldritch/src/assets/copy_impl.rs b/implants/lib/eldritch/src/assets/copy_impl.rs index 8a7244ea1..25017c6a8 100644 --- a/implants/lib/eldritch/src/assets/copy_impl.rs +++ b/implants/lib/eldritch/src/assets/copy_impl.rs @@ -217,7 +217,7 @@ mod tests { .collect::>(); assert!(errors.is_empty()); - let mut contents = String::new(); + let mut contents: String = String::new(); tmp_file_dst.read_to_string(&mut contents)?; assert!(contents.contains("hello from an embedded shell script")); diff --git a/implants/lib/eldritch/src/runtime/environment.rs b/implants/lib/eldritch/src/runtime/environment.rs index 94afabfa0..62861b182 100644 --- a/implants/lib/eldritch/src/runtime/environment.rs +++ b/implants/lib/eldritch/src/runtime/environment.rs @@ -41,11 +41,11 @@ impl PrintHandler for Environment { fn println(&self, text: &str) -> Result<()> { self.send(ReportTextMessage { id: self.id, - text: String::from(text), + text: format!("{}\n", text), })?; #[cfg(feature = "print_stdout")] - print!("{}", text); + println!("{}", text); Ok(()) } diff --git a/implants/lib/eldritch/src/runtime/eprint_impl.rs b/implants/lib/eldritch/src/runtime/eprint_impl.rs index f8bede0b3..877ea1abc 100644 --- a/implants/lib/eldritch/src/runtime/eprint_impl.rs +++ b/implants/lib/eldritch/src/runtime/eprint_impl.rs @@ -4,7 +4,7 @@ use anyhow::Result; pub fn eprint(env: &Environment, message: String) -> Result<()> { env.send(ReportErrorMessage { id: env.id(), - error: message.clone(), + error: format!("{}\n", message), })?; #[cfg(feature = "print_stdout")] @@ -59,7 +59,7 @@ mod test { parameters: HashMap::new(), file_names: Vec::new(), }, - want_error: String::from("Beep Boop an error occured"), + want_error: String::from("Beep Boop an error occured\n"), }, } } diff --git a/implants/lib/eldritch/src/runtime/mod.rs b/implants/lib/eldritch/src/runtime/mod.rs index 03be08930..7ef9aa5e3 100644 --- a/implants/lib/eldritch/src/runtime/mod.rs +++ b/implants/lib/eldritch/src/runtime/mod.rs @@ -55,7 +55,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from("2"), + want_text: format!("{}\n", "2"), want_error: None, }, multi_print: TestCase { @@ -65,7 +65,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"oceans rise, empires fall"#), + want_text: String::from("oceans \nrise, \nempires \nfall\n"), want_error: None, }, input_params: TestCase{ @@ -79,7 +79,7 @@ mod tests { ]), file_names: Vec::new(), }, - want_text: String::from("echo hello_world"), + want_text: format!("{}\n", "echo hello_world"), want_error: None, }, file_bindings: TestCase { @@ -89,7 +89,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["append", "compress", "copy", "download", "exists", "find", "follow", "is_dir", "is_file", "list", "mkdir", "moveto", "read", "remove", "replace", "replace_all", "template", "timestomp", "write"]"#), + want_text: format!("{}\n", r#"["append", "compress", "copy", "download", "exists", "find", "follow", "is_dir", "is_file", "list", "mkdir", "moveto", "read", "remove", "replace", "replace_all", "template", "timestomp", "write"]"#), want_error: None, }, process_bindings: TestCase { @@ -99,7 +99,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["info", "kill", "list", "name", "netstat"]"#), + want_text: format!("{}\n", r#"["info", "kill", "list", "name", "netstat"]"#), want_error: None, }, sys_bindings: TestCase { @@ -109,7 +109,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["dll_inject", "dll_reflect", "exec", "get_env", "get_ip", "get_os", "get_pid", "get_reg", "get_user", "hostname", "is_linux", "is_macos", "is_windows", "shell", "write_reg_hex", "write_reg_int", "write_reg_str"]"#), + want_text: format!("{}\n", r#"["dll_inject", "dll_reflect", "exec", "get_env", "get_ip", "get_os", "get_pid", "get_reg", "get_user", "hostname", "is_linux", "is_macos", "is_windows", "shell", "write_reg_hex", "write_reg_int", "write_reg_str"]"#), want_error: None, }, pivot_bindings: TestCase { @@ -119,7 +119,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["arp_scan", "bind_proxy", "ncat", "port_forward", "port_scan", "smb_exec", "ssh_copy", "ssh_exec", "ssh_password_spray"]"#), + want_text: format!("{}\n", r#"["arp_scan", "bind_proxy", "ncat", "port_forward", "port_scan", "smb_exec", "ssh_copy", "ssh_exec", "ssh_password_spray"]"#), want_error: None, }, assets_bindings: TestCase { @@ -129,7 +129,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["copy", "list", "read", "read_binary"]"#), + want_text: format!("{}\n", r#"["copy", "list", "read", "read_binary"]"#), want_error: None, }, crypto_bindings: TestCase { @@ -139,7 +139,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["aes_decrypt_file", "aes_encrypt_file", "decode_b64", "encode_b64", "from_json", "hash_file", "to_json"]"#), + want_text: format!("{}\n", r#"["aes_decrypt_file", "aes_encrypt_file", "decode_b64", "encode_b64", "from_json", "hash_file", "to_json"]"#), want_error: None, }, time_bindings: TestCase { @@ -149,7 +149,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["format_to_epoch", "format_to_readable", "now", "sleep"]"#), + want_text: format!("{}\n", r#"["format_to_epoch", "format_to_readable", "now", "sleep"]"#), want_error: None, }, report_bindings: TestCase { @@ -159,7 +159,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["file", "process_list", "ssh_key", "user_password"]"#), + want_text: format!("{}\n", r#"["file", "process_list", "ssh_key", "user_password"]"#), want_error: None, }, regex_bindings: TestCase { @@ -169,7 +169,7 @@ mod tests { parameters: HashMap::new(), file_names: Vec::new(), }, - want_text: String::from(r#"["match", "match_all", "replace", "replace_all"]"#), + want_text: format!("{}\n", r#"["match", "match_all", "replace", "replace_all"]"#), want_error: None, }, } diff --git a/tavern/tomes/hostname/main.eldritch b/tavern/tomes/hostname/main.eldritch index 7f559ae29..f8016f40b 100644 --- a/tavern/tomes/hostname/main.eldritch +++ b/tavern/tomes/hostname/main.eldritch @@ -1,4 +1 @@ print(sys.hostname()) -print("\n") -print("\n") -print("\n")