PY44N / LuaObfuscatorV2

A program that obfuscates Lua programs so no one can steal your source code
60 stars 9 forks source link

New TableUnpack implementation is buggy #19

Closed 9382 closed 2 months ago

9382 commented 2 months ago

Normal lua unpack takes an i and a j arg, which are a starting and finishing position. The custom implementation added in eb5aba74424255fc61558f57c63d7fb2e411bf27 takes a starting position i and a count remaining, which is slightly different. Either certain code (the executor part) needs to use the original unpack or needs to be adjusted for the new unpack or the new implementation needs to follow the original lua implementation (a short look at temp3 on a basic script pops up OpReturn and OpCall at the very least that use TableUnpack)

Example failing script:

print(1,2,3)
print(1,2)
print(1)

This will print 1, 2, 3 every time under the VM

9382 commented 2 months ago

If you're looking for a version to match the original lua implementation, here's a fixed version with as little change as possible to the original function

local function TableUnpack(tbl, i, j)
    i = i or 1
    j = j or #tbl
    if j-i+1 >= 10 then
        return tbl[i], tbl[i + 1], tbl[i + 2], tbl[i + 3], tbl[i + 4],
               tbl[i + 5], tbl[i + 6], tbl[i + 7], tbl[i + 8], tbl[i + 9],
               TableUnpack(tbl, i + 10, j)
    end
    if i <= j then return tbl[i], TableUnpack(tbl, i + 1, j) end
end