You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

detached-sig-apply.sh 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. set -e
  3. UNSIGNED="$1"
  4. SIGNATURE="$2"
  5. ARCH=x86_64
  6. ROOTDIR=dist
  7. TEMPDIR=signed.temp
  8. OUTDIR=signed-app
  9. if [ -z "$UNSIGNED" ]; then
  10. echo "usage: $0 <unsigned app> <signature>"
  11. exit 1
  12. fi
  13. if [ -z "$SIGNATURE" ]; then
  14. echo "usage: $0 <unsigned app> <signature>"
  15. exit 1
  16. fi
  17. rm -rf ${TEMPDIR} && mkdir -p ${TEMPDIR}
  18. tar -C ${TEMPDIR} -xf ${UNSIGNED}
  19. cp -rf "${SIGNATURE}"/* ${TEMPDIR}
  20. if [ -z "${PAGESTUFF}" ]; then
  21. PAGESTUFF=${TEMPDIR}/pagestuff
  22. fi
  23. if [ -z "${CODESIGN_ALLOCATE}" ]; then
  24. CODESIGN_ALLOCATE=${TEMPDIR}/codesign_allocate
  25. fi
  26. find ${TEMPDIR} -name "*.sign" | while read i; do
  27. SIZE=`stat -c %s "${i}"`
  28. TARGET_FILE="`echo "${i}" | sed 's/\.sign$//'`"
  29. echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}"
  30. ${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp"
  31. OFFSET=`${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g'`
  32. if [ -z ${QUIET} ]; then
  33. echo "Attaching signature at offset ${OFFSET}"
  34. fi
  35. dd if="$i" of="${i}.tmp" bs=1 seek=${OFFSET} count=${SIZE} 2>/dev/null
  36. mv "${i}.tmp" "${TARGET_FILE}"
  37. rm "${i}"
  38. echo "Success."
  39. done
  40. mv ${TEMPDIR}/${ROOTDIR} ${OUTDIR}
  41. rm -rf ${TEMPDIR}
  42. echo "Signed: ${OUTDIR}"