Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more function for Process #188

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions frida-gum/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -91,6 +97,38 @@ 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()
}
}

/// 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()
}
}

/// 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()
}
}

/// Get this thread’s OS-specific id as a number
pub fn current_thread_id(&self) -> u32 {
unsafe { gum_sys::gum_process_get_current_thread_id() as u32 }
}

/// Enumerates memory ranges satisfying `protection` given
pub fn enumerate_ranges(&self, protection: PageProtection) -> Vec<Range<'a>> {
struct CallbackData<'a> {
Expand Down
Loading