Tutorial How to hook IEnumerable methods in Unity's Il2cpp

Tiuu

Solid & Active Platinian
Original poster
Skilled
May 23, 2017
76
584
183
Hey guys, slice cast here again with another tutorial. I will show you how to hook an IEnumerable.

Let's say you found a method something like Username, Ban, Recoil, Reload, or whatever it is and it's an IEnumerable type. I don't really understand the concept of IEnumerable, but you can find out what it does by searching it.

Anyways let's get started.

We have this method like
C++:
private IEnumerator UnBanPlayer (string playerToKick)
Now if you scroll all the way down of the class, you will find something like this called
<UnbanPlayer>d__507>
Something like that.


We open that and we see some fields. One could say UserID or playername.

lets say we modify UserID and it's an integer/int type. So how do we modify it?


It's simple.

We're basically gonna hook this by calling the method with MoveNext().

C++:
//the void *instance is a self-created variable.
Void (*old_UnbanPlayer_MoveNext)(void *instance);
Void UnbanPlayer_MoveNext(void *instance) {
    //Check if instance is NULL to prevent CRASH
    if (instance != NULL)
    {
        *(int *) ((uint64_t)instance + 0x4C) = 18372819; //Return how many value
    }
    old_UnbanPlayer_MoveNext(instance);
}
Easy, now call your hooks using MSHook if using substrate.

C++:
MSHookFunction((void*)getAbsoluteAddress(OFFSETS), (void*)UnbanPlayer_MoveNext, (void**)&UnbanPlayer_MoveNext;
That's all for now, hope you enjoyed this tutorial.
If you're new to this and don't know how to do it, please don't come into the comment section and asking me for help. This is all the help you will get because I explained it for you since this is a tutorial after all. If you're a newbie, don't try the hard stuff.
 
Last edited:

DawnBreaker

Approved Modder
Approved Modder
Nov 4, 2018
44
266
53
21
Earth
what if the offset of the methods just like this " 0x6C " the offset are shorter than usual offset? should i just put it straight into the hook?
 

Tiuu

Solid & Active Platinian
Original poster
Skilled
May 23, 2017
76
584
183
@Tiuu I just need help with what do we hook?
Do we hook this part of an IEnumerable:
C#:
private IEnumerator UnBanPlayer (string playerToKick)
Or this part:
<UnbanPlayer>d__507>
You're looking for an IEnumerator or Enumeral method, so yeah you will need to use and hook <UnbanPlayer>d__507>
 

7.Hackers

Solid & Active Platinian
Apr 22, 2020
58
1,361
193
Egypt
You're looking for an IEnumerator or Enumeral method, so yeah you will need to use and hook <UnbanPlayer>d__507>
if i have an invoke method like this [Address(RVA = "0x1B5AA2C", Offset = "0x1B5AA2C", VA = "0x1B5AA2C", Slot = "12")]
public extern void Invoke(int inXP, bool lVisible);
How to use it ? i can't use pointer function cuz it needs Update method . i can't use Hooking Function cuz that invoke has int inXP, bool lVisible , it does not return like normal functions to hook it like [Address(RVA = "0x1A57F80", Offset = "0x1A57F80", VA = "0x1A57F80")]
public bool IsBuildable()
{
return default(bool);
}
 
  • Like
Reactions: Abhay Sinha

About us

  • Welcome to platinmods.com! We are proud to present you the place which let's dreams come true! Focusing on quality and trust we have spend much time to build a gaming community fitting to your wishes and needs. Actually we offer you the finest MODs and Games of the Android section and we slowly expand to the iOS section as well. But games, Android MODs & iOS MODs are not the only things we can offer you. We have tutorials, tools, a very friendly, active and solid community which will help you with any problem you have =) Your happiness is our goal. We hope you enjoy!

Forum statistics

Threads
30,780
Messages
760,947
Members
2,019,822
Latest member
Foxy Liu