Skip to content

Commit

Permalink
Fix iOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk authored Aug 13, 2023
1 parent bf0e83e commit d7fcdcf
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,20 @@ jobs:
with:
command: run
args: --target x86_64-unknown-linux-gnu -p linux-no-std

build-ios:
runs-on: macOS-latest
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: install ios
run: rustup target add aarch64-apple-ios
- name: install cargo ndk
run: cargo install cargo-ndk
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Build iOS
run: cargo build --target aarch64-apple-ios --features=event-sink,invocation-listener,stalker-observer,stalker-params,auto-download

1 change: 1 addition & 0 deletions examples/gum/linux_no_std/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![allow(internal_features)]
#![feature(alloc_error_handler, lang_items)]

use {
Expand Down
15 changes: 8 additions & 7 deletions frida-gum-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use std::env;
use std::path::PathBuf;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
#[cfg(feature = "event-sink")]
{
println!("cargo:rerun-if-changed=event_sink.c");
Expand Down Expand Up @@ -51,7 +54,7 @@ fn main() {
#[cfg(not(feature = "auto-download"))]
println!("cargo:rustc-link-lib=frida-gum");

if target_os != "android" && (target_os == "linux" || target_os == "macos") {
if target_os != "android" && (target_os == "linux" || target_vendor == "apple") {
println!("cargo:rustc-link-lib=pthread");
}

Expand Down Expand Up @@ -187,13 +190,11 @@ fn main() {
}

if target_os == "windows" {
[
for lib in [
"dnsapi", "iphlpapi", "psapi", "winmm", "ws2_32", "advapi32", "crypt32", "gdi32",
"kernel32", "ole32", "secur32", "shell32", "shlwapi", "user32",
]
.iter()
.for_each(|lib| {
println!("cargo:rustc-link-lib=dylib={}", lib);
});
] {
println!("cargo:rustc-link-lib=dylib={lib}");
}
}
}
7 changes: 1 addition & 6 deletions frida-gum-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ mod bindings {

pub use bindings::*;

#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "windows",
target_os = "android"
)))]
#[cfg(not(any(target_os = "windows", target_os = "android", target_vendor = "apple",)))]
pub use _frida_g_object_unref as g_object_unref;

