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