diff --git a/mach-test/build.rs b/mach-test/build.rs index 661e3fa..7ba095b 100644 --- a/mach-test/build.rs +++ b/mach-test/build.rs @@ -128,6 +128,8 @@ fn main() { .header("mach/vm_task.h") .header("mach/vm_types.h"); + cfg.header("mach-o/loader.h").header("mach-o/dyld.h"); + // The below doesn't exist in Xcode 14: if xcode < Xcode(14, 0) { cfg.header("mach/lock_set.h"); diff --git a/src/dyld.rs b/src/dyld.rs new file mode 100644 index 0000000..8202d37 --- /dev/null +++ b/src/dyld.rs @@ -0,0 +1,16 @@ +//! This module roughly corresponds to `mach-o/dyld.h`. + +use loader::mach_header; + +extern "C" { + pub fn _dyld_image_count() -> u32; + pub fn _dyld_get_image_header(image_index: u32) -> *const mach_header; + pub fn _dyld_get_image_vmaddr_slide(image_index: u32) -> ::libc::intptr_t; + pub fn _dyld_get_image_name(image_index: u32) -> *const ::libc::c_char; + pub fn _dyld_register_func_for_add_image( + callback: unsafe extern "C" fn(mh: *const mach_header, vmaddr_slide: ::libc::intptr_t), + ); + pub fn _dyld_register_func_for_remove_image( + callback: unsafe extern "C" fn(mh: *const mach_header, vmaddr_slide: ::libc::intptr_t), + ); +} diff --git a/src/lib.rs b/src/lib.rs index 4306ee3..e0c87a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,11 +24,13 @@ pub mod clock; pub mod clock_priv; pub mod clock_reply; pub mod clock_types; // TODO: test +pub mod dyld; pub mod dyld_kernel; // pub mod error; // TODO pub mod exc; pub mod exception_types; pub mod kern_return; +pub mod loader; pub mod mach_init; pub mod mach_port; pub mod mach_time; diff --git a/src/loader.rs b/src/loader.rs new file mode 100644 index 0000000..1b0d3a9 --- /dev/null +++ b/src/loader.rs @@ -0,0 +1,14 @@ +//! This module roughly corresponds to `mach-o/loader.h`. + +#[repr(C)] +#[allow(dead_code, non_snake_case)] +#[derive(Copy, Clone, Debug)] +pub struct mach_header { + pub magic: u32, + pub cputype: ::libc::cpu_type_t, + pub cpusubtype: ::libc::cpu_subtype_t, + pub filetype: u32, + pub ncmds: u32, + pub sizeofcmds: u32, + pub flags: u32, +}