Scripts2026年7月14日·1 分钟阅读

UPX — The Ultimate Packer for Executables

UPX is a portable, high-performance executable packer that compresses executables and shared libraries by 50-70 percent while keeping them directly runnable with no extraction step.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
UPX Executable Packer
直接安装命令
npx -y tokrepo@latest install def92077-7f1b-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

UPX (Ultimate Packer for eXecutables) is a free, open-source executable compressor that works on Linux, macOS, and Windows binaries. It reduces binary size by 50-70% while keeping the output directly executable — no unpacking step or installer is needed. UPX is widely used in container images, embedded systems, and CLI tool distribution to shrink binary artifacts.

What UPX Does

  • Compresses ELF, PE, Mach-O, and other executable formats in place
  • Produces self-decompressing executables that run without an extraction step
  • Supports multiple compression algorithms including LZMA, NRV, and zstd
  • Preserves executable permissions and can decompress back to the original
  • Works on static and dynamically linked binaries across architectures

Architecture Overview

UPX applies a compression stub to the front of the binary and stores the compressed payload after it. At runtime the stub decompresses the payload into memory and transfers control to the original entry point. The decompression overhead is typically a few milliseconds. UPX itself is written in C++ and uses the UCL compression library plus optional LZMA.

Self-Hosting & Configuration

  • Install via package managers (apt, brew, choco) or download static binaries from GitHub releases
  • No configuration files; all options are command-line flags
  • Use --best for maximum compression or --ultra-brute for exhaustive optimization
  • Add --strip-relocs to strip relocation records on Linux ELF binaries
  • Integrate into Dockerfiles with a simple RUN upx --best /app to shrink final images

Key Features

  • In-place compression — the output replaces the input file
  • Decompression support with upx -d to restore the original binary
  • Cross-platform: Linux (ELF), Windows (PE), macOS (Mach-O), DOS, and more
  • No runtime dependency or library required on the target system
  • Deterministic output when given the same input and flags

Comparison with Similar Tools

  • strip — removes debug symbols but does not compress code; UPX compresses the entire binary
  • Brotli/zstd — general-purpose compressors that produce archives; UPX produces runnable executables
  • Docker multi-stage builds — reduce image layers; UPX further shrinks the binary inside the layer
  • Go ldflags -s -w — strips debug info at compile time; UPX compresses on top of that
  • Cosmopolitan — produces polyglot binaries; UPX focuses purely on size reduction

FAQ

Q: Does UPX slow down application startup? A: Decompression adds a few milliseconds. For long-running processes the overhead is negligible.

Q: Can I compress Go, Rust, or C++ binaries? A: Yes. UPX works on statically linked Go and Rust binaries. Dynamically linked C++ binaries work if the loader can map the decompressed segments.

Q: Is UPX safe for production containers? A: Yes. Many teams use UPX in Docker multi-stage builds to shrink final images by 50%+.

Q: Does UPX modify the binary signature? A: Yes. Code-signed binaries will lose their signature after compression. Re-sign after packing if needed.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产