From b39cea283bb0ab787bedd57b72aeedfac4955c12 Mon Sep 17 00:00:00 2001 From: WasserEsser Date: Thu, 30 Apr 2026 12:53:48 +0200 Subject: [PATCH] Add ELF binary file type validation --- patch.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/patch.sh b/patch.sh index 2f17a53..104d9a2 100644 --- a/patch.sh +++ b/patch.sh @@ -16,7 +16,7 @@ cleanup() { trap cleanup EXIT # Check for required dependencies -DEPENDENCIES=(hexdump xxd grep awk dd tr mktemp) +DEPENDENCIES=(hexdump xxd grep awk dd tr mktemp file) MISSING_DEPS=() for dep in "${DEPENDENCIES[@]}"; do @@ -51,6 +51,13 @@ if [ ! -w "$BINARY_FILE" ]; then exit 5 fi +# Check if file is an ELF binary +FILE_TYPE=$(file -b "$BINARY_FILE" 2>/dev/null || echo "unknown") +if ! echo "$FILE_TYPE" | grep -q "ELF"; then + echo "Error: '$BINARY_FILE' does not appear to be an ELF binary (detected: $FILE_TYPE)." + exit 11 +fi + SEARCH_PATTERN=$(echo "$PATTERN" | tr -d ' ' | tr '?' '.' | tr 'A-Z' 'a-z') PATCHED_PATTERN=$(echo "$PATTERN" | sed 's/74 53/75 53/' | tr -d ' ' | tr '?' '.' | tr 'A-Z' 'a-z')