python / python/cpython

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

未關閉
#126,905 17 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

OS-windows type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

未指定任何儲存庫檔案或測試。首先,在使用 LoadLibraryA/W 載入 CPython 核心 DLL 時重現僅發生於 Windows 的失敗,接著將其與透過可執行檔的 IMPORT_ADDRESS_TABLE 載入進行比較,並調查遭懷疑的 LdrpHandleTlsData 行為。完成條件是找出 encodings 模組失敗的原因,並為這種 embedding 方法確立受支援的修正方案或明確的限制。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
operating-systems
Issue 類型
缺陷
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。