Fix image base calculation for PyInstaller MacOS bundles - #858
Open
trisiak wants to merge 2 commits into
Open
Conversation
… map On macOS, `PythonProcessInfo::new` used the first executable memory map matching the libpython filename (`libmaps[0]`) as the dylib's load base, and `parse_binary` slides every symbol/section address by that base. With some dyld layouts — notably PyInstaller onedir bundles, where a separate `libpythonX.Y.dylib` is loaded by the bootloader — small executable stubs of the dylib are mapped at lower addresses than its real `__TEXT` segment. `libmaps[0]` then points at a stub, not the image base, so every symbol read lands on the wrong address: `Py_Version` reads as 0 (yielding a bogus "0.0.0" and an "Unsupported version of Python" error), and `_PyRuntime` / BSS lookups fail as well. Pick the base by probing each candidate executable map for a Mach-O magic at its start (the image header lives at the start of `__TEXT`), falling back to the first map if none match so existing layouts are unaffected. Linux and Windows paths are unchanged.
`get_python_version` returns immediately on the Py_Version symbol path, even when the decoded result is nonsense (e.g. "0.0.0" from a misresolved symbol address) and even propagating a read error with `?`. Either case aborts detection before the sys.version string scan — which often still succeeds — gets a chance. Treat the Py_Version path as best-effort: ignore a read error, and only short-circuit on a plausible decode (major 2 or 3); otherwise fall through to the remaining strategies. Defense in depth alongside the image-base fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
with this, I was able to connect to my bundled app