diff --git a/patcher b/patcher index 558a01d..379f73b 100755 --- a/patcher +++ b/patcher @@ -7,6 +7,10 @@ export LC_ALL=C # This variable is used as a command. Set it to either true or false. It's case-sensitive. debug=false +if ${debug}; then + set -x +fi + iOS12_usrlib=( "libDHCPServer.dylib" "libMatch.dylib" "libSystem.B_asan.dylib" "libSystem.dylib" "libSystem_asan.dylib" "libarchive.dylib" @@ -52,8 +56,7 @@ sed_stdout() { } sed_file() { - sed -i "" "$1" "$2" 2&> /dev/null - printf "$2" + sed -i "" "$1" "$2" 2> /dev/null } patch_strings() { @@ -65,22 +68,22 @@ patch_strings() { elif [ "$1" == "-f" ]; then sed="sed_file" else return 1; fi - result="$(${sed} 's/\/Library\//\/var\/LIB\//g' "${result}")" - result="$(${sed} 's/\/System\/var\/LIB\//\/System\/Library\//g' "${result}")" - result="$(${sed} 's/%@\/var\/LIB\//%@\/Library\//g' "${result}")" - result="$(${sed} 's/mobile\/var\/LIB\//mobile\/Library\//g' "${result}")" + result=$(${sed} 's/\/Library\//\/var\/LIB\//g' "${result}") + result=$(${sed} 's/\/System\/var\/LIB\//\/System\/Library\//g' "${result}") + result=$(${sed} 's/%@\/var\/LIB\//%@\/Library\//g' "${result}") + result=$(${sed} 's/mobile\/var\/LIB\//mobile\/Library\//g' "${result}") # The trick: # 1. Replace every "/usr/lib" with "/var/lib" # 2. Iterate over iOS12_usrlib and revert the system libraries # This way, we only need to hardcode the system libraries which will never change. We won't need to hardcode the libraries that are for jailbroken devices. - result="$(${sed} 's/\/usr\/lib\//\/var\/ulb\//g' "${result}")" + result=$(${sed} 's/\/usr\/lib\//\/var\/ulb\//g' "${result}") if [ $? -eq 0 ]; then for usr_lib_system_file in "${iOS12_usrlib[@]}"; do escaped_dot='\.' escaped_file="${usr_lib_system_file//./${escaped_dot}}" expression='s/\/var\/ulb\/'"${escaped_file}"'/\/usr\/lib\/'"${escaped_file}"'/g' - result="$(${sed} "${expression}" "${result}")" + result=$(${sed} "${expression}" "${result}") done fi [ "$1" == "-r" ] && printf "${result}"