thebitguru / play-button-itunes-patch

Play Button iTunes Patch
http://www.thebitguru.com/projects/iTunesPatch
Other
644 stars 19 forks source link

Codesign of rcd fails on 10.12 GM (16A320) #32

Closed leonmelein closed 8 years ago

leonmelein commented 8 years ago

Hi! I always use your program to patch that annoying play button behavior away. I tried it the other day on the macOS Sierra GM, but for some reason codesigning seems to fail. The error message I got was:

Unexpected error Could not codesign the modified binary.

The program will continue patching and finish eventually, but after a reboot macOS will annoy the user with numerous error messages. Because the program makes a backup of rcd, it's easy to fix, but nevertheless it would be nice if this bug was fixed before the official launch of Sierra on the 20th. Hopefully, it's an easy fix. Thanks in advance!

thebitguru commented 8 years ago

Thanks for reporting this. I don't have access to Sierra right now so I can't address this right away. I will see if I can create a VM to address this.

I am assuming that you tried this with SIP disabled, right? (probably because, otherwise, it wouldn't let you create the backup).

leonmelein commented 8 years ago

I indeed have SIP disabled. In the meantime, I found a log file created by the program: com.thebitguru.Play-Button-iTunes-Patch 2016-09-09 15-58.txt

thebitguru commented 8 years ago

Yeah, it's definitely related to the code sign. I am waiting for a new VM to install and then upgrade to Sierra. I will report back what I learn.

thebitguru commented 8 years ago

OK, after stumbling through the macOS Sierra installation I was finally able to successfully get the Sierra GM running in Parallels. I haven't figured out how to emulate the Play/Pause yet, but the patching process seems to have worked correctly.

2016/09/11 21:57:16:853 | INFO | AppDelegate:65 - --------------- New session - Version 1.0 ---------------
2016/09/11 21:57:16:857 | INFO | AppDelegate:66 - Log file directory: /Users/farhanahmad/Library/Logs/Play Button iTunes Patch
2016/09/11 21:57:16:859 | INFO | AppDelegate:78 - OS Version: Version 10.12 (Build 16A320)
...
...
2016/09/11 21:59:54:829 | INFO | Patcher:161 - Patching rcd...
2016/09/11 21:59:54:831 | INFO | Patcher:176 - Replaced instance #1 at 36125:48
2016/09/11 21:59:54:832 | INFO | Patcher:171 - No more instances.
2016/09/11 21:59:54:832 | INFO | Patcher:184 - Replaced 1 total instances
2016/09/11 21:59:57:373 | INFO | Patcher:204 - Creating backup file /System/Library/CoreServices/rcd.app/Contents/MacOS//rcd_backup_1.0_20160911_21_59.57 before overwriting rcd.
2016/09/11 21:59:57:374 | DEBUG | Patcher:280 - writeDataToProtectedFile: /System/Library/CoreServices/rcd.app/Contents/MacOS//rcd_backup_1.0_20160911_21_59.57
2016/09/11 21:59:57:414 | INFO | Patcher:209 - Writing the updated bytes to original file (/System/Library/CoreServices/rcd.app/Contents/MacOS//rcd).
2016/09/11 21:59:57:415 | DEBUG | Patcher:280 - writeDataToProtectedFile: /System/Library/CoreServices/rcd.app/Contents/MacOS//rcd
2016/09/11 21:59:57:430 | INFO | Patcher:214 - Signing file.
2016/09/11 21:59:59:270 | INFO | Patcher:218 - Killing existing rcd processes...
2016/09/11 21:59:59:270 | INFO | Patcher:303 - Killing all rcd.
2016/09/11 22:00:01:454 | INFO | Patcher:311 - killall returned 'No matching porcesses were found'
2016/09/11 22:00:01:455 | INFO | Patcher:318 - Restarting rcd process as current user.

After patching, I manually ran the rcd process and did not see any complaints about the signature. I also validated the code signature afterwards, as shown below.

os-x-sierra:MacOS farhanahmad$ csrutil status
System Integrity Protection status: enabled.

os-x-sierra:MacOS farhanahmad$ codesign -dv /System/Library/CoreServices/rcd.app/
Executable=/System/Library/CoreServices/rcd.app/Contents/MacOS/rcd
Identifier=com.apple.rcd
Format=app bundle with Mach-O thin (x86_64)
CodeDirectory v=20100 size=830 flags=0x2(adhoc) hashes=21+3 location=embedded
Signature=adhoc
Info.plist entries=21
TeamIdentifier=not set
Sealed Resources version=2 rules=13 files=2
Internal requirements count=0 size=12

I am seeing that this is the same macOS build as the one that you have (16A320) so I am not sure yet why it did not work for you, but it worked for me. I confirmed that the MD5 sums of the original rcd executable are the same.

In your case, I did notice the log saying... codesign task returned false! so we have to figure why that failed. Can you try manually signing the patched rcd? Try the following command. I would suggest backing up rcd.app in some other location before proceeding any further in case if you need any file from there.

codesign -f -s - /System/Library/CoreServices/rcd.app/Contents/MacOS/rcd
leonmelein commented 8 years ago

I tried signing rcd and then I found the root cause of the problem: the upgrade messed up my Xcode Developer Tools, which in turn lead to the failed codesign. A simple xcode-select --install was all it took to get it working again. The program fortunately works fine on Sierra. If people do run into trouble, they should first try to reinstall the developer tools.

thebitguru commented 8 years ago

I am glad to hear that you were able to figure out the root cause and get it fixed. How were you able to tell that the dev tools were messed up? I ask because I am wondering if I can add an additional check to the app to address this for other users.

I will add a note to the website so other folks know. Thanks for reporting the issue and working on a resolution.

leonmelein commented 8 years ago

I upgraded to the final version of Sierra this afternoon, so I could finally find out what error it was throwing. Here's the error in full: /System/Library/CoreServices/rcd.app/Contents/MacOS/rcd: replacing existing signature xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun /System/Library/CoreServices/rcd.app/Contents/MacOS/rcd: the codesign_allocate helper tool cannot be found or used

As earlier, xcode-select --install fixed it.

thebitguru commented 8 years ago

Thanks for the update. I am glad to hear that it is working now. This seems to be a recurring issue with upgrades so I will see if I can add a check for it as well.

ellsta5 commented 8 years ago

Hi, @thebitguru , thanks for this page! It helped a lot, as I was having the same issue.

serhatbolsu commented 7 years ago

"in sierra" I have xcode command line tools, but as soon as I click "patch" , app closes and evidently it is not effective. When I re-opened to app, status seems "unpatched". Can I debug this ?

Great idea btw, thank you