]> git.saurik.com Git - cycript.git/blobdiff - trampoline.sh
Prefer __NSCFBoolean to non-__ for iOS compatibility.
[cycript.git] / trampoline.sh
index 81ac2ce7afdc50b48e83a5bb763380b097bcd8dd..7c3cfaf7b8d1d2687034d28cc5c41da5de24e2a0 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+set -e
+
 shopt -s extglob
 
 hpp=$1
@@ -16,19 +18,31 @@ shift 7
 
 "$@"
 
-detailed=$(lipo -detailed_info "${object}")
+detailed=$("${lipo}" -detailed_info "${object}")
 
 {
 
+regex=$'\nNon-fat file: .* is architecture: (.*)'
+if [[ ${detailed} =~ ${regex} ]]; then
+    archs=(${BASH_REMATCH[1]})
+    unset detailed
+else
+    archs=($(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;'))
+fi
+
 echo '#include "Trampoline.hpp"'
 
-for arch in $(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;'); do
-    offset=$(echo "${detailed}" | "${sed}" -e '
-        /^architecture / { x; s/.*/0/; x; };
-        /^architecture '${arch}'$/ { x; s/.*/1/; x; };
-        x; /^1$/ { x; /^ *offset / { s/^ *offset //; p; }; x; }; x;
-        d;
-    ')
+for arch in "${archs[@]}"; do
+    if [[ "${detailed+@}" ]]; then
+        offset=$(echo "${detailed}" | "${sed}" -e '
+            /^architecture / { x; s/.*/0/; x; };
+            /^architecture '${arch}'$/ { x; s/.*/1/; x; };
+            x; /^1$/ { x; /^ *offset / { s/^ *offset //; p; }; x; }; x;
+            d;
+        ')
+    else
+        offset=0
+    fi
 
     file=($("${otool}" -arch "${arch}" -l "${object}" | "${sed}" -e '
         x; /^1$/ { x;
@@ -52,7 +66,7 @@ for arch in $(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architectu
             s@^        @//  @;
             s/\(....\)/ \1/g;
             s@^ // @//@;
-            s/ *$//;
+            s/ *$/,/;
         };
 
         /^[0-7]/ {