ByNameModding / BNM-Android

Modding il2cpp games by classes, methods, field names on Android.
MIT License
196 stars 38 forks source link

Question: How to get value of "int" field of another class? #26

Closed dvgmdvgm closed 6 months ago

dvgmdvgm commented 6 months ago

Hello. I have some fighting Unity game. And every hit is calling method "void CritChance(void* attribute)" I need to read field of this attribute and after read another int value from another filed. Before I use frida script and my snippet looks like that: int player_id = Memory.readInt(Memory.readPointer(attribute.add(0x38)).add(0x8));

Which "add(0x38)" is field of current class. "add(0x8)" is field of other class called.

How can I achieve it with BNM? If you need I can show some part of dump of il2cpp. Thank you.

ArifRios1st commented 6 months ago

maybe i can help, you can do like this : void* attributeClass = *(void **)((uint64_t)attribute+ 0x38); int player_id = *(int*)((uint64_t)()+ 0x8);

or with bnm maybe you can do like this : BNM::LoadClass attributeClass = BNM::LoadClass((BNM::IL2CPP::Il2CppObject*)attribute); int player_id = RoomDatabaseClass.GetFieldByName(OBFUSCATE_BNM("player_id")).cast<int>().Get();

dvgmdvgm commented 6 months ago

maybe i can help, you can do like this : void* attributeClass = *(void **)((uint64_t)attribute+ 0x38); int player_id = *(int*)((uint64_t)()+ 0x8);

or with bnm maybe you can do like this : BNM::LoadClass attributeClass = BNM::LoadClass((BNM::IL2CPP::Il2CppObject*)attribute); int player_id = RoomDatabaseClass.GetFieldByName(OBFUSCATE_BNM("player_id")).cast<int>().Get();

1st example working great. May be you can help me how to invoke non static method but with Instance? I know that i need to use instance of class to call this method but i'm very first with C++ hooking on Android. For example i have class:

Screen-072

As i understand i have to call LoadMap method like this: get_Instance().method(LoadMap).Call(); But how to reproduce it with BNM?

Thank you

ArifRios1st commented 6 months ago

maybe i can help, you can do like this : void* attributeClass = *(void **)((uint64_t)attribute+ 0x38); int player_id = *(int*)((uint64_t)()+ 0x8); or with bnm maybe you can do like this : BNM::LoadClass attributeClass = BNM::LoadClass((BNM::IL2CPP::Il2CppObject*)attribute); int player_id = RoomDatabaseClass.GetFieldByName(OBFUSCATE_BNM("player_id")).cast<int>().Get();

1st example working great. May be you can help me how to invoke non static method but with Instance? I know that i need to use instance of class to call this method but i'm very first with C++ hooking on Android. For example i have class:

Screen-072

As i understand i have to call LoadMap method like this: get_Instance().method(LoadMap).Call(); But how to reproduce it with BNM?

Thank you

if Instance is property, you can do BNM::LoadClass ManagerClass = LoadClass("", "Manager"); BNM::Property<BNM::IL2CPP::Il2CppObject*> Manager$$Instance = ManagerClass.GetPropertyByName("Instance"); BNM::Method<void> Manager$$LoadMap = ManagerClass.GetMethodByName("LoadMap",0);

because is static you can direcly call it BNM::IL2CPP::Il2CppObject* Instance = Manager$$Instance.Get();

and then call LoadMap method Manager$$LoadMap[Instance](); or Manager$$LoadMap.SetInstance(Instance).Call();