MCPcopy Create free account
hub / github.com/DFHack/dfhack / internal_patchBytes

Function internal_patchBytes

library/LuaApi.cpp:3844–3917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3842}
3843
3844static int internal_patchBytes(lua_State *L)
3845{
3846 luaL_checktype(L, 1, LUA_TTABLE);
3847 lua_settop(L, 2);
3848
3849 MemoryPatcher patcher;
3850
3851 if (!lua_isnil(L, 2))
3852 {
3853 luaL_checktype(L, 2, LUA_TTABLE);
3854
3855 lua_pushnil(L);
3856
3857 while (lua_next(L, 2))
3858 {
3859 uint8_t *addr = (uint8_t*)checkaddr(L, -2, true);
3860 int isnum;
3861 uint8_t value = (uint8_t)lua_tounsignedx(L, -1, &isnum);
3862 if (!isnum)
3863 luaL_error(L, "invalid value in verify table");
3864 lua_pop(L, 1);
3865
3866 if (!patcher.verifyAccess(addr, 1, false))
3867 {
3868 lua_pushnil(L);
3869 lua_pushstring(L, "invalid verify address");
3870 lua_pushvalue(L, -3);
3871 return 3;
3872 }
3873
3874 if (*addr != value)
3875 {
3876 lua_pushnil(L);
3877 lua_pushstring(L, "wrong verify value");
3878 lua_pushvalue(L, -3);
3879 return 3;
3880 }
3881 }
3882 }
3883
3884 lua_pushnil(L);
3885
3886 while (lua_next(L, 1))
3887 {
3888 uint8_t *addr = (uint8_t*)checkaddr(L, -2, true);
3889 int isnum;
3890 lua_tounsignedx(L, -1, &isnum);
3891 if (!isnum)
3892 luaL_error(L, "invalid value in write table");
3893 lua_pop(L, 1);
3894
3895 if (!patcher.verifyAccess(addr, 1, true))
3896 {
3897 lua_pushnil(L);
3898 lua_pushstring(L, "invalid write address");
3899 lua_pushvalue(L, -3);
3900 return 3;
3901 }

Callers

nothing calls this directly

Calls 10

luaL_checktypeFunction · 0.85
lua_settopFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
checkaddrFunction · 0.85
luaL_errorFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushbooleanFunction · 0.85
verifyAccessMethod · 0.80

Tested by

no test coverage detected