| 3937 | } |
| 3938 | |
| 3939 | static 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 | |
| 3966 | static int internal_diffscan(lua_State *L) |
| 3967 | { |
nothing calls this directly
no test coverage detected