From 74dfb5f2411d26f28db0785a57488cbee860704e Mon Sep 17 00:00:00 2001 From: CPunch Date: Sun, 11 Apr 2021 18:47:59 -0500 Subject: [PATCH] More sensible get_bits() implementation --- luac.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/luac.py b/luac.py index 014b91f..a9b89da 100644 --- a/luac.py +++ b/luac.py @@ -39,8 +39,8 @@ def get_bits(num, p, k): for i in range(32 - len(binary)): binary = '0' + binary - end = len(binary) - p + 1 - start = len(binary) - k + 1 + end = len(binary) - p + start = len(binary) - k # extract k bit sub-string kBitSubStr = binary[start : end] @@ -151,7 +151,7 @@ class LuaUndump: } data = self.get_int32() - opcode = get_bits(data, 1, 6) + opcode = get_bits(data, 0, 6) tp = lua_opcode_types[opcode] instruction['OPCODE'] = opcode @@ -159,12 +159,12 @@ class LuaUndump: instruction['A'] = get_bits(data, 7, 14) if instruction['TYPE'] == "ABC": - instruction['B'] = get_bits(data, 24, 32) + instruction['B'] = get_bits(data, 24, 31) instruction['C'] = get_bits(data, 15, 23) elif instruction['TYPE'] == "ABx": - instruction['Bx'] = get_bits(data, 15, 32) + instruction['Bx'] = get_bits(data, 15, 31) elif instruction['TYPE'] == "AsBx": - instruction['sBx'] = get_bits(data, 15, 32) - 131071 + instruction['sBx'] = get_bits(data, 15, 31) - 131071 chunk['INSTRUCTIONS'][i] = instruction