Help! Help hook class

MisteryNinja

Platinian
Original poster
Aug 19, 2023
8
0
1
31
Nowhere
Hi, i'm making a mod for a simple android game (lgl mod menu). I hooked an update function, it's working ok, now i need to patch some static fields in the main class.
I've tried 2 methods thus far:
1. Hook class directly from offset, I'm using the typeinfo method
1697650902162.png

I have the header file for this game, so i do this
C++:
Main__Class* mainclass = (Main__Class*) getAbsoluteAddress(targetLibName, 0x029a6a68)
Returns a wrong address and i get segfault later
2. Hook from instance (my hooked function is a Main function)
C++:
Main__Class* mainclass = (Main__Class*) instance;
Doesn't work and idk why. i also tried casting Main* (not Main__Class), didn't work either. Plz help
 

mIsmanXP

Approved Modder
Approved Modder
Feb 20, 2022
205
9,482
193
Republic of Indonesia
Can you elaborate more on
1. What do you mean wrong address? Do you know the right address?
2. Doesn't work how? How's your function looks like
 

NullCoder

Inactive Approved Modder
Jun 8, 2020
110
901
93
21
None
As I understand it, you want to get a class object to call any methods or use variables in it.

I advise you to intercept any called method in the class and receive the first argument, which will be a pointer to the class object itself.

This is a pointer to the class object itself, with the help of which you can call or receive something.
or in this class.

Also, if the class is static, you can take this address and analyze in the disassembler the receipt of an object for this class in some code, get the offset that is added to this TypeInfo and do it in your code, so you can get a pointer to the class without intercepting methods in it .
 

MisteryNinja

Platinian
Original poster
Aug 19, 2023
8
0
1
31
Nowhere
Can you elaborate more on
1. What do you mean wrong address? Do you know the right address?
2. Doesn't work how? How's your function looks like
Hi, i want to change some static fields in my main class (typeinfo), so
C++:
mainclass->static_fields->InstanceField->money = some_number;
But apparently static_fields is null for some reason so i get a segfault error. I know the typeinfo address from il2cpp.json above. i just guessed my pointer doesn't point to Main__Class but to something else
As I understand it, you want to get a class object to call any methods or use variables in it.

I advise you to intercept any called method in the class and receive the first argument, which will be a pointer to the class object itself.

This is a pointer to the class object itself, with the help of which you can call or receive something.
or in this class.

Also, if the class is static, you can take this address and analyze in the disassembler the receipt of an object for this class in some code, get the offset that is added to this TypeInfo and do it in your code, so you can get a pointer to the class without intercepting methods in it .
hey, that's what i tried with instance here (which is inside my hook that works), so something like
Code:
Main* main = (Main*) instance;
LOGI(OBFUSCATE("found %d money"), main->money);
But i just get random values here (mostly zeros). I disassembled the code in ghidra and the first argument is Main*, so idk what's the problem here

thanks for replying btw