Skip to content

Commit 37dfa63

Browse files
authored
chore: improve naming (#39)
# chore: improve naming - Fix typo of `asni`​ - Renamed `fixture` to `artifact` throughout the codebase to better reflect the purpose of these embedded resources.
1 parent c38d9f4 commit 37dfa63

File tree

10 files changed

+42
-40
lines changed

10 files changed

+42
-40
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::{
33
io::{self, Write},
44
path::{Path, PathBuf},
55
};
6-
pub struct Fixture {
6+
7+
/// An artifact (e.g., a DLL or shared library) whose content is embedded and needs to be written to disk.
8+
pub struct Artifact {
79
pub name: &'static str,
810
pub content: &'static [u8],
911
pub hash: &'static str,
@@ -12,9 +14,9 @@ pub struct Fixture {
1214
#[cfg(target_os = "macos")]
1315
#[doc(hidden)]
1416
#[macro_export]
15-
macro_rules! fixture {
17+
macro_rules! artifact {
1618
($name: literal) => {
17-
$crate::fixture::Fixture::new(
19+
$crate::artifact::Artifact::new(
1820
$name,
1921
::core::include_bytes!(::core::concat!(::core::env!("OUT_DIR"), "/", $name)),
2022
::core::include_str!(::core::concat!(::core::env!("OUT_DIR"), "/", $name, ".hash")),
@@ -23,9 +25,9 @@ macro_rules! fixture {
2325
}
2426

2527
#[cfg(target_os = "macos")]
26-
pub use fixture;
28+
pub use artifact;
2729

28-
impl Fixture {
30+
impl Artifact {
2931
#[cfg(not(target_os = "linux"))]
3032
pub const fn new(name: &'static str, content: &'static [u8], hash: &'static str) -> Self {
3133
Self { name, content, hash }

crates/fspy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(once_cell_try)]
33

44
// Persist the injected DLL/shared library somewhere in the filesystem.
5-
mod fixture;
5+
mod artifact;
66

77
pub mod error;
88

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::fixture::{Fixture, fixture};
1+
use crate::artifact::{Artifact, artifact};
22

3-
pub const COREUTILS_BINARY: Fixture = fixture!("coreutils");
4-
pub const OILS_BINARY: Fixture = fixture!("oils-for-unix");
3+
pub const COREUTILS_BINARY: Artifact = artifact!("coreutils");
4+
pub const OILS_BINARY: Artifact = artifact!("oils-for-unix");
55

66
#[cfg(test)]
77
mod tests {

crates/fspy/src/unix/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
mod syscall_handler;
33

44
#[cfg(target_os = "macos")]
5-
mod macos_fixtures;
5+
mod macos_artifacts;
66

77
use std::{io, path::Path};
88

99
#[cfg(target_os = "linux")]
1010
use fspy_seccomp_unotify::supervisor::supervise;
1111
use fspy_shared::ipc::{NativeString, PathAccess, channel::channel};
1212
#[cfg(target_os = "macos")]
13-
use fspy_shared_unix::payload::Fixtures;
13+
use fspy_shared_unix::payload::Artifacts;
1414
use fspy_shared_unix::{
1515
exec::ExecResolveConfig,
1616
payload::{Payload, encode_payload},
@@ -31,7 +31,7 @@ use crate::{
3131
#[derive(Debug, Clone)]
3232
pub struct SpyImpl {
3333
#[cfg(target_os = "macos")]
34-
fixtures: Fixtures,
34+
artifacts: Artifacts,
3535

3636
preload_path: NativeString,
3737
}
@@ -44,9 +44,9 @@ impl SpyImpl {
4444
use const_format::formatcp;
4545
use xxhash_rust::const_xxh3::xxh3_128;
4646

47-
use crate::fixture::Fixture;
47+
use crate::artifact::Artifact;
4848

49-
const PRELOAD_CDYLIB: Fixture = Fixture {
49+
const PRELOAD_CDYLIB: Artifact = Artifact {
5050
name: "fspy_preload",
5151
content: PRELOAD_CDYLIB_BINARY,
5252
hash: formatcp!("{:x}", xxh3_128(PRELOAD_CDYLIB_BINARY)),
@@ -56,10 +56,10 @@ impl SpyImpl {
5656
Ok(Self {
5757
preload_path: preload_cdylib_path.as_path().into(),
5858
#[cfg(target_os = "macos")]
59-
fixtures: {
60-
let coreutils_path = macos_fixtures::COREUTILS_BINARY.write_to(dir, "")?;
61-
let bash_path = macos_fixtures::OILS_BINARY.write_to(dir, "")?;
62-
Fixtures {
59+
artifacts: {
60+
let coreutils_path = macos_artifacts::COREUTILS_BINARY.write_to(dir, "")?;
61+
let bash_path = macos_artifacts::OILS_BINARY.write_to(dir, "")?;
62+
Artifacts {
6363
bash_path: bash_path.as_path().into(),
6464
coreutils_path: coreutils_path.as_path().into(),
6565
}
@@ -78,7 +78,7 @@ impl SpyImpl {
7878
ipc_channel_conf,
7979

8080
#[cfg(target_os = "macos")]
81-
fixtures: self.fixtures.clone(),
81+
artifacts: self.artifacts.clone(),
8282

8383
preload_path: self.preload_path.clone(),
8484

crates/fspy/src/windows/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ use xxhash_rust::const_xxh3::xxh3_128;
2222

2323
use crate::{
2424
ChildTermination, TrackedChild,
25+
artifact::Artifact,
2526
command::Command,
2627
error::SpawnError,
27-
fixture::Fixture,
2828
ipc::{OwnedReceiverLockGuard, SHM_CAPACITY},
2929
};
3030

3131
const PRELOAD_CDYLIB_BINARY: &[u8] = include_bytes!(env!("CARGO_CDYLIB_FILE_FSPY_PRELOAD_WINDOWS"));
32-
const INTERPOSE_CDYLIB: Fixture = Fixture::new(
32+
const INTERPOSE_CDYLIB: Artifact = Artifact::new(
3333
"fsyp_preload",
3434
PRELOAD_CDYLIB_BINARY,
3535
formatcp!("{:x}", xxh3_128(PRELOAD_CDYLIB_BINARY)),
@@ -52,27 +52,27 @@ impl PathAccessIterable {
5252

5353
#[derive(Debug, Clone)]
5454
pub struct SpyImpl {
55-
asni_dll_path_with_nul: Arc<CStr>,
55+
ansi_dll_path_with_nul: Arc<CStr>,
5656
}
5757

5858
impl SpyImpl {
5959
pub fn init_in(path: &Path) -> io::Result<Self> {
6060
let dll_path = INTERPOSE_CDYLIB.write_to(&path, ".dll").unwrap();
6161

6262
let wide_dll_path = dll_path.as_os_str().encode_wide().collect::<Vec<u16>>();
63-
let mut asni_dll_path =
63+
let mut ansi_dll_path =
6464
winsafe::WideCharToMultiByte(CP::ACP, WC::NoValue, &wide_dll_path, None, None)
6565
.map_err(|err| io::Error::from_raw_os_error(err.raw() as i32))?;
6666

67-
asni_dll_path.push(0);
67+
ansi_dll_path.push(0);
6868

69-
let asni_dll_path_with_nul =
70-
unsafe { CStr::from_bytes_with_nul_unchecked(asni_dll_path.as_slice()) };
71-
Ok(Self { asni_dll_path_with_nul: asni_dll_path_with_nul.into() })
69+
let ansi_dll_path_with_nul =
70+
unsafe { CStr::from_bytes_with_nul_unchecked(ansi_dll_path.as_slice()) };
71+
Ok(Self { ansi_dll_path_with_nul: ansi_dll_path_with_nul.into() })
7272
}
7373

7474
pub(crate) async fn spawn(&self, command: Command) -> Result<TrackedChild, SpawnError> {
75-
let asni_dll_path_with_nul = Arc::clone(&self.asni_dll_path_with_nul);
75+
let ansi_dll_path_with_nul = Arc::clone(&self.ansi_dll_path_with_nul);
7676
let mut command = command.into_tokio_command();
7777

7878
command.creation_flags(CREATE_SUSPENDED);
@@ -87,7 +87,7 @@ impl SpyImpl {
8787
let std_child = std_command.spawn()?;
8888
*spawn_success = true;
8989

90-
let mut dll_paths = asni_dll_path_with_nul.as_ptr().cast::<c_char>();
90+
let mut dll_paths = ansi_dll_path_with_nul.as_ptr().cast::<c_char>();
9191
let process_handle = std_child.as_raw_handle().cast::<winapi::ctypes::c_void>();
9292
let success =
9393
unsafe { DetourUpdateProcessWithDll(process_handle, &mut dll_paths, 1) };
@@ -97,7 +97,7 @@ impl SpyImpl {
9797

9898
let payload = Payload {
9999
channel_conf: channel_conf.clone(),
100-
asni_dll_path_with_nul: asni_dll_path_with_nul.to_bytes(),
100+
ansi_dll_path_with_nul: ansi_dll_path_with_nul.to_bytes(),
101101
};
102102
let payload_bytes = bincode::encode_to_vec(payload, BINCODE_CONFIG).unwrap();
103103
let success = unsafe {

crates/fspy_preload_windows/src/windows/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl<'a> Client<'a> {
5252
}
5353
}
5454

55-
pub fn asni_dll_path(&self) -> &'a CStr {
56-
unsafe { CStr::from_bytes_with_nul_unchecked(self.payload.asni_dll_path_with_nul) }
55+
pub fn ansi_dll_path(&self) -> &'a CStr {
56+
unsafe { CStr::from_bytes_with_nul_unchecked(self.payload.ansi_dll_path_with_nul) }
5757
}
5858
}
5959

crates/fspy_preload_windows/src/windows/detours/create_process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static DETOUR_CREATE_PROCESS_W: Detour<
148148
lp_current_directory,
149149
lp_startup_info,
150150
lp_process_information,
151-
client.asni_dll_path().as_ptr().cast(),
151+
client.ansi_dll_path().as_ptr().cast(),
152152
Some(create_process_with_payload_w),
153153
)
154154
}
@@ -261,7 +261,7 @@ static DETOUR_CREATE_PROCESS_A: Detour<
261261
lp_current_directory,
262262
lp_startup_info,
263263
lp_process_information,
264-
client.asni_dll_path().as_ptr().cast(),
264+
client.ansi_dll_path().as_ptr().cast(),
265265
Some(create_process_with_payload_a),
266266
)
267267
}

crates/fspy_shared/src/windows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ DEFINE_GUID!(PAYLOAD_ID, 0xfc4845f1, 0x3a8b, 0x4f05, 0xa3, 0xd3, 0xa5, 0xe9, 0xe
1010
#[derive(Encode, BorrowDecode, Debug, Clone)]
1111
pub struct Payload<'a> {
1212
pub channel_conf: ChannelConf,
13-
pub asni_dll_path_with_nul: &'a [u8],
13+
pub ansi_dll_path_with_nul: &'a [u8],
1414
}

crates/fspy_shared_unix/src/payload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ pub struct Payload {
1212
pub preload_path: NativeString,
1313

1414
#[cfg(target_os = "macos")]
15-
pub fixtures: Fixtures,
15+
pub artifacts: Artifacts,
1616

1717
#[cfg(target_os = "linux")]
1818
pub seccomp_payload: fspy_seccomp_unotify::payload::SeccompPayload,
1919
}
2020

2121
#[cfg(target_os = "macos")]
2222
#[derive(Debug, Encode, Decode, Clone)]
23-
pub struct Fixtures {
23+
pub struct Artifacts {
2424
pub bash_path: NativeString,
2525
pub coreutils_path: NativeString,
2626
// pub interpose_cdylib_path: NativeString,

crates/fspy_shared_unix/src/spawn/macos.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ pub fn handle_exec(
4242
(program_path.parent(), program_path.file_name())
4343
{
4444
if matches!(parent.as_os_str().as_bytes(), b"/bin" | b"/usr/bin") {
45-
let fixtures = &encoded_payload.payload.fixtures;
45+
let artifacts = &encoded_payload.payload.artifacts;
4646
if matches!(file_name.as_bytes(), b"sh" | b"bash") {
47-
command.program = fixtures.bash_path.as_os_str().as_bytes().into();
47+
command.program = artifacts.bash_path.as_os_str().as_bytes().into();
4848
true
4949
} else if COREUTILS_FUNCTIONS.contains(file_name.as_bytes()) {
50-
command.program = fixtures.coreutils_path.as_os_str().as_bytes().into();
50+
command.program = artifacts.coreutils_path.as_os_str().as_bytes().into();
5151
true
5252
} else {
5353
false

0 commit comments

Comments
 (0)