mirror of
https://github.com/CPunch/LuaPytecode.git
synced 2024-12-21 22:00:07 +00:00
Fixed local vector deserialization
- minor refactoring
This commit is contained in:
parent
0b94b64c89
commit
fda8ec118c
42
luac.py
42
luac.py
@ -39,6 +39,9 @@ class Constant:
|
||||
self.type = type
|
||||
self.data = data
|
||||
|
||||
def toString(self):
|
||||
return "[" + self.type.name + "] " + str(self.data)
|
||||
|
||||
class Local:
|
||||
def __init(self, name: str, start: int, end: int):
|
||||
self.name = name
|
||||
@ -71,6 +74,20 @@ class Chunk:
|
||||
def appendProto(self, proto):
|
||||
self.protos.append(proto)
|
||||
|
||||
def print(self):
|
||||
print("\n==== [[" + str(self.name) + "'s constants]] ====\n")
|
||||
for z in range(len(self.constants)):
|
||||
i = self.constants[z]
|
||||
print(str(z) + ": " + i.toString())
|
||||
|
||||
print("\n==== [[" + str(self.name) + "'s dissassembly]] ====\n")
|
||||
for i in range(len(self.instructions)):
|
||||
print("[%3d] %s" % (i, self.instructions[i].toString()))
|
||||
|
||||
print("\n==== [[" + str(self.name) + "'s protos]] ====\n")
|
||||
for z in self.protos:
|
||||
z.print()
|
||||
|
||||
instr_lookup_tbl = [
|
||||
Instruction(InstructionType.ABC, "MOVE"), Instruction(InstructionType.ABx, "LOADK"), Instruction(InstructionType.ABC, "LOADBOOL"),
|
||||
Instruction(InstructionType.ABC, "LOADNIL"), Instruction(InstructionType.ABC, "GETUPVAL"), Instruction(InstructionType.ABx, "GETGLOBAL"),
|
||||
@ -115,21 +132,12 @@ class LuaUndump:
|
||||
|
||||
@staticmethod
|
||||
def dis_chunk(chunk: Chunk):
|
||||
print("\n==== [[" + str(chunk.name) + "'s constants]] ====\n")
|
||||
for z in range(len(chunk.constants)):
|
||||
i = chunk.constants[z]
|
||||
print(str(z) + ": [" + i.type.name + "] " + str(i.data))
|
||||
|
||||
print("\n==== [[" + str(chunk.name) + "'s dissassembly]] ====\n")
|
||||
for i in range(len(chunk.instructions)):
|
||||
print("[%3d] %s" % (i, chunk.instructions[i].toString()))
|
||||
|
||||
print("\n==== [[" + str(chunk.name) + "'s protos]] ====\n")
|
||||
for z in chunk.protos:
|
||||
print("** decoding proto\n")
|
||||
LuaUndump.dis_chunk(z)
|
||||
chunk.print()
|
||||
|
||||
def loadBlock(self, sz) -> bytearray:
|
||||
if self.index + sz > len(self.bytecode):
|
||||
raise Exception("Malformed bytecode!")
|
||||
|
||||
temp = bytearray(self.bytecode[self.index:self.index+sz])
|
||||
self.index = self.index + sz
|
||||
return temp
|
||||
@ -234,14 +242,14 @@ class LuaUndump:
|
||||
# line numbers
|
||||
num = self.get_int()
|
||||
for i in range(num):
|
||||
self.get_int32()
|
||||
self.get_int()
|
||||
|
||||
# locals
|
||||
num = self.get_int()
|
||||
for i in range(num):
|
||||
#print(self.get_string(None)[:-1]) # local name
|
||||
self.get_int32() # local start PC
|
||||
self.get_int32() # local end PC
|
||||
self.get_string(None)[:-1] # local name
|
||||
self.get_int() # local start PC
|
||||
self.get_int() # local end PC
|
||||
|
||||
# upvalues
|
||||
num = self.get_int()
|
||||
|
Loading…
Reference in New Issue
Block a user