Advertisement
Sc2ad

Static Copy Transpilers

Dec 10th, 2020
1,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. /*
  2. Static copy approach. Copies to a statically allocated region of memory which should certainly be permissible.
  3. Assumes a size of 1 << 12, but can be modified to be larger as necessary. Fail in the event that size is not correct.
  4. This may actually be considerably better to do in general, but the lack of runtime size corrections may be a bit dissuading.
  5. Not to mention that the copying could be optimized a bit too :)
  6. */
  7.  
  8. #define SIZE (1 << 12)
  9. uint32_t func[SIZE];
  10.  
  11. MAKE_HOOK_OFFSETLESS(LateUpdate, void, void *self) {
  12.     reinterpret_cast<void (*)(void*)>(func)(self);
  13. }
  14.  
  15. extern "C" void load() {
  16.     auto lateUpdateInfo = il2cpp_utils::FindMethodUnsafe("", "BeatmapObjectCallbackController", "LateUpdate", 0);
  17.     auto nextMethodInfo = il2cpp_utils::FindMethodUnsafe("", "BeatmapObjectCallbackController", "AddBeatmapObjectCallback", 2);
  18.     uint32_t *startAddr = (uint32_t *) lateUpdateInfo->methodPointer;
  19.     uint32_t *endAddr = (uint32_t *) nextMethodInfo->methodPointer;
  20.  
  21.     std::vector<uint32_t> instructions(startAddr, endAddr);
  22.     if (endAddr - startAddr > SIZE) {
  23.         // Fail
  24.     }
  25.  
  26.     int dstIdx = 0;
  27.     for (int i = 0; i < instructions.size(); i++) {
  28.         uint32_t ins = instructions[i];
  29.         func[dstIdx] = ins;
  30.         ++dstIdx;
  31.         if (ins == 0x1e293901) { // 0x0139291e fsub s1,s8,s9
  32.             // Append instructions here, increase dstIdx
  33.             // This assumes you want to KEEP the fsub instruction (you can ofc move that stuff below)
  34.             func[dstIdx] = 0x0;
  35.             ++dstIdx;
  36.         }
  37.     }
  38.  
  39.     if (mprotect(reinterpret_cast<void*>(func), SIZE, PROT_EXEC) == 0) {
  40.         // Success
  41.     }
  42.  
  43.     INSTALL_HOOK_OFFSETLESS(LateUpdate, il2cpp_utils::FindMethodUnsafe("", "BeatmapObjectCallbackController", "LateUpdate", 0));
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement