Skip to content

Commit

Permalink
Added more function for Process
Browse files Browse the repository at this point in the history
- Process.getCurrentDir()
- Process.getHomeDir()
- Process.getTmpDir()
- Process.getCurrentThreadId()
  • Loading branch information
Xoffio committed Dec 18, 2024
1 parent ce60e74 commit a3942e3
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 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,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

Check failure on line 136 in frida-gum/src/process.rs

View workflow job for this annotation

GitHub Actions / Check (x86_64)

returning the result of a `let` binding from a block
}

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

0 comments on commit a3942e3

Please sign in to comment.