Skip to main content

staticer

Know it when you create a dynamiclly-linked executable,
And try to execute it on other machines, but it fails to find expected symbols?
Using your linux-executable on other machines with different libc, and can't find expected GLIBC function versions?
Compiling a Windows-program and failing to run it on other machines? Or simply want your project to be published as onefile?
Wait no more as staticer is here to the rescue!
No more execution failures or long-taking compilation adaptions,
Just to simply support same-kernel different-OS / OS versioning!

NOTE you should use this tool for legit-development / debugging / educational purposes only!

Installation

Simply run:

pip install staticer

Make sure to have python scripts folder in your path,
And use the correct version of pip for python3.

Usage

staticer <input> -o <output> [--exclude NAME[,NAME...]] [--lib-dir PATH]

NOTE -o/--output overwrites an existing file at that path without warning or backup.

Goals & Parctice

We want to get en executable-file and embed its dependencies recursively.
We need to patch the executable-file's import-table and prevent it from loading the dynamic libraries.
We need to patch the executable-file's import-table and have the resolved symbol addresses in it,
And make the loader ignore that import-table in order not to clash, as it is invalidated.
We need to embed the code/data/... sections of each embedded dependency,
Patch their import-table the same way, and call their initializers (i.e. DllMain / Constructor)

In order to intercept explicit dynamic-loading (from the executed code itself),
We'll have to hook dlopen+dlsym / LoadLibraryW+GetProcAddress and make them return addresses to embedded resources,
Or make them call the original functions, if they try to access dynamic-libraries that weren't embedded.

NOTE OS-based / C++ exception unwinding works across embedded-dependency boundaries (unwind metadata is preserved); a self-contained embedded module that both throws and catches internally may still hit compiler-specific personality-routine details beyond the documented ABI NOTE we currently do NOT support invoking elf-destructor / DllMain process-detach NOTE we might never support DllMain invoking for thread attach/detach reasons

Features & How They're Implemented

