diff --git a/frida-gum/src/process.rs b/frida-gum/src/process.rs index fff714a..e877c02 100644 --- a/frida-gum/src/process.rs +++ b/frida-gum/src/process.rs @@ -10,13 +10,19 @@ use crate::{FileMapping, NativePointer}; use { crate::{module, Gum, PageProtection, RangeDetails}, - core::ffi::c_void, + core::ffi::{c_char, c_void, CStr}, frida_gum_sys as gum_sys, frida_gum_sys::{gboolean, gpointer}, }; #[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use alloc::{string::String, string::ToString, vec::Vec}; + +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; +} #[derive(Clone, FromPrimitive, Debug)] #[repr(u32)] @@ -91,6 +97,45 @@ impl<'a> Process<'a> { } } + /// Returns a string specifying the filesystem path to the current working directory + pub fn get_current_dir(&self) -> String { + let current_dir = unsafe { + CStr::from_ptr(_frida_g_get_current_dir()) + .to_string_lossy() + .to_string() + }; + + current_dir + } + + /// Returns a string specifying the filesystem path to the directory to use for temporary files + pub fn get_tmp_dir(&self) -> String { + let tmp_dir = unsafe { + CStr::from_ptr(_frida_g_get_tmp_dir()) + .to_string_lossy() + .to_string() + }; + + tmp_dir + } + + /// Returns a string specifying the filesystem path to the current user’s home directory + pub fn get_home_dir(&self) -> String { + let home_dir = unsafe { + CStr::from_ptr(_frida_g_get_home_dir()) + .to_string_lossy() + .to_string() + }; + + home_dir + } + + /// Get this thread’s OS-specific id as a number + pub fn get_current_thread_id(&self) -> u64 { + let id = unsafe { gum_sys::gum_process_get_current_thread_id() }; + id + } + /// Enumerates memory ranges satisfying `protection` given pub fn enumerate_ranges(&self, protection: PageProtection) -> Vec> { struct CallbackData<'a> {