UnityResolve.hpp
UnityResolve.hpp copied to clipboard
Game Object Manager?
//经过测试应该适用大多数Unity游戏
ULONG64 GetGOM()
{
ULONG64 addr = _UnityPlayer;
ULONG64 end = _UnityPlayer + _UnityPlayer_ModuleSize;
ULONG64 offset = 0;
bool found = false;
unsigned char tmp[0x1000];
ULONG64 code_addr = 0;
while (!found && end - offset > 0x1000)
{
mread_buffer((void*)tmp, addr + offset, 0x1000);
auto p = FindPattern(tmp, "E8 ? ? ? ? 83 FF 03", 0x1000);
if (p)
{
code_addr = ((ULONG64)p - (ULONG64)tmp) + offset;
break;
}
offset += 0x1000;
}
printf("CODE_ADDR=[ 0x%x ]\n", code_addr);
ULONG64 code_addr1 = mread<int>(_UnityPlayer + code_addr + 1) + (_UnityPlayer + code_addr + 5);
printf("code_addr1=[ 0x%x ]\n", code_addr1);
mread_buffer((void*)tmp, code_addr1, 0x100);
for (int i = 0; i < 240; i++)
{
if (tmp[i] == 0x48 && tmp[i + 1] == 0x8B && tmp[i + 2] == 0x05)
{
int gom_offset = *(int*)&tmp[i + 3];
ULONG64 gom = (code_addr1 + i + 7) + gom_offset;
return gom;
}
}
return NULL;
}
Internal version:
UnityResolve::UnityType::Object* GetGOM(){
uint8_t* tmp = (uint8_t*)FindPattern("UnityPlayer.dll", "48 89 ? 48 89 05 ? ? ? ? 48 83 C4");
if (tmp){
int _offset = *(int*)&tmp[6];
BYTE* p = (BYTE*)tmp + 10 + _offset;
return (UnityResolve::UnityType::Object*)p;
}
tmp = (uint8_t*)FindPattern("UnityPlayer.dll", "E8 ? ? ? ? 83 FF 03");
if (tmp){
uint8_t* code_addr = (uint8_t*)tmp + 5;
code_addr += *(int*)(code_addr + 1);
for (int i = 0; i < 240; i++){
if (code_addr[i] == 0x48 && code_addr[i + 1] == 0x8B && code_addr[i + 2] == 0x05)
{
int gom_offset = *(int*)&code_addr[i + 3];
uint8_t* gom = (code_addr + i + 7) + gom_offset;
return(UnityResolve::UnityType::Object*)gom;
}
}
}
return NULL;
}
printf("GOM = %p\n", GameObjectManager = GetGOM());
uint64_t GOM = *(uint64_t*)(GameObjectManager);
auto obj_tmp = *(uint64_t*)(GOM + 0x28);
auto obj_last = *(uint64_t*)(GOM + 0x20);
while (!IsBadReadPtr((void*)obj_tmp,8))
{
uint64_t object_ptr = *(uint64_t*)(obj_tmp + 0x10);
uint64_t object_name_ptr = *(uint64_t*)(object_ptr + 0x60);
if (object_name_ptr)
printf("%s\n", object_name_ptr);
if (obj_tmp == obj_last)
break;
obj_tmp = *(uint64_t*)(obj_tmp + 0x8);
}