-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathstat.rs
More file actions
43 lines (39 loc) · 1.8 KB
/
stat.rs
File metadata and controls
43 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use fspy_shared::ipc::AccessMode;
use libc::{c_char, c_int, stat as stat_struct};
use crate::{
client::{convert::PathAt, handle_open},
macros::intercept,
};
intercept!(stat(64): unsafe extern "C" fn(path: *const c_char, buf: *mut stat_struct) -> c_int);
unsafe extern "C" fn stat(path: *const c_char, buf: *mut stat_struct) -> c_int {
// SAFETY: path is a valid C string pointer provided by the caller of the interposed function
unsafe {
handle_open(path, AccessMode::READ);
}
// SAFETY: calling the original libc stat() with the same arguments forwarded from the interposed function
unsafe { stat::original()(path, buf) }
}
intercept!(lstat(64): unsafe extern "C" fn(path: *const c_char, buf: *mut stat_struct) -> c_int);
unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat_struct) -> c_int {
// TODO: add accessmode ReadNoFollow
// SAFETY: path is a valid C string pointer provided by the caller of the interposed function
unsafe {
handle_open(path, AccessMode::READ);
}
// SAFETY: calling the original libc lstat() with the same arguments forwarded from the interposed function
unsafe { lstat::original()(path, buf) }
}
intercept!(fstatat(64): unsafe extern "C" fn(dirfd: c_int, pathname: *const c_char, buf: *mut stat_struct, flags: c_int) -> c_int);
unsafe extern "C" fn fstatat(
dirfd: c_int,
pathname: *const c_char,
buf: *mut stat_struct,
flags: c_int,
) -> c_int {
// SAFETY: dirfd and pathname are valid arguments provided by the caller of the interposed function
unsafe {
handle_open(PathAt(dirfd, pathname), AccessMode::READ);
}
// SAFETY: calling the original libc fstatat() with the same arguments forwarded from the interposed function
unsafe { fstatat::original()(dirfd, pathname, buf, flags) }
}