mirror of
https://github.com/CPunch/LuaDecompy.git
synced 2024-11-22 14:50:05 +00:00
lparser.py: don't read RK values here, use lundump.py to read them
This commit is contained in:
parent
eb1d3ffe87
commit
055af56e27
24
README.md
24
README.md
@ -26,18 +26,18 @@ example.luac
|
||||
|
||||
==== [[example.lua's dissassembly]] ====
|
||||
|
||||
[ 0] LOADK : R[0] K[1]
|
||||
[ 1] LOADK : R[1] K[2]
|
||||
[ 2] CONCAT : R[0] R[0] R[1]
|
||||
[ 3] SETGLOBAL : R[0] R[0]
|
||||
[ 4] EQ : R[0] K[3] K[3]
|
||||
[ 5] JMP : R[0] R[5]
|
||||
[ 6] GETGLOBAL : R[0] K[4]
|
||||
[ 7] GETGLOBAL : R[1] K[0]
|
||||
[ 8] GETTABLE : R[0] R[0] R[1]
|
||||
[ 9] LOADK : R[1] K[5]
|
||||
[ 10] CALL : R[0] R[2] R[1]
|
||||
[ 11] RETURN : R[0] R[1] R[0]
|
||||
[ 0] LOADK : R[0] K[1] ; load "pri" into R[0]
|
||||
[ 1] LOADK : R[1] K[2] ; load "nt" into R[1]
|
||||
[ 2] CONCAT : R[0] R[0] R[1] ; concat 2 values from R[0] to R[1]
|
||||
[ 3] SETGLOBAL : R[0] R[0] ;
|
||||
[ 4] EQ : R[0] K[3] K[3] ;
|
||||
[ 5] JMP : R[0] R[5] ;
|
||||
[ 6] GETGLOBAL : R[0] K[4] ;
|
||||
[ 7] GETGLOBAL : R[1] K[0] ;
|
||||
[ 8] GETTABLE : R[0] R[0] R[1] ;
|
||||
[ 9] LOADK : R[1] K[5] ; load "Hello world" into R[1]
|
||||
[ 10] CALL : R[0] R[2] R[1] ;
|
||||
[ 11] RETURN : R[0] R[1] R[0] ;
|
||||
|
||||
==== [[example.lua's decompiled source]] ====
|
||||
|
||||
|
14
lparser.py
14
lparser.py
@ -1,14 +1,14 @@
|
||||
'''
|
||||
lparser.py
|
||||
|
||||
Depends on ldump.py for lua dump deserialization.
|
||||
Depends on lundump.py for lua dump deserialization.
|
||||
|
||||
An experimental bytecode decompiler.
|
||||
'''
|
||||
|
||||
from operator import concat
|
||||
from subprocess import call
|
||||
from lundump import Chunk, LuaUndump, Constant, Instruction, InstructionType, Opcodes
|
||||
from lundump import Chunk, Constant, Instruction, Opcodes, whichRK, readRKasK
|
||||
|
||||
class _Scope:
|
||||
def __init__(self, startPC: int, endPC: int):
|
||||
@ -104,8 +104,8 @@ class LuaDecomp:
|
||||
|
||||
# 'RK's are special in because can be a register or a konstant. a bitflag is read to determine which
|
||||
def __readRK(self, rk: int) -> str:
|
||||
if (rk & (1 << 8)) > 0:
|
||||
return self.chunk.constants[(rk & ~(1 << 8))].toCode()
|
||||
if (whichRK(rk)) > 0:
|
||||
return self.chunk.getConstant(readRKasK(rk)).toCode()
|
||||
else:
|
||||
return self.__getReg(rk)
|
||||
|
||||
@ -117,19 +117,19 @@ class LuaDecomp:
|
||||
# move registers
|
||||
self.__setReg(instr.A, self.__getReg(instr.B))
|
||||
elif instr.opcode == Opcodes.LOADK:
|
||||
self.__setReg(instr.A, self.chunk.constants[instr.B].toCode())
|
||||
self.__setReg(instr.A, self.chunk.getConstant(instr.B).toCode())
|
||||
elif instr.opcode == Opcodes.LOADBOOL:
|
||||
if instr.B == 0:
|
||||
self.__setReg(instr.A, "false")
|
||||
else:
|
||||
self.__setReg(instr.A, "true")
|
||||
elif instr.opcode == Opcodes.GETGLOBAL:
|
||||
self.__setReg(instr.A, self.chunk.constants[instr.B].data)
|
||||
self.__setReg(instr.A, self.chunk.getConstant(instr.B).data)
|
||||
elif instr.opcode == Opcodes.GETTABLE:
|
||||
self.__setReg(instr.A, self.__getReg(instr.B) + "[" + self.__readRK(instr.C) + "]")
|
||||
elif instr.opcode == Opcodes.SETGLOBAL:
|
||||
self.__startStatement()
|
||||
self.__addExpr(self.chunk.constants[instr.B].data + " = " + self.__getReg(instr.A))
|
||||
self.__addExpr(self.chunk.getConstant(instr.B).data + " = " + self.__getReg(instr.A))
|
||||
elif instr.opcode == Opcodes.SETTABLE:
|
||||
self.__startStatement()
|
||||
self.__addExpr(self.__getReg(instr.A) + "[" + self.__readRK(instr.B) + "] = " + self.__readRK(instr.C))
|
||||
|
Loading…
Reference in New Issue
Block a user