-
-
Save iJasonY/146ea1636350be2147103ddee20c2588 to your computer and use it in GitHub Desktop.
替换block原有实现
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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