Jump to content

[IL2CPP] ICallHook - Unity Internal Hooking: MonoBehaviour, Time, Input & Much More


3 posts in this topic

Recommended Posts

Posted

 

 

ICallHook - Tutorial

Hello everyone I am Rednick16 (Red16) its been a while since I last made a tutorial so stay with me if this is a bit hard to follow along with.

 

Ann ale (Lets begin).

 

By now I am sure everyone participating in the unity modding scene have heard about IL2CPP (Intermediate Language To C++)

Okay so let's actually begin. I am going to try and keep this tutorial straight forward and easy as possible to follow along with.
In this tutorial you will be learning how to hook the following icalls. I should also mention that this does not need JIT (Just-In-Time).

UnityEngine.Camera::get_fieldOfView()
  
UnityEngine.Time::get_timeScale()
UnityEngine.Time::set_timeScale(System.Single)

UnityEngine.Input::GetKeyUpInt(UnityEngine.KeyCode)
UnityEngine.Input::GetKeyDownInt(UnityEngine.KeyCode)

 

The hooking method.

See the spoiler box for a thorough tutorial on how this was achieved and why it works. 

NOTE: Timing is everything with this method.  You must be very precise with where you setup the hook calls, for example the best place to put it would be in il2cpp_init ref:  https://github.com/Rednick16/ICallHook/blob/a4cb7a17ac1abc9187080f0d7afea8ee6cd7cc46/Tweak.x#L67

#include <stdbool.h>
#include <dlfcn.h>

void* il2cpp_library_get_handle(void)
{
    static void *handle = NULL;
#if defined(__ANDROID__)
    if (NULL == handle)
        handle = dlopen("libil2cpp.so", RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL);
    return handle;
#elif defined(__APPLE__)
    return RTLD_DEFAULT;
#else
#error "Unsupported target"
#endif
}

bool il2cpp_hook_icall(const char* name, void* hook, void** old)
{
    if (name == NULL || hook == NULL)
        return false;
    
    /* NOTE: resolve these ahead of time if possible, dlsym is really slow, but should be fine to use here
     since we only use these at startup anyways */
    void *(*il2cpp_resolve_icall)(const char *name) = NULL;
    if (il2cpp_resolve_icall == NULL)
        il2cpp_resolve_icall = (void * (*)(const char*))dlsym(il2cpp_library_get_handle(), "il2cpp_resolve_icall");
    
    void (*il2cpp_add_internal_call)(const char* name, void* methodPointer) = NULL;
    if (!il2cpp_add_internal_call)
        il2cpp_add_internal_call = (void (*)(const char*, void*))dlsym(il2cpp_library_get_handle(), "il2cpp_add_internal_call");
    
    if (il2cpp_resolve_icall == NULL || il2cpp_add_internal_call == NULL)
        return false;
    
    // The actual impl
    
    void* resolved = il2cpp_resolve_icall(name);
    if (!resolved) return false;
    
    if (old)
        *old = resolved;
    
    il2cpp_add_internal_call(name, hook);
    
    return true;
}
Spoiler

Swaps a registered function in the ICallMap

HOW IT WORKS: Unity registers internal calls via il2cpp_add_internal_call during engine startup, building a map of name -> fptr (s_InternalCalls). When managed code calls an icall, il2cpp resolves it through il2cpp_resolve_icall.

THE FEAT: Stumbled upon this while poking around UnityEngine.Time::get_timeScale() in IDA Pro. Noticed the generated code was doing this:

float __fastcall UnityEngine_Time__get_timeScale(const MethodInfo *method)
{
    void *v1; // x0
    
    v1 = off_340F6E0; /* cached static ptr */
    if ( !off_340F6E0 )
    {
        /* first call resolves icall by name via il2cpp_resolve_icall */
        v1 = (void *)sub_886C28("UnityEngine.Time::get_timeScale()"); // -> il2cpp_resolve_icall
        off_340F6E0 = v1; /* icall gets cached here */
    }
    /* subsequent calls directly use the cached fptr */
    return ((float (*)(void))v1)();
}

Lazy caching. The function resolves the icall once, caches it. That means if we replace the icall BEFORE the first call, our hook survives otherwise the hook fails.

That's when it clicked. I had no idea the engine was doing this - saw the pattern, said "wtf", and instantly knew I could abuse it.

So by calling il2cpp_add_internal_call again with the same name, we overwrite the existing entry. Just an entry swap in the ICallMap. The original function pointer is backed up so we can call through if needed.

Here's why this works: ref https://github.com/MlgmXyysd/libil2cpp/blob/df0b51462fbbfa111ea3e741a7edf3795536ff2b/libil2cpp/Unity_2021.3/2021.3.16f1/vm/InternalCalls.cpp#L15

void InternalCalls::Add(const char* name, Il2CppMethodPointer method)
{
    IL2CPP_ASSERT(method);
    s_InternalCalls[name] = method; // std::map, last writer wins
}

No duplicate check. Nothing prevents us from calling il2cpp_add_internal_call twice with the same name. Last writer wins.

NOTE: Must only be used after il2cpp has been initialized. Unity registers icalls during engine startup; using this before il2cpp is initialized will fail.

Lets have some fun and make some hooks

static float (*_get_fieldOfView)(void *) = NULL;
static float hooked_get_fieldOfView(void *_this) 
{
	float fov = _get_fieldOfView(_this);
	// printf(@"--> get_fieldOfView(): %f\n", fov);
    return fov;
}

static float (*_get_timeScale)() = NULL;
static float hooked_get_timeScale()
{
	float scale = _get_timeScale();
    // printf(@"--> get_timeScale(): %f\n", scale);
    return scale;
}

static bool (*_GetKeyUpInt)(int keyCode) = NULL;
static bool hooked_GetKeyUpInt(int keyCode) 
{
	bool status = _GetKeyUpInt(keyCode);
    // printf(@"--> GetKeyUpInt(): up: %s\n", status ? "YES" : "NO");
    return status;
}

static bool (*_GetKeyDownInt)(int keyCode) = NULL;
static bool hooked_GetKeyDownInt(int keyCode) 
{
	bool status = _GetKeyDownInt(keyCode);
    // printf(@"--> GetKeyDownInt(): down: %s\n", status ? "YES" : "NO");
    return status;
}

void Il2CppDidInit(void) 
{
    // Called after il2cpp_init completes

	Il2CppHookInternalCall("UnityEngine.Camera::get_fieldOfView()", 
                           (void *)&hooked_get_fieldOfView, 
                           (void **)&_get_fieldOfView);

	Il2CppHookInternalCall("UnityEngine.Time::get_timeScale()", 
                           (void *)&hooked_get_timeScale, 
                           (void **)&_get_timeScale);

	Il2CppHookInternalCall("UnityEngine.Input::GetKeyUpInt(UnityEngine.KeyCode)", 
                           (void *)&hooked_GetKeyUpInt, 
                           (void **)&_GetKeyUpInt);
    
    Il2CppHookInternalCall("UnityEngine.Input::GetKeyDownInt(UnityEngine.KeyCode)", 
                           (void *)&hooked_GetKeyDownInt, 
                           (void **)&_GetKeyDownInt);
}


Thats it.
You guys were probably expecting more from me but this all I got haha
Test it out: https://github.com/Rednick16/ICallHook

Yep thats it there are many other techniques that can be used along side this such as methodPointer swaps on Update, LateUpdate, Start, Awake for classes deriving from MonoBehaviour, and VTables are mostly intact as well. goodby

 

Credits:
@Red16

  • Winner 1
Posted
On 8/29/2026 at 3:56 AM, Batch said:

Naisu!!!

