MCPcopy Create free account
hub / github.com/Nariod/RustPacker / build_sandbox

Function build_sandbox

src/sandbox.rs:3–56  ·  view source on GitHub ↗
(expected_domain: &str)

Source from the content-addressed store, hash-verified

1use crate::tools::SandboxOutput;
2
3pub 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}

Callers 1

build_replacementsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected