Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Utility Script for allowing debug of hardened macOS apps.
#! /bin/bash
# Simple Utility Script for allowing debug of hardened macOS apps.
# This is useful mostly for plug-in developer that would like keep developing without turning SIP off.
# Credit for idea goes to (McMartin): https://forum.juce.com/t/apple-gatekeeper-notarised-distributables/29952/57?u=ttg
app_path=$1
if [ -z "$app_path" ];
then
echo "You need to specify app to re-codesign!"
exit 0
fi
# 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
/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
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
@DanielRudrich
Copy link

DanielRudrich commented Mar 21, 2020

Thanks!
I tried it with REAPER and I had to use xattr -rc prior to running that script to make it work. Otherwise this error occurred:
resource fork, Finder information, or similar detritus not allowed

Loading

@jnicol
Copy link

jnicol commented Apr 18, 2020

This is great. Helped me to debug in Ableton Live. I've noticed that periodically debugging will stop working again, but re-running this script does the trick.

Loading

@talaviram
Copy link
Author

talaviram commented Apr 21, 2020

I tried it with REAPER and I had to use xattr -rc

Thanks Daniel! I'll update REAPER team as this seems to be better if they would add this to their Hardened build script (https://developer.apple.com/library/archive/qa/qa1940/_index.html)

I've noticed that periodically debugging will stop working again

That's common for software with updates. Ableton Live auto-updates itself.

Loading

@blues3
Copy link

blues3 commented May 15, 2020

Hi, Thank you very much for providing this solution; please, could you explain how to apply this to Ableton Live 10 ? I have tried to execute this script and I get : You need to specify app to re-codesign! Indeed, I still get the ERROR 1 in XCODE after this execution, and JUCE's debugger is unlinked from Ableton Live, so I'm sure the script was not correctly executed. Thank you very much for your help.

Xcode 11.3.1, Juce, OS 10.14.6, MacBook Pro 15" 2019.

Loading

@talaviram
Copy link
Author

talaviram commented May 17, 2020

It's pretty self explanatory in the shell script :) , it says you need to tell him what App (Ableton to patch...).
./add_debug_entitlment.sh "/Applications/Ableton Live 10 Suite.app" (or whatever the name of the app and its location...

Loading

@blues3
Copy link

blues3 commented May 17, 2020

Loading

@prefergui
Copy link

prefergui commented Jul 21, 2020

Thanks.
For further improvement, if original app does not have entitlement,
a file $entitlements_plist is empty.
In this case, template need to be written.

codesign -d --entitlements :- "$app_path" >> $entitlements_plist || { exit 1; }

if ! test -s $entitlements_plist ; then
cat > $entitlements_plist << EOT
<?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>
</dict>
</plist>
EOT
fi

Loading

@talaviram
Copy link
Author

talaviram commented Jul 22, 2020

thanks @prefergui but would be nice to understand why you need this scenario.
As far as I know, there's no hardened and notarized app without entitlements.
So if it doesn't exists then why would you want to add it?

Loading

@prefergui
Copy link

prefergui commented Jul 22, 2020

Quartz Composer v4.6.2

Loading

@laurentNoudohounsi
Copy link

laurentNoudohounsi commented Mar 16, 2021

Thank you very much for sharing!
However, is it me or the dev_id doesn't seem to be used in this script?

Loading

@talaviram
Copy link
Author

talaviram commented Mar 17, 2021

However, is it me or the dev_id doesn't seem to be used in this script?

Thanks. I've removed this unused dev_id and add a comment related to current signing.

Loading

@laurentNoudohounsi
Copy link

laurentNoudohounsi commented Mar 17, 2021

You're welcome!
Also, is it the only step to do? It doesn't seem to work on my side 🤔

Loading

@meverett
Copy link

meverett commented Jun 13, 2021

First of all, thanks for making this. However, it fails for me with the following error when trying to resign Ableton Live 11 on macOS 10.15.7:

Re-applying entitlements (if missing)...
/Applications/Ableton Live 11 Suite.app: replacing existing signature
/Applications/Ableton Live 11 Suite.app: resource fork, Finder information, or similar detritus not allowed
codesign failed!

Has anyone encountered this error before? Any insights?

UPDATE:
It turned out to be some extended attributes that needed to be removed first:

xattr -rc "/Applications/Ableton Live 11 Suite.app"

Loading

@bogre
Copy link

bogre commented Oct 7, 2021

Thanksssssssss!

Loading

@da-maestro
Copy link

da-maestro commented Nov 5, 2021

Hi thanks for a great tool.
When I run it for Ableton Live 10 I get this error:
/Applications/Ableton Live 10 Suite.app: replacing existing signature /Applications/Ableton Live 10 Suite.app: invalid or unsupported format for signature In subcomponent: /Applications/Ableton Live 10 Suite.app/Contents/MacOS/Live.cstemp codesign failed! Removing temporary plist...

What do I do?

Loading

@adaskar
Copy link

adaskar commented Nov 26, 2021

Hi,
After applying this script one of the app installed on my system, it says application damaged, any idea what should i do now?

Loading

@talaviram
Copy link
Author

talaviram commented Nov 27, 2021

After applying this script one of the app installed on my system

What system app you've used it on??

It's intended for allowing debugging on DAWs. System shouldn't even be possible since Catalina iirc.

Some apps kept some additional system attributes by mistake (xattr -rc )

See this post as an example:
https://gist.github.com/talaviram/1f21e141a137744c89e81b58f73e23c3#gistcomment-3778228

Loading

@adaskar
Copy link

adaskar commented Nov 29, 2021

After applying this script one of the app installed on my system

What system app you've used it on??

It's intended for allowing debugging on DAWs. System shouldn't even be possible since Catalina iirc.

Some apps kept some additional system attributes by mistake (xattr -rc )

See this post as an example: https://gist.github.com/talaviram/1f21e141a137744c89e81b58f73e23c3#gistcomment-3778228

it's not a systema app, it's an app downloaded from internet.
i have tried xattr -rc either, even if the code signing process not gives an error though. still getting application crashed.
i'm missing something but what?

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment