3 # Cycript - Optimizing JavaScript Compiler/Runtime
4 # Copyright (C) 2009-2013 Jay Freeman (saurik)
6 # GNU General Public License, Version 3 {{{
8 # Cycript is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published
10 # by the Free Software Foundation, either version 3 of the License,
11 # or (at your option) any later version.
13 # Cycript is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Cycript. If not, see <http://www.gnu.org/licenses/>.
34 detailed
=$("${lipo}" -detailed_info "${object}")
36 regex
=$
'\nNon-fat file: .* is architecture: (.*)'
37 if [[ ${detailed} =~
${regex} ]]; then
38 archs
=(${BASH_REMATCH[1]})
41 archs
=($(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;'))
44 echo '#include "Trampoline.hpp"'
46 for arch
in "${archs[@]}"; do
47 if [[ "${detailed+@}" ]]; then
48 offset
=$
(echo "${detailed}" | "${sed}" -e '
49 /^architecture / { x; s/.*/0/; x; };
50 /^architecture '${arch}'$/ { x; s/.*/1/; x; };
51 x; /^1$/ { x; /^ *offset / { s/^ *offset //; p; }; x; }; x;
58 file=($
("${otool}" -arch "${arch}" -l "${object}" | "${sed}" -e '
60 /^ *fileoff / { s/^.* //; p; };
61 /^ *filesize / { s/^.* //; p; };
64 /^ *cmd LC_SEGMENT/ { x; s/.*/1/; x; };
73 echo "static const char ${name}_${arch}_data_[] = {"
75 LANG
=C
od -v -t x1
-t c
-j "$((offset + fileoff))" -N "${filesize}" "${object}" | "${sed}" -e '
89 s/\([^,][^,]\)/0x\1/g;
91 /^,$/ ! { s/^/ /g; p; }; d;
98 entry
=$("${nm}" -arch "${arch}" "${object}" | "${sed}" -e '/ _Start$/ { s/ .*//; p; }; d;')
100 echo "static size_t ${name}_${arch}_entry_ = 0x${entry:=0};"
104 "${otool}" -arch "${arch}" -vVt "${object}"
108 echo "_disused static Trampoline ${name}_${arch}_ = {"
109 echo " ${name}_${arch}_data_,"
110 echo " sizeof(${name}_${arch}_data_),"
111 echo " ${name}_${arch}_entry_,"