luadec icon indicating copy to clipboard operation
luadec copied to clipboard

lua5.3 decompilation special case issue

Open tst2005 opened this issue 5 years ago • 6 comments

  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())

  1. 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.

tst2005 avatar Oct 13 '20 21:10 tst2005

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 avatar Mar 11 '22 18:03 rocky

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

rocky avatar Mar 13 '22 11:03 rocky

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

tst2005 avatar Mar 14 '22 09:03 tst2005

@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.)

rocky avatar Mar 14 '22 09:03 rocky

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

tst2005 avatar Mar 14 '22 14:03 tst2005

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.

rocky avatar Mar 14 '22 15:03 rocky