viruscamp / luadec

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

单独的 OP_JMP 跳到 OP_LOADBOOL 时,与 #1 相关 #8

Open viruscamp opened 10 years ago

viruscamp commented 10 years ago

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

processing OP_JMP to } else if (GET_OPCODE(idest) == OP_LOADBOOL) {

基本确认这是错误的处理方法

测试代码

local upv0 = nil
local upv1 = nil
-- 程序反编译出的
DecompiledFunction = function(arg0)
    -- function num : 0_246_0 , upvalues : upv1 , upv2
    if upv0 and (not upv1 or ((upv1 and arg0.bFightState) or IsPlayerExist(arg0.dwID))) then
        return true
    end
    return false
    -- DECOMPILER ERROR: 2 unprocessed JMP targets
end

-- 人工反编译的,字节码相同,已验证
GuessedFunction = function(arg0)
    if upv0 then
        if (not upv1) or (upv1 and arg0.bFightState or IsPlayerExist(arg0.dwID)) then
            return true
        end
    else
        return true
    end
    return false
end
viruscamp commented 9 years ago
local a,b,c,y
y = (a or b==c) -- assigne statement may be bool (calucate at last)
--[[
[1] testset    3   0   1    ; if R0 then R3 = R0 else pc+=1 (goto [3])
[2] jmp        4            ; pc+=4 (goto [7])
[3] eq         1   1   2    ; R1 == R2, pc+=1 (goto [5]) if false
[4] jmp        1            ; pc+=1 (goto [6])
[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/4#issuecomment-96223337