Fix access violation when loading script files - #1
Conversation
Utilize C++ standard APIs for opening script files in lieu of C `fopen`.
|
I've also found other issues, e.g., when setting breakpoints via the API. I will leave this PR as-is since it resolves the original issue and open new PRs for the others. |
|
Hello. For example script for listing afd.sys driver endpoints: https://github.com/gerhart01/Hyper-V-scripts/blob/master/ParseAfdEndpointListHead.py |
|
@gerhart01 Did you compile my branch or is this the official pykd release? If the former, my guess is you ran into one of the other problems I mentioned in my comment above. I'm still planning on coming back to this and fix everything once and for all but haven't had the time. |
|
Yes, i downloaded your compiled version from ivellioscolin/pykd#6 (comment). |
|
@gerhart01 I'll include it in my PR with proper attribution, of course. Thanks. |
|
Thank you all for your feedback. If the access violation is due to unstable API _Py_fopen, it should been already fixed by commit However the binary on release page https://github.com/ivellioscolin/pykd-ext/releases points to the original HEAD 857b62e, which doesn't include all fixes I made after. I should have put a HEAD build just as did for pykd. I'm trying to make sometime to finish some other pending issues, and will put a pykd-ext nightly build on release page as well. |
|
Fixes for pykd Python 3.14 supporting (partitially or full). Tested on WinDBG scripts for Kernel Mode: |

This PR addresses the "Access violation" reported in ivellioscolin/pykd#6.
The exception was caused by an unconditional usage of the
_Py_fopenAPI which is no longer exported as of Python 3.10-3.13. According to python/cpython#127350 (comment) the API will return for Python 3.14 (and presumably future versions). My solution instead relies on the standard C++ file I/O APIs to read the file into memory and execute viaPyRun_Stringin lieu of the previousPyRun_FileExFlags.Finally, during the course of my investigation I found other APIs no longer exported by CPython (as of 3.13.5) also in-use by PyKD. As I cannot commit time to a bigger PR at this time I've left their usage intact, but the below list provides their names for future reference.
PyString_Type_PyThreadState_CurrentPyString_FromStringPyString_AsStringPyImport_CleanupPyClass_NewPyInstance_NewPyFile_FromStringPyFile_AsFile