]> git.saurik.com Git - cycript.git/blame - trampoline.sh
Add Objective-C @ prefix to CYONified primitives.
[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
25echo '#include "Trampoline.hpp"'
26
27for 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@^ // @//@;
73d3a679 57 s/ *$/,/;
eed4f174
JF
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 "};"
90done
91
92} >"${hpp}"
93
94#rm -f "${object}"