How to create thunk in x64?
问题 I've found nice example how to create thunk for closure, but it's 32-bit version: #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> struct env { int x; }; struct __attribute__((packed)) thunk { unsigned char push; struct env * env_addr; unsigned char call; signed long call_offset; unsigned char add_esp[3]; unsigned char ret; }; struct thunk default_thunk = {0x68, 0, 0xe8, 0, {0x83, 0xc4, 0x04}, 0xc3}; typedef void (* cfunc)(); struct thunk * make_thunk(struct env * env, void * code