Skip to content

Instantly share code, notes, and snippets.

@iJasonY iJasonY/main.m forked from Skifary/main.m
Created Mar 12, 2019

Embed
What would you like to do?
替换block原有实现
#import <Foundation/Foundation.h>
typedef struct __block_impl {
void *isa;
int Flags;
int Reserved;
void *FuncPtr;
}__block_impl;
typedef void(^GlobalBlock)(void);
void hookFunc() {
NSLog(@"hello world");
}
void HookBlockToPrintHelloWorld(id blk) {
__block_impl *ptr = (__bridge __block_impl *)blk;
ptr->FuncPtr = &hookFunc;
}
int main(int argc, const char * argv[]) {
GlobalBlock blk = ^void() {
};
HookBlockToPrintHelloWorld(blk);
blk();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.