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

Tool:cx_Freeze

From ReverseEngineering.wiki
Tool
Developer Marcelo Duarte, Anthony Tuininga and contributors
License PSF-derived license (see LICENSE.md in the repository)
Website https://cx-freeze.readthedocs.io
On this wiki Facts · Code · Notes · Topics

Python freezer for Windows, Linux and macOS: the program is a small prebuilt C executable next to a lib/ folder whose library.zip holds every module as a .pyc file; the build also injects a BUILD_CONSTANTS module and per-executable __init__ and __main__ modules.

Identification

  • A cx_Freeze build is a folder: the executable (a prebuilt C stub renamed after the script), the Python runtime DLL or shared library, and lib/ with library.zip, extension modules and data. In the default setup every Python module is a .pyc inside lib/library.zip; packages listed in zip_exclude_packages (the default is all of them, ["*"]) are written as plain .pyc files below lib/ instead of into the zip. A one-line file lib/library.dat holds the zip file name (Fact:cx_Freeze/behavior/library.zip layout and library.dat).
  • Frozen-module names: each executable gets an init module __init__<name> and a main module __main__<name> (the script), both stored in the zip like normal modules; BUILD_CONSTANTS is a generated module with BUILD_RELEASE_STRING and BUILD_COPYRIGHT, and __startup__ is the common start-up script. Use these names to find the entry point after unzipping (Fact:cx_Freeze/behavior/Frozen module names).
  • At commit 9f258f9d7340c40df48b11dd4f83af65f87c5a38 the repository no longer contains the C stub source or the initscripts/ directory: pyproject.toml lines 31-32 depend on the separate PyPI package freeze-core (>=0.6.1; >=0.8.0 for Python 3.15), cx_Freeze/freezer.py imports freeze_core.util and freeze_core.winmsvcr (lines 48-54) and loads initscripts/__startup__.py through resource_path (lines 460-461). freezer.py lines 821-830 write lib/library.dat containing the zip file name when the zip name differs from the default, or extract the zip into lib/ when no zip is used. Unverified: how the prebuilt stub reads library.dat and puts the zip on sys.path at run time; that code is in freeze-core, which was not read.

.pyc files

The writer prepends the interpreter's MAGIC_NUMBER, then struct.pack("<iLL", 0, mtime, size) (flags 0, source mtime, source size; with no source file the mtime is the build time and size 0) and then marshal.dumps(code) (Fact:cx_Freeze/struct/pyc header written by cx_Freeze). Unlike py2exe the timestamp and size are normally real values. Zip entry timestamps below 1980 are clamped to 1980-01-01.

Extraction

Unzip library.zip with any ZIP tool; the .pyc files decompile with a decompiler that supports the Python version of the magic number (Format:PYC (Python compiled bytecode), Technique:Bundled-runtime applications). Compare Format:PyInstaller archive (CArchive and PYZ) and Tool:Py2exe.

Code & repositories

See the repository list below.

  • https://github.com/marcelotduarte/cx_Freeze @ 9f258f9d7340c40df48b11dd4f83af65f87c5a38 · license: LicenseRef-PSF-derived (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
    cx_Freeze: cx_Freeze/freezer.py writes lib/library.zip (_write_modules), executable.py names the __init__ and __main__ modules, module.py generates BUILD_CONSTANTS.
    Tested on: source read, not run · checked 2026-10-18; last activity 2026-10-16