viruscamp / luadec

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

单独的 OP_JMP 跳到 OP_LOADBOOL 且 sbc=2 时,与 #1 相关 #4

Open viruscamp opened 10 years ago

viruscamp commented 10 years ago

单独的 OP_JMP 跳到 OP_LOADBOOL 且 sbc=2 时,与 #1 相关 在 ProcessCode case:OP_JMP 到下列分支

} else if (sbc == 2 && GET_OPCODE(code[pc+2]) == OP_LOADBOOL) {

测试代码

-- or操作符, 不能用 if 表示, 需要中间变量
function debug_or()
  local f,a,b
  fg = ((not a) or b)
  -- if (a) then x = b else x = true end; fg = x
end

-- and操作符,不能用 if 表示, 需要中间变量
function debug_and_call()
  local f,a,b,c
  fg = ((a<b) and c)
  -- if (a<b) then x = c else x = false end; fg = x
end

-- and操作符,可以用 if 表示,已反编译成 if,正常无视了一条 LOADBOOL
function debug_and_set()
  local f,a,b,c
  f = ((a<b) and c)
  -- if (a<b) then f = c else f = false end;
end
viruscamp commented 10 years ago

test codes: https://github.com/viruscamp/luadec/tree/master/test/issues/issue4_jmp_loadbool.lua https://github.com/viruscamp/luadec/tree/master/test/issues/issue4_jmp_loadbool_all.lua

viruscamp commented 10 years ago

跳转的 LOADBOOL 只有这种形式 LOADBOOL R0 0 1 LOADBOOL R0 1 0

https://github.com/viruscamp/luadec/blob/master/lua-5.1/src/lcode.c#L400

viruscamp commented 9 years ago
local a,b,c,y
y = (a > b or c) -- assigne statement may be bool or value, bool is not calucated at last
--[[
[1] lt         1   1   0    ; R1 < R0, pc+=1 (goto [3]) if false
[2] jmp        3            ; pc+=3 (goto [6])
[3] move       3   2        ; R3 := R2
[4] jmp        2            ; pc+=2 (goto [7])
[5] loadbool   3   0   1    ; R3 := false; PC := pc+=1 (goto [7])
[6] loadbool   3   1   0    ; R3 := true
[7] return     0   1        ; return
]]--

当赋值语句值可能为 bool 或其他,且 bool 不是最后计算时

https://github.com/viruscamp/luadec/issues/8#issuecomment-96224579