Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Orig copy approach. Uses the fact that the installation already protects a (sufficiently large enough) region of memory for any inserted instructions. Not always guaranteed, but will almost always work.
- This is if you don't want to do one of the other options, or if the heap is always mapped as -X (which it might be).
- */
- MAKE_HOOK_OFFSETLESS(LateUpdate, void, void *self) {
- // We actually modified orig, so we just call it here.
- // You could do something similar to the first approach (allocate a temporary array) and call that instead if you prefer
- LateUpdate(self);
- }
- extern "C" void load() {
- auto lateUpdateInfo = il2cpp_utils::FindMethodUnsafe("", "BeatmapObjectCallbackController", "LateUpdate", 0);
- auto nextMethodInfo = il2cpp_utils::FindMethodUnsafe("", "BeatmapObjectCallbackController", "AddBeatmapObjectCallback", 2);
- uint32_t *startAddr = (uint32_t *) lateUpdateInfo->methodPointer;
- uint32_t *endAddr = (uint32_t *) nextMethodInfo->methodPointer;
- INSTALL_HOOK_OFFSETLESS(LateUpdate, il2cpp_utils::FindMethodUnsafe("", "BeatmapObjectCallbackController", "LateUpdate", 0));
- // Copy instructions from trampoline
- std::vector<uint32_t> instructions(reinterpret_cast<uint32_t*>(LateUpdate), reinterpret_cast<uint32_t*>(
- reinterpret_cast<std::size_t>(LateUpdate) + (endAddr - startAddr)
- ));
- int dstIdx = -1;
- for (int i = 0; i < instructions.size(); i++) {
- uint32_t ins = instructions[i];
- if (ins == 0x1e293901) { // 0x0139291e fsub s1,s8,s9
- dstIdx = i;
- // Insert instructions, can insert at index i, since insts is copied
- // This will replace the fsub instruction (can skip if you add 1 to dstIdx first)
- reinterpret_cast<uint32_t*>(LateUpdate)[dstIdx] = 0x0;
- ++dstIdx;
- }
- if (dstIdx >= 0) {
- // Only overwrite orig when necessary
- // (Can save some code if you use a local)
- reinterpret_cast<uint32_t*>(LateUpdate)[dstIdx] = ins;
- ++dstIdx;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement