Guest User

Untitled

a guest
Aug 17th, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.88 KB | None | 0 0
  1. from binascii import hexlify, unhexlify
  2.  
  3.  
  4. def parse_variable_type(fd):
  5.     type = int(hexlify(boop.read(1)), 16)  # type
  6.     if type == 0:  # null type, contains nothing
  7.         pass
  8.     elif type == 1:  # identifier type
  9.         boop.seek(2, 1)
  10.     elif type == 2:  # string type
  11.         boop.seek(2, 1)
  12.     elif type == 3:  # integer type
  13.         boop.seek(4, 1)
  14.     elif type == 4:  # float type
  15.         boop.seek(4, 1)
  16.     elif type == 5:  # boolean type
  17.         boop.seek(1, 1)
  18.  
  19.  
  20. with open("somepexfile.pex", "r+b") as boop:
  21.     boop.seek(16, 0)  # skip the header
  22.  
  23.     boop.seek(int(hexlify(boop.read(2)), 16), 1)  # sourcefilename
  24.     boop.seek(int(hexlify(boop.read(2)), 16), 1)  # username
  25.     boop.seek(int(hexlify(boop.read(2)), 16), 1)  # machinename
  26.    
  27.     string_table_count = int(hexlify(boop.read(2)), 16)  # count
  28.     for a in range(string_table_count):
  29.         boop.seek(int(hexlify(boop.read(2)), 16), 1)  # skip the strings in the table, no one really cares.
  30.         #print(boop.read(int(hexlify(boop.read(2)), 16)))  # or print them, whatever
  31.    
  32.     boop.seek(1, 1)  # hasDebugInfo
  33.     boop.seek(8, 1)  # modificationTime
  34.     functionCount = int(hexlify(boop.read(2)), 16)  # functionCount
  35.     for a in range(functionCount):
  36.         boop.seek(2, 1)  # objectNameIndex
  37.         boop.seek(2, 1)  # stateNameIndex
  38.         boop.seek(2, 1)  # functionNameIndex
  39.         boop.seek(1, 1)  # functionType
  40.         instructionCount = int(hexlify(boop.read(2)), 16)  # instructionCount
  41.         boop.seek(2 * instructionCount, 1)  # lineNumbers
  42.        
  43.     userFlagCount = int(hexlify(boop.read(2)), 16)  # userFlagCount
  44.     for a in range(userFlagCount):
  45.         boop.seek(2, 1)  # nameIndex
  46.         boop.seek(1, 1)  # flagIndex
  47.        
  48.     objectCount = int(hexlify(boop.read(2)), 16)  # objectCount
  49.     for a in range(objectCount):
  50.         boop.seek(2, 1)  # nameIndex
  51.         boop.seek(4, 1)  # size; true size of object data is size-4 because size includes itself
  52.         boop.seek(2, 1)  # parentClassName
  53.         boop.seek(2, 1)  # docstring
  54.         boop.seek(4, 1)  # userFlags
  55.         boop.seek(2, 1)  # autoStateName
  56.         numVariables = int(hexlify(boop.read(2)), 16)  # numVariables
  57.         for c in range(numVariables):
  58.             boop.seek(2, 1)  # name
  59.             boop.seek(2, 1)  # typeName
  60.             boop.seek(4, 1)  # userFlags
  61.             parse_variable_type(boop)
  62.         numProperties = int(hexlify(boop.read(2)), 16)  # numProperties
  63.         for c in range(numProperties):
  64.             boop.seek(2, 1)  # name
  65.             boop.seek(2, 1)  # type
  66.             boop.seek(2, 1)  # docstring
  67.             boop.seek(4, 1)  # userFlags
  68.             flags = type = int(hexlify(boop.read(1)), 16)  # flags
  69.             if (flags & 4) != 0:
  70.                 boop.seek(2, 1)  # autoVarName
  71.             for d in [e for e in ((flags & 5) == 1, (flags & 6) == 2) if e is True]:
  72.                 boop.seek(2, 1)  # returnType
  73.                 boop.seek(2, 1)  # docstring
  74.                 boop.seek(4, 1)  # userFlags
  75.                 boop.seek(1, 1)  # flags
  76.                 numParams = int(hexlify(boop.read(2)), 16)  # numParams
  77.                 for e in range(numParams):
  78.                     boop.seek(2, 1)  # name
  79.                     boop.seek(2, 1)  # type
  80.                 numLocals = int(hexlify(boop.read(2)), 16)  # numLocals
  81.                 for e in range(numLocals):
  82.                     boop.seek(2, 1)  # name
  83.                     boop.seek(2, 1)  # type
  84.                 numInstructions = int(hexlify(boop.read(2)), 16)  # numInstructions
  85.                 for e in range(numInstructions):
  86.                     opcode = int(hexlify(boop.read(1)), 16)  # opcodes
  87.                     if opcode == 0:  # no arguments
  88.                         pass
  89.                     elif opcode in (20, 26):  # 1 argument
  90.                         parse_variable_type(boop)
  91.                     elif opcode in (10, 11, 12, 13, 14, 21, 22, 30, 31):  # 2 arguments
  92.                         for g in range(2):
  93.                             parse_variable_type(boop)
  94.                     elif opcode in (1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 27, 28, 29, 32, 33):  # 3 arguments
  95.                         for g in range(3):
  96.                             parse_variable_type(boop)
  97.                     elif opcode in (34, 35):  # 4 arguments
  98.                         for g in range(4):
  99.                             parse_variable_type(boop)
  100.                     elif opcode in (24,):  # variable-length 2 arguments min
  101.                         for g in range(2):
  102.                             parse_variable_type(boop)
  103.                         type = int(hexlify(boop.read(1)), 16)  # type
  104.                         if type == 3:  # integer type
  105.                             extra_arguments_count = int(hexlify(boop.read(4)), 16)
  106.                         else:
  107.                             raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
  108.                         for g in range(extra_arguments_count):
  109.                             parse_variable_type(boop)
  110.                     elif opcode in (23, 25):  # # variable-length 3 arguments min
  111.                         for g in range(3):
  112.                             parse_variable_type(boop)
  113.                         type = int(hexlify(boop.read(1)), 16)  # type
  114.                         if type == 3:  # integer type
  115.                             extra_arguments_count = int(hexlify(boop.read(4)), 16)
  116.                         else:
  117.                             raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
  118.                         for g in range(extra_arguments_count):
  119.                             parse_variable_type(boop)
  120.         numStates = int(hexlify(boop.read(2)), 16)  # numStates
  121.         for c in range(numStates):
  122.             boop.seek(2, 1)  # name
  123.             numFunctions = int(hexlify(boop.read(2)), 16)  # numFunctions
  124.             for d in range(numFunctions):
  125.                 boop.seek(2, 1)  # functionName
  126.                 boop.seek(2, 1)  # returnType
  127.                 boop.seek(2, 1)  # docstring
  128.                 boop.seek(4, 1)  # userFlags
  129.                 boop.seek(1, 1)  # flags
  130.                 numParams = int(hexlify(boop.read(2)), 16)  # numParams
  131.                 for e in range(numParams):
  132.                     boop.seek(2, 1)  # name
  133.                     boop.seek(2, 1)  # type
  134.                 numLocals = int(hexlify(boop.read(2)), 16)  # numLocals
  135.                 for e in range(numLocals):
  136.                     boop.seek(2, 1)  # name
  137.                     boop.seek(2, 1)  # type
  138.                 numInstructions = int(hexlify(boop.read(2)), 16)  # numInstructions
  139.                 for e in range(numInstructions):
  140.                     opcode = int(hexlify(boop.read(1)), 16)  # opcodes
  141.                     if opcode == 0:  # no arguments
  142.                         pass
  143.                     elif opcode in (20, 26):  # 1 argument
  144.                         parse_variable_type(boop)
  145.                     elif opcode in (10, 11, 12, 13, 14, 21, 22, 30, 31):  # 2 arguments
  146.                         for g in range(2):
  147.                             parse_variable_type(boop)
  148.                     elif opcode in (1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 27, 28, 29, 32, 33):  # 3 arguments
  149.                         for g in range(3):
  150.                             parse_variable_type(boop)
  151.                     elif opcode in (34, 35):  # 4 arguments
  152.                         for g in range(4):
  153.                             parse_variable_type(boop)
  154.                     elif opcode in (24,):  # variable-length 2 arguments min
  155.                         for g in range(2):
  156.                             parse_variable_type(boop)
  157.                         type = int(hexlify(boop.read(1)), 16)  # type
  158.                         if type == 3:  # integer type
  159.                             extra_arguments_count = int(hexlify(boop.read(4)), 16)
  160.                         else:
  161.                             raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
  162.                         for g in range(extra_arguments_count):
  163.                             parse_variable_type(boop)
  164.                     elif opcode in (23, 25):  # # variable-length 3 arguments min
  165.                         for g in range(3):
  166.                             parse_variable_type(boop)
  167.                         type = int(hexlify(boop.read(1)), 16)  # type
  168.                         if type == 3:  # integer type
  169.                             extra_arguments_count = int(hexlify(boop.read(4)), 16)
  170.                         else:
  171.                             raise Exception("Hishy's a dick and this should be an integer but isn't so yh. type = {}".format(type))
  172.                         for g in range(extra_arguments_count):
  173.                             parse_variable_type(boop)
Advertisement
Add Comment
Please, Sign In to add comment