# rust_fake_file **Repository Path**: greycode/rust_fake_file ## Basic Information - **Project Name**: rust_fake_file - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-26 - **Last Updated**: 2026-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # rust_fake_file Generate random images, append ZIP archives to them, and recover the embedded files later. **How it works:** The tool creates a random image (or reuses an existing one), compresses your files into a ZIP archive, and appends the ZIP bytes to the end of the image. Because ZIP readers scan from the end of the file for the central directory, the resulting file is both a valid image and a valid ZIP archive. You can then decode it to extract the original files. ## Install ### From source ```bash git clone https://gitee.com/greycode/rust_fake_file.git cd rust_fake_file cargo build --release # Binary: target/release/rust_fake_file ``` ### Minimal binary size (Windows) ```bash cargo build --profile release-small # Binary: target/release-small/rust_fake_file.exe ``` This profile enables `opt-level = "z"`, cross-crate LTO, one codegen unit, `panic = "abort"`, and symbol stripping. The `zip` dependency also excludes unused compression backends (bzip2, lzma, zstd, zopfli, deflate64), keeping only AES encryption and flate2-backed Deflate. ## Quick setup After building, rename the binary to a shorter name and add it to your PATH so you can call it from anywhere. ### Windows **Option A — Copy to a default PATH directory (no extra setup):** Windows already includes some user-level directories in PATH. You can copy the binary directly: ```powershell copy target\release\rust_fake_file.exe "%LOCALAPPDATA%\Microsoft\WindowsApps\fake.exe" ``` `%LOCALAPPDATA%\Microsoft\WindowsApps` is on the default user PATH for Windows 10/11. After copying, restart your terminal and `fake` is ready to use. **Option B — Copy to the Cargo bin directory:** Since you already have Cargo installed, `%USERPROFILE%\.cargo\bin` is already on your PATH: ```powershell copy target\release\rust_fake_file.exe "%USERPROFILE%\.cargo\bin\fake.exe" ``` No extra configuration needed — `fake` is available immediately after restarting your terminal. **Option C — Create a custom tools directory:** ```powershell mkdir C:\Tools copy target\release\rust_fake_file.exe C:\Tools\fake.exe ``` Then add `C:\Tools` to your user PATH: 1. Open **System Properties** → **Environment Variables** 2. Under **User variables**, select `Path` → **Edit** → **New** → enter `C:\Tools` 3. Restart your terminal Now you can use `fake` instead of the full name: ```powershell fake input.txt fake decode out.png fake info image.png ``` ### Linux / macOS ```bash # Copy to a directory already on your PATH cp target/release/rust_fake_file ~/.local/bin/fake # Or system-wide sudo cp target/release/rust_fake_file /usr/local/bin/fake ``` Now you can use `fake` instead of the full name: ```bash fake input.txt fake decode out.png fake info image.png ``` ## Quick Start ```bash # Encode a file into a random image rust_fake_file mydoc.txt # → creates mydoc.png # Decode and extract rust_fake_file mydoc.png # → restores mydoc.txt in current directory # Encode an entire folder rust_fake_file myproject/ # → creates myproject.png # Encode with password protection rust_fake_file secret.txt --password s3cret # → creates secret.png (AES-256 encrypted ZIP) # Decode with password rust_fake_file secret.png --password s3cret # → restores secret.txt ``` ## Usage ### Auto mode (default) When no explicit subcommand is given, the tool automatically routes based on input: | Command | Behavior | |---------|----------| | `rust_fake_file input.txt` | Encode `input.txt` → `input.png` | | `rust_fake_file mydir/` | Encode directory `mydir/` → `mydir.png` | | `rust_fake_file input.png` | Try decode first; if no ZIP found, encode → `input-encoded.png` | | `rust_fake_file https://example.com/hidden.png` | Download and decode a remote image | | `rust_fake_file` | Prompt to compress current directory into `.png` | | `rust_fake_file -y` | Compress current directory immediately, no prompt | | `rust_fake_file input.txt -o out.png` | Encode with explicit output path | Auto mode also accepts `--password` and image size/format options. It also accepts split-volume options when encoding large payloads. Remote image inputs support `http://`, `https://`, and `ftp://`; they are decoded only and do not fall back to encode. ### Explicit subcommands | Command | Description | |---------|-------------| | `gen_image` | Generate a random image (`png`, `jpg`, `jpeg`, or `bmp`) | | `encode` | Package a file or directory into a random or existing image | | `decode` | Extract the embedded ZIP payload and restore original files | | `info` | Inspect an image without extracting the embedded ZIP payload | | `version` | Print the package version | The alias `gen-image` is also accepted. ### Examples ```bash # --- Generate a random image --- rust_fake_file gen_image --output out.png rust_fake_file gen_image -w 800 -H 600 -f jpg -o out.jpg # --- Encode a file --- rust_fake_file encode input.txt --output out.png rust_fake_file encode input.txt --image cover.png --output out.png rust_fake_file encode input.txt -i cover.png -o out.png rust_fake_file encode input.txt -w 800 -H 600 -f bmp -o out.bmp # --- Encode one raw file with PNG LSB mode --- rust_fake_file encode payload.bin --output hidden.png --mode lsb --width 128 --height 128 rust_fake_file encode payload.bin --image cover.png --output hidden.png --mode lsb --bit-index 1 # --- Encode with password (AES-256) --- rust_fake_file encode input.txt --output encrypted.png --password secret rust_fake_file encode input.txt --output encrypted.png --password-file ~/.secret_key # Or in auto mode: rust_fake_file input.txt --output encrypted.png --password secret # --- Split large payloads across multiple images --- rust_fake_file encode myproject/ --output album.png --part-size 50MiB # → creates album.part001-of003.png, album.part002-of003.png, ... rust_fake_file encode myproject/ --output album.png --parts 5 rust_fake_file encode myproject/ --image cover.png --output hidden.png --parts 3 # --- Decode --- rust_fake_file decode out.png rust_fake_file decode https://example.com/hidden.png --output extracted/ rust_fake_file decode ftp://example.com/hidden.png --output extracted/ rust_fake_file decode encrypted.png --password secret rust_fake_file decode encrypted.png --password-file ~/.secret_key rust_fake_file decode out.png --output extracted/ rust_fake_file decode album.part001-of003.png --output extracted/ rust_fake_file decode album.part003-of003.png album.part001-of003.png album.part002-of003.png rust_fake_file decode hidden.png --output restored.bin --mode lsb --bit-index 1 # --- Inspect without extracting --- rust_fake_file info out.png # --- Auto mode shortcuts --- rust_fake_file input.txt # encode → input.png rust_fake_file input.txt --output custom.png # encode → custom.png rust_fake_file input.png # decode if embedded, else encode rust_fake_file https://example.com/hidden.png # download and decode rust_fake_file # prompt to compress cwd rust_fake_file -y # compress cwd without prompt # --- Help and version --- rust_fake_file help rust_fake_file version ``` ## Options ### Common options | Option | Description | |--------|-------------| | `-o, --output ` | Output file or directory | | `-i, --image ` | Image file to use as encode carrier | | `--mode ` | Encoding model for explicit `encode`/`decode` commands | | `--bit-index <0-7>` | PNG LSB bit index for `--mode lsb`; default is `0` | | `-p, --password ` | Encrypt or decrypt the ZIP payload (AES-256) | | `--password-file ` | Read the password from the first line of a file | | `--no-verify` | Skip embedded payload integrity verification during decode/info | | `--quiet` | Disable progress output | | `--strip-metadata` | Strip JPEG/PNG metadata from a carrier image before encoding | | `--part-size ` | Split encoded ZIP bytes across images with this maximum chunk size | | `--parts ` | Split encoded ZIP bytes across exactly this many images | | `-y, --yes` | Skip the current-directory prompt | | `-h, --help` | Print help | | `-V, --version` | Print the package version | ### Image options `gen_image`, `encode`, and auto mode all accept: | Option | Description | Default | |--------|-------------|---------| | `-w, --width ` | Image width | `400` | | `-H, --height ` | Image height | `400` | | `-f, --format ` | Generated image format | `png` | Generated images default to `400x400` PNG files. When using `encode` with `--image`, the tool appends the ZIP to that carrier image instead of generating a new random one: ```bash rust_fake_file encode input.txt --image cover.png --output out.png rust_fake_file encode input.txt --image photo.jpg --output out.jpg --strip-metadata ``` Use `--strip-metadata` with JPEG or PNG carrier images to remove EXIF/XMP/IPTC/ICC or PNG text metadata before appending the ZIP payload. Randomly generated images do not need this option. In auto mode, specify an explicit output path when changing format so the file extension matches: ```bash rust_fake_file input.txt --width 800 --height 600 --format jpg --output input.jpg ``` ## Split volumes Use `--part-size ` or `--parts ` when the embedded ZIP would make one image too large. The two options are mutually exclusive. ```bash # Split by maximum ZIP chunk size per image rust_fake_file encode myproject/ --output album.png --part-size 50MiB # Split into an exact number of images rust_fake_file encode myproject/ --output album.png --parts 5 ``` Supported size suffixes are `KB`, `KiB`, `MB`, `MiB`, `GB`, and `GiB`; a plain number means bytes. Split output names preserve the requested output path: ```text album.part001-of003.png album.part002-of003.png album.part003-of003.png ``` When using `--image cover.png`, the same carrier image bytes are copied into every part: ```bash rust_fake_file encode myproject/ --image cover.png --output hidden.png --parts 3 ``` Decode can be given one split image or all split images in any order. With one split image, the decoder searches the same directory for the rest of the set: ```bash rust_fake_file decode album.part001-of003.png --output extracted/ rust_fake_file decode album.part003-of003.png album.part001-of003.png album.part002-of003.png ``` ## Encoding modes: append-zip vs LSB The tool supports two fundamentally different embedding strategies. Choose based on your threat model, payload type, and capacity needs. ### Default mode (append-zip) The default mode appends a ZIP archive after the image data. ZIP readers locate the central directory by scanning from the end of the file, so the result is both a valid image and a valid ZIP archive. The image pixels are untouched — the payload lives entirely in the trailing bytes. - **How detection works:** Anyone who inspects the file tail will see ZIP structures (local file headers, central directory). The file size exceeds what the image dimensions would normally produce. - **Capacity:** Virtually unlimited — constrained only by the filesystem. Split volumes transparently handle payloads larger than practical single-image sizes. - **Multi-file:** Directories, multiple files, and file trees are first compressed into a ZIP before appending. - **Encryption:** AES-256 ZIP encryption is built in via `--password`. - **Integrity:** A SHA-256 checksum is appended after the ZIP for corruption detection. ### LSB mode (`--mode lsb`) LSB mode writes the payload directly into the least significant bits of PNG pixel bytes. Each pixel contributes one bit (or more, depending on `--bit-index`) to storage. The image remains visually plausible because flipping the lowest bit of a color channel produces a negligible perceptual change. - **How detection works:** There is no ZIP structure anywhere in the file. The payload is diffused across pixels. A casual viewer sees only a normal PNG. Statistical analysis can still reveal LSB embedding, but it requires specialized tools. - **Capacity:** Limited by image dimensions. A W×H image at bit 0 stores `W × H × 3 ÷ 8` bytes (one bit per RGB channel). For example, a 400×400 image holds about 60 KB. Using a higher bit index multiplies capacity but increases visible artifacts. - **Single-file only:** No ZIP archive is created. The raw file bytes are written into pixels directly. Decode requires an explicit `--output` path. - **No encryption:** The payload is stored as-is at the bit level. Encrypt the file before encoding if confidentiality is needed. - **No integrity checksum:** LSB mode does not append `[sha256][RFKSUM]`. Verify the round-tripped file yourself. ### Side-by-side comparison | Property | append-zip (default) | LSB (`--mode lsb`) | |---|---|---| | Embedding method | ZIP appended after image data | Bits overwritten in pixel channels | | Image pixels modified | No | Yes (lowest bits) | | Visual artifacts | None | Subtle at bit 0; visible at higher bits | | Capacity | Unlimited (split volumes) | `W×H×3÷8` bytes at bit 0 | | Multi-file / directories | Yes (compressed into ZIP) | No (single raw file) | | Encryption | AES-256 via `--password` | Not built-in; pre-encrypt manually | | Integrity checksum | SHA-256 appended automatically | None | | Carrier format | PNG, JPG, JPEG, BMP | PNG only | | Detectability | ZIP structures visible at file tail | No overt structures; statistical detection | | File size increase | Proportional to payload + ZIP overhead | None (image dimensions unchanged) | | Split volumes | Supported via `--part-size` / `--parts` | Not supported | | Metadata stripping | Supported via `--strip-metadata` | Not supported | | `info` command | Supported | Not supported | | Auto mode | Supported | Not supported | ### When to use each mode **Use append-zip when you:** - Need to bundle multiple files or directories - Care about capacity (large payloads, split volumes) - Want built-in AES-256 encryption - Want integrity verification on decode - Prefer zero pixel alteration - Are OK with the file being identifiable as a carrier under casual inspection **Use LSB when you:** - Need the image to pass casual visual inspection without obvious ZIP tails - Are embedding a single, possibly pre-encrypted payload - Want the image dimensions to remain exactly as generated - Accept the lower capacity and manual verification trade-offs - Are working in a context where appended ZIP bytes would be flagged ### Usage ```bash # Encode a single raw file into PNG pixels (bit 0, least visible) rust_fake_file encode payload.bin --output hidden.png --mode lsb --width 128 --height 128 # Use a higher bit index for more capacity (bit 1 = more data, slightly more visible) rust_fake_file encode payload.bin --image cover.png --output hidden.png --mode lsb --bit-index 1 # Decode requires the same --bit-index and an explicit output path rust_fake_file decode hidden.png --output restored.bin --mode lsb --bit-index 1 ``` ## Passwords Use the same password source with both `encode` and `decode` to encrypt and decrypt the ZIP payload. The encryption uses AES-256. ```bash # Environment variable export RUST_FAKE_FILE_PASSWORD=s3cret rust_fake_file encode secrets/ --output vault.png rust_fake_file decode vault.png # Password file rust_fake_file encode secrets/ --output vault.png --password-file ~/.secret_key rust_fake_file decode vault.png --password-file ~/.secret_key # Direct command-line password (compatible, but visible in shell history/process lists) rust_fake_file encode secrets/ --output vault.png --password mypass rust_fake_file decode vault.png --password mypass ``` Password priority is `--password`, then `--password-file`, then `RUST_FAKE_FILE_PASSWORD`, then no password. `--password` and `--password-file` are mutually exclusive. If `decode` detects an encrypted ZIP and no password source was provided, it prompts for a password. ## Integrity verification `encode` automatically appends a SHA-256 checksum after the embedded ZIP payload: ```text [image bytes][zip bytes][sha256][RFKSUM] ``` `decode` verifies this checksum before extraction and reports a corruption warning if it does not match. Split volumes are verified independently per part. Use `--no-verify` only when intentionally working with truncated or manually modified files. ## Info `info` reports embedded status, payload size, encryption, split part metadata, entry counts, file names when not encrypted, integrity status, and carrier image format/dimensions: ```bash rust_fake_file info out.png ``` Exit codes are `0` for embedded data, `1` for no embedded data, and `2` for missing or unreadable files. ## Progress Operations over inputs larger than 10 MiB show progress on stderr. Small files stay quiet to avoid flicker. Use `--quiet` to disable progress output completely. ## Decode behavior - `rust_fake_file decode out.png` — extracts files to the same directory as `out.png` - `rust_fake_file decode out.png -o extracted/` — extracts to the specified directory - `rust_fake_file decode https://example.com/hidden.png -o extracted/` — downloads the image and extracts to the specified directory - `rust_fake_file decode album.part001-of003.png` — discovers sibling split parts and extracts the reconstructed ZIP - Auto mode (`rust_fake_file out.png`) tries decode first; falls back to encode if no embedded ZIP is found - Auto mode with `http://`, `https://`, or `ftp://` downloads and decodes the URL without falling back to encode ## Development ```bash # Run all tests cargo test # Run with release optimizations cargo test --release # Check clippy cargo clippy ``` ## Notes - The tool produces valid image files that can be opened in any image viewer - ZIP archives are appended after the image data, so the image remains viewable - Supported image formats for carrier images: PNG, JPG/JPEG, BMP - Password encryption uses AES-256 via the `zip` crate