viruscamp / luadec

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

lua5.3 decompilation special case issue #75

Open tst2005 opened 4 years ago

tst2005 commented 4 years ago

1) Case without the issue

local function foo()
        local a = 123
        local b = a or 456 -- here there is "or a value"
        return b
end
print(foo())

Decompiled:

-- Decompiled using luadec 2.2 rev: 895d923 for Lua 5.3 from https://github.com/viruscamp/luadec
-- Command line: decompil-bug.bytecode

-- params : ...
-- function num : 0 , upvalues : _ENV
local foo = function()
  -- function num : 0_0
  local a = 123
  local b = a or 456
  return b
end

print(foo())

2) Case with the issue

local function foo()
        local a = 123
        local b = a or {} -- there is "or a table" not a value
        return b
end
print(foo())

decompiled:

-- Decompiled using luadec 2.2 rev: 895d923 for Lua 5.3 from https://github.com/viruscamp/luadec
-- Command line: decompil-bug2.bytecode

-- params : ...
-- function num : 0 , upvalues : _ENV
local foo = function()
  -- function num : 0_0
  local a = 123
  if not a then
    local b = {}
  end
  return b
end

print(foo())

The b is define localy inside the if scope. The value can not be used outside of the "if" block.

rocky commented 2 years ago

I know from my own experience that handling this kind of expression logic is difficult. It is mentioned as a problem in th 5.1 code that this was based on. See Status in https://github.com/sztupy/luadec51/blob/master/README.markdown

rocky commented 2 years ago

I'll note that unluac doesn't have a problem decompling this.

tst2005 commented 2 years ago

@rocky thanks for your feedback. There is a still maintained project on sourceforce, amazing !

rocky commented 2 years ago

@rocky thanks for your feedback. There is a still maintained project on sourceforce, amazing !

(I have a couple of projects that I still maintain on sourceforge that I somewhat maintain when I have bugs too.)

tst2005 commented 2 years ago

( and you never thought to move your projects elsewhere since the sourceforge scandal ? )

rocky commented 2 years ago

Wasn't aware of this. I will reconsider sourceforge. (And github is now Microsoft; gitlab or bitbucket then?) Speaking of dodgy info https://stackoverflow.com/a/67565648/546218 seems wrong based on what I have recently come to understand about Lua bytecode.