validation.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. ERROR_FOUND=0
  3. REQUIRED_PATTERNS=(
  4. "^Filetype: Flipper NFC device$"
  5. "^Version: 4$"
  6. "^Device type: SLIX$"
  7. "^UID:( [A-F0-9]{2}){8}$"
  8. "^DSFID: 00$"
  9. "^AFI: 00$"
  10. "^IC Reference: 03$"
  11. "^Lock DSFID: false$"
  12. "^Lock AFI: false$"
  13. "^Block Count: 8$"
  14. "^Block Size: 04$"
  15. "^Data Content:( [A-F0-9]{2}){32}$"
  16. "^Security Status: 00 00 00 00 00 00 00 00$"
  17. "^Capabilities: Default$"
  18. "^Password Privacy: 7F FD 6E 5B$"
  19. "^Password Destroy: 0F 0F 0F 0F$"
  20. "^Password EAS: 00 00 00 00$"
  21. "^Privacy Mode: false$"
  22. "^Lock EAS: false$"
  23. )
  24. FORBIDDEN_PATTERNS=(
  25. # This showed up in Unleashed firmware, see https://github.com/nortakales/flipper-zero-tonies/pull/82
  26. "Subtype: ([0-9]){2}"
  27. )
  28. # Use process substitution so that ERROR_FOUND is updated in the main shell.
  29. while read -r filename; do
  30. content=$(cat "$filename")
  31. for pattern in "${REQUIRED_PATTERNS[@]}"; do
  32. if ! echo "$content" | awk "/$pattern/ { found=1 } END { exit !found }"; then
  33. echo "$filename"
  34. echo " Missing pattern: $pattern"
  35. ERROR_FOUND=1
  36. fi
  37. done
  38. for pattern in "${FORBIDDEN_PATTERNS[@]}"; do
  39. if echo "$content" | awk "/$pattern/ { found=1 } END { exit !found }"; then
  40. echo "$filename"
  41. echo " Forbidden pattern found: $pattern"
  42. ERROR_FOUND=1
  43. fi
  44. done
  45. # The likelihood of two blocks of 00 in data content is almost impossible,
  46. # so use that as a check for when the full data is not read
  47. if echo "$content" | awk '/Data Content:( [A-F0-9]{2})* 00 00( [A-F0-9]{2})*/ { found=1 } END { exit !found }'; then
  48. echo "$filename"
  49. echo " Full data not read"
  50. ERROR_FOUND=1
  51. fi
  52. # Not necessarily going to cause issues, but keep line endings the same for consistency
  53. if echo "$content" | awk '/\r/ { found=1 } END { exit !found }'; then
  54. echo "$filename"
  55. echo " Has carriage return characters"
  56. ERROR_FOUND=1
  57. fi
  58. done < <(find . -type f -name "*.nfc")
  59. exit $ERROR_FOUND