/add_debug_entitlement.sh Secret
Last active
June 21, 2023 14:27
Star
You must be signed in to star a gist
Simple Utility Script for allowing debug of hardened macOS apps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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