JonathonReinhart / staticx

Create static executable from dynamic executable
https://staticx.readthedocs.io/
Other
345 stars 37 forks source link

PyInstalled applications fail with "Cannot open self" #170

Closed JonathonReinhart closed 1 year ago

JonathonReinhart commented 3 years ago

First reported here: https://github.com/JonathonReinhart/staticx/issues/167#issuecomment-773790859

I also see this in CI jobs: https://travis-ci.org/github/JonathonReinhart/staticx/jobs/757788708

This is definitely a recent issue with a new version of PyInstaller, because staticx master was passing but now fails: https://travis-ci.org/github/JonathonReinhart/staticx/builds/757790293

JonathonReinhart commented 3 years ago

This build job for master (e91a9054 2020-09-29) passed w/ pyinstaller-4.0.

This build job for master (same commit, e91a9054 2021-02-06) failed w/ pyinstaller-4.2.

That narrows it down a lot.

Local test:

git bisect pointed me at pyinstaller/pyinstaller@3873f0492b71cd7c04ed5e831a49f6331921957a but that was just a recompile of the prebuilt bootloader.


When I actually forced a compilation of PyInstaller bootloader, I couldn't get the staticx to work at all:

pyinstaller $ (cd bootloader && ./waf configure --no-lsb all)
staticx $ PYINSTALLER="python3 $(realpath ~/gitrepos/pyinstaller/pyinstaller.py)" test/pyinstall/run_test.sh
...
Running staticx executable
[16941] Cannot open self /tmp/staticx-kjnU4r/app or archive /tmp/staticx-kjnU4r/app.pkg
git bisect start
# bad: [40c9abce2d8de879e414fd377c933dccaab1e156] Release 4.2.
git bisect bad 40c9abce2d8de879e414fd377c933dccaab1e156
# bad: [19fb799a11d2d796fc8758808f873c40e2bf5118] Release 4.0.
git bisect bad 19fb799a11d2d796fc8758808f873c40e2bf5118
# bad: [6d4cce1f8eb80c0bf49d35876d28daa55a05800f] Release 3.6.
git bisect bad 6d4cce1f8eb80c0bf49d35876d28daa55a05800f
# bad: [0f31b35fe96de59e1a6faf692340a9ef93492472] Release 3.4.
git bisect bad 0f31b35fe96de59e1a6faf692340a9ef93492472
JonathonReinhart commented 3 years ago

Debug:

$ PYINSTALLER="python3 $(realpath ~/gitrepos/pyinstaller/pyinstaller.py) --debug bootloader" test/pyinstall/run_test.sh
...
Running staticx executable
[18646] PyInstaller Bootloader 3.x
[18646] LOADER: executable is /tmp/staticx-zepJSf/app
[18646] LOADER: homepath is /tmp/staticx-zepJSf
[18646] LOADER: _MEIPASS2 is NULL
[18646] LOADER: archivename is /tmp/staticx-zepJSf/app
[18646] Loader: Cannot find cookie[18646] LOADER: archivename is /tmp/staticx-zepJSf/app.pkg
[18646] LOADER: Cannot open archive: /tmp/staticx-zepJSf/app.pkg
[18646] Cannot open self /tmp/staticx-zepJSf/app or archive /tmp/staticx-zepJSf/app.pkg
aptalca commented 3 years ago

We've been hitting this issue with any pyinstaller version compiled locally. We can provide some more test results, but in a nutshell: pyinstaller 3.5 and 3.6 --> works on x86_64 with prebuilt wheels, but fails when built locally pyinstaller >=4.1 --> fails with or without prebuilt wheels (I don't think I tested 4.0 specifically)

By fail, I mean that when the binary is put through staticx, it produces the error Cannot open self . . .

JonathonReinhart commented 3 years ago

@aptalca Yep, that's exactly what I was seeing too. I was starting to debug the bootloader but I didn't get very far. I did confirm that the embedded user app does indeed still have the MEI... "cookie" at the same location in the pyidata section, so I'm not yet sure why it's failing, but I'm sure GDB will tell me when I get back to it.

danihodovic commented 3 years ago

Works with py3.9.1, pyinstaller 4.0.

Fails with py3.9.1, pyinstaller 4.2.

ErwanMAS commented 3 years ago

i had this problem

with python 3.5 ( debian strech ) works with pyinstaller 4.0 does not work with pyinstaller 4.1 , pyinstaller 4.2

with python 3.7 ( debian buster ) works with pyinstaller 4.0 does not work with pyinstaller 4.1 , pyinstaller 4.2 , but works pyinstaller 4.3 , pyinstaller 4.4

so if you are using 3.5 you must use pyinstaller 4.0 so if you are using 3.7 you must use pyinstaller 4.0 or 4.3 or 4.4

pyinstaller drop compatiblity with python 3.5 starting version 4.3

I dont know if you can detect if the binary was build with pyinstaller and wich version . So you can generate a error if you try to statify a exe build with version 4.1 and 4.2