work_script/CP02/read_bytes.sh
Ching L 8f928a93e8 feat(cp02): add firmware processing and signing utilities
- Add get_last_bytes.sh to extract final 2 bytes from IUM files
  - Add read_bytes.sh for reading specific byte offsets from binaries
  - Add pack_resources.sh to package and upload CP02S resources to S3
  - Add signer_new.py for firmware and bootloader signing with custom SHA1
  - Update extract_firmware.sh to use fixed output filenames
  - Update README.md with comprehensive documentation for new tools
2026-01-04 15:08:17 +08:00

32 lines
753 B
Bash
Executable File

#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <bin_file>"
exit 1
fi
BIN_FILE="$1"
OFFSET=0x1dcfe
if [ ! -f "$BIN_FILE" ]; then
echo "Error: File '$BIN_FILE' not found"
exit 1
fi
FILE_SIZE=$(stat -f%z "$BIN_FILE" 2>/dev/null || stat -c%s "$BIN_FILE" 2>/dev/null)
DECIMAL_OFFSET=$((OFFSET))
if [ $DECIMAL_OFFSET -ge $FILE_SIZE ]; then
echo "Error: Offset $OFFSET ($DECIMAL_OFFSET) exceeds file size ($FILE_SIZE bytes)"
exit 1
fi
if [ $((DECIMAL_OFFSET + 2)) -gt $FILE_SIZE ]; then
echo "Error: Cannot read 2 bytes starting from offset $OFFSET (file too small)"
exit 1
fi
BYTES=$(xxd -s $DECIMAL_OFFSET -l 2 -p "$BIN_FILE")
BYTE1=$(echo "$BYTES" | cut -c1-2)
BYTE2=$(echo "$BYTES" | cut -c3-4)
echo "$BYTE2$BYTE1"