Skip to content

Instantly share code, notes, and snippets.

@gadmyth
Created November 27, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadmyth/5bfcb998bc9b360462e9277f771e8bd1 to your computer and use it in GitHub Desktop.
Save gadmyth/5bfcb998bc9b360462e9277f771e8bd1 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
struct __block_impl;
struct __block_impl_0;
struct __Block_byref_happy_0 {
void *__isa;
__Block_byref_happy_0 *__forwarding;
int __flags;
int __size;
int happy;
};
struct __block_impl {
void *isa;
int Flags;
int Reserved;
void (*FuncPtr)(__block_impl_0 *);
};
struct __block_impl_0 {
struct __block_impl impl;
struct __block_desc_0* Desc;
__Block_byref_happy_0 *happy;
__block_impl_0(void *fp, struct __block_desc_0 *desc, __Block_byref_happy_0 *_happy, int flags=0) : happy(_happy->__forwarding) {
impl.isa = &_NSConcreteStackBlock;
impl.Flags = flags;
impl.FuncPtr = (void(*)(__block_impl_0 *))fp;
Desc = desc;
}
};
static struct __block_desc_0 {
size_t reserved;
size_t Block_size;
};
static void real_block_func(struct __block_impl_0 *__cself) {
__Block_byref_happy_0 *happy = __cself->happy;
NSLog(@"real_block_func: %d", happy->__forwarding->happy);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
__Block_byref_happy_0 happy = {(void*)0, &happy, 0, 0, 10};
__block_desc_0 desc = {0, sizeof(__block_impl_0)};
struct __block_impl_0 wrapper = __block_impl_0((void *) real_block_func, &desc, &happy);
(happy.__forwarding->happy) = 20;
wrapper.impl.FuncPtr(&wrapper);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment