Add ELF binary file type validation

This commit is contained in:
WasserEsser
2026-04-30 12:53:48 +02:00
parent 19431a6601
commit b39cea283b
+8 -1
View File
@@ -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')