Skip to content

Commit 97d8f09

Browse files
authored
Merge branch 'frida:main' into main
2 parents 8b43539 + 42220b3 commit 97d8f09

8 files changed

Lines changed: 41 additions & 22 deletions

File tree

examples/core/console_log/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() {
4646
struct Handler;
4747

4848
impl ScriptHandler for Handler {
49-
fn on_message(&mut self, message: &frida::Message, _data: Option<Vec<u8>>) {
49+
fn on_message(&mut self, message: frida::Message, _data: Option<Vec<u8>>) {
5050
println!("{:?}", message);
5151
}
5252
}

examples/core/list_exports/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn main() {
7474
struct Handler;
7575

7676
impl frida::ScriptHandler for Handler {
77-
fn on_message(&mut self, message: &Message, _data: Option<Vec<u8>>) {
77+
fn on_message(&mut self, message: Message, _data: Option<Vec<u8>>) {
7878
println!("- {:?}", message);
7979
}
8080
}

examples/core/rpc_execute_function/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn main() {
111111
struct Handler;
112112

113113
impl frida::ScriptHandler for Handler {
114-
fn on_message(&mut self, message: &Message, _data: Option<Vec<u8>>) {
114+
fn on_message(&mut self, message: Message, _data: Option<Vec<u8>>) {
115115
println!("- {:?}", message);
116116
}
117117
}

frida-gum/src/backtracer.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ use {core::mem::MaybeUninit, frida_gum_sys as gum_sys};
1212

1313
// The following function is not exposed through the `frida-gum.h` header, so we don't have an
1414
// auto-generated binding for it. This may change in a future version.
15-
#[cfg(not(target_os = "windows"))]
1615
extern "C" {
1716
// On some platforms `ucontext` contains a u128 which does not have a defined ABI. In this case,
1817
// we disable the error as we assume the behaviour is correct (all other platforms are unaffected).
18+
#[cfg(target_os = "linux")]
1919
#[allow(improper_ctypes)]
2020
fn gum_linux_parse_ucontext(
2121
context: *const libc::ucontext_t,
2222
cpu_context: *mut gum_sys::GumCpuContext,
2323
);
24+
25+
#[cfg(target_os = "freebsd")]
26+
#[allow(improper_ctypes)]
27+
fn gum_freebsd_parse_ucontext(
28+
context: *const libc::ucontext_t,
29+
cpu_context: *mut gum_sys::GumCpuContext,
30+
);
2431
}
2532

2633
pub struct Backtracer;
@@ -84,24 +91,36 @@ impl Backtracer {
8491

8592
/// Generate an accurate backtrace as a list of return addresses for the supplied signal
8693
/// context.
87-
#[cfg(not(target_os = "windows"))]
94+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
8895
pub fn accurate_with_signal_context(context: &libc::ucontext_t) -> Vec<usize> {
8996
let mut cpu_context = MaybeUninit::<gum_sys::GumCpuContext>::uninit();
9097

9198
unsafe {
99+
#[cfg(target_os = "linux")]
92100
gum_linux_parse_ucontext(context as *const libc::ucontext_t, cpu_context.as_mut_ptr());
101+
#[cfg(target_os = "freebsd")]
102+
gum_freebsd_parse_ucontext(
103+
context as *const libc::ucontext_t,
104+
cpu_context.as_mut_ptr(),
105+
);
93106
Self::accurate_with_context(&cpu_context.assume_init())
94107
}
95108
}
96109

97110
/// Generate a fuzzy backtrace as a list of return addresses for the supplied signal
98111
/// context.
99-
#[cfg(not(target_os = "windows"))]
112+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
100113
pub fn fuzzy_with_signal_context(context: &libc::ucontext_t) -> Vec<usize> {
101114
let mut cpu_context = MaybeUninit::<gum_sys::GumCpuContext>::uninit();
102115

103116
unsafe {
117+
#[cfg(target_os = "linux")]
104118
gum_linux_parse_ucontext(context as *const libc::ucontext_t, cpu_context.as_mut_ptr());
119+
#[cfg(target_os = "freebsd")]
120+
gum_freebsd_parse_ucontext(
121+
context as *const libc::ucontext_t,
122+
cpu_context.as_mut_ptr(),
123+
);
105124
Self::fuzzy_with_context(&cpu_context.assume_init())
106125
}
107126
}

frida-gum/src/process.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use alloc::{string::String, string::ToString, vec::Vec};
2020
use cstr_core::CString;
2121
use frida_gum_sys::GumThreadFlags_GUM_THREAD_FLAGS_ALL;
2222

23-
#[cfg(target_os = "linux")]
23+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
2424
extern "C" {
2525
pub fn _frida_g_get_home_dir() -> *const c_char;
2626
pub fn _frida_g_get_current_dir() -> *const c_char;
2727
pub fn _frida_g_get_tmp_dir() -> *const c_char;
2828
}
2929

30-
#[cfg(not(target_os = "linux"))]
30+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
3131
extern "C" {
3232
pub fn g_get_home_dir() -> *const c_char;
3333
pub fn g_get_current_dir() -> *const c_char;
@@ -130,9 +130,9 @@ impl<'a> Process<'a> {
130130
/// Returns a string specifying the filesystem path to the current working directory
131131
pub fn current_dir(&self) -> String {
132132
unsafe {
133-
#[cfg(target_os = "linux")]
133+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
134134
let dir = _frida_g_get_current_dir();
135-
#[cfg(not(target_os = "linux"))]
135+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
136136
let dir = g_get_current_dir();
137137

138138
CStr::from_ptr(dir).to_string_lossy().to_string()
@@ -142,9 +142,9 @@ impl<'a> Process<'a> {
142142
/// Returns a string specifying the filesystem path to the directory to use for temporary files
143143
pub fn tmp_dir(&self) -> String {
144144
unsafe {
145-
#[cfg(target_os = "linux")]
145+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
146146
let dir = _frida_g_get_tmp_dir();
147-
#[cfg(not(target_os = "linux"))]
147+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
148148
let dir = g_get_tmp_dir();
149149

150150
CStr::from_ptr(dir).to_string_lossy().to_string()
@@ -154,9 +154,9 @@ impl<'a> Process<'a> {
154154
/// Returns a string specifying the filesystem path to the current user’s home directory
155155
pub fn home_dir(&self) -> String {
156156
unsafe {
157-
#[cfg(target_os = "linux")]
157+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
158158
let dir = _frida_g_get_home_dir();
159-
#[cfg(not(target_os = "linux"))]
159+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
160160
let dir = g_get_home_dir();
161161

162162
CStr::from_ptr(dir).to_string_lossy().to_string()

frida-gum/src/script/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use {
33
frida_gum_sys::{GMainContext, GMainLoop},
44
};
55

6-
#[cfg(any(target_os = "linux", target_os = "android"))]
6+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
77
use frida_gum_sys::{
88
_frida_g_main_context_iteration as g_main_context_iteration,
99
_frida_g_main_context_pending as g_main_context_pending,
1010
_frida_g_main_context_push_thread_default as g_main_context_push_thread_default,
1111
_frida_g_main_loop_new as g_main_loop_new,
1212
};
1313

14-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
14+
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "freebsd")))]
1515
use frida_gum_sys::{
1616
g_main_context_iteration, g_main_context_pending, g_main_context_push_thread_default,
1717
g_main_loop_new,

frida-gum/src/script/data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use {
1313
};
1414

1515
/* glib exports are aliased in frida devkit for Linux and Android */
16-
#[cfg(any(target_os = "linux", target_os = "android"))]
16+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
1717
use frida_gum_sys::_frida_g_bytes_get_data as g_bytes_get_data;
1818

19-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
19+
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "freebsd")))]
2020
use frida_gum_sys::g_bytes_get_data;
2121

2222
pub(crate) struct ScriptData<F>

frida/src/script.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ unsafe extern "C" fn call_on_message<I: ScriptHandler>(
121121

122122
// Retrieve extra message data, if any.
123123
if data.is_null() {
124-
handler.on_message(&formatted_msg, None);
124+
handler.on_message(formatted_msg, None);
125125
return;
126126
}
127127

@@ -140,7 +140,7 @@ unsafe extern "C" fn call_on_message<I: ScriptHandler>(
140140
.to_vec(),
141141
)
142142
};
143-
handler.on_message(&formatted_msg, data_vec);
143+
handler.on_message(formatted_msg, data_vec);
144144
}
145145
}
146146
}
@@ -153,7 +153,7 @@ fn on_message(cb_handler: &mut CallbackHandler, message: Message) {
153153
/// Represents a script signal handler.
154154
pub trait ScriptHandler {
155155
/// Handler called when a message is shared from JavaScript to Rust.
156-
fn on_message(&mut self, message: &Message, data: Option<Vec<u8>>);
156+
fn on_message(&mut self, message: Message, data: Option<Vec<u8>>);
157157
}
158158

159159
/// Represents a Frida script.
@@ -234,7 +234,7 @@ impl<'a> Script<'a> {
234234
/// struct Handler;
235235
///
236236
/// impl ScriptHandler for Handler {
237-
/// fn on_message(&mut self, message: &frida::Message, data: Option<Vec<u8>>) {
237+
/// fn on_message(&mut self, message: frida::Message, data: Option<Vec<u8>>) {
238238
/// println!("Message: {:?}", message);
239239
/// println!("Data: {:?}", data);
240240
/// }

0 commit comments

Comments
 (0)