From efa390f05cbce95ecf1882de7e2a89debc116ea7 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Mon, 18 Nov 2024 15:50:47 +0100 Subject: [PATCH] Use bash always --- .github/workflows/rust-ci.yml | 1 + src/lib.rs | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index 27075a7..dfd7a2d 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -45,6 +45,7 @@ jobs: - name: cargo test build run: cargo build --tests --release - name: cargo test + shell: bash run: cargo test --release - name: detects powershell if: ${{ matrix.os != 'macos-14' }} diff --git a/src/lib.rs b/src/lib.rs index a33f640..29b0f69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -301,13 +301,13 @@ pub fn is_powershell_parent() -> bool { while let Some(ph) = handle { let mut basic_info = std::mem::MaybeUninit::::uninit(); let mut length = 0; - if dbg!(nt_query_information_process( + if nt_query_information_process( ph.handle, Processinfoclass::ProcessBasicInformation, basic_info.as_mut_ptr().cast(), std::mem::size_of::() as _, &mut length, - )) != StatusSuccess + ) != StatusSuccess { break; } @@ -331,12 +331,12 @@ pub fn is_powershell_parent() -> bool { unique_process: ppid, unique_thread: 0, }; - if dbg!(nt_open_process( + if nt_open_process( &mut parent_handle, ProcessAccessRights::ProcessQueryInformation, &obj_attr, - &client_id - )) != StatusSuccess + &client_id, + ) != StatusSuccess { break; } @@ -345,13 +345,13 @@ pub fn is_powershell_parent() -> bool { handle: parent_handle, }); - if dbg!(nt_query_information_process( + if nt_query_information_process( parent_handle, Processinfoclass::ProcessImageFileName, file_name.as_mut_ptr().cast(), (file_name.len() * 2) as _, &mut length, - )) != StatusSuccess + ) != StatusSuccess { break; } @@ -362,11 +362,11 @@ pub fn is_powershell_parent() -> bool { (ustr.length >> 1) as usize, )); - let path = os.to_string_lossy(); - eprintln!("{path}"); - let p = std::path::Path::new(path.as_ref()); - if p.file_stem() == Some(std::ffi::OsStr::new("pwsh")) { - return true; + let path = std::path::Path::new(&os); + if let Some(stem) = path.file_stem().and_then(|stem| stem.to_str()) { + if stem == "pwsh" || stem == "powershell" { + return true; + } } }