Skip to content

Commit

Permalink
Avoid more extra cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Jun 5, 2024
1 parent 3129b27 commit 0496503
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/nsis-process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use windows_sys::Win32::{
CreateProcessW, GetCurrentProcessId, InitializeProcThreadAttributeList, OpenProcess,
OpenProcessToken, TerminateProcess, UpdateProcThreadAttribute,
CREATE_NEW_PROCESS_GROUP, CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT,
PROCESS_CREATE_PROCESS, PROCESS_INFORMATION, PROCESS_QUERY_INFORMATION,
PROCESS_TERMINATE, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, STARTUPINFOEXW, STARTUPINFOW,
LPPROC_THREAD_ATTRIBUTE_LIST, PROCESS_CREATE_PROCESS, PROCESS_INFORMATION,
PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
STARTUPINFOEXW, STARTUPINFOW,
},
},
UI::WindowsAndMessaging::{GetShellWindow, GetWindowThreadProcessId},
Expand Down Expand Up @@ -233,8 +234,8 @@ unsafe fn run_as_user(command: &str, arguments: &str) -> bool {
if GetWindowThreadProcessId(*hwnd, &mut proccess_id) == 0 {
return false;
}
let handle = OwnedHandle::new(OpenProcess(PROCESS_CREATE_PROCESS, FALSE, proccess_id));
if handle.is_invalid() {
let process = OwnedHandle::new(OpenProcess(PROCESS_CREATE_PROCESS, FALSE, proccess_id));
if process.is_invalid() {
return false;
}
let mut size = 0;
Expand All @@ -243,16 +244,15 @@ unsafe fn run_as_user(command: &str, arguments: &str) -> bool {
{
return false;
}
let mut attribute_list = vec![0u8; size];
if InitializeProcThreadAttributeList(attribute_list.as_mut_ptr() as _, 1, 0, &mut size) == FALSE
{
let attribute_list = vec![0u8; size].as_mut_ptr() as LPPROC_THREAD_ATTRIBUTE_LIST;
if InitializeProcThreadAttributeList(attribute_list, 1, 0, &mut size) == FALSE {
return false;
}
if UpdateProcThreadAttribute(
attribute_list.as_mut_ptr() as _,
attribute_list,
0,
PROC_THREAD_ATTRIBUTE_PARENT_PROCESS as _,
&*handle as *const _ as _,
&*process as *const _ as _,
mem::size_of::<HANDLE>(),
ptr::null_mut(),
ptr::null(),
Expand All @@ -265,7 +265,7 @@ unsafe fn run_as_user(command: &str, arguments: &str) -> bool {
cb: mem::size_of::<STARTUPINFOEXW>() as _,
..mem::zeroed()
},
lpAttributeList: attribute_list.as_mut_ptr() as _,
lpAttributeList: attribute_list,
};
let mut process_info = PROCESS_INFORMATION { ..mem::zeroed() };
let mut command_line = command.to_owned();
Expand Down

0 comments on commit 0496503

Please sign in to comment.