|
1 | 1 | #ifndef TINYHOOK_PRIVATE_H |
2 | 2 | #define TINYHOOK_PRIVATE_H |
3 | 3 |
|
4 | | -#ifndef COMPACT |
5 | | -#include <mach/mach_error.h> // mach_error_string() |
6 | | -#include <printf.h> // fprintf() |
7 | | -#define LOG_ERROR(fmt, ...) fprintf(stderr, "ERROR [%s:%d]: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) |
| 4 | +#include <TargetConditionals.h> |
| 5 | + |
| 6 | +#include <mach/mach_init.h> // mach_task_self() |
| 7 | +#if TARGET_OS_IPHONE |
| 8 | + #include <mach/vm_map.h> // vm_* |
| 9 | + #define mach_vm_address_t vm_address_t |
| 10 | + #define mach_vm_allocate vm_allocate |
| 11 | + #define mach_vm_deallocate vm_deallocate |
| 12 | + #define mach_vm_read vm_read |
| 13 | + #define mach_vm_write vm_write |
| 14 | + #define mach_vm_protect vm_protect |
| 15 | +#elif TARGET_OS_MAC |
| 16 | + #include <mach/mach_vm.h> // mach_vm_* |
| 17 | +#endif |
| 18 | + |
| 19 | +#ifdef COMPACT |
| 20 | + #define LOG_ERROR(fmt, ...) ((void)0) |
8 | 21 | #else |
9 | | -#define LOG_ERROR(fmt, ...) ((void)0) |
| 22 | + #include <mach/mach_error.h> // mach_error_string() |
| 23 | + #include <printf.h> // fprintf() |
| 24 | + #define LOG_ERROR(fmt, ...) fprintf(stderr, "ERROR [%s:%d]: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) |
10 | 25 | #endif |
11 | 26 |
|
12 | 27 | #define MB (1ll << 20) |
13 | 28 | #define GB (1ll << 30) |
14 | 29 |
|
15 | 30 | #ifdef __aarch64__ |
16 | | -#define AARCH64_B 0x14000000 // b +0 |
17 | | -#define AARCH64_BL 0x94000000 // bl +0 |
18 | | -#define AARCH64_ADRP 0x90000011 // adrp x17, 0 |
19 | | -#define AARCH64_BR 0xd61f0220 // br x17 |
20 | | -#define AARCH64_BLR 0xd63f0220 // blr x17 |
21 | | -#define AARCH64_ADD 0x91000231 // add x17, x17, 0 |
22 | | -#define AARCH64_SUB 0xd1000231 // sub x17, x17, 0 |
23 | | - |
| 31 | + #define AARCH64_B 0x14000000 // b +0 |
| 32 | + #define AARCH64_BL 0x94000000 // bl +0 |
| 33 | + #define AARCH64_ADRP 0x90000011 // adrp x17, 0 |
| 34 | + #define AARCH64_BR 0xd61f0220 // br x17 |
| 35 | + #define AARCH64_BLR 0xd63f0220 // blr x17 |
| 36 | + #define AARCH64_ADD 0x91000231 // add x17, x17, 0 |
| 37 | + #define AARCH64_SUB 0xd1000231 // sub x17, x17, 0 |
24 | 38 | #elif __x86_64__ |
25 | | -#define X86_64_CALL 0xe8 // call |
26 | | -#define X86_64_JMP 0xe9 // jmp |
27 | | -#define X86_64_JMP_RIP 0x000025ff // jmp [rip] |
28 | | -#define X86_64_CALL_RIP 0x000015ff // call [rip] |
29 | | -#define X86_64_MOV_RI64 0xb848 // mov r64, m64 |
30 | | -#define X86_64_MOV_RM64 0x8b48 // mov r64, [r64] |
| 39 | + #define X86_64_CALL 0xe8 // call |
| 40 | + #define X86_64_JMP 0xe9 // jmp |
| 41 | + #define X86_64_JMP_RIP 0x000025ff // jmp [rip] |
| 42 | + #define X86_64_CALL_RIP 0x000015ff // call [rip] |
| 43 | + #define X86_64_MOV_RI64 0xb848 // mov r64, m64 |
| 44 | + #define X86_64_MOV_RM64 0x8b48 // mov r64, [r64] |
31 | 45 | #endif |
32 | 46 |
|
33 | 47 | bool need_far_jump(void *src, void *dst); |
|
0 commit comments