]> git.saurik.com Git - cycript.git/blame - trampoline.sh
Use new ^ syntax to bridge Blocks (with @ offset).
[cycript.git] / trampoline.sh
CommitLineData
eed4f174
JF
1#!/bin/bash
2
eaf660f1
JF
3set -e
4
eed4f174
JF
5shopt -s extglob
6
7hpp=$1
8object=$2
9name=$3
10sed=$4
11otool=$5
12lipo=$6
13nm=$7
14shift 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
fae1d9be 21detailed=$("${lipo}" -detailed_info "${object}")
eed4f174
JF
22
23{
24
6d3af51e
JF
25regex=$'\nNon-fat file: .* is architecture: (.*)'
26if [[ ${detailed} =~ ${regex} ]]; then
27 archs=(${BASH_REMATCH[1]})
28 unset detailed
29else
30 archs=($(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;'))
31fi
32
eed4f174
JF
33echo '#include "Trampoline.hpp"'
34
6d3af51e
JF
35for arch in "${archs[@]}"; do
36 if [[ "${detailed+@}" ]]; then
37 offset=$(echo "${detailed}" | "${sed}" -e '
38 /^architecture / { x; s/.*/0/; x; };
39 /^architecture '${arch}'$/ { x; s/.*/1/; x; };
40 x; /^1$/ { x; /^ *offset / { s/^ *offset //; p; }; x; }; x;
41 d;
42 ')
43 else
44 offset=0
45 fi
eed4f174
JF
46
47 file=($("${otool}" -arch "${arch}" -l "${object}" | "${sed}" -e '
48 x; /^1$/ { x;
49 /^ *fileoff / { s/^.* //; p; };
50 /^ *filesize / { s/^.* //; p; };
51 x; }; x;
52
53 /^ *cmd LC_SEGMENT/ { x; s/.*/1/; x; };
54
55 d;
56 '))
57
58 fileoff=${file[0]}
59 filesize=${file[1]}
60
61 echo
62 echo "static const char ${name}_${arch}_data_[] = {"
63
64 od -v -t x1 -t c -j "$((offset + fileoff))" -N "${filesize}" "${object}" | "${sed}" -e '
65 /^[0-7]/ ! {
66 s@^ @// @;
67 s/\(....\)/ \1/g;
68 s@^ // @//@;
73d3a679 69 s/ *$/,/;
eed4f174
JF
70 };
71
72 /^[0-7]/ {
73 s/^[^ ]*//;
74 s/ */ /g;
75 s/^ *//;
76 s/ $//;
77 s/ /,/g;
78 s/\([^,][^,]\)/0x\1/g;
79 s/$/,/;
80 /^,$/ ! { s/^/ /g; p; }; d;
81 };
82 '
83
84 echo "};"
85
86 echo
87 entry=$("${nm}" -arch "${arch}" "${object}" | "${sed}" -e '/ _Start$/ { s/ .*//; p; }; d;')
88 entry=${entry##*(0)}
89 echo "static size_t ${name}_${arch}_entry_ = 0x${entry:=0};"
90
91 echo
92 echo "/*"
93 "${otool}" -vVt -arch "${arch}" "${object}"
94 echo "*/"
95
96 echo
97 echo "static Trampoline ${name}_${arch}_ = {"
98 echo " ${name}_${arch}_data_,"
99 echo " sizeof(${name}_${arch}_data_),"
100 echo " ${name}_${arch}_entry_,"
101 echo "};"
102done
103
104} >"${hpp}"
105
106#rm -f "${object}"