wraith/manipulation/syscall/
mod.rs1mod direct;
23mod enumerator;
24mod indirect;
25mod table;
26mod wrappers;
27
28pub use direct::DirectSyscall;
29pub use enumerator::{enumerate_syscalls, EnumeratedSyscall, SyscallEnumerator};
30pub use indirect::IndirectSyscall;
31pub use table::{hashes, SyscallEntry, SyscallTable};
32pub use wrappers::*;
33
34use crate::error::Result;
35
36#[cfg(feature = "std")]
37use std::sync::OnceLock;
38
39#[cfg(all(not(feature = "std"), feature = "alloc"))]
40use alloc::format;
41
42#[cfg(feature = "std")]
43static SYSCALL_TABLE: OnceLock<Result<SyscallTable>> = OnceLock::new();
44
45#[cfg(feature = "std")]
51pub fn get_syscall_table() -> Result<&'static SyscallTable> {
52 let result = SYSCALL_TABLE.get_or_init(SyscallTable::enumerate);
53 match result {
54 Ok(table) => Ok(table),
55 Err(e) => Err(crate::error::WraithError::SyscallEnumerationFailed {
56 reason: format!("{}", e),
57 }),
58 }
59}
60
61#[cfg(not(feature = "std"))]
65pub fn enumerate_syscall_table() -> Result<SyscallTable> {
66 SyscallTable::enumerate()
67}
68
69#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71pub enum SyscallMode {
72 Direct,
74 Indirect,
76 Native,
78}
79
80impl Default for SyscallMode {
81 fn default() -> Self {
82 Self::Direct
83 }
84}
85
86static PREFERRED_MODE: core::sync::atomic::AtomicU8 = core::sync::atomic::AtomicU8::new(0);
88
89pub fn set_syscall_mode(mode: SyscallMode) {
91 let value = match mode {
92 SyscallMode::Direct => 0,
93 SyscallMode::Indirect => 1,
94 SyscallMode::Native => 2,
95 };
96 PREFERRED_MODE.store(value, core::sync::atomic::Ordering::Relaxed);
97}
98
99pub fn get_syscall_mode() -> SyscallMode {
101 match PREFERRED_MODE.load(core::sync::atomic::Ordering::Relaxed) {
102 0 => SyscallMode::Direct,
103 1 => SyscallMode::Indirect,
104 _ => SyscallMode::Native,
105 }
106}
107
108#[inline]
110pub const fn nt_success(status: i32) -> bool {
111 status >= 0
112}
113
114pub mod status {
116 pub const STATUS_SUCCESS: i32 = 0;
117 pub const STATUS_INVALID_HANDLE: i32 = 0xC0000008_u32 as i32;
118 pub const STATUS_ACCESS_DENIED: i32 = 0xC0000022_u32 as i32;
119 pub const STATUS_BUFFER_TOO_SMALL: i32 = 0xC0000023_u32 as i32;
120 pub const STATUS_INFO_LENGTH_MISMATCH: i32 = 0xC0000004_u32 as i32;
121}