#!/usr/bin/env bash
# ==========================================================
# check_icon.sh
# ----------------------------------------------------------
# Checks whether an executable contains embedded icon data.
# Works on Linux, macOS, or WSL using the `strings` utility.
# ----------------------------------------------------------
# Author : Alessandro Maestri
# Version: 1.2
# Date   : 2025-10-30
# ==========================================================

set -e

# --------------------------------------
# Helper: print Unicode character
# --------------------------------------
print_unicode() {
    # Usage: print_unicode 2705
    printf "\\U$1"
}

# --------------------------------------
# Parse arguments
# --------------------------------------
if [[ "$1" == "--path" && -n "$2" ]]; then
    EXE="$2"
else
    echo "Usage: $0 --path <executable>"
    exit 1
fi

# --------------------------------------
# Check file existence
# --------------------------------------
if [[ ! -f "$EXE" ]]; then
    print_unicode 274C; echo "  Executable not found: $EXE"
    exit 1
fi

# --------------------------------------
# Search for ICON / RT_GROUP_ICON patterns
# --------------------------------------
if strings "$EXE" | grep -qE "ICON|RT_GROUP_ICON"; then
    print_unicode 2705; echo "  Icon resource appears to be embedded in '$EXE'"
    exit 0
else
    print_unicode 26A0; echo "  No icon resource found in '$EXE'"
    echo "     Possible causes: invalid .ico file, wrong resource ID, or missing .rc link."
    exit 1
fi
