• Mac mini外接显示器 调整分辨率 HiDPI


    按住commond+R 进入安全模式   

    打开终端   

    输入 csrutil  disable 关闭权限

    重启

    新建脚本 CoreDisplay-patcher.command    内容如下:

    #!/bin/sh
    
    thiscommand=$0
    
    # change for debug purposes
    CoreDisplayLocation="/System/Library/Frameworks/CoreDisplay.framework/Versions/A/CoreDisplay"
    
    # for development
    # CoreDisplayLocation="/Users/<user>/Desktop/CoreDisplay"
    
    # Current CoreDisplay md5 Checksum
    CoreDisplayCurrent="$(md5 -q $CoreDisplayLocation)"
    
    # Current CoreDisplay md5 Checksum of the '(__DATA,__data)' section exported by otool
    # This makes it possible to detect a patch regardless of the signing certificate
    oToolCoreDisplayCurrent="$(otool -t $CoreDisplayLocation |tail -n +2 |md5 -q)"
    
    # md5 checksum of '(__DATA,__data)' section exported by otool from unpatched CoreDisplays
    # for future use of detecting a false patch, where the executible's checksum is changed by codesigning but not the actual code.
    oToolCoreDisplayUnpatched=(
      49cd8062ed1c8f610b71e9a3231cf804 '10.12 16A254g' 1
      8e1030235b90d6ab0644bd7a1b6f9cdb '10.12 16A284a' 1
      f4c6e84ffa97e06624e5504edd87bf7d '10.12 16A284a' 1 # I don't know why these two are different
      4cba52b41ceee7bc658020c9e58780a3 '10.12 16A294a' 1
      d41d8cd98f00b204e9800998ecf8427e '10.12 16A313a' 1
      aa7607dd72a2a4ca70ce094a2fc39cce '10.12  ' 1  # Sierra 10.12 release
      172b7e2fe2e45e99b078e69684dd3c10 '10.12.1' 2
      9c717568024daa81c364a839f09a1bfd '10.12.2 and 10.12.3' 3
      b7e8464b101f343012ba28cbd2db5ee8 '10.12.4 16E195' 3
      54a5a1adfb1225411bacf5c3ee0b4d9a '10.12.5 16F73' 3
      9a653ffdfb5e1bcfaa71412000d0b111 '10.12.6 16G29' 3
      5f51331dce01f1ced84643f6c996e324 '10.13.2 (17C88) and 10.13.3 (17D47)' 4
      6e04ad9d1f2bf43dc01ed92a0ba4b8ac '10.13.4 (17E199)' 4
      a273850d90c3cdf39f17ad63ed43203a '10.13.5 (17F77)' 4
      714a9e14ccc64b0cf4bef2f083087d8e '10.14.2 (18C54)' 5
      176fcc0d47bcdfb463357c3864bf9bd1 '10.14.4 (18E226)' 5
      814fe7a8695f6583d821b5665f6df71a '10.14.5 (18F132)' 5
      105051509e563ba96f190ed78a52feb9 '10.14.6 (18G87)' 5
    )
    
    # md5 checksum of '(__DATA,__data)' section exported by otool from patched CoreDisplays
    oToolCoreDisplayPatched=(
      4e469fbf1c36d96fc25fb931c6670649 '10.12 16A254g'
      b6ee4943c2fce505faceb568e1c8f4b1 '10.12 16A284a'
      82f97933a3ae90d47054316fa8259f6c '10.12 16A284a'
      1371f71ca7949cfbe01ede8e8b52e61d '10.12 16A294a'
      f9c185d9e4c4ba12d5ecf41483055e39 '10.12 16A313a'
      eb27b5d68e9fb15aa65ea0153637eae2 '10.12  '  # Sierra 10.12 release
      cf8373138af4671a561c1a4d6cdba771 '10.12.1'
      e9d7a42b6613a45a69a41e8099d0e369 '10.12.2 and 10.12.3'
      ec01e0df5f71699c77bf2650a1c84f4f '10.12.4 16E195'
      8b876f14be2bf7b1bfd3f89341bce0f6 '10.12.5 16F73'
      6708362921f852600e59e68c3e811eda '10.12.6 16G29'
      a337a6a85264817d78a90122ebbc2723 '10.13.2 (17C88) and 10.13.3 (17D47)'
      11882f5e04a525da6701777c814c920a '10.13.4 (17E199)'
      b5dd02fe05903d7c39791afc642f9b2b '10.13.5 (17F77)'
      2d71736504e14882b2eb5e994859ec09 '10.14.2 (18C54)'
      2d71736504e14882b2eb5e994859ec09 '10.14.4 (18E226)'
      2d71736504e14882b2eb5e994859ec09 '10.14.5 (18F132)'
      2d71736504e14882b2eb5e994859ec09 '10.14.6 (18G87)'
    )
    
    function makeExit {
      printf "Closing...
    "
      exit
    }
    
    function askExit {
      read -p "Do you want to continue? [Y/n] " -n 1 -r
      echo 
      if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        makeExit
      fi
    }
      
    function SIPInfo {
      printf "Google for 'MacOS System Integrity Protection' to get more info on the subject.
    "
    }
    
    function help {
      printf "Using this script without input will patch CoreDisplay if a supported version can be found.
    "
      printf "Supported arguments:
    "
      printf "patch [v1-v3]	 patch on a specific version
    "
      printf "		 eg. $(basename $thiscommand) patch v2
    "
      printf "unpatch		 undo patch
    "
      printf "status		 Shows you if you have an known or unknown patch
    "
      printf "md5		 gives all your md5 hashes
    "
      printf "help		 show this help message
    "
    }
    
    function testSIP {
      if hash csrutil 2>/dev/null; then
        if [[ "$(csrutil status | head -n 1)" == *"status: enabled (Custom Configuration)"* ]]; then
          printf "SIP might or might not be disabled
    "
          printf "This script might or might not be working
    "
          printf "Check "$ csrutil status"
    "
          SIPInfo
          askExit
        elif [[ "$(csrutil status | head -n 1)" == *"status: enabled"* ]]; then
          printf "SIP is enabled, this script will only work if SIP is disabled
    "
          if [[ -z $1 ]]; then
            makeExit
          fi
          
        elif [[ "$(csrutil status | head -n 1)" == *"status: disabled"* ]]; then
          printf "SIP looks to be disabled, all good!
    "
        fi
      fi  
    }
    
    function CoreDisplayPatch {
      testSIP
      case "$1" in
      1)  printf "Patching CoreDisplay with patch version 1
    "
              sudo perl -i.bak -pe '$before = qr"xB8x01x00x00x00xF6xC1x01x0Fx85x05x04x00x00"s;s/$before/x31xC0x90x90x90x0Fx1Fx00xE9x06x04x00x00x90/g' $CoreDisplayLocation
              sudo touch /System/Library/Extensions
              printf "Re-signing $CoreDisplayLocation
    "
              sudo codesign -f -s - $CoreDisplayLocation
              ;;
      2)  printf "Patching CoreDisplay with patch version 2
    "
            sudo perl -i.bak -pe '$before = qr"xB8x01x00x00x00xF6xC1x01x0Fx85x96x04x00x00"s;s/$before/x31xC0x90x90x90x90x90x90xE9x97x04x00x00x90/g' $CoreDisplayLocation
             sudo touch /System/Library/Extensions
              printf "Re-signing $CoreDisplayLocation
    "
              sudo codesign -f -s - $CoreDisplayLocation
              ;;
      3)  printf "Patching CoreDisplay with patch version 3
    "
              sudo perl -i.bak -pe '$before = qr"xB8x01x00x00x00xF6xC1x01x0Fx85xADx04x00x00"s;s/$before/x31xC0x90x90x90x90x90x90xE9xAEx04x00x00x90/g' $CoreDisplayLocation
              sudo touch /System/Library/Extensions
              printf "Re-signing $CoreDisplayLocation
    "
              sudo codesign -f -s - $CoreDisplayLocation
              ;;
      4)  printf "Patching CoreDisplay with patch version 4
    "
              sudo perl -i.bak -pe '$oldtest1 = qr"xE8x37x02x00x00xBBxE6x02x00xE0x85xC0x0Fx85x9Cx00x00x00"s;$newtest1 = "xE8x37x02x00x00xBBxE6x02x00xE0x31xC0x0Fx85x9Cx00x00x00"; $oldtest2 = qr"xE8x65x00x00x00x85xC0xBBxE6x02x00xE0x0Fx85xCAxFExFFxFF"s;$newtest2 = "xE8x65x00x00x00x31xC0xBBxE6x02x00xE0x0Fx85xCAxFExFFxFF";s/$oldtest1/$newtest1/g;s/$oldtest2/$newtest2/g' $CoreDisplayLocation
               sudo touch /System/Library/Extensions
            printf "Re-signing $CoreDisplayLocation
    "
            sudo codesign -f -s - $CoreDisplayLocation
            printf "Running 'sudo update_dyld_shared_cache' (Might need a re-run after reboot) - CAN TAKE A WHILE (Maybe even 10/30 minutes)"
            sudo update_dyld_shared_cache
            ;;
      # Version 5 is an experimental patch for Mojave 10.14.1 and 10.14.2 from https://github.com/Floris497/mac-pixel-clock-patch-V2/issues/280.
      5)  printf "Patching CoreDisplay with patch version 5
    "
            sudo perl -i.bak -pe '$before = qr"xBBx01x00x00x00xA8x01x0Fx85"s;s/$before/x31xDBx90x90x90x90x90x90xE9/g' $CoreDisplayLocation
            sudo touch /System/Library/Extensions
            printf "Re-signing $CoreDisplayLocation
    "
            sudo codesign -f -s - $CoreDisplayLocation
            sudo update_dyld_shared_cache
            ;;
      *)  printf "This patch does not exist, make sure you used the right patch identfier
    "
          exit
          ;;
      esac
    }
    
    function CoreDisplayUnpatch {
      testSIP
      
      if [[ -f "$CoreDisplayLocation.bak" ]]; then
        printf "Moving backup file back in place
    "
        sudo mv $CoreDisplayLocation.bak $CoreDisplayLocation
      else 
        printf "No backup found, the patch has either not been applied, or the backup file has been deleted."
      fi
    }
    
    function CoreDisplayPrintAllMD5 {
      echo "---- BEGINNING MD5 HASH SUMS ---- version: $(sw_vers -productVersion) build:$(sw_vers -buildVersion)"
      echo
      printf "     otool CoreDisplay: $(otool -t $CoreDisplayLocation |tail -n +2 |md5 -q)
    "
      if [[ -f "$CoreDisplayLocation.bak" ]]; then
        printf " otool CoreDisplay.bak: $(otool -t $CoreDisplayLocation.bak |tail -n +2 |md5 -q)
    "
      else
        printf " otool CoreDisplay.bak: NO FILE (this is okay)
    "
      fi
      printf "           CoreDisplay: $(md5 -q $CoreDisplayLocation)
    "
      if [[ -f "$CoreDisplayLocation.bak" ]]; then
        printf "       CoreDisplay.bak: $(md5 -q $CoreDisplayLocation.bak)
    "
      else
        printf "       CoreDisplay.bak: NO FILE (this is okay)
    "
      fi
      echo
      echo "---- ENDING MD5 HASH SUMS -------"
    }
    
    function testCoreDisplayPatch {
      if [[ ! -f "$CoreDisplayLocation.bak" ]]; then
        echo "Patch failed to run"
      elif [[ $(otool -t $CoreDisplayLocation.bak |tail -n +2 |md5 -q) !=  $(otool -t $CoreDisplayLocation |tail -n +2 |md5 -q) ]]; then
        echo "The code of CoreDisplay changed, the patch was probably successful."
      else
        echo "The code is still the same. Patch seemed to run, but was probably for the wrong version."
        echo "If you are running a new OS, run $thiscommand md5 and ask the maintainer of this script to add support for your system."
      fi
    
    }
    
    function test {
      if [[ ! -z $1 && $1 == "status" ]]; then
        testSIP "Don't Exit"  # Just checking patch status, can do it even if SIP is enabled
      else
        testSIP
      fi
      
      printf "
    "
      nothingWasFound=true;
      for ((i=0; i < ${#CoreDisplayUnpatched[@]}; i+=3)); do
        if [[ $CoreDisplayCurrent == ${CoreDisplayUnpatched[$i]} ]]; then
          printf "Detected unpatched CoreDisplay on OS X %s.
    " "${CoreDisplayUnpatched[$i+1]}"
          nothingWasFound=false
          if [[ ! -z $1 ]]; then
            if [[ $1 == "patch" ]]; then
              CoreDisplayPatch ${CoreDisplayUnpatched[$i+2]}
              makeExit
            fi
          fi
        fi
      done
      for ((i=0; i < ${#oToolCoreDisplayUnpatched[@]}; i+=3)); do
        if [[ $oToolCoreDisplayCurrent == ${oToolCoreDisplayUnpatched[$i]} ]]; then
          printf "(otool) Detected unpatched CoreDisplay on OS X %s.
    " "${oToolCoreDisplayUnpatched[$i+1]}"
          nothingWasFound=false
          if [[ ! -z $1 ]]; then
            if [[ $1 == "patch" ]]; then
              CoreDisplayPatch ${oToolCoreDisplayUnpatched[$i+2]} 
              makeExit
            fi
          fi
        fi
      done
      for ((i=0; i < ${#CoreDisplayPatched[@]}; i+=2)); do
        if [[ $CoreDisplayCurrent == ${CoreDisplayPatched[$i]} ]]; then
          printf "Detected patched CoreDisplay on OS X %s.
    " "${CoreDisplayPatched[$i+1]}"
          nothingWasFound=false
        fi
      done
      for ((i=0; i < ${#oToolCoreDisplayPatched[@]}; i+=2)); do
        if [[ $oToolCoreDisplayCurrent == ${oToolCoreDisplayPatched[$i]} ]]; then
          printf "(otool) Detected patched CoreDisplay on OS X %s.
    " "${oToolCoreDisplayPatched[$i+1]}"
          nothingWasFound=false
        fi
      done
      if $nothingWasFound; then
        echo "Unknown version of CoreDisplay found."
        CoreDisplayPrintAllMD5
      fi
    }
    
    
    function options {
      if [[ $1 == "patch" ]]; then
        #test if there is a backup file
        if [[ -f "$CoreDisplayLocation.bak" ]]; then
          printf "A backup file already exists - If you force this patch on an already patched version you will lose your original backup!
    "
          printf "Be careful: Having no working version of CoreDisplay requires you to reinstall the OS.
    "
          printf "It might be wise to undo the patch before trying to redo it using: $thiscommand unpatch
    "
          askExit
        fi
        if [[ -z $2 ]]; then
          printf "Did not specify patch version
    "
          makeExit
        fi
        case "$2" in
          v1) CoreDisplayPatch 1;;
          v2) CoreDisplayPatch 2;;
          v3) CoreDisplayPatch 3;;
          v4) CoreDisplayPatch 4;;
          v5) CoreDisplayPatch 5;;
          *)  CoreDisplayPatch 0;;
        esac
        testCoreDisplayPatch 
        exit 
      elif [[ $1 == 'unpatch' ]] || [[ $1 == 'depatch' ]]; then
        if [[ ! -f "$CoreDisplayLocation.bak" ]]; then
          printf "There is no backup file, we cannot undo the patch. The patch might have not even been applied.
    "
          makeExit
        fi
        CoreDisplayUnpatch
      elif [[ $1 == 'test' ]] || [[ $1 == 'status' ]]; then
        test 'status'
        exit
      elif [[ $1 == 'md5' ]]; then
        CoreDisplayPrintAllMD5
        exit
      elif [[ $1 == 'help' ]] || [[ $1 == '-h' ]] || [[ $1 == '--help' ]]; then
        help
        exit
      elif [[ -z $1 ]]; then
        test "patch"
        exit
      else
        printf "Option is not valid
    "
        printf "
    "
          help
        exit
      fi
    }
    
    # Run the script
    options $1 $2

    执行脚本

    ..... 省略

    logout

    Saving session...

    ...copying shared history...

    ...saving history...truncating history files...

    ...completed.

    Deleting expired sessions...76 completed.

     

    [进程已完成]

    完成

    重启电脑

    打开设置 调整分辨率

  • 相关阅读:
    MOSS发生“未能转换部分或所有标识引用”错误的处理
    Excel嵌入网页(二) 转载
    GridView的PagerTemplate分页
    深入探讨:如何理解.Net的三层架构(转)
    IIS报Service Unavailable错的解决方案
    浅谈C#托管程序中的资源释放问题(转)
    C#程序节省内存
    网页中嵌入Excel控件(补充)
    解决ajax的status=0问题
    翻开我的博客之旅
  • 原文地址:https://www.cnblogs.com/arvin-an/p/11777898.html
Copyright © 2020-2023  润新知