gzexe
Compress executables and make them self-extracting
TLDR
Compress an executable file in-place
[d]ecompress a compressed executable in-place (i.e. convert the shell script back to an uncompressed binary)
SYNOPSIS
gzexe [-d] [name ...]
PARAMETERS
-d
Decompresses the specified gzexe file(s) back to their original uncompressed state.
name ...
One or more executable files to be compressed or decompressed by gzexe.
DESCRIPTION
gzexe is a shell script that allows you to compress executable files while still being able to run them transparently. When you run gzexe on an executable, it replaces the original file with a compressed version that has a small shell script prepended to it. This script's purpose is to decompress the original executable into a temporary file (usually in /tmp or /var/tmp) and then execute it. The primary benefit of gzexe is disk space saving, particularly useful for large, infrequently used binaries. It effectively wraps the gzip compression and zcat decompression into a self-executing package. The original executable is preserved with a ~ suffix.
CAVEATS
Performance Overhead: Executables processed by gzexe incur a slight delay on execution due to the decompression step, making it unsuitable for frequently used or performance-critical applications.
Temporary Files: gzexe creates temporary files (e.g., in /tmp) during execution. While modern implementations use secure methods, the underlying mechanism relies on temporary file handling, which can be a point of concern if not properly secured.
Disk Space During Execution: While it saves space on disk for the compressed binary, it requires additional temporary space for decompression during each execution.
Original File Renaming: The original executable is renamed with a ~ suffix (e.g., program~), which might affect scripts or tools expecting the exact original file path.
Compatibility: Primarily designed for standalone executables; may not work correctly with shared libraries or complex multi-file binaries.
WORKING MECHANISM
When a file processed by gzexe is executed, the prepended shell script first checks for necessary permissions and temporary space. It then uses zcat to decompress the embedded original executable into a temporary file in a secure location (e.g., /tmp or /var/tmp). Once decompressed, the script executes this temporary file. After the execution finishes, the temporary file is typically removed, although abnormal termination might leave it behind. The temporary file is usually created with appropriate permissions to prevent unauthorized access.
SECURITY CONSIDERATIONS
The reliance on temporary files for decompression, while generally handled securely by modern gzexe implementations using facilities like mktemp, historically posed potential vulnerabilities. Concerns included race conditions or symbolic link attacks if the temporary directory was not properly secured or if the script's handling of temporary files was naive. Users should ensure their temporary directories are configured securely (e.g., with noexec where appropriate, though gzexe can often work around this) and their system's gzexe version is up-to-date.
HISTORY
gzexe is an integral part of the gzip package, which was developed by Jean-Loup Gailly and Mark Adler. gzip was initially released in 1992 as a free and more efficient replacement for the proprietary compress utility, quickly becoming the standard for file compression on Unix-like systems. gzexe was created as a complementary utility to allow users to save disk space on executable binaries while maintaining transparent execution. Its usage has decreased over time due to increasing disk capacities and the emergence of more specialized executable compressors like UPX.