Work on reading buffers.

This commit is contained in:
Michael Mikovsky
2025-08-18 16:45:17 -06:00
parent 856d7e467f
commit 59792420b5
18 changed files with 4958 additions and 2819 deletions
+31 -32
View File
@@ -1,9 +1,8 @@
mod host;
mod syscall_exec;
#[allow(dead_code)]
mod syscall_intercept;
use syscall_lib::syscall_should_proxy;
use syscall_lib::Syscall;
use libc::exit;
use std::{
@@ -20,17 +19,17 @@ static mut HOST: Option<Mutex<Host>> = None;
#[ctor::ctor]
fn start() {
unsafe {
HOST = Some({
match Host::new() {
Ok(host) => Mutex::new(host),
Err(e) => {
eprintln!("Failed to connect to server: {}", e);
exit(1);
}
}
});
}
// unsafe {
// HOST = Some({
// match Host::new() {
// Ok(host) => Mutex::new(host),
// Err(e) => {
// eprintln!("Failed to connect to server: {}", e);
// exit(1);
// }
// }
// });
// }
unsafe { set_hook_fn(hook) };
}
@@ -68,13 +67,13 @@ impl Drop for InterceptGuard {
}
extern "C" fn hook(
syscall_num: usize,
arg0: usize,
arg1: usize,
arg2: usize,
arg3: usize,
arg4: usize,
arg5: usize,
syscall_num: libc::c_long,
arg0: libc::c_ulong,
arg1: libc::c_ulong,
arg2: libc::c_ulong,
arg3: libc::c_ulong,
arg4: libc::c_ulong,
arg5: libc::c_ulong,
result: &mut isize,
) -> InterceptResult {
// detect and avoid recursive interception
@@ -95,11 +94,11 @@ extern "C" fn hook(
}
let args = [arg0, arg1, arg2, arg3, arg4, arg5];
let syscall = syscall_lib::create_syscall(syscall_num, args);
let syscall = Syscall::from_syscall(syscall_num as libc::c_long, args).unwrap();
if !syscall_should_proxy(&syscall) {
return InterceptResult::Forward;
}
// if !syscall_should_proxy(&syscall) {
// return InterceptResult::Forward;
// }
// Return if is print
// if syscall_num == libc::SYS_write as _ && arg0 == 1 {
@@ -110,18 +109,18 @@ extern "C" fn hook(
// return InterceptResult::Forward;
// }
// println!("{:?}", desc);
println!("{:?}", syscall);
unsafe {
#[allow(static_mut_refs)]
if let Some(host) = HOST.as_ref() {
*result = host.lock().unwrap().execute(&syscall);
}
}
// unsafe {
// #[allow(static_mut_refs)]
// if let Some(host) = HOST.as_ref() {
// *result = host.lock().unwrap().execute(&syscall);
// }
// }
unsafe {
set_hook_fn(hook);
}
InterceptResult::Hook
InterceptResult::Forward
}