extremecoders-re / pyinstxtractor

PyInstaller Extractor
GNU General Public License v3.0
2.93k stars 612 forks source link

Correct python version in pyc header #53

Closed bberna closed 2 years ago

bberna commented 2 years ago

Hi,

When one launches pyinstxtractor with a python interpetor that has a different version than the one used in the packed python script, then the header of the current used python version is put in the pyc header instead of the version packed.

As this seems to be intentional, what is the reason for this?

It is checked here:

 if pyc_magic != pycHeader:
                print('[!] Warning: This script is running in a different Python version than the one used to build the executable.')
                print('[!] Please run this script in Python {0}.{1} to prevent extraction errors during unmarshalling'.format(self.pymaj, self.pymin))
                print('[!] Skipping pyz extraction')
                return

but when writing the file we could just put pycHeader instead of pyc_magic and it would solve the python version problem.

pycFile.write(pyc_magic)    #why not use pycHeader here?

I understand it may not be unmarshalled in some cases but at least the generated pyc file would be correct.

extremecoders-re commented 2 years ago

Thanks for the report. This will be implemented eventually to use the existing pyc header rather than use the runtime python version magic.