Skip to content

Commit ee64220

Browse files
authored
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
1 parent 34464d5 commit ee64220

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

frida-gum/src/process.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ use {
1919
use alloc::{string::String, string::ToString, vec::Vec};
2020
use cstr_core::CString;
2121

22+
#[cfg(target_os = "linux")]
2223
extern "C" {
2324
pub fn _frida_g_get_home_dir() -> *const c_char;
2425
pub fn _frida_g_get_current_dir() -> *const c_char;
2526
pub fn _frida_g_get_tmp_dir() -> *const c_char;
2627
}
2728

29+
#[cfg(not(target_os = "linux"))]
30+
extern "C" {
31+
pub fn _g_get_home_dir() -> *const c_char;
32+
pub fn _g_get_current_dir() -> *const c_char;
33+
pub fn _g_get_tmp_dir() -> *const c_char;
34+
}
35+
2836
#[derive(Clone, FromPrimitive, Debug)]
2937
#[repr(u32)]
3038
pub enum CodeSigningPolicy {
@@ -121,27 +129,36 @@ impl<'a> Process<'a> {
121129
/// Returns a string specifying the filesystem path to the current working directory
122130
pub fn current_dir(&self) -> String {
123131
unsafe {
124-
CStr::from_ptr(_frida_g_get_current_dir())
125-
.to_string_lossy()
126-
.to_string()
132+
#[cfg(target_os = "linux")]
133+
let dir = _frida_g_get_current_dir();
134+
#[cfg(not(target_os = "linux"))]
135+
let dir = _g_get_current_dir();
136+
137+
CStr::from_ptr(dir).to_string_lossy().to_string()
127138
}
128139
}
129140

130141
/// Returns a string specifying the filesystem path to the directory to use for temporary files
131142
pub fn tmp_dir(&self) -> String {
132143
unsafe {
133-
CStr::from_ptr(_frida_g_get_tmp_dir())
134-
.to_string_lossy()
135-
.to_string()
144+
#[cfg(target_os = "linux")]
145+
let dir = _frida_g_get_tmp_dir();
146+
#[cfg(not(target_os = "linux"))]
147+
let dir = _g_get_tmp_dir();
148+
149+
CStr::from_ptr(dir).to_string_lossy().to_string()
136150
}
137151
}
138152

139153
/// Returns a string specifying the filesystem path to the current user’s home directory
140154
pub fn home_dir(&self) -> String {
141155
unsafe {
142-
CStr::from_ptr(_frida_g_get_home_dir())
143-
.to_string_lossy()
144-
.to_string()
156+
#[cfg(target_os = "linux")]
157+
let dir = _frida_g_get_home_dir();
158+
#[cfg(not(target_os = "linux"))]
159+
let dir = _g_get_home_dir();
160+
161+
CStr::from_ptr(dir).to_string_lossy().to_string()
145162
}
146163
}
147164

0 commit comments

Comments
 (0)