#!/usr/bin/env bash set -euo pipefail # Print usage message usage() { cat < [...] For each : 1) Look for its AppleDouble at /@eaDir/@SynoResource 2) Try to read File Type + Creator from Finder Info (entry ID 9) 3) If invalid or missing, parse Resource Fork: • read mapOffset at RF offset+4 • go to RF offset + mapOffset + 16 and read 8 bytes (first 4 = File Type, next 4 = Creator) 4) Print: EOF exit 1 } # Require at least one argument [ $# -ge 1 ] || usage for datafile in "$@"; do # derive directory and filename dirpath=$(dirname -- "$datafile") base=$(basename -- "$datafile") # path to the AppleDouble companion apple="$dirpath/@eaDir/${base}@SynoResource" if [ ! -f "$apple" ]; then printf 'Error: no AppleDouble for "%s": %s\n' \ "$datafile" "$apple" >&2 continue fi # read number of entry descriptors (big‑endian uint16 at offset 24) num_entries=$( printf "%d\n" 0x$( xxd -ps -s 24 -l 2 -- "$apple" ) ) # initialize Finder Info and Resource Fork offsets/lengths off9=0; len9=0 off2=0; len2=0 entry_table_start=26 # loop through each 12‑byte descriptor for ((i=0; i/dev/null \ | tr -d '\000' ) creator_ascii=$( echo -n "$cr_hex" \ | xxd -r -p 2>/dev/null \ | tr -d '\000' ) # validate exactly 4 alphanumeric chars if ! [[ $filetype_ascii =~ ^[A-Za-z0-9]{4}$ ]]; then filetype_ascii=''; fi if ! [[ $creator_ascii =~ ^[A-Za-z0-9]{4}$ ]]; then creator_ascii=''; fi fi # 2) Fallback: parse Resource Fork’s Resource Map if [ -z "$filetype_ascii" ] && [ "$len2" -ge 16 ]; then # read mapOffset (big‑endian uint32 at off2+4) map_hex=$(dd if="$apple" bs=1 skip=$((off2+4)) count=4 status=none | xxd -ps) map_off=$((0x$map_hex)) # compute where the embedded Finder Info lives attr_off=$((off2 + map_off + 16)) # read 8 bytes from that location h2=$(dd if="$apple" bs=1 skip="$attr_off" count=8 status=none | xxd -ps) ft_hex=${h2:0:8}; cr_hex=${h2:8:8} # convert hex → ASCII, strip nulls filetype_ascii=$( echo -n "$ft_hex" \ | xxd -r -p 2>/dev/null \ | tr -d '\000' ) creator_ascii=$( echo -n "$cr_hex" \ | xxd -r -p 2>/dev/null \ | tr -d '\000' ) # validate exactly 4 alphanumeric chars if ! [[ $filetype_ascii =~ ^[A-Za-z0-9]{4}$ ]]; then filetype_ascii=''; fi if ! [[ $creator_ascii =~ ^[A-Za-z0-9]{4}$ ]]; then creator_ascii=''; fi fi # only print if both FileType and Creator are non‐empty if [[ -n "$filetype_ascii" && -n "$creator_ascii" ]]; then printf '%s\t%s\t%s\n' "$datafile" "$filetype_ascii" "$creator_ascii" fi done