diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff856bf..dbea0b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 + diff --git a/examples/gum/linux_no_std/src/main.rs b/examples/gum/linux_no_std/src/main.rs index cb879b0..57db8c8 100644 --- a/examples/gum/linux_no_std/src/main.rs +++ b/examples/gum/linux_no_std/src/main.rs @@ -1,5 +1,6 @@ #![no_std] #![no_main] +#![allow(internal_features)] #![feature(alloc_error_handler, lang_items)] use { diff --git a/frida-gum-sys/build.rs b/frida-gum-sys/build.rs index 34e72cb..eb3fedd 100644 --- a/frida-gum-sys/build.rs +++ b/frida-gum-sys/build.rs @@ -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"); @@ -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"); } @@ -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}"); + } } } diff --git a/frida-gum-sys/src/lib.rs b/frida-gum-sys/src/lib.rs index c029769..e246f1c 100644 --- a/frida-gum-sys/src/lib.rs +++ b/frida-gum-sys/src/lib.rs @@ -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. diff --git a/frida-gum/src/debug_symbol.rs b/frida-gum/src/debug_symbol.rs index 9847ca1..447a6a0 100644 --- a/frida-gum/src/debug_symbol.rs +++ b/frida-gum/src/debug_symbol.rs @@ -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 @@ -73,7 +75,7 @@ impl DebugSymbol { pub fn find_function>(name: S) -> Option { 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 { diff --git a/frida-gum/src/memory_range.rs b/frida-gum/src/memory_range.rs index 004ba96..69b7f19 100644 --- a/frida-gum/src/memory_range.rs +++ b/frida-gum/src/memory_range.rs @@ -17,7 +17,8 @@ impl MatchPattern { pub fn from_string(pattern: &str) -> Option { 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 { diff --git a/frida-gum/src/module.rs b/frida-gum/src/module.rs index 16b565b..8657266 100644 --- a/frida-gum/src/module.rs +++ b/frida-gum/src/module.rs @@ -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; @@ -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() { @@ -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, + ) } } @@ -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, @@ -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, ); @@ -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, ); diff --git a/frida-sys/build.rs b/frida-sys/build.rs index 8999ffd..bfd6bed 100644 --- a/frida-sys/build.rs +++ b/frida-sys/build.rs @@ -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 = { @@ -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(); @@ -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}"); + } } }