viruscamp / luadec

Lua Decompiler for lua 5.1 , 5.2 and 5.3
1.14k stars 343 forks source link

_ENV may not be the first upval #47

Open viruscamp opened 8 years ago

viruscamp commented 8 years ago

_ENV may not be the first upval in 5.2 and 5.3 , pay attention to it when processing stripped code

local a
local function c()
    a=a+1
    return math.abs(a)
end

upval list from chunkspy

                         * upvalue names:
00E2  02000000           size_upvalue_names (2)
                         upvalue [0]: a
00E6  02000000           string size (2)
00EA  6100               "a\0"
                         upvalue [1]: _ENV
00EC  05000000           string size (5)
00F0  5F454E5600         "_ENV\0"

decompiled:

local a = nil
local c = function()
  -- function num : 0_0 , upvalues : a, _ENV
  a = a + 1
  return (math.abs)(a)
end
viruscamp commented 8 years ago

So , if I got a stripped function chunk , I cannot determine whether _ENV is used or which upval is _ENV .