/// A single disassembled CPU instruction.
Expand Down
10 changes: 6 additions & 4 deletions frida-gum/src/debug_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ impl Symbol {

/// Name of the symbol
pub fn module_name(&self) -> Result<&str, Utf8Error> {
unsafe { CStr::from_ptr(self.gum_debug_symbol_details.module_name.as_ptr()) }.to_str()
unsafe { CStr::from_ptr(self.gum_debug_symbol_details.module_name.as_ptr().cast()) }
.to_str()
}

/// Module name owning this symbol
pub fn symbol_name(&self) -> Result<&str, Utf8Error> {
unsafe { CStr::from_ptr(self.gum_debug_symbol_details.symbol_name.as_ptr()) }.to_str()
unsafe { CStr::from_ptr(self.gum_debug_symbol_details.symbol_name.as_ptr().cast()) }
.to_str()
}

/// File name owning this symbol
pub fn file_name(&self) -> Result<&str, Utf8Error> {
unsafe { CStr::from_ptr(self.gum_debug_symbol_details.file_name.as_ptr()) }.to_str()
unsafe { CStr::from_ptr(self.gum_debug_symbol_details.file_name.as_ptr().cast()) }.to_str()
}

/// Line number in file_name
Expand Down Expand Up @@ -73,7 +75,7 @@ impl DebugSymbol {
pub fn find_function<S: AsRef<str>>(name: S) -> Option<NativePointer> {
match CString::new(name.as_ref()) {
Ok(name) => {
let address = unsafe { gum_find_function(name.into_raw()) };
let address = unsafe { gum_find_function(name.into_raw().cast()) };
if address.is_null() {
None
} else {
Expand Down
3 changes: 2 additions & 1 deletion frida-gum/src/memory_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ impl MatchPattern {
pub fn from_string(pattern: &str) -> Option<Self> {
let pattern = CString::new(pattern).unwrap();

let internal = unsafe { gum_sys::gum_match_pattern_new_from_string(pattern.as_ptr()) };
let internal =
unsafe { gum_sys::gum_match_pattern_new_from_string(pattern.as_ptr().cast()) };
if !internal.is_null() {
Some(Self { internal })
} else {
Expand Down
25 changes: 18 additions & 7 deletions frida-gum/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ impl Module {

let ptr = match module_name {
None => unsafe {
gum_sys::gum_module_find_export_by_name(core::ptr::null_mut(), symbol_name.as_ptr())
gum_sys::gum_module_find_export_by_name(
core::ptr::null_mut(),
symbol_name.as_ptr().cast(),
)
},
Some(name) => unsafe {
let module_name = CString::new(name).unwrap();
gum_sys::gum_module_find_export_by_name(module_name.as_ptr(), symbol_name.as_ptr())
gum_sys::gum_module_find_export_by_name(
module_name.as_ptr().cast(),
symbol_name.as_ptr().cast(),
)
},
} as *mut c_void;

Expand All @@ -91,7 +97,10 @@ impl Module {

let module_name = CString::new(module_name).unwrap();
let ptr = unsafe {
gum_sys::gum_module_find_symbol_by_name(module_name.as_ptr(), symbol_name.as_ptr())
gum_sys::gum_module_find_symbol_by_name(
module_name.as_ptr().cast(),
symbol_name.as_ptr().cast(),
)
} as *mut c_void;

if ptr.is_null() {
Expand All @@ -107,7 +116,9 @@ impl Module {
let module_name = CString::new(module_name).unwrap();

unsafe {
NativePointer(gum_sys::gum_module_find_base_address(module_name.as_ptr()) as *mut c_void)
NativePointer(
gum_sys::gum_module_find_base_address(module_name.as_ptr().cast()) as *mut c_void,
)
}
}

Expand All @@ -125,7 +136,7 @@ impl Module {
)) as *mut _ as *mut c_void;

gum_sys::gum_module_enumerate_ranges(
module_name.as_ptr(),
module_name.as_ptr().cast(),
prot as u32,
Some(enumerate_ranges_callout),
user_data,
Expand Down Expand Up @@ -199,7 +210,7 @@ impl Module {

unsafe {
frida_gum_sys::gum_module_enumerate_exports(
module_name.as_ptr(),
module_name.as_ptr().cast(),
Some(callback),
&result as *const _ as *mut c_void,
);
Expand Down Expand Up @@ -236,7 +247,7 @@ impl Module {

unsafe {
frida_gum_sys::gum_module_enumerate_symbols(
module_name.as_ptr(),
module_name.as_ptr().cast(),
Some(callback),
&result as *const _ as *mut c_void,
);
Expand Down
17 changes: 9 additions & 8 deletions frida-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn main() {
env::var("CARGO_MANIFEST_DIR").unwrap()
);
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();

#[cfg(feature = "auto-download")]
let include_dir = {
Expand All @@ -30,11 +31,13 @@ fn main() {
println!("cargo:rustc-link-lib=resolv");
}

if target_os == "macos" {
if target_vendor == "apple" {
println!("cargo:rustc-link-lib=bsm");
println!("cargo:rustc-link-lib=resolv");
println!("cargo:rustc-link-lib=pthread");
println!("cargo:rustc-link-lib=framework=AppKit");
if target_os == "macos" {
println!("cargo:rustc-link-lib=framework=AppKit");
}
}

let bindings = bindgen::Builder::default();
Expand Down Expand Up @@ -63,13 +66,11 @@ fn main() {
.unwrap();

if target_os == "windows" {
let _ = &[
for lib in [
"dnsapi", "iphlpapi", "psapi", "winmm", "ws2_32", "advapi32", "crypt32", "gdi32",
"kernel32", "ole32", "secur32", "shell32", "shlwapi", "user32",
]
.iter()
.for_each(|lib| {
println!("cargo:rustc-link-lib=dylib={}", lib);
});
] {
println!("cargo:rustc-link-lib=dylib={lib}");
}
}
}

0 comments on commit d7fcdcf

Please sign in to comment.