From ee642206a0e6d4fa27f4fc3ed5b0fe40d3d0dda8 Mon Sep 17 00:00:00 2001 From: s1341 Date: Sun, 2 Feb 2025 08:48:00 +0200 Subject: [PATCH] Process: fix imports of frida namespaced glib functions (#194) * Process: fix imports of frida namespaced glib functions * Process: fix imports of frida namespaced glib functions * fmt --- frida-gum/src/process.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/frida-gum/src/process.rs b/frida-gum/src/process.rs index baa10f1..18fc88c 100644 --- a/frida-gum/src/process.rs +++ b/frida-gum/src/process.rs @@ -19,12 +19,20 @@ use { use alloc::{string::String, string::ToString, vec::Vec}; use cstr_core::CString; +#[cfg(target_os = "linux")] extern "C" { pub fn _frida_g_get_home_dir() -> *const c_char; pub fn _frida_g_get_current_dir() -> *const c_char; pub fn _frida_g_get_tmp_dir() -> *const c_char; } +#[cfg(not(target_os = "linux"))] +extern "C" { + pub fn _g_get_home_dir() -> *const c_char; + pub fn _g_get_current_dir() -> *const c_char; + pub fn _g_get_tmp_dir() -> *const c_char; +} + #[derive(Clone, FromPrimitive, Debug)] #[repr(u32)] pub enum CodeSigningPolicy { @@ -121,27 +129,36 @@ impl<'a> Process<'a> { /// Returns a string specifying the filesystem path to the current working directory pub fn current_dir(&self) -> String { unsafe { - CStr::from_ptr(_frida_g_get_current_dir()) - .to_string_lossy() - .to_string() + #[cfg(target_os = "linux")] + let dir = _frida_g_get_current_dir(); + #[cfg(not(target_os = "linux"))] + let dir = _g_get_current_dir(); + + CStr::from_ptr(dir).to_string_lossy().to_string() } } /// Returns a string specifying the filesystem path to the directory to use for temporary files pub fn tmp_dir(&self) -> String { unsafe { - CStr::from_ptr(_frida_g_get_tmp_dir()) - .to_string_lossy() - .to_string() + #[cfg(target_os = "linux")] + let dir = _frida_g_get_tmp_dir(); + #[cfg(not(target_os = "linux"))] + let dir = _g_get_tmp_dir(); + + CStr::from_ptr(dir).to_string_lossy().to_string() } } /// Returns a string specifying the filesystem path to the current user’s home directory pub fn home_dir(&self) -> String { unsafe { - CStr::from_ptr(_frida_g_get_home_dir()) - .to_string_lossy() - .to_string() + #[cfg(target_os = "linux")] + let dir = _frida_g_get_home_dir(); + #[cfg(not(target_os = "linux"))] + let dir = _g_get_home_dir(); + + CStr::from_ptr(dir).to_string_lossy().to_string() } }