[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/errhal/python_bytecode_reader/master/bytecode_reader.py [Back]  [Original]

import dis
import marshal
import types

ifPtr = open("input.pyc", 'rb')
header = ifPtr.read(8)
codeObject = marshal.load(ifPtr)
ifPtr.close()


def parse_code_object(code_object):
    co_argcount = code_object.co_argcount
    co_nlocals = code_object.co_nlocals
    co_stacksize = code_object.co_stacksize
    co_flags = code_object.co_flags

    insBytes = bytearray(code_object.co_code)

    i = 0
    while i < len(insBytes):
        opcode = insBytes[i]
        if opcode not in dis.opmap.values():
            print(str(i) + ":", "NOT EXISTING INSTRUCTION")
            i += 1
        elif opcode < dis.HAVE_ARGUMENT:
            print(str(i) + " : ", dis.opname[opcode], opcode, 0, 1)
            i += 1
        elif opcode >= dis.HAVE_ARGUMENT:
            if len(insBytes) > i + 2:
                arg = (insBytes[i + 2] 

Web Proxy Viewer  |  New URL  |  Original Page