| 1 | #ifndef MMAN_H |
| 2 | #define MMAN_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include "3ds.h" |
| 9 | #include "stdlib.h" |
| 10 | #include "stdio.h" |
| 11 | |
| 12 | #define PROT_READ MEMPERM_READ |
| 13 | #define PROT_WRITE MEMPERM_WRITE |
| 14 | #define PROT_EXEC MEMPERM_EXECUTE |
| 15 | #define MAP_PRIVATE 2 |
| 16 | #define MAP_ANONYMOUS 0x20 |
| 17 | |
| 18 | #define MAP_FAILED ((void *)-1) |
| 19 | |
| 20 | static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) |
| 21 | { |
| 22 | (void)addr; |
| 23 | (void)prot; |
| 24 | (void)flags; |
| 25 | (void)fd; |
| 26 | (void)offset; |
| 27 | |
| 28 | void* addr_out; |
| 29 | |
| 30 | addr_out = malloc(len); |
| 31 | if(!addr_out) |
| 32 | return MAP_FAILED; |
| 33 | |
| 34 | return addr_out; |
| 35 | } |
| 36 | |
| 37 | static inline int mprotect(void *addr, size_t len, int prot) |
| 38 | { |
| 39 | extern int ctr_svchack_init_success; |
| 40 | |
| 41 | if(ctr_svchack_init_success) |
| 42 | { |
| 43 | uint32_t currentHandle; |
| 44 | svcDuplicateHandle(¤tHandle, 0xFFFF8001); |
| 45 | svcControlProcessMemory(currentHandle, (u32)addr, 0x0, |
| 46 | len, MEMOP_PROT, prot); |
| 47 | svcCloseHandle(currentHandle); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | printf("mprotect called without svcControlProcessMemory access !\n"); |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | static inline int munmap(void *addr, size_t len) |
| 56 | { |
| 57 | free(addr); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | #ifdef __cplusplus |
| 62 | }; |
| 63 | #endif |
| 64 | |
| 65 | #endif // MMAN_H |
| 66 | |