make_more_helpers.sh 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE-CHROMIUM file.
  5. # Usage: make_more_helpers.sh <directory_within_contents> <app_name>
  6. #
  7. # This script creates additional helper .app bundles for Chromium, based on
  8. # the existing helper .app bundle, changing their Mach-O header's flags to
  9. # enable and disable various features. Based on Chromium Helper.app, it will
  10. # create Chromium Helper EH.app, which has the MH_NO_HEAP_EXECUTION bit
  11. # cleared to support Chromium child processes that require an executable heap,
  12. # and Chromium Helper NP.app, which has the MH_PIE bit cleared to support
  13. # Chromium child processes that cannot tolerate ASLR.
  14. #
  15. # This script expects to be called from the chrome_exe target as a postbuild,
  16. # and operates directly within the built-up browser app's versioned directory.
  17. #
  18. # Each helper is adjusted by giving it the proper bundle name, renaming the
  19. # executable, adjusting several Info.plist keys, and changing the executable's
  20. # Mach-O flags.
  21. set -eu
  22. make_helper() {
  23. local containing_dir="${1}"
  24. local app_name="${2}"
  25. local feature="${3}"
  26. local flags="${4}"
  27. local helper_name="${app_name} Helper"
  28. local helper_stem="${containing_dir}/${helper_name}"
  29. local original_helper="${helper_stem}.app"
  30. if [[ ! -d "${original_helper}" ]]; then
  31. echo "${0}: error: ${original_helper} is a required directory" >& 2
  32. exit 1
  33. fi
  34. local original_helper_exe="${original_helper}/Contents/MacOS/${helper_name}"
  35. if [[ ! -f "${original_helper_exe}" ]]; then
  36. echo "${0}: error: ${original_helper_exe} is a required file" >& 2
  37. exit 1
  38. fi
  39. local feature_helper="${helper_stem} ${feature}.app"
  40. rsync -acC --delete --include '*.so' "${original_helper}/" "${feature_helper}"
  41. local helper_feature="${helper_name} ${feature}"
  42. local helper_feature_exe="${feature_helper}/Contents/MacOS/${helper_feature}"
  43. mv "${feature_helper}/Contents/MacOS/${helper_name}" "${helper_feature_exe}"
  44. local change_flags="$(dirname "${0}")/change_mach_o_flags.py"
  45. "${change_flags}" ${flags} "${helper_feature_exe}"
  46. local feature_info="${feature_helper}/Contents/Info"
  47. local feature_info_plist="${feature_info}.plist"
  48. defaults write "${feature_info}" "CFBundleDisplayName" "${helper_feature}"
  49. defaults write "${feature_info}" "CFBundleExecutable" "${helper_feature}"
  50. cfbundleid="$(defaults read "${feature_info}" "CFBundleIdentifier")"
  51. feature_cfbundleid="${cfbundleid}.${feature}"
  52. defaults write "${feature_info}" "CFBundleIdentifier" "${feature_cfbundleid}"
  53. cfbundlename="$(defaults read "${feature_info}" "CFBundleName")"
  54. feature_cfbundlename="${cfbundlename} ${feature}"
  55. defaults write "${feature_info}" "CFBundleName" "${feature_cfbundlename}"
  56. # As usual, defaults might have put the plist into whatever format excites
  57. # it, but Info.plists get converted back to the expected XML format.
  58. plutil -convert xml1 "${feature_info_plist}"
  59. # `defaults` also changes the file permissions, so make the file
  60. # world-readable again.
  61. chmod a+r "${feature_info_plist}"
  62. }
  63. if [[ ${#} -ne 2 ]]; then
  64. echo "usage: ${0} <directory_within_contents> <app_name>" >& 2
  65. exit 1
  66. fi
  67. DIRECTORY_WITHIN_CONTENTS="${1}"
  68. APP_NAME="${2}"
  69. CONTENTS_DIR="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}"
  70. CONTAINING_DIR="${CONTENTS_DIR}/${DIRECTORY_WITHIN_CONTENTS}"
  71. make_helper "${CONTAINING_DIR}" "${APP_NAME}" "EH" "--executable-heap"
  72. make_helper "${CONTAINING_DIR}" "${APP_NAME}" "NP" "--no-pie"