Everything below operates on the real on-disk binary format directly (pefile for PE, pyelftools for reading ELF + hand-packed structs for writing it back, since pyelftools is read-only) — no linker, compiler, or native toolchain is invoked by the installed package itself.

  • Dependency graph & embed order. staticer recursively resolves a binary's imports (PE Import Directory / ELF DT_NEEDED) into a dependency graph, then topologically sorts it so each embedded dependency's own initializer runs before anything that depends on it, mirroring normal loader behavior. Exclusion (--exclude, or a dependency found outside --lib-dir) propagates transitively: anything an excluded dependency itself imports is also left dynamic, so the same code never ends up both embedded and dynamically loaded as two independent copies. Cycles among embeddable dependencies are detected and rejected with a clear error naming the cycle, rather than looping forever or silently picking an order.

  • PIC / relocation-bearing dependencies (the common case). A dependency's code/data sections are appended into the host as new sections/segments, its relocations (PE .reloc, ELF .rela/.rel) are re-applied against the new placement, and the host's import-table entries pointing at it are patched to the embedded address and removed from the import table / DT_NEEDED. On ELF, new content extends the host's own existing loadable segment in place rather than adding a new one — adding a genuinely new segment and relocating the program-header table into it breaks the kernel's AT_PHDR calculation (its skew assumption only holds for a segment that shares the original image's vaddr - offset skew), silently breaking TLS/RELRO/stack-flag setup. This took three real, execution-verified fix rounds to get right.

  • Fixed-base / non-relocatable dependencies. A dependency with no usable relocation data (as opposed to one that merely prefers a fixed base but still carries relocations — those always take the normal path above) is placed at its own declared preferred address instead, with every such reservation checked against the host's own image, every other reserved dependency, and any bridging filler sections, failing loudly on a genuine address conflict rather than producing a silently-malformed binary. On PE, embedding any such dependency also clears DYNAMIC_BASE/HIGH_ENTROPY_VA on the output, since a fixed-base dependency's untracked absolute references are only valid if the whole combined image never gets relocated as a whole. ELF has no equivalent per-image flag to clear, so embedding a fixed-base dependency into a PIE host fails loudly instead.

  • Exception / unwind metadata. PE .pdata/.xdata (the RUNTIME_FUNCTION/UNWIND_INFO exception directory) and ELF .eh_frame/.eh_frame_hdr entries are merged into the host rather than discarded, with every RVA/offset they reference patched to the relocated address — so a C++ exception, or a Windows structured exception, can unwind correctly across the boundary between the host and an embedded dependency. A fully self-contained module that both throws and catches entirely within itself can still hit compiler-internal personality-routine details beyond the documented unwind ABI (see the note above) — this is a real limit of the public unwind data format, not something this project's implementation chose to skip.

  • Generated entrypoint stub. The output's entrypoint is replaced with a small generated stub that calls each embedded dependency's initializer (DllMain process-attach / ELF constructor) in dependency order, then jumps to the original entrypoint. On PE, the stub correctly distinguishes real process-attach from thread-attach/detach when the output itself is a DLL (so embedded initializers run exactly once, not on every thread event). On ELF, a .so input can't rely on e_entry at all — the dynamic linker never calls it for a shared object — so its init sequence is injected as an additional DT_INIT_ARRAY entry instead, which does run via the normal constructor-calling mechanism.

  • --exclude / --lib-dir scoping. --exclude NAME[,NAME...] keeps specific dependencies dynamic by name (case-insensitively on PE, matching Windows' own case-insensitive filenames; case-sensitively on ELF, matching real filesystem semantics on Linux). --lib-dir PATH restricts embedding to dependencies actually found inside that folder — anything resolved from elsewhere (including system directories) stays a normal dynamic import. Dependency names come straight from the binary being processed, so they're treated as untrusted input: a crafted name with path-traversal components or an absolute path is rejected rather than allowed to escape the intended search directory.

  • Real-world binaries. Tested against actual system binaries (cmd.exe/hostname.exe on Windows, bash/grep on Linux), both as a curated subset (via --lib-dir/--exclude) and as closer-to-full transitive closures. A handful of real-world-only bugs only ever surfaced against genuine system DLLs/.sos — forwarded exports, ordinal-only imports, forwarder import cycles, stale DT_VERNEED entries, R_*_COPY relocations for a dependency's own globals, and weak symbols from the C runtime's own startup boilerplate — all fixed and covered by regression tests built from the same binaries that found them. Also tried against a genuine real-world instrumentation library (Frida's own frida-gadget, downloaded for real from its GitHub release assets — see tests/windows/test_pe_frida_gadget.py / tests/linux/test_elf_frida_gadget.py): it carries its own TLS directory on both PE and ELF, so it currently hits the already-documented TLS limitation below rather than embedding end-to-end — confirmed by reading frida-core's own config-resolution source that, were TLS merging supported, frida-gadget's config-file lookup would resolve relative to the host's own path once embedded (since there's no longer a separately-loaded module for it to resolve against), so the config would need to be named after the host binary's stem, not the gadget's.

Limitations

  • Explicit dynamic-loading from the executed code itself (dlopen+dlsym / LoadLibraryW+GetProcAddress) is not hooked yet; only dependencies resolved through the input's own import/dynamic-section table are embedded.
  • A "full closure" embed on ELF still bottoms out at glibc's own dynamic linker/loader internals, which stay dynamically linked rather than embedded.
  • Process-detach cleanup (elf-destructor / DllMain DLL_PROCESS_DETACH) is not invoked for embedded dependencies, and thread attach/detach notifications may never be supported.
  • Because DLL_PROCESS_DETACH is never delivered to an embedded dependency (see above), calling FreeLibrary on a staticer-produced DLL before process exit can crash the process: a dependency built against a dynamically-linked CRT registers process-wide TLS/FLS state during its (real, CRT-startup) DLL_PROCESS_ATTACH that nothing ever tears down, and the CRT's own exit-time bookkeeping later dereferences it after the freed library's memory is gone. Confirmed reproducible. Safe as long as the output DLL stays loaded for the life of the process (the common case); avoid FreeLibrary-ing it otherwise.
  • -o/--output silently overwrites an existing file at that path (see Usage above).
  • A dependency using PE Thread Local Storage (__declspec(thread)) is rejected with a clear error rather than embedded incorrectly — TLS-directory merging isn't implemented yet.
  • ELF embedding of a dependency whose own further imports aren't themselves embedded or excluded (an "in-between" import) isn't supported; such a dependency fails loudly rather than silently losing that further dependency.
  • A COPY-relocated ELF symbol larger than one pointer, containing its own interior pointer fields, doesn't get relocation entries for those interior pointers — a genuine architectural limit, since ELF carries no type/layout metadata for a COPY-relocated symbol beyond a byte count.

Metadata

Release files for staticer 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for staticer 0.0.1
File Size Uploaded Provenance Actions
staticer-0.0.1.tar.gz 80.4 kB Without provenance Details for staticer-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for staticer 0.0.1
File Interpreter ABI Platform Actions
staticer-0.0.1-py3-none-any.whl Python 3 none any Details for staticer-0.0.1-py3-none-any.whl

Total release size: 157.0 kB

Release files / staticer-0.0.1.tar.gz

Download URL staticer-0.0.1.tar.gz
Size 80.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5296d501f25678e963ed013e0a58aa3f64e24500c4ec59fb05b9860819c9e787
BLAKE2b-256 checksum
How to use checksums
627aa15d27d4a93d39210ce84f3e5dc465c4e226c32c2b1e255f2b31ee2c9c83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / staticer-0.0.1-py3-none-any.whl

Download URL staticer-0.0.1-py3-none-any.whl
Size 76.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9a97f6e43445aa9c6ebc8b0f081d2098785b96a605303a51867821395776681
BLAKE2b-256 checksum
How to use checksums
a5502d5b96cf8a67badbb79a8972271d6cfd76508ef0e0cd42a254b8ce216a6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for staticer 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page