Skip to content

Commit

Permalink
Process: fix imports of frida namespaced glib functions (#194)
Browse files Browse the repository at this point in the history
* Process: fix imports of frida namespaced glib functions

* Process: fix imports of frida namespaced glib functions

* fmt
  • Loading branch information
s1341 authored Feb 2, 2025
1 parent 34464d5 commit ee64220
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions frida-gum/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit ee64220

Please sign in to comment.