Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When loading the python core dll using LoadLibraryA/W the encodings module cannot load. #126905

Open
AraHaan opened this issue Nov 16, 2024 · 0 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@AraHaan
Copy link
Contributor

AraHaan commented Nov 16, 2024

Bug report

Bug description:

I am trying to embed python inside of an exe where I don't want it inside of the exe's IMPORT_ADDRESS_TABLE and expected that when loading the python core with LoadLibraryA/W from the Windows API to work out of box just like it does when it is in the IMPORT_ADDRESS_TABLE.

I suspect the problem might be because the IMPORT_ADDRESS_TABLE is eventually calling the undocumented and non-exportedLdrpHandleTlsData function and that the LoadLibraryA/W API's might not be calling it but I am not entirely sure.

I even went as far as implementing my own copy of LoadLibraryA/W that does call this function in a creative way and it still does not work and I am not sure why. I expected for the normal LoadLibraryA/W functions to work out of box though without manually implementing the logic behind those functions to test if this was the case.

Why do I want to manually load the python core dll instead of letting the IMPORT_ADDRESS_TABLE and Windows to load it for me?

This is because I am embedding python and I am doing it with the python core itself inside of it's win32 resource section and then writing it out to disk before attempting to LoadLibraryA/W it. This is so I can then distribute a single standalone exe file that extracts the python core, uses the zip file with the standard library, c extensions (memory loaded), and any site-packages inside of the zip file from within the win32 resource section as well for properly loading up the python interpreter.

All of the logic behind loading the zip file with all of it's contents within the embed exe's win32 resource section works flawlessly when the core dll is in the IMPORT_ADDRESS_TABLE though. Sadly I doubt manually loading the python core and then injecting the python core dll inside of the currently running process's IMPORT_ADDRESS_TABLE (to make it use the existing handle from manually loading said dll) via code would work though as I suspect the code behind the IAT parts of the exe in memory is made readonly by the OS.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

@AraHaan AraHaan added the type-bug An unexpected behavior, bug, or error label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants