oc-hook-macros 0.1.0

Some convenient macros for hooking Objective-C functions
Documentation
  • Coverage
  • 8.33%
    1 out of 12 items documented1 out of 7 items with examples
  • Size
  • Source code size: 13.54 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 474.79 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hangj/oc-hook-macros
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hangj

Usage

use oc_hook_macros::*;

hook_helper! {
    // hook instance method
    - (void) [NSApplication run]
    unsafe extern "C" fn hook_run(_this: &NSObject, _cmd: Sel) {
        log::error!("hook_run, bye bye");
    }

    // hook class method
    +(id)[ClassA hello]
    unsafe extern "C" fn hello(this: &NSObject, _cmd: Sel) -> *mut NSObject{
        // call the original method by the hooked selector which starts with `hook_`
        let ret: Retained<NSObject> msg_send_id![this, hook_hello];
        Retained::into_raw(ret)
    }
}

// insert new method into existing class
new_selector! {
    -(void)[NSObject openNewXXInstace:]
    unsafe extern "C" fn openNewXXInstace(_this:&NSObject, _cmd: Sel, _sender: *mut NSObject) {
        // ...
    }
}