While MSHookMemory is great, I hate I have to do this:
const uint8_t hack[] = {
0x00, 0x00, 0x80, 0x52, // mov w0, #0
0xc0, 0x03, 0x5f, 0xd6, // ret
};
So I wrote some code which won't need you to do that:
#include <substrate.h>
#include <mach-o/dyld.h>
#define ASLR_BIAS _dyld_get_image_vmaddr_slide(0)
uint64_t getRealOffset(uint64_t offset){
return ASLR_BIAS + offset;
}
// main func
void inject(uint64_t offset, uint64_t hackedHex) {
hackedHex = CFSwapInt32(hackedHex);
MSHookMemory((void *)getRealOffset(offset), (void *)&hackedHex, sizeof(hackedHex));
}
How to import this code to your project?
You have two options:
1. Copy & paste the code from above under your "imports"
2. Download this file & paste it in /var/theos/includes & write this on top of tweak.xm:
#include <inject.h>
Usage of the function:
//parameters it takes
inject(0xIDAOffset, 0xHackedHex);
//actual usage on a offset
inject(0x100299DC4, 0xC0035FD6);
Bugs to be fixed:
1. If you wanna write a hex more than 4 bytes, it won't work the way you think, example:
inject(0x100299DC0, 0x20008052C0035FD6);
/*
This will write C0035FD620008052 instead of what you entered due the CFSwapInt32
/*
NOTE: I'm no pro at this kinda stuff (dealing with memory), so if there's anything just mention it ^^
Credits
- Saurik
- topics from https://stackoverflow.com/ which helped me understand several things
- Me for this simplified version