Created
November 23, 2015 13:42
-
-
Save kkirby/23f4e7e661d2d35426ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <sys/mman.h> | |
| #include <errno.h> | |
| #include <fcntl.h> | |
| #include <sys/types.h> | |
| #include <sys/stat.h> | |
| #include <unistd.h> | |
| #include <mach-o/dyld.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define abc_stuff(var) char* var = malloc(sizeof(char) * 5); memcpy(var,&"hello",5); fprintf(stderr,"%s: %s\n",#var,var); | |
| int main(){ | |
| for(int i = 0; i < 2; i++){ | |
| abc_stuff(abc1); | |
| } | |
| int gExeFd = open("/Users/kkirbatski/Downloads/OpenRCT2/openrct2.exe",O_RDONLY); | |
| if (gExeFd < 0) { | |
| fprintf(stderr,"failed to open errno = %d\n",errno); | |
| exit(1); | |
| } | |
| off_t file_size = 6750208; | |
| int len = 0x01429000 - 0x8a4000; // 0xB85000, 12079104 bytes or around 11.5MB | |
| // section: rw data | |
| void *gDataSegment = mmap((void *)0x8a4000, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANON | MAP_SHARED, 0, 0); | |
| if (gDataSegment != (void *)0x8a4000) { | |
| fprintf(stderr,"mmap failed to get required offset for data segment! got %p, expected %p, errno = %d", gDataSegment, (void *)(0x8a4000), errno); | |
| exit(1); | |
| } | |
| len = 0x004A3000; | |
| // section: text | |
| void *gTextSegment = mmap((void *)(0x401000), len, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_FIXED | MAP_PRIVATE, gExeFd, 0x1000); | |
| if (gTextSegment != (void *)(0x401000)){ | |
| fprintf(stderr,"mmap failed to get required offset for text segment! got %p, expected %p, errno = %d\n", gTextSegment, (void *)(0x401000), errno); | |
| exit(1); | |
| } | |
| for(int i = 0; i < 2; i++){ | |
| abc_stuff(abc2); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment