Last active
June 17, 2025 06:14
-
-
Save Willian-Zhang/c34861d2010414bd972f48d32d8d7006 to your computer and use it in GitHub Desktop.
Mac enable AI Fix 15.4.1
This file contains hidden or 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 | |
| if [[ $EUID -ne 0 ]]; then | |
| sleep 3 | |
| echo "Not running as root" | |
| exit 3 | |
| fi | |
| label=com.apple.eligibilityd | |
| getpid() { | |
| pgrep eligibilityd | |
| } | |
| detect_invoker() { | |
| ppid=$(ps -o ppid= -p $$ | tr -d ' ') | |
| parent=$(ps -o comm= -p $ppid) | |
| if [[ "$parent" == "launchd" || "$parent" == "/sbin/launchd" ]]; then | |
| echo "[INFO] Started by launchd/launchctl (parent: $parent)" | |
| return 0 | |
| else | |
| echo "[INFO] Started from terminal or other process: $parent" | |
| return 1 | |
| fi | |
| } | |
| check_and_install_launchd() { | |
| INSTALL_PATH="/usr/local/bin/eligibilityfix.sh" | |
| if [[ ! -f "$INSTALL_PATH" ]]; then | |
| sudo mkdir -p /usr/local/bin | |
| sudo cp "$0" "$INSTALL_PATH" | |
| sudo chmod +x "$INSTALL_PATH" | |
| echo "Installed to $INSTALL_PATH" | |
| fi | |
| LAUNCHD_PLIST=/Library/LaunchDaemons/com.chinaSKU.eligibility.fix.plist | |
| if [[ ! -f "$LAUNCHD_PLIST" ]]; then | |
| cat <<EOL | sudo tee $LAUNCHD_PLIST > /dev/null | |
| <?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>Label</key> | |
| <string>com.chinaSKU.eligibility.fix</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/bin/bash</string> | |
| <string>/usr/local/bin/eligibilityfix.sh</string> | |
| </array> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| <key>KeepAlive</key> | |
| <dict> | |
| <key>OtherJobEnabled</key> | |
| <dict> | |
| <key>com.apple.eligibilityd</key> | |
| <true/> | |
| </dict> | |
| </dict> | |
| <key>StandardErrorPath</key> | |
| <string>/tmp/eligibilityfix.err</string> | |
| <key>StandardOutPath</key> | |
| <string>/tmp/eligibilityfix.log</string> | |
| </dict> | |
| </plist> | |
| EOL | |
| sudo chown root:wheel $LAUNCHD_PLIST | |
| sudo chmod 644 $LAUNCHD_PLIST | |
| sudo launchctl load "$LAUNCHD_PLIST" | |
| fi | |
| } | |
| detect_invoker | |
| TEMP_PID_FILE="/tmp/eligibilityfix.pid" | |
| PID=$(pgrep eligibilityd) | |
| if [ ! -z "$PID" ]; then | |
| echo "eligibilityd found with PID $PID" | |
| # Check if we've already handled this PID | |
| if [ -f "$TEMP_PID_FILE" ] && [ "$(cat $TEMP_PID_FILE)" == "$PID" ]; then | |
| echo "Already processed eligibilityd with PID $PID" | |
| else | |
| lldb --batch \ | |
| -o "process attach --name eligibilityd" \ | |
| -o 'e (void) [[[InputManager sharedInstance] objectForInputValue:6] setValue:@"US" forKey:@"_deviceRegionCode"]' \ | |
| -o 'e (void) [[EligibilityEngine sharedInstance] recomputeAllDomainAnswers]' \ | |
| -o "process detach" \ | |
| -o quit || { echo "lldb command failed"; sleep 3; exit 1; } | |
| lldb -b <<'LLDB' || { echo "lldb command hook failed"; sleep 3; exit 4; } | |
| process attach --name eligibilityd | |
| expr -l objc -- @import ObjectiveC | |
| expr -l objc -- method_setImplementation( class_getInstanceMethod(objc_getClass("GlobalConfiguration"), sel_getUid("supportsForcedAnswers")), imp_implementationWithBlock(^BOOL(id _self){ return YES; })) | |
| expr -l objc -- method_setImplementation( class_getInstanceMethod(objc_getClass("DeviceRegionCodeInput"), sel_getUid("isChinaSKU")), imp_implementationWithBlock(^BOOL(id _self){ return NO; })) | |
| process detach | |
| quit | |
| LLDB | |
| out=$(lldb -b \ | |
| -o 'process attach --name eligibilityd' \ | |
| -o 'expr -- (int)[[GlobalConfiguration new] supportsForcedAnswers]' \ | |
| -o quit 2>/dev/null) || { echo "lldb command hook failed"; sleep 3; exit 5; } | |
| val=$(echo "$out" | awk -F'= ' '/=/{v=$2} END{print v}') | |
| [ "$val" = 0 ] && exit 5 | |
| out=$(lldb -b \ | |
| -o 'process attach --name eligibilityd' \ | |
| -o 'expr -- (int)[[DeviceRegionCodeInput new] isChinaSKU]' \ | |
| -o quit 2>/dev/null) || { echo "lldb command hook failed"; sleep 3; exit 6; } | |
| val=$(echo "$out" | awk -F'= ' '/=/{v=$2} END{print v}') | |
| [ "$val" = 1 ] && exit 6 | |
| # Save PID to temp file only if lldb command succeeded | |
| echo "$PID" > "$TEMP_PID_FILE" | |
| echo "Successfully processed and saved PID" | |
| fi | |
| else | |
| echo "eligibilityd not found" | |
| check_and_install_launchd | |
| sleep 1 | |
| exit 2 | |
| fi | |
| check_and_install_launchd | |
| echo "Done!!!" | |
| if detect_invoker; then | |
| echo "Running from launchd/launchctl, waiting for eligibilityd to restart" | |
| while :; do | |
| curPID=$(getpid) | |
| if [ -n "$curPID" ] && [ "$curPID" != "$PID" ]; then | |
| echo "eligibilityd PID changed from $PID to $curPID" | |
| exit 0 | |
| fi | |
| sleep 2 | |
| done | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update: run does not loop on terminal exec. more log details