Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from binascii import hexlify, unhexlify
- def parse_variable_type(fd):
- type = int(hexlify(boop.read(1)), 16) # type
- if type == 0: # null type, contains nothing
- pass
- elif type == 1: # identifier type
- boop.seek(2, 1)
- elif type == 2: # string type
- boop.seek(2, 1)
- elif type == 3: # integer type
- boop.seek(4, 1)
- elif type == 4: # float type
- boop.seek(4, 1)
- elif type == 5: # boolean type
- boop.seek(1, 1)
- with open("somepexfile.pex", "r+b") as boop:
- boop.seek(16, 0) # skip the header
- boop.seek(int(hexlify(boop.read(2)), 16), 1) # sourcefilename
- boop.seek(int(hexlify(boop.read(2)), 16), 1) # username
- boop.seek(int(hexlify(boop.read(2)), 16), 1) # machinename
- string_table_count = int(hexlify(boop.read(2)), 16) # count
- for a in range(string_table_count):
- boop.seek(int(hexlify(boop.read(2)), 16), 1) # skip the strings in the table, no one really cares.
- #print(boop.read(int(hexlify(boop.read(2)), 16))) # or print them, whatever
- boop.seek(1, 1) # hasDebugInfo
- boop.seek(8, 1) # modificationTime
- functionCount = int(hexlify(boop.read(2)), 16) # functionCount
- for a in range(functionCount):
- boop.seek(2, 1) # objectNameIndex
- boop.seek(2, 1) # stateNameIndex
- boop.seek(2, 1) # functionNameIndex
- boop.seek(1, 1) # functionType
- instructionCount = int(hexlify(boop.read(2)), 16) # instructionCount
- boop.seek(2 * instructionCount, 1) # lineNumbers
- userFlagCount = int(hexlify(boop.read(2)), 16) # userFlagCount
- for a in range(userFlagCount):
- boop.seek(2, 1) # nameIndex
- boop.seek(1, 1) # flagIndex
- objectCount = int(hexlify(boop.read(2)), 16) # objectCount
- for a in range(objectCount):
- boop.seek(2, 1) # nameIndex
- boop.seek(4, 1) # size; true size of object data is size-4 because size includes itself
- boop.seek(2, 1) # parentClassName
- boop.seek(2, 1) # docstring
- boop.seek(4, 1) # userFlags
- boop.seek(2, 1) # autoStateName
- numVariables = int(hexlify(boop.read(2)), 16) # numVariables
- for c in range(numVariables):
- boop.seek(2, 1) # name
- boop.seek(2, 1) # typeName
- boop.seek(4, 1) # userFlags
- parse_variable_type(boop)
- numProperties = int(hexlify(boop.read(2)), 16) # numProperties
- for c in range(numProperties):
- boop.seek(2, 1) # name
- boop.seek(2, 1) # type
- boop.seek(2, 1) # docstring
- boop.seek(4, 1) # userFlags
- flags = type = int(hexlify(boop.read(1)), 16) # flags
- if (flags & 4) != 0:
- boop.seek(2, 1) # autoVarName
- for d in [e for e in ((flags & 5) == 1, (flags & 6) == 2) if e is True]:
- boop.seek(2, 1) # returnType
- boop.seek(2, 1) # docstring
- boop.seek(4, 1) # userFlags
- boop.seek(1, 1) # flags
- numParams = int(hexlify(boop.read(2)), 16) # numParams
- for e in range(numParams):
- boop.seek(2, 1) # name
- boop.seek(2, 1) # type
- numLocals = int(hexlify(boop.read(2)), 16) # numLocals
- for e in range(numLocals):
- boop.seek(2, 1) # name
- boop.seek(2, 1) # type
- numInstructions = int(hexlify(boop.read(2)), 16) # numInstructions
- for e in range(numInstructions):
- opcode = int(hexlify(boop.read(1)), 16) # opcodes
- if opcode == 0: # no arguments
- pass
- elif opcode in (20, 26): # 1 argument
- parse_variable_type(boop)
- elif opcode in (10, 11, 12, 13, 14, 21, 22, 30, 31): # 2 arguments
- for g in range(2):
- parse_variable_type(boop)
- elif opcode in (1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 27, 28, 29, 32, 33): # 3 arguments
- for g in range(3):
- parse_variable_type(boop)
- elif opcode in (34, 35): # 4 arguments
- for g in range(4):
- parse_variable_type(boop)
- elif opcode in (24,): # variable-length 2 arguments min
- for g in range(2):
- parse_variable_type(boop)
- type = int(hexlify(boop.read(1)), 16) # type
- if type == 3: # integer type
- extra_arguments_count = int(hexlify(boop.read(4)), 16)
- else:
- raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
- for g in range(extra_arguments_count):
- parse_variable_type(boop)
- elif opcode in (23, 25): # # variable-length 3 arguments min
- for g in range(3):
- parse_variable_type(boop)
- type = int(hexlify(boop.read(1)), 16) # type
- if type == 3: # integer type
- extra_arguments_count = int(hexlify(boop.read(4)), 16)
- else:
- raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
- for g in range(extra_arguments_count):
- parse_variable_type(boop)
- numStates = int(hexlify(boop.read(2)), 16) # numStates
- for c in range(numStates):
- boop.seek(2, 1) # name
- numFunctions = int(hexlify(boop.read(2)), 16) # numFunctions
- for d in range(numFunctions):
- boop.seek(2, 1) # functionName
- boop.seek(2, 1) # returnType
- boop.seek(2, 1) # docstring
- boop.seek(4, 1) # userFlags
- boop.seek(1, 1) # flags
- numParams = int(hexlify(boop.read(2)), 16) # numParams
- for e in range(numParams):
- boop.seek(2, 1) # name
- boop.seek(2, 1) # type
- numLocals = int(hexlify(boop.read(2)), 16) # numLocals
- for e in range(numLocals):
- boop.seek(2, 1) # name
- boop.seek(2, 1) # type
- numInstructions = int(hexlify(boop.read(2)), 16) # numInstructions
- for e in range(numInstructions):
- opcode = int(hexlify(boop.read(1)), 16) # opcodes
- if opcode == 0: # no arguments
- pass
- elif opcode in (20, 26): # 1 argument
- parse_variable_type(boop)
- elif opcode in (10, 11, 12, 13, 14, 21, 22, 30, 31): # 2 arguments
- for g in range(2):
- parse_variable_type(boop)
- elif opcode in (1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 27, 28, 29, 32, 33): # 3 arguments
- for g in range(3):
- parse_variable_type(boop)
- elif opcode in (34, 35): # 4 arguments
- for g in range(4):
- parse_variable_type(boop)
- elif opcode in (24,): # variable-length 2 arguments min
- for g in range(2):
- parse_variable_type(boop)
- type = int(hexlify(boop.read(1)), 16) # type
- if type == 3: # integer type
- extra_arguments_count = int(hexlify(boop.read(4)), 16)
- else:
- raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
- for g in range(extra_arguments_count):
- parse_variable_type(boop)
- elif opcode in (23, 25): # # variable-length 3 arguments min
- for g in range(3):
- parse_variable_type(boop)
- type = int(hexlify(boop.read(1)), 16) # type
- if type == 3: # integer type
- extra_arguments_count = int(hexlify(boop.read(4)), 16)
- else:
- raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
- for g in range(extra_arguments_count):
- parse_variable_type(boop)
Advertisement
Add Comment
Please, Sign In to add comment