stegosaurus icon indicating copy to clipboard operation
stegosaurus copied to clipboard

bad marshal data (unknown type code)

Open b3yondgui opened this issue 1 year ago • 1 comments

$ python stegosaurus.py LOL.pyc -x Traceback (most recent call last): File "stegosaurus.py", line 251, in main() File "stegosaurus.py", line 217, in main header, code = _loadBytecode(carrier, logger) File "stegosaurus.py", line 124, in _loadBytecode code = marshal.load(f) ValueError: bad marshal data (unknown type code)

b3yondgui avatar Aug 17 '25 02:08 b3yondgui

higher python version have a different header size, it is not 12.

you can just try brute forcing the header size if you don't want to read every python version's source code and hard code the header size.

also note that you need a corresponding python version to unmarshal the code object. eg: for a python 3.12 pyc file, you need to run stegosaurus.py with a python 3.12 interpreter.

def _loadBytecode(carrier, logger):
    try:
        for i in range(12,200):
            f = open(carrier, "rb")
            try:
                header = f.read(i)
                code = marshal.load(f)
                if type(code) is not types.CodeType:
                    logger.info("type(code) is %s, not CodeType, you need a higher python version", type(code))
                logger.debug("Read header and bytecode from carrier,i=%d",i)
                return (header, code)
            except Exception as e:
                pass
            finally:
                f.close()
        else:
            logger.critical("Failed to read carrier file after multiple attempts")
            sys.exit(1)
    finally:
        pass

CwithW avatar Nov 29 '25 10:11 CwithW