lua ternary operator possibilities

Viewed 88

i try to recover lua code from the compiled op code. I hope you can help me with this.

195 [-] GETTABLE    7 0 177 ; "formcontainer"
196 [-] GETTABLE    7 7 178 ; "form"
197 [-] GETTABLE    8 7 179 ; "elements"
198 [-] GETTABLE    8 8 180 ; "appear"
199 [-] TEST        5 5 0
200 [-] JMP         0 3 ; to 204
201 [-] MOVE        9 6 0
202 [-] JMP         0 2 ; to 205
203 [-] LOADBOOL    9 0 1
204 [-] LOADBOOL    9 1 0
205 [-] SETTABLE    8 181 9 ; "hidden" 

This is the code that it is all about. what i already recovered is this part:

form.elements["appear"].hidden =

Lines 195 to 198 just get the right table and temporary store it in register 8 (r8) in the lines 199 to 204 the value that should be stored ins determined and temporary set to r9, so it can be set to the member hidden of r8.

r5 is called bCouldBeXLive and r6 is bIsGalaxy i'm sure it's something like

form.elements["appear"].hidden = if bCouldBeXLive then bIsGalaxy else true end

But this is not valid lua 5.0.2 code.

Already tried

form.elements["appear"].hidden = bCouldBeXLive and bIsGalaxy or true

but this would end in two TEST operations.

195 [-] GETTABLE    7 0 177 ; "formcontainer"
196 [-] GETTABLE    7 7 178 ; "form"
197 [-] GETTABLE    8 7 179 ; "elements"
198 [-] GETTABLE    8 8 180 ; "appear"
199 [-] TEST        5 5 0
200 [-] JMP         0 2 ; to 203
201 [-] TEST        9 6 1
202 [-] JMP         0 1 ; to 204
203 [-] LOADBOOL    9 1 0                   
204 [-] SETTABLE    8 181 9 ; "hidden" 

Specially the line 203 of the original op code surprise me, because it's never executed.

For me the op code looks like a ternary operator. Do you know a variant that fits the original op code?

1 Answers

Decompiled code would be:

R7 = R0.formcontainer.form
R7.elements.appear.hidden = not bCouldBeXLive or bIsGalaxy

Specially the line 203 of the original op code surprise me, because it's never executed.

Instruction #203 calculates value not bCouldBeXLive.
The Lua bytecode generator lacks optimization at all, so the fact that a falsey value of not bCouldBeXLive never goes into final result does not lead to removing of non-accessible code.

Related