Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Library:CPython

From ReverseEngineering.wiki
Library
Developer Python Software Foundation
License PSF-2.0
Website https://www.python.org
On this wiki Facts · Code · Notes · Topics

CPython (PSF license) is often embedded in games and applications as pythonXY.dll / libpythonX.Y.so with a zip of the standard library or frozen modules; the version is read from the DLL name, Py_GetVersion() or the PYC magic number.

Identification

  • File names on Windows: python3XY.dll (for example python311.dll = 3.11), plus the stable-ABI forwarder python3.dll which re-exports the limited-API functions to python3XY.dll (PC/python3dll.c, generated from the stable ABI manifest). Linux: libpython3.X.so.1.0; embedded distributions: python3XY.zip or pythonXY.zip holding the standard library, python3XY._pth limiting sys.path.
  • Version text: PY_VERSION (Include/patchlevel.h, for example 3.16.0a1+dev) is returned by the export Py_GetVersion(); the banner string looks like 3.11.4 (main, Jun 7 2023, 12:45:18) [MSC v.1934 64 bit (AMD64)].
  • Exports that tell an embedding: Py_Initialize, Py_InitializeEx, Py_InitializeFromConfig, Py_Finalize, PyRun_SimpleString, PyRun_SimpleFileExFlags, PyImport_ImportModule, PyImport_AppendInittab, PyImport_ExtendInittab, PyImport_FrozenModules, Py_FrozenMain, PyMarshal_ReadObjectFromString, PyEval_EvalCode.
  • Native extension modules are .pyd DLLs exporting PyInit_<name>.

Where the code is

  • Plain .py/.pyc files, or a zip (.zip, library.zip) on sys.path; see Format:PYC (Python compiled bytecode): the 2-byte magic number identifies the exact minor version (3.11: 0xA7 0x0D plus CR LF).
  • Frozen modules: PyImport_FrozenModules is a table of _frozen {name, code, size, is_package} records; CPython freezes importlib._bootstrap as _frozen_importlib, _frozen_importlib_external, and since 3.11 also os, codecs, io, site and others (Python/frozen.c). Each code is a Format:Marshal (Python) stream of a code object. Application freezers (PyInstaller, cx_Freeze, py2exe, Nuitka) are different containers with their own pages if present.
  • Decrypted/obfuscated variants: games sometimes patch the importer or the marshal loader; look at who calls PyMarshal_ReadObjectFromString and PyEval_EvalCode.

Reading the version quickly

  1. DLL file name, 2. export Py_GetVersion or the string 3.X.Y ( in .rdata, 3. magic number of any .pyc in the archive.

Code & repositories

  • https://github.com/python/cpython @ 6af655301a19806a3f8ebe21b166f499cb431e70 · license: PSF-2.0 (declared by the contributor; GitHub's detector did not recognize LICENSE)
    CPython source. Useful without running: Include/patchlevel.h (version), PC/python3dll.c (stable ABI forwarder), Python/frozen.c (frozen modules), Lib/importlib/_bootstrap_external.py (pyc magic number).
    Tested on: source read, not run: source read, not run · checked 2026-10-18

See also

Library:Lua, Library:Squirrel, Library:QuickJS for other embedded languages.