Help! Detouring functions in android games

NotALegitGuy

Solid & Active Platinian
Original poster
Sep 24, 2018
69
66
18
Costa Rica
I wanna know how I would go about detouring a function in an Android game.

So far I've seen it being done in PC to obtain things such as a variable that is used as a parameter for a function, such as a LuaState.
I wanna know how to do it in android games to obtain LuaStates instead of having to make my own one by hooking the game's luaL_newstate function, mainly because the disadvantage of using my own is that I wont have access to functions the game has for it's environment, making it inconvenient as sometimes those functions are needed and remaking them is also quite tedious and inconvenient.

Also, No, the game isn't Roblox, Roblox's LuaState is easy to get.

Here's an example of detouring functions in PC from Guided Hacking just so you get an idea of what I'm talking about:

C++:
int lua_State = 0;
DWORD _gettop(int state)
{
    if (lua_State == 0) {
        lua_State = state;
    }
    return (*(DWORD*)(state + 16) - *(DWORD*)(state + 28)) >> 4;
}

typedef int(__cdecl *gettop)(int);
gettop lua_gettop_p = (gettop)0x00f0f0f00f; // this is the actual lua_gettop function in memory that we place the detour at

void getLuaState()
{
    //_gettop(lua_State); I don't think you need this but if you do you can just add it!
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(LPVOID&)lua_gettop_p, (PBYTE)_gettop); // Detours the original lua_gettop_p with our _gettop
    DetourTransactionCommit();
}
 
  • Like
Reactions: andreybillsar1

yLeon

Platinian
Sep 28, 2022
8
0
1
18
New York City
the adresses is not a problem because we can easily get It with c++ but some beginners cry to learn It they can learn It theyself