XD

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Our picks

    • Match Fighters v2.0.2 [ +42 Cheats ] Debug Menu
      Modded/Hacked App: Match Fighters By UNICO STUDIO LLC
      Bundle ID: com.unicostudio.matchfighters
      App Store Link: https://apps.apple.com/us/app/match-fighters/id6768616691?uo=4

      🤩 Hack Features

      - Debug Menu
      • 0 replies
    • Match Fighters v2.0.2 [ +42 Jailed ] Debug Menu
      Modded/Hacked App: Match Fighters By UNICO STUDIO LLC
      Bundle ID: com.unicostudio.matchfighters
      App Store Link: https://apps.apple.com/us/app/match-fighters/id6768616691?uo=4

      🤩 Hack Features

      - Debug Menu
      • 0 replies
    • (18+) Ark ReCode +2 Jailed Cheats
      Modded/Hacked App: Ark ReCode By EroLabs
      Bundle ID: com.nerversoft.ark.recode
      iTunes Store Link: https://www.ero-labs.com/en/game.html?id=32


      Mod Requirements:
      - Non-Jailbroken/Jailed or Jailbroken iPhone/iPad/iPod Touch.
      - Sideloadly / Cydia Impactor or alternatives.
      - A Computer Running Windows/macOS/Linux with iTunes installed.


      Hack Features:
      - Damage Multiplier
      - Defense Multiplier


      Jailbreak required hack(s): 


      iOS Hack Download IPA Link:

      Hidden Content

      Download via the iOSGods App








      PC Installation Instructions:
      STEP 1: If necessary, uninstall the app if you have it installed on your iDevice. Some hacked IPAs will install as a duplicate app. Make sure to back it up so you don't lose your progress.
      STEP 2: Download the pre-hacked .IPA file from the link above to your computer. To download from the iOSGods App, see this tutorial topic.
      STEP 3: Download Sideloadly and install it on your PC.
      STEP 4: Open/Run Sideloadly on your computer, connect your iOS Device, and wait until your device name shows up.
      STEP 5: Once your iDevice appears, drag the modded .IPA file you downloaded and drop it inside the Sideloadly application.
      STEP 6: You will now have to enter your iTunes/Apple ID email login, press "Start" & then you will be asked to enter your password. Go ahead and enter the required information.
      STEP 7: Wait for Sideloadly to finish sideloading/installing the hacked IPA. If there are issues during installation, please read the note below.
      STEP 8: Once the installation is complete and you see the app on your Home Screen, you will need to go to Settings -> General -> Profiles/VPN & Device Management. Once there, tap on the email you entered from step 6, and then tap on 'Trust [email protected]'.
      STEP 9: Now go to your Home Screen and open the newly installed app and everything should work fine. You may need to follow further per app instructions inside the hack's popup in-game.

      NOTE: iOS/iPadOS 16 and later, you must enable Developer Mode. For free Apple Developer accounts, you will need to repeat this process every 7 days. Jailbroken iDevices can also use Sideloadly/Filza/IPA Installer to normally install the IPA with AppSync. If you have any questions or problems, read our Sideloadly FAQ section of the topic and if you don't find a solution, please post your issue down below and we'll do our best to help! If the hack does work for you, post your feedback below and help out other fellow members that are encountering issues.


      Credits:
      - AlyssaX64


      Cheat Video/Screenshots:

      N/A
      • 314 replies
    • Subsea Survival +2 Cheats
      Modded/Hacked App: Subsea Survival By ONEMT PTE. LTD.
      Bundle ID: com.miner.ios.sss
      App Store Link: https://apps.apple.com/us/app/subsea-survival/id6751192772?uo=4

       

      📌 Mod Requirements

      - Jailbroken iPhone or iPad.
      - iGameGod / Filza / iMazing.
      - Cydia Substrate, ElleKit, Substitute or libhooker depending on your jailbreak (from Sileo, Cydia or Zebra).

       

      🤩 Hack Features

      - Damage Multiplier
      - Defense Multiplier

       

      ⬇️ iOS Hack Download Link


      Hidden Content

      Download Hack







       

      📖 iOS Installation Instructions

      STEP 1: Download the .deb hack file from the link above. Use Safari, Google Chrome or other iOS browsers to download.
      STEP 2: Once the file has downloaded, tap on it and then you will be prompted on whether you want to open the deb with iGameGod or copy it to Filza.
      STEP 3: If needed, tap on the downloaded file again, then select ‘Normal Install’ from the options on your screen.
      STEP 4: Let iGameGod/Filza finish the cheat installation. If it doesn’t install successfully, see the note below.
      STEP 5: Open the game, log in to your iOSGods account when asked, then toggle on the features you want and enjoy!

       

      NOTE: If you have any questions or problems, read our Jailbreak iOS Hack Troubleshooting & Frequently Asked Questions & Answers topic. If you still haven't found a solution, post your issue below and we'll do our best to help! If the hack does work for you, please post your feedback below and help out other fellow members that are encountering issues.

       

      🙌 Credits

      - AlyssaX64

       

      📷 Cheat Video/Screenshots

      N/A

       

      More iOS App Hacks
      If you’re looking for Non-Jailbroken & No Jailbreak required iOS IPA hacks, visit the iOS Game Cheats & Hacks or the iOSGods App for a variety of modded games and apps for non-jailbroken iOS devices.

      Modded Android APKs
      Need modded apps or games for Android? Check out the latest custom APK mods, cheats & more in our Android Section.
      • 0 replies
    • Subsea Survival +2 Jailed Cheats
      Modded/Hacked App: Subsea Survival By ONEMT PTE. LTD.
      Bundle ID: com.miner.ios.sss
      App Store Link: https://apps.apple.com/us/app/subsea-survival/id6751192772?uo=4

       

      📌 Mod Requirements

      - Non-Jailbroken/Jailed or Jailbroken iPhone or iPad.
      - Sideloadly or alternatives.
      - Computer running Windows/macOS/Linux with iTunes installed.

       

      🤩 Hack Features

      - Damage Multiplier
      - Defense Multiplier

       

      ⬇️ iOS Hack Download IPA Link


      Hidden Content

      Download via the iOSGods App







       

      📖 PC Installation Instructions

      STEP 1: Download the pre-hacked .IPA file from the link above to your computer. To download from the iOSGods App, see our iOSGods App IPA Download Tutorial which includes a video example.
      STEP 2: Download Sideloadly and install it on your Windows or Mac.
      STEP 3: Open Sideloadly on your computer, connect your iOS device, and wait until your device name appears in Sideloadly.
      STEP 4: Once your iDevice is recognized, drag the modded .IPA file you downloaded and drop it into the Sideloadly application.
      STEP 5: Enter your Apple Account email, then press “Start.” You’ll then be asked to enter your password. Go ahead and provide the required information.
      STEP 6: Wait for Sideloadly to finish sideloading/installing the hacked IPA. If there are issues during installation, please read the note below.
      STEP 7: Once the installation is complete and you see the app on your Home Screen, you will need to go to Settings -> General -> Profiles / VPN & Device Management. Once there, tap on the email you entered from step 6, and then tap on 'Trust [email protected]'.
      STEP 8: Now go to your Home Screen and open the newly installed app and everything should work fine. You may need to follow further per app instructions inside the hack's popup in-game.

      NOTE: iOS/iPadOS 16 and later, you must enable Developer Mode. For free Apple Developer accounts, you will need to repeat this process every 7 days. If you have any questions or problems, read our Sideloadly FAQ section of the topic and if you don't find a solution, please post your issue below and we'll do our best to help! If the hack does work for you, post your feedback below and help out other fellow members that are encountering issues.

       

      🙌 Credits

      - AlyssaX64

       

      📷 Cheat Video/Screenshots

      N/A
      • 0 replies
    • Skyward: Feel Spike v1.5.0 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Skyward: Feel Spike By Ilhan Akbudak
      Bundle ID: com.skyward.feelspike
      App Store Link: https://apps.apple.com/us/app/skyward-feel-spike/id6803478292?uo=4

      🤩 Hack Features

      - Unlimited Gems
      - Unlimited Coins
      - Unlimited XP
      - Unlimited Lives
      • 0 replies
    • Skyward: Feel Spike v1.5.0 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Skyward: Feel Spike By Ilhan Akbudak
      Bundle ID: com.skyward.feelspike
      App Store Link: https://apps.apple.com/us/app/skyward-feel-spike/id6803478292?uo=4

      🤩 Hack Features

      - Unlimited Gems
      - Unlimited Coins
      - Unlimited XP
      - Unlimited Lives
      • 0 replies
    • 도깨비 서바이버: 각성 Dokkaebi Survivor: Awakening v1.0 [ +4 Cheats ] ATK MAX
      Modded/Hacked App: Dokkaebi Survivor: Awakening By Alphaloop
      Bundle ID: dev.alphaloop.dokkaebisurvivor
      App Store Link: https://apps.apple.com/us/app/dokkaebi-survivor-awakening/id6814417487?uo=4

      🤩 Hack Features

      - Unlimited Coin
      - Energy Max
      - ATK MAX
      - HP MAX
      • 0 replies
    • 도깨비 서바이버: 각성 Dokkaebi Survivor: Awakening v1.0 [ +4 Jailed ] ATK MAX
      Modded/Hacked App: Dokkaebi Survivor: Awakening By Alphaloop
      Bundle ID: dev.alphaloop.dokkaebisurvivor
      App Store Link: https://apps.apple.com/us/app/dokkaebi-survivor-awakening/id6814417487?uo=4

      🤩 Hack Features

      - Unlimited Coin
      - Energy Max
      - ATK MAX
      - HP MAX
      • 0 replies
    • UFO Attack: Last Defense v1.8 [ +1 Cheats ] Auto Win
      Modded/Hacked App: UFO Attack: Last Defense By Mikhail Marhel
      Bundle ID: com.Magenta.EarthDefense
      App Store Link: https://apps.apple.com/us/app/ufo-attack-last-defense/id6803860825?uo=4

      🤩 Hack Features

      - Auto Win / Tap Green Button
      • 0 replies
    • UFO Attack: Last Defense v1.8 [ +1 Jailed  ] Auto Win
      Modded/Hacked App: UFO Attack: Last Defense By Mikhail Marhel
      Bundle ID: com.Magenta.EarthDefense
      App Store Link: https://apps.apple.com/us/app/ufo-attack-last-defense/id6803860825?uo=4

      🤩 Hack Features

      - Auto Win / Tap Green Button
      • 0 replies
    • The Posthumous Investigation +1 Jailed Cheat [ Full Game Unlocked ]
      Modded/Hacked App: The Posthumous Investigation By Mother Gaia Studio
      Bundle ID: br.com.mothergaia.theposthumousinvestigation
      App Store Link: https://apps.apple.com/us/app/the-posthumous-investigation/id1614001053?uo=4

       


      🤩 Hack Features

      -- Full Game Unlocked
      • 0 replies
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines