]>
Commit | Line | Data |
---|---|---|
944dc32c | 1 | #!/usr/bin/env bash |
eed4f174 | 2 | |
c15969fd JF |
3 | # Cycript - Optimizing JavaScript Compiler/Runtime |
4 | # Copyright (C) 2009-2013 Jay Freeman (saurik) | |
5 | ||
6 | # GNU General Public License, Version 3 {{{ | |
7 | # | |
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. | |
12 | # | |
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. | |
17 | # | |
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/>. | |
20 | # }}} | |
21 | ||
eaf660f1 JF |
22 | set -e |
23 | ||
eed4f174 JF |
24 | hpp=$1 |
25 | object=$2 | |
26 | name=$3 | |
27 | sed=$4 | |
a243b558 JF |
28 | lipo=$5 |
29 | nm=$6 | |
30 | otool=$7 | |
eed4f174 | 31 | |
a243b558 | 32 | exec >"${hpp}" |
eed4f174 | 33 | |
fae1d9be | 34 | detailed=$("${lipo}" -detailed_info "${object}") |
eed4f174 | 35 | |
6d3af51e JF |
36 | regex=$'\nNon-fat file: .* is architecture: (.*)' |
37 | if [[ ${detailed} =~ ${regex} ]]; then | |
38 | archs=(${BASH_REMATCH[1]}) | |
39 | unset detailed | |
40 | else | |
41 | archs=($(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;')) | |
42 | fi | |
43 | ||
eed4f174 JF |
44 | echo '#include "Trampoline.hpp"' |
45 | ||
6d3af51e JF |
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; | |
52 | d; | |
53 | ') | |
54 | else | |
55 | offset=0 | |
56 | fi | |
eed4f174 JF |
57 | |
58 | file=($("${otool}" -arch "${arch}" -l "${object}" | "${sed}" -e ' | |
59 | x; /^1$/ { x; | |
60 | /^ *fileoff / { s/^.* //; p; }; | |
61 | /^ *filesize / { s/^.* //; p; }; | |
62 | x; }; x; | |
63 | ||
64 | /^ *cmd LC_SEGMENT/ { x; s/.*/1/; x; }; | |
a243b558 | 65 | |
eed4f174 JF |
66 | d; |
67 | ')) | |
68 | ||
69 | fileoff=${file[0]} | |
70 | filesize=${file[1]} | |
71 | ||
72 | echo | |
73 | echo "static const char ${name}_${arch}_data_[] = {" | |
74 | ||
75 | od -v -t x1 -t c -j "$((offset + fileoff))" -N "${filesize}" "${object}" | "${sed}" -e ' | |
76 | /^[0-7]/ ! { | |
77 | s@^ @// @; | |
78 | s/\(....\)/ \1/g; | |
79 | s@^ // @//@; | |
73d3a679 | 80 | s/ *$/,/; |
eed4f174 JF |
81 | }; |
82 | ||
83 | /^[0-7]/ { | |
84 | s/^[^ ]*//; | |
85 | s/ */ /g; | |
86 | s/^ *//; | |
87 | s/ $//; | |
88 | s/ /,/g; | |
89 | s/\([^,][^,]\)/0x\1/g; | |
90 | s/$/,/; | |
91 | /^,$/ ! { s/^/ /g; p; }; d; | |
92 | }; | |
93 | ' | |
94 | ||
95 | echo "};" | |
96 | ||
97 | echo | |
98 | entry=$("${nm}" -arch "${arch}" "${object}" | "${sed}" -e '/ _Start$/ { s/ .*//; p; }; d;') | |
99 | entry=${entry##*(0)} | |
100 | echo "static size_t ${name}_${arch}_entry_ = 0x${entry:=0};" | |
101 | ||
102 | echo | |
103 | echo "/*" | |
a243b558 | 104 | "${otool}" -arch "${arch}" -vVt "${object}" |
eed4f174 JF |
105 | echo "*/" |
106 | ||
107 | echo | |
a69dc826 | 108 | echo "_disused static Trampoline ${name}_${arch}_ = {" |
eed4f174 JF |
109 | echo " ${name}_${arch}_data_," |
110 | echo " sizeof(${name}_${arch}_data_)," | |
111 | echo " ${name}_${arch}_entry_," | |
112 | echo "};" | |
eed4f174 | 113 | |
a243b558 | 114 | done |