myph-v2~ rust shellcode loader with evasive capabilities |
| git clone https://github.com/djnnvx/myph-v2.git |
| log | files | refs | archive | README |
windows_types.rs (3033B)
1 //! Common Windows API types and structures used across multiple techniques. 2 //! 3 //! This module centralizes Windows API structure definitions to eliminate duplication 4 //! and ensure consistency across all shellcode execution techniques. 5 6 /// Generate StartupInfoW structure definition. 7 /// 8 /// This structure is used by CreateProcess and related APIs to specify 9 /// how a new process should be created. 10 pub fn startup_info_w_struct() -> &'static str { 11 r#"#[repr(C)] 12 struct StartupInfoW { 13 cb: u32, 14 reserved1: *mut u16, 15 desktop: *mut u16, 16 title: *mut u16, 17 x: u32, 18 y: u32, 19 x_size: u32, 20 y_size: u32, 21 x_count_chars: u32, 22 y_count_chars: u32, 23 fill_attribute: u32, 24 flags: u32, 25 show_window: u16, 26 reserved2: u16, 27 reserved3: *mut u8, 28 std_input: *mut std::ffi::c_void, 29 std_output: *mut std::ffi::c_void, 30 std_error: *mut std::ffi::c_void, 31 }"# 32 } 33 34 /// Generate ProcessInformation structure definition. 35 /// 36 /// This structure receives information about a newly created process 37 /// from CreateProcess and related APIs. 38 pub fn process_information_struct() -> &'static str { 39 r#"#[repr(C)] 40 struct ProcessInformation { 41 process: *mut std::ffi::c_void, 42 thread: *mut std::ffi::c_void, 43 process_id: u32, 44 thread_id: u32, 45 }"# 46 } 47 48 /// Generate both StartupInfoW and ProcessInformation structures together. 49 /// 50 /// This is the most common case where both structures are needed. 51 pub fn process_structures() -> String { 52 format!( 53 "{}\n\n{}", 54 startup_info_w_struct(), 55 process_information_struct() 56 ) 57 } 58 59 /// Generate initialization code for StartupInfoW structure. 60 /// 61 /// Creates a properly initialized StartupInfoW with all fields set to 62 /// their default values. 63 pub fn init_startup_info_w() -> &'static str { 64 r#"let mut si = StartupInfoW { 65 cb: std::mem::size_of::<StartupInfoW>() as u32, 66 reserved1: ptr::null_mut(), 67 desktop: ptr::null_mut(), 68 title: ptr::null_mut(), 69 x: 0, 70 y: 0, 71 x_size: 0, 72 y_size: 0, 73 x_count_chars: 0, 74 y_count_chars: 0, 75 fill_attribute: 0, 76 flags: 0, 77 show_window: 0, 78 reserved2: 0, 79 reserved3: ptr::null_mut(), 80 std_input: ptr::null_mut(), 81 std_output: ptr::null_mut(), 82 std_error: ptr::null_mut(), 83 };"# 84 } 85 86 /// Generate initialization code for ProcessInformation structure. 87 /// 88 /// Creates a zeroed ProcessInformation structure ready to receive 89 /// process information from CreateProcess. 90 pub fn init_process_information() -> &'static str { 91 r#"let mut pi = ProcessInformation { 92 process: ptr::null_mut(), 93 thread: ptr::null_mut(), 94 process_id: 0, 95 thread_id: 0, 96 };"# 97 } 98 99 #[cfg(test)] 100 mod tests { 101 use super::*; 102 103 #[test] 104 fn test_process_structures_contains_both() { 105 let code = process_structures(); 106 assert!(code.contains("struct StartupInfoW")); 107 assert!(code.contains("struct ProcessInformation")); 108 } 109 }