Skip to content

Instantly share code, notes, and snippets.

@carlospolop
Last active January 31, 2024 07:22
Show Gist options
  • Save carlospolop/a66b8d72bb8f43913c4b5ae45672578b to your computer and use it in GitHub Desktop.
Save carlospolop/a66b8d72bb8f43913c4b5ae45672578b to your computer and use it in GitHub Desktop.
Simple Utility Script for allowing debug of hardened macOS apps.
#! /bin/bash
# Copied from https://gist.github.com/talaviram/1f21e141a137744c89e81b58f73e23c3
# Adding the else part to sign binaries giving the error:
## Cannot parse a NULL or zero-length data
## Error Reading File: /tmp/debug_entitlements.plist
app_path=$1
if [ -z "$app_path" ];
then
echo "You need to specify app to re-codesign!"
exit 0
fi
xattr -rc "$app_path"
# This uses local codesign. so it'll be valid ONLY on the machine you've re-signed with.
entitlements_plist=/tmp/debug_entitlements.plist
echo "Grabbing entitlements from app..."
codesign -d --entitlements :- "$app_path" >> $entitlements_plist || { exit 1; }
echo "Patch entitlements (if missing)..."
/usr/libexec/PlistBuddy -c "Add :com.apple.security.cs.disable-library-validation bool true" $entitlements_plist
if [ $? -eq 0 ]; then
/usr/libexec/PlistBuddy -c "Add :com.apple.security.cs.allow-unsigned-executable-memory bool true" $entitlements_plist
/usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" $entitlements_plist
else
cat > $entitlements_plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>
EOF
fi
echo "Re-applying entitlements (if missing)..."
codesign --force --options runtime --sign - --entitlements $entitlements_plist "$app_path" || { echo "codesign failed!"; }
echo "Removing temporary plist..."
rm $entitlements_plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment