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

Function internal_memscan

library/LuaApi.cpp:3939–3964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3937}
3938
3939static int internal_memscan(lua_State *L)
3940{
3941 uint8_t *haystack = (uint8_t*)checkaddr(L, 1);
3942 int hcount = luaL_checkint(L, 2);
3943 int hstep = luaL_checkint(L, 3);
3944 if (hstep == 0) luaL_argerror(L, 3, "zero step");
3945 void *needle = checkaddr(L, 4);
3946 int nsize = luaL_checkint(L, 5);
3947 if (nsize < 0) luaL_argerror(L, 5, "negative size");
3948
3949 for (int i = 0; i <= hcount; i++)
3950 {
3951 uint8_t *p = haystack + i*hstep;
3952 if (p + nsize > haystack + (hcount * hstep)) {
3953 break;
3954 }
3955 if (memcmp(p, needle, nsize) == 0) {
3956 lua_pushinteger(L, i);
3957 lua_pushinteger(L, (lua_Integer)p);
3958 return 2;
3959 }
3960 }
3961
3962 lua_pushnil(L);
3963 return 1;
3964}
3965
3966static int internal_diffscan(lua_State *L)
3967{

Callers

nothing calls this directly

Calls 4

checkaddrFunction · 0.85
luaL_argerrorFunction · 0.85
lua_pushintegerFunction · 0.85
lua_pushnilFunction · 0.85

Tested by

no test coverage detected