JB=$(ls -d /var/containers/Bundle/Application/.jbroot-* | head -1)
APP="$JB/Applications/Driver.app"
echo "--- sign all Mach-O files under the app bundle ---"
n=0; fail=0
for f in $(find "$APP" -type f); do
  b=$(basename "$f")
  case "$b" in *.png|*.nib|*.car|*.strings|*.plist|*.lproj) continue ;; esac
  if head -c 4 "$f" | od -An -tx1 | grep -q "cf fa ed fe"; then
    if "$JB/usr/bin/ldid" -S "$f" >/dev/null 2>&1; then n=$((n+1)); else fail=$((fail+1)); echo "FAIL $f"; fi
  fi
done
echo "signed=$n failed=$fail"
echo "--- verify AMPopTip signature accepted ---"
"$JB/usr/bin/ldid" -S "$APP/Frameworks/AMPopTip.framework/AMPopTip" && echo ampoptip_signed
echo "--- launch ---"
"$JB/usr/bin/uiopen" --bundleid vn.gsm.md 2>&1 | head -2
sleep 10
launchctl list 2>/dev/null | grep "UIKitApplication:vn.gsm.md" | head -2
echo "--- newest crashes ---"
ls -t /rootfs/private/var/mobile/Library/Logs/CrashReporter/ 2>/dev/null | grep -i "^Driver" | head -2
echo SIGNFW_DONE
