From 7fad81a0c52d4c2075794b801354f1119989074d Mon Sep 17 00:00:00 2001 From: branchseer Date: Wed, 19 Nov 2025 10:50:36 +0800 Subject: [PATCH 1/2] chore: improve naming --- crates/fspy/src/windows/mod.rs | 18 +++++++++--------- .../fspy_preload_windows/src/windows/client.rs | 4 ++-- .../src/windows/detours/create_process.rs | 4 ++-- crates/fspy_shared/src/windows/mod.rs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/fspy/src/windows/mod.rs b/crates/fspy/src/windows/mod.rs index 29c5962c..4761158d 100644 --- a/crates/fspy/src/windows/mod.rs +++ b/crates/fspy/src/windows/mod.rs @@ -52,7 +52,7 @@ impl PathAccessIterable { #[derive(Debug, Clone)] pub struct SpyImpl { - asni_dll_path_with_nul: Arc, + ansi_dll_path_with_nul: Arc, } impl SpyImpl { @@ -60,19 +60,19 @@ impl SpyImpl { let dll_path = INTERPOSE_CDYLIB.write_to(&path, ".dll").unwrap(); let wide_dll_path = dll_path.as_os_str().encode_wide().collect::>(); - let mut asni_dll_path = + let mut ansi_dll_path = winsafe::WideCharToMultiByte(CP::ACP, WC::NoValue, &wide_dll_path, None, None) .map_err(|err| io::Error::from_raw_os_error(err.raw() as i32))?; - asni_dll_path.push(0); + ansi_dll_path.push(0); - let asni_dll_path_with_nul = - unsafe { CStr::from_bytes_with_nul_unchecked(asni_dll_path.as_slice()) }; - Ok(Self { asni_dll_path_with_nul: asni_dll_path_with_nul.into() }) + let ansi_dll_path_with_nul = + unsafe { CStr::from_bytes_with_nul_unchecked(ansi_dll_path.as_slice()) }; + Ok(Self { ansi_dll_path_with_nul: ansi_dll_path_with_nul.into() }) } pub(crate) async fn spawn(&self, command: Command) -> Result { - let asni_dll_path_with_nul = Arc::clone(&self.asni_dll_path_with_nul); + let ansi_dll_path_with_nul = Arc::clone(&self.ansi_dll_path_with_nul); let mut command = command.into_tokio_command(); command.creation_flags(CREATE_SUSPENDED); @@ -87,7 +87,7 @@ impl SpyImpl { let std_child = std_command.spawn()?; *spawn_success = true; - let mut dll_paths = asni_dll_path_with_nul.as_ptr().cast::(); + let mut dll_paths = ansi_dll_path_with_nul.as_ptr().cast::(); let process_handle = std_child.as_raw_handle().cast::(); let success = unsafe { DetourUpdateProcessWithDll(process_handle, &mut dll_paths, 1) }; @@ -97,7 +97,7 @@ impl SpyImpl { let payload = Payload { channel_conf: channel_conf.clone(), - asni_dll_path_with_nul: asni_dll_path_with_nul.to_bytes(), + ansi_dll_path_with_nul: ansi_dll_path_with_nul.to_bytes(), }; let payload_bytes = bincode::encode_to_vec(payload, BINCODE_CONFIG).unwrap(); let success = unsafe { diff --git a/crates/fspy_preload_windows/src/windows/client.rs b/crates/fspy_preload_windows/src/windows/client.rs index 7d5df7ac..7e60e038 100644 --- a/crates/fspy_preload_windows/src/windows/client.rs +++ b/crates/fspy_preload_windows/src/windows/client.rs @@ -52,8 +52,8 @@ impl<'a> Client<'a> { } } - pub fn asni_dll_path(&self) -> &'a CStr { - unsafe { CStr::from_bytes_with_nul_unchecked(self.payload.asni_dll_path_with_nul) } + pub fn ansi_dll_path(&self) -> &'a CStr { + unsafe { CStr::from_bytes_with_nul_unchecked(self.payload.ansi_dll_path_with_nul) } } } diff --git a/crates/fspy_preload_windows/src/windows/detours/create_process.rs b/crates/fspy_preload_windows/src/windows/detours/create_process.rs index 4c8ee84b..8215552b 100644 --- a/crates/fspy_preload_windows/src/windows/detours/create_process.rs +++ b/crates/fspy_preload_windows/src/windows/detours/create_process.rs @@ -148,7 +148,7 @@ static DETOUR_CREATE_PROCESS_W: Detour< lp_current_directory, lp_startup_info, lp_process_information, - client.asni_dll_path().as_ptr().cast(), + client.ansi_dll_path().as_ptr().cast(), Some(create_process_with_payload_w), ) } @@ -261,7 +261,7 @@ static DETOUR_CREATE_PROCESS_A: Detour< lp_current_directory, lp_startup_info, lp_process_information, - client.asni_dll_path().as_ptr().cast(), + client.ansi_dll_path().as_ptr().cast(), Some(create_process_with_payload_a), ) } diff --git a/crates/fspy_shared/src/windows/mod.rs b/crates/fspy_shared/src/windows/mod.rs index cb34aa85..ac3598a2 100644 --- a/crates/fspy_shared/src/windows/mod.rs +++ b/crates/fspy_shared/src/windows/mod.rs @@ -10,5 +10,5 @@ DEFINE_GUID!(PAYLOAD_ID, 0xfc4845f1, 0x3a8b, 0x4f05, 0xa3, 0xd3, 0xa5, 0xe9, 0xe #[derive(Encode, BorrowDecode, Debug, Clone)] pub struct Payload<'a> { pub channel_conf: ChannelConf, - pub asni_dll_path_with_nul: &'a [u8], + pub ansi_dll_path_with_nul: &'a [u8], } From fa534f4444696d5f45e4470a149e9c2fde4a9cb1 Mon Sep 17 00:00:00 2001 From: branchseer Date: Wed, 19 Nov 2025 10:54:39 +0800 Subject: [PATCH 2/2] rename fixture -> artifact --- crates/fspy/src/{fixture.rs => artifact.rs} | 12 ++++++----- crates/fspy/src/lib.rs | 2 +- .../{macos_fixtures.rs => macos_artifacts.rs} | 6 +++--- crates/fspy/src/unix/mod.rs | 20 +++++++++---------- crates/fspy/src/windows/mod.rs | 4 ++-- crates/fspy_shared_unix/src/payload.rs | 4 ++-- crates/fspy_shared_unix/src/spawn/macos.rs | 6 +++--- 7 files changed, 28 insertions(+), 26 deletions(-) rename crates/fspy/src/{fixture.rs => artifact.rs} (87%) rename crates/fspy/src/unix/{macos_fixtures.rs => macos_artifacts.rs} (86%) diff --git a/crates/fspy/src/fixture.rs b/crates/fspy/src/artifact.rs similarity index 87% rename from crates/fspy/src/fixture.rs rename to crates/fspy/src/artifact.rs index 17685fcb..0c3fcba0 100644 --- a/crates/fspy/src/fixture.rs +++ b/crates/fspy/src/artifact.rs @@ -3,7 +3,9 @@ use std::{ io::{self, Write}, path::{Path, PathBuf}, }; -pub struct Fixture { + +/// An artifact (e.g., a DLL or shared library) whose content is embedded and needs to be written to disk. +pub struct Artifact { pub name: &'static str, pub content: &'static [u8], pub hash: &'static str, @@ -12,9 +14,9 @@ pub struct Fixture { #[cfg(target_os = "macos")] #[doc(hidden)] #[macro_export] -macro_rules! fixture { +macro_rules! artifact { ($name: literal) => { - $crate::fixture::Fixture::new( + $crate::artifact::Artifact::new( $name, ::core::include_bytes!(::core::concat!(::core::env!("OUT_DIR"), "/", $name)), ::core::include_str!(::core::concat!(::core::env!("OUT_DIR"), "/", $name, ".hash")), @@ -23,9 +25,9 @@ macro_rules! fixture { } #[cfg(target_os = "macos")] -pub use fixture; +pub use artifact; -impl Fixture { +impl Artifact { #[cfg(not(target_os = "linux"))] pub const fn new(name: &'static str, content: &'static [u8], hash: &'static str) -> Self { Self { name, content, hash } diff --git a/crates/fspy/src/lib.rs b/crates/fspy/src/lib.rs index 33f8e8c2..cfcdb78c 100644 --- a/crates/fspy/src/lib.rs +++ b/crates/fspy/src/lib.rs @@ -2,7 +2,7 @@ #![feature(once_cell_try)] // Persist the injected DLL/shared library somewhere in the filesystem. -mod fixture; +mod artifact; pub mod error; diff --git a/crates/fspy/src/unix/macos_fixtures.rs b/crates/fspy/src/unix/macos_artifacts.rs similarity index 86% rename from crates/fspy/src/unix/macos_fixtures.rs rename to crates/fspy/src/unix/macos_artifacts.rs index 461399cc..70ee101e 100644 --- a/crates/fspy/src/unix/macos_fixtures.rs +++ b/crates/fspy/src/unix/macos_artifacts.rs @@ -1,7 +1,7 @@ -use crate::fixture::{Fixture, fixture}; +use crate::artifact::{Artifact, artifact}; -pub const COREUTILS_BINARY: Fixture = fixture!("coreutils"); -pub const OILS_BINARY: Fixture = fixture!("oils-for-unix"); +pub const COREUTILS_BINARY: Artifact = artifact!("coreutils"); +pub const OILS_BINARY: Artifact = artifact!("oils-for-unix"); #[cfg(test)] mod tests { diff --git a/crates/fspy/src/unix/mod.rs b/crates/fspy/src/unix/mod.rs index 81cceb1d..03bb0f13 100644 --- a/crates/fspy/src/unix/mod.rs +++ b/crates/fspy/src/unix/mod.rs @@ -2,7 +2,7 @@ mod syscall_handler; #[cfg(target_os = "macos")] -mod macos_fixtures; +mod macos_artifacts; use std::{io, path::Path}; @@ -10,7 +10,7 @@ use std::{io, path::Path}; use fspy_seccomp_unotify::supervisor::supervise; use fspy_shared::ipc::{NativeString, PathAccess, channel::channel}; #[cfg(target_os = "macos")] -use fspy_shared_unix::payload::Fixtures; +use fspy_shared_unix::payload::Artifacts; use fspy_shared_unix::{ exec::ExecResolveConfig, payload::{Payload, encode_payload}, @@ -31,7 +31,7 @@ use crate::{ #[derive(Debug, Clone)] pub struct SpyImpl { #[cfg(target_os = "macos")] - fixtures: Fixtures, + artifacts: Artifacts, preload_path: NativeString, } @@ -44,9 +44,9 @@ impl SpyImpl { use const_format::formatcp; use xxhash_rust::const_xxh3::xxh3_128; - use crate::fixture::Fixture; + use crate::artifact::Artifact; - const PRELOAD_CDYLIB: Fixture = Fixture { + const PRELOAD_CDYLIB: Artifact = Artifact { name: "fspy_preload", content: PRELOAD_CDYLIB_BINARY, hash: formatcp!("{:x}", xxh3_128(PRELOAD_CDYLIB_BINARY)), @@ -56,10 +56,10 @@ impl SpyImpl { Ok(Self { preload_path: preload_cdylib_path.as_path().into(), #[cfg(target_os = "macos")] - fixtures: { - let coreutils_path = macos_fixtures::COREUTILS_BINARY.write_to(dir, "")?; - let bash_path = macos_fixtures::OILS_BINARY.write_to(dir, "")?; - Fixtures { + artifacts: { + let coreutils_path = macos_artifacts::COREUTILS_BINARY.write_to(dir, "")?; + let bash_path = macos_artifacts::OILS_BINARY.write_to(dir, "")?; + Artifacts { bash_path: bash_path.as_path().into(), coreutils_path: coreutils_path.as_path().into(), } @@ -78,7 +78,7 @@ impl SpyImpl { ipc_channel_conf, #[cfg(target_os = "macos")] - fixtures: self.fixtures.clone(), + artifacts: self.artifacts.clone(), preload_path: self.preload_path.clone(), diff --git a/crates/fspy/src/windows/mod.rs b/crates/fspy/src/windows/mod.rs index 4761158d..5a180c90 100644 --- a/crates/fspy/src/windows/mod.rs +++ b/crates/fspy/src/windows/mod.rs @@ -22,14 +22,14 @@ use xxhash_rust::const_xxh3::xxh3_128; use crate::{ ChildTermination, TrackedChild, + artifact::Artifact, command::Command, error::SpawnError, - fixture::Fixture, ipc::{OwnedReceiverLockGuard, SHM_CAPACITY}, }; const PRELOAD_CDYLIB_BINARY: &[u8] = include_bytes!(env!("CARGO_CDYLIB_FILE_FSPY_PRELOAD_WINDOWS")); -const INTERPOSE_CDYLIB: Fixture = Fixture::new( +const INTERPOSE_CDYLIB: Artifact = Artifact::new( "fsyp_preload", PRELOAD_CDYLIB_BINARY, formatcp!("{:x}", xxh3_128(PRELOAD_CDYLIB_BINARY)), diff --git a/crates/fspy_shared_unix/src/payload.rs b/crates/fspy_shared_unix/src/payload.rs index 925b714a..c0de11ec 100644 --- a/crates/fspy_shared_unix/src/payload.rs +++ b/crates/fspy_shared_unix/src/payload.rs @@ -12,7 +12,7 @@ pub struct Payload { pub preload_path: NativeString, #[cfg(target_os = "macos")] - pub fixtures: Fixtures, + pub artifacts: Artifacts, #[cfg(target_os = "linux")] pub seccomp_payload: fspy_seccomp_unotify::payload::SeccompPayload, @@ -20,7 +20,7 @@ pub struct Payload { #[cfg(target_os = "macos")] #[derive(Debug, Encode, Decode, Clone)] -pub struct Fixtures { +pub struct Artifacts { pub bash_path: NativeString, pub coreutils_path: NativeString, // pub interpose_cdylib_path: NativeString, diff --git a/crates/fspy_shared_unix/src/spawn/macos.rs b/crates/fspy_shared_unix/src/spawn/macos.rs index 155be1eb..fe487374 100644 --- a/crates/fspy_shared_unix/src/spawn/macos.rs +++ b/crates/fspy_shared_unix/src/spawn/macos.rs @@ -42,12 +42,12 @@ pub fn handle_exec( (program_path.parent(), program_path.file_name()) { if matches!(parent.as_os_str().as_bytes(), b"/bin" | b"/usr/bin") { - let fixtures = &encoded_payload.payload.fixtures; + let artifacts = &encoded_payload.payload.artifacts; if matches!(file_name.as_bytes(), b"sh" | b"bash") { - command.program = fixtures.bash_path.as_os_str().as_bytes().into(); + command.program = artifacts.bash_path.as_os_str().as_bytes().into(); true } else if COREUTILS_FUNCTIONS.contains(file_name.as_bytes()) { - command.program = fixtures.coreutils_path.as_os_str().as_bytes().into(); + command.program = artifacts.coreutils_path.as_os_str().as_bytes().into(); true } else { false