#!/bin/bash # Script to get the last two bytes of ium file # Returns the bytes in 0x format # Usage: ./get_last_bytes.sh [ium_file_path] # Use provided path or default to ium.bin ium_file=${1:-ium.bin} if [ ! -f "$ium_file" ]; then echo "Error: $ium_file file not found" exit 1 fi # Get file size file_size=$(stat -f%z "$ium_file") if [ "$file_size" -lt 2 ]; then echo "Error: File is too small (less than 2 bytes)" exit 1 fi # Extract last 2 bytes and reverse byte order last_bytes=$(xxd -s -2 "$ium_file" | cut -d' ' -f2 | tr -d '\n') # Reverse the byte order (swap first and second byte) byte1=${last_bytes:0:2} byte2=${last_bytes:2:2} echo "${byte2}${byte1}"