#!/usr/bin/env bash
# Quick first-pass triage of an artifact: file type, header bytes, strings,
# binwalk signatures, and radare2 architecture hints. Nothing is written.
#
# Usage: ./re-identify <file-in-artifacts>
set -euo pipefail
cd "$(dirname "$0")"
if [ "$#" -ne 1 ]; then
    echo "usage: $0 <file-in-artifacts>" >&2
    exit 2
fi
ART="$1"
exec docker compose run --rm -T -e ART="$ART" --entrypoint /bin/bash tools -lc '
set -euo pipefail
F="/data/artifacts/$ART"
echo "################ file ################"; file "$F"
echo; echo "################ size / hashes ################"
ls -l "$F"; sha256sum "$F"
echo; echo "############## first 256 bytes ##############"; xxd -l 256 "$F"
echo; echo "############## last 256 bytes ###############"; tail -c 256 "$F" | xxd
echo; echo "############## ascii strings (top 40) ########"; strings -n 4 "$F" | head -40
echo; echo "############## binwalk signatures ############"; binwalk "$F"
echo; echo "############## rabin2 -I (arch hints) ########"
rabin2 -I "$F" 2>/dev/null || echo "(rabin2 could not identify a known format)"
'
