(expected_domain: &str)
| 1 | use crate::tools::SandboxOutput; |
| 2 | |
| 3 | pub fn build_sandbox(expected_domain: &str) -> SandboxOutput { |
| 4 | if expected_domain.is_empty() { |
| 5 | return SandboxOutput { |
| 6 | sandbox_function: String::new(), |
| 7 | sandbox_import: String::new(), |
| 8 | }; |
| 9 | } |
| 10 | |
| 11 | let sandbox_function = format!( |
| 12 | "fn get_domain_name() -> Option<String> {{ |
| 13 | let mut size: u32 = 256; |
| 14 | let mut buffer: Vec<u16> = vec![0; size as usize]; |
| 15 | |
| 16 | let success = unsafe {{ |
| 17 | GetComputerNameExW(ComputerNameDnsDomain, buffer.as_mut_ptr(), &mut size) |
| 18 | }}; |
| 19 | if success == 0 || size == 0 {{ |
| 20 | return None; |
| 21 | }} |
| 22 | |
| 23 | let domain_name = String::from_utf16(&buffer[..size as usize]) |
| 24 | .map(|s| s.trim_end_matches('\\0').to_string()) |
| 25 | .ok()?; |
| 26 | |
| 27 | if domain_name.is_empty() {{ |
| 28 | return None; |
| 29 | }} |
| 30 | Some(domain_name) |
| 31 | }} |
| 32 | fn sandbox() {{ |
| 33 | match get_domain_name() {{ |
| 34 | Some(domain) => {{ |
| 35 | println!(\"Domain: {{}}\",domain); |
| 36 | if !domain.as_str().eq_ignore_ascii_case(\"{0}\") {{ |
| 37 | panic!(\"Sandbox check failed\"); |
| 38 | }} |
| 39 | }} |
| 40 | None => {{ |
| 41 | panic!(\"Sandbox check failed\"); |
| 42 | }} |
| 43 | }} |
| 44 | }} |
| 45 | sandbox();", |
| 46 | expected_domain |
| 47 | ); |
| 48 | |
| 49 | let sandbox_import = |
| 50 | "use winapi::um::sysinfoapi::{GetComputerNameExW, ComputerNameDnsDomain};\n".to_string(); |
| 51 | |
| 52 | SandboxOutput { |
| 53 | sandbox_function, |
| 54 | sandbox_import, |
| 55 | } |
| 56 | } |
no outgoing calls
no test coverage detected