oc-hook-macros

Crates.iooc-hook-macros
lib.rsoc-hook-macros
version0.1.1
created_at2024-12-14 10:15:59.614432+00
updated_at2024-12-14 10:26:09.857176+00
descriptionSome convenient macros for hooking Objective-C functions
homepage
repositoryhttps://github.com/hangj/oc-hook-macros
max_upload_size
id1483032
size12,130
hangj (hangj)

documentation

README

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) {
        // ...
    }
}

Commit count: 3

cargo fmt