viruscamp / luadec

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

Fix incorrect OP_CLOSURE decompilation (register C -> Bx) #73

Open jalbert-dev opened 4 years ago

jalbert-dev commented 4 years ago

Fix #74.

The decompiler currently handles OP_CLOSURE improperly, and looks for the function index in register C, when Lua uses combined register Bx. This will actually work as expected with vanilla Lua implementations that use the typical Op-A-C-B opcode-operand ordering, as C happens to be the lower 9 bits of Bx, but will fail with Lua implementations that use a different ordering.

This patch makes some tiny changes to ProcessCode so that it reads the function index from Bx instead.

(The disassembler part of luadec already reads from Bx instead of C, so no changes are necessary there.)