]> git.saurik.com Git - cycript.git/blob - trampoline.sh
Fix silly mistake in control.in causing 0.9.0.9.*.
[cycript.git] / trampoline.sh
1 #!/bin/bash
2
3 set -e
4
5 shopt -s extglob
6
7 hpp=$1
8 object=$2
9 name=$3
10 sed=$4
11 otool=$5
12 lipo=$6
13 nm=$7
14 shift 7
15
16 #shift 1
17 #set /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr/include "$@"
18
19 "$@"
20
21 detailed=$("${lipo}" -detailed_info "${object}")
22
23 {
24
25 echo '#include "Trampoline.hpp"'
26
27 for arch in $(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;'); do
28 offset=$(echo "${detailed}" | "${sed}" -e '
29 /^architecture / { x; s/.*/0/; x; };
30 /^architecture '${arch}'$/ { x; s/.*/1/; x; };
31 x; /^1$/ { x; /^ *offset / { s/^ *offset //; p; }; x; }; x;
32 d;
33 ')
34
35 file=($("${otool}" -arch "${arch}" -l "${object}" | "${sed}" -e '
36 x; /^1$/ { x;
37 /^ *fileoff / { s/^.* //; p; };
38 /^ *filesize / { s/^.* //; p; };
39 x; }; x;
40
41 /^ *cmd LC_SEGMENT/ { x; s/.*/1/; x; };
42
43 d;
44 '))
45
46 fileoff=${file[0]}
47 filesize=${file[1]}
48
49 echo
50 echo "static const char ${name}_${arch}_data_[] = {"
51
52 od -v -t x1 -t c -j "$((offset + fileoff))" -N "${filesize}" "${object}" | "${sed}" -e '
53 /^[0-7]/ ! {
54 s@^ @// @;
55 s/\(....\)/ \1/g;
56 s@^ // @//@;
57 s/ *$/,/;
58 };
59
60 /^[0-7]/ {
61 s/^[^ ]*//;
62 s/ */ /g;
63 s/^ *//;
64 s/ $//;
65 s/ /,/g;
66 s/\([^,][^,]\)/0x\1/g;
67 s/$/,/;
68 /^,$/ ! { s/^/ /g; p; }; d;
69 };
70 '
71
72 echo "};"
73
74 echo
75 entry=$("${nm}" -arch "${arch}" "${object}" | "${sed}" -e '/ _Start$/ { s/ .*//; p; }; d;')
76 entry=${entry##*(0)}
77 echo "static size_t ${name}_${arch}_entry_ = 0x${entry:=0};"
78
79 echo
80 echo "/*"
81 "${otool}" -vVt -arch "${arch}" "${object}"
82 echo "*/"
83
84 echo
85 echo "static Trampoline ${name}_${arch}_ = {"
86 echo " ${name}_${arch}_data_,"
87 echo " sizeof(${name}_${arch}_data_),"
88 echo " ${name}_${arch}_entry_,"
89 echo "};"
90 done
91
92 } >"${hpp}"
93
94 #rm -f "${object}"