├── .gitignore ├── libsubstrate.dylib ├── Makefile ├── codesign ├── codesign_fix.cpp ├── README.md └── substrate.h /.gitignore: -------------------------------------------------------------------------------- 1 | codesign_fix.dylib 2 | -------------------------------------------------------------------------------- /libsubstrate.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conradev/codesign_fix/HEAD/libsubstrate.dylib -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean all 2 | 3 | all: 4 | @ clang -dynamiclib codesign_fix.cpp -L. -lsubstrate -o codesign_fix.dylib 5 | 6 | clean: 7 | @ rm -f codesign_fix.dylib 8 | -------------------------------------------------------------------------------- /codesign: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SOURCE="${BASH_SOURCE[0]}" 3 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink 4 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 5 | SOURCE="$(readlink "$SOURCE")" 6 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" 7 | done 8 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 9 | unset CODESIGN_ALLOCATE 10 | DYLD_INSERT_LIBRARIES="${DIR}/codesign_fix.dylib" /usr/bin/codesign_old "${@:1}" 11 | -------------------------------------------------------------------------------- /codesign_fix.cpp: -------------------------------------------------------------------------------- 1 | #include "substrate.h" 2 | 3 | typedef int32_t CSSM_RETURN; 4 | enum { 5 | CSSM_OK = 0 6 | }; 7 | 8 | struct TPCertGroup; 9 | 10 | static CSSM_RETURN fake_check(TPCertGroup &certGroup) { 11 | return CSSM_OK; 12 | } 13 | 14 | __attribute__((constructor)) 15 | static void fix_all_the_things() { 16 | MSImageRef image = MSGetImageByName("/System/Library/Frameworks/Security.framework/Security"); 17 | CSSM_RETURN (*tpCheckCertificateAllowList)(TPCertGroup &) = (CSSM_RETURN (*)(TPCertGroup &))MSFindSymbol(image, "_tpCheckCertificateAllowList"); 18 | MSHookFunction(tpCheckCertificateAllowList, &fake_check); 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # codesign_fix 2 | 3 | This tweak exists to work around [this](https://forums.developer.apple.com/thread/66418) issue. 4 | 5 | ## Installation 6 | 7 | You will need to [disable](http://www.imore.com/el-capitan-system-integrity-protection-helps-keep-malware-away) System Integrity Protection in order for this to work. 8 | 9 | **Install at your own risk** :smiley:: 10 | 11 | ```sh 12 | $ git clone https://github.com/conradev/codesign_fix.git 13 | $ cd codesign_fix 14 | $ make 15 | $ sudo mv /usr/bin/codesign /usr/bin/codesign_old 16 | $ sudo ln -s $PWD/codesign /usr/bin/codesign 17 | ``` 18 | 19 | To uninstall, undo the changes made above: 20 | 21 | ```sh 22 | $ sudo rm /usr/bin/codesign 23 | $ sudo mv /usr/bin/codesign_old /usr/bin/codesign 24 | $ make clean 25 | ``` 26 | -------------------------------------------------------------------------------- /substrate.h: -------------------------------------------------------------------------------- 1 | /* Cydia Substrate - Powerful Code Insertion Platform 2 | * Copyright (C) 2008-2015 Jay Freeman (saurik) 3 | */ 4 | 5 | /* GNU General Public License, Version 3 {{{ */ 6 | /* 7 | * Substrate is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published 9 | * by the Free Software Foundation, either version 3 of the License, 10 | * or (at your option) any later version. 11 | * 12 | * Substrate is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Substrate. If not, see . 19 | **/ 20 | /* }}} */ 21 | 22 | #ifndef SUBSTRATE_H_ 23 | #define SUBSTRATE_H_ 24 | 25 | #ifdef __APPLE__ 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | #include 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #include 35 | #include 36 | #endif 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #define _finline \ 43 | inline __attribute__((__always_inline__)) 44 | #define _disused \ 45 | __attribute__((__unused__)) 46 | 47 | #ifdef __cplusplus 48 | #define _default(value) = value 49 | #else 50 | #define _default(value) 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | typedef const struct MSImage *MSImageRef; 58 | 59 | MSImageRef MSMapImage(const char *file); 60 | const void *MSImageAddress(MSImageRef image); 61 | void MSCloseImage(MSImageRef); 62 | 63 | MSImageRef MSGetImageByName(const char *file); 64 | 65 | void *MSFindSymbol(MSImageRef image, const char *name); 66 | char *MSFindAddress(MSImageRef image, void **address); 67 | 68 | void MSHookFunction(void *symbol, void *replace, void **result); 69 | 70 | #ifdef __APPLE__ 71 | #ifdef __arm__ 72 | __attribute__((__deprecated__)) 73 | IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL)); 74 | #endif 75 | void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result); 76 | void MSHookClassPair(Class target, Class hook, Class old); 77 | #endif 78 | 79 | #ifdef __ANDROID__ 80 | #include 81 | void MSJavaHookClassLoad(JNIEnv *jni, const char *name, void (*callback)(JNIEnv *, jclass, void *), void *data _default(NULL)); 82 | void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID methodID, void *function, void **result); 83 | void MSJavaBlessClassLoader(JNIEnv *jni, jobject loader); 84 | 85 | typedef struct MSJavaObjectKey_ *MSJavaObjectKey; 86 | MSJavaObjectKey MSJavaCreateObjectKey(); 87 | void MSJavaReleaseObjectKey(MSJavaObjectKey key); 88 | void *MSJavaGetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key); 89 | void MSJavaSetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key, void *value, void (*clean)(void *, JNIEnv *, void *) _default(NULL), void *data _default(NULL)); 90 | #endif 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #ifdef __APPLE__ 97 | 98 | #define MSHookInterface(target, hook, base) \ 99 | @class target; \ 100 | @interface $ ## hook : base { target *$self; } @end \ 101 | @implementation $ ## hook \ 102 | + (void) initialize {} \ 103 | @end \ 104 | @interface hook : $ ## hook @end \ 105 | @implementation hook (MS) + (void) load { \ 106 | MSHookClassPair(objc_getClass(#target), self, class_getSuperclass(self)); \ 107 | } @end 108 | 109 | #define MSSelf ((__typeof__($self)) self) 110 | 111 | #endif 112 | 113 | #ifdef __cplusplus 114 | 115 | #ifdef __APPLE__ 116 | 117 | namespace etl { 118 | 119 | template 120 | struct Case { 121 | static char value[Case_ + 1]; 122 | }; 123 | 124 | typedef Case Yes; 125 | typedef Case No; 126 | 127 | namespace be { 128 | template 129 | static Yes CheckClass_(void (Checked_::*)()); 130 | 131 | template 132 | static No CheckClass_(...); 133 | } 134 | 135 | template 136 | struct IsClass { 137 | void gcc32(); 138 | 139 | static const bool value = (sizeof(be::CheckClass_(0).value) == sizeof(Yes::value)); 140 | }; 141 | 142 | } 143 | 144 | #ifdef __arm__ 145 | template 146 | __attribute__((__deprecated__)) 147 | static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) { 148 | return reinterpret_cast(MSHookMessage(_class, sel, reinterpret_cast(imp), prefix)); 149 | } 150 | #endif 151 | 152 | template 153 | static inline void MSHookMessage(Class _class, SEL sel, Type_ *imp, Type_ **result) { 154 | return MSHookMessageEx(_class, sel, reinterpret_cast(imp), reinterpret_cast(result)); 155 | } 156 | 157 | template 158 | static inline Type_ &MSHookIvar(id self, const char *name) { 159 | Ivar ivar(class_getInstanceVariable(object_getClass(self), name)); 160 | void *pointer(ivar == NULL ? NULL : reinterpret_cast( 161 | #if __has_feature(objc_arc) 162 | (__bridge void *) 163 | #endif 164 | self) + ivar_getOffset(ivar)); 165 | return *reinterpret_cast(pointer); 166 | } 167 | 168 | #define MSAddMessage0(_class, type, arg0) \ 169 | class_addMethod($ ## _class, @selector(arg0), (IMP) &$ ## _class ## $ ## arg0, type); 170 | #define MSAddMessage1(_class, type, arg0) \ 171 | class_addMethod($ ## _class, @selector(arg0:), (IMP) &$ ## _class ## $ ## arg0 ## $, type); 172 | #define MSAddMessage2(_class, type, arg0, arg1) \ 173 | class_addMethod($ ## _class, @selector(arg0:arg1:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $, type); 174 | #define MSAddMessage3(_class, type, arg0, arg1, arg2) \ 175 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $, type); 176 | #define MSAddMessage4(_class, type, arg0, arg1, arg2, arg3) \ 177 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $, type); 178 | #define MSAddMessage5(_class, type, arg0, arg1, arg2, arg3, arg4) \ 179 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $, type); 180 | #define MSAddMessage6(_class, type, arg0, arg1, arg2, arg3, arg4, arg5) \ 181 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $, type); 182 | #define MSAddMessage7(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ 183 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $, type); 184 | #define MSAddMessage8(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ 185 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $ ## arg7 ## $, type); 186 | 187 | #define MSHookMessage0(_class, arg0) \ 188 | MSHookMessage($ ## _class, @selector(arg0), MSHake(_class ## $ ## arg0)) 189 | #define MSHookMessage1(_class, arg0) \ 190 | MSHookMessage($ ## _class, @selector(arg0:), MSHake(_class ## $ ## arg0 ## $)) 191 | #define MSHookMessage2(_class, arg0, arg1) \ 192 | MSHookMessage($ ## _class, @selector(arg0:arg1:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $)) 193 | #define MSHookMessage3(_class, arg0, arg1, arg2) \ 194 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $)) 195 | #define MSHookMessage4(_class, arg0, arg1, arg2, arg3) \ 196 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $)) 197 | #define MSHookMessage5(_class, arg0, arg1, arg2, arg3, arg4) \ 198 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $)) 199 | #define MSHookMessage6(_class, arg0, arg1, arg2, arg3, arg4, arg5) \ 200 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $)) 201 | #define MSHookMessage7(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ 202 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $)) 203 | #define MSHookMessage8(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ 204 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $ ## arg7 ## $)) 205 | 206 | #define MSRegister_(name, dollar, colon) \ 207 | namespace { static class C_$ ## name ## $ ## dollar { public: _finline C_$ ## name ## $ ##dollar() { \ 208 | MSHookMessage($ ## name, @selector(colon), MSHake(name ## $ ## dollar)); \ 209 | } } V_$ ## name ## $ ## dollar; } \ 210 | 211 | #define MSIgnore_(name, dollar, colon) 212 | 213 | #ifdef __arm64__ 214 | #define MS_objc_msgSendSuper_stret objc_msgSendSuper 215 | #else 216 | #define MS_objc_msgSendSuper_stret objc_msgSendSuper_stret 217 | #endif 218 | 219 | #define MSMessage_(extra, type, _class, name, dollar, colon, call, args...) \ 220 | static type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args); \ 221 | MSHook(type, name ## $ ## dollar, _class self, SEL _cmd, ## args) { \ 222 | Class const _cls($ ## name); \ 223 | type (* const _old)(_class, SEL, ## args, ...) = reinterpret_cast(_ ## name ## $ ## dollar); \ 224 | typedef type (*msgSendSuper_t)(struct objc_super *, SEL, ## args, ...); \ 225 | msgSendSuper_t const _spr(::etl::IsClass::value ? reinterpret_cast(&MS_objc_msgSendSuper_stret) : reinterpret_cast(&objc_msgSendSuper)); \ 226 | return _$ ## name ## $ ## dollar call; \ 227 | } \ 228 | extra(name, dollar, colon) \ 229 | static _finline type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args) 230 | 231 | /* for((x=1;x!=7;++x)){ echo -n "#define MSMessage${x}_(extra, type, _class, name";for((y=0;y!=x;++y));do echo -n ", sel$y";done;for((y=0;y!=x;++y));do echo -n ", type$y, arg$y";done;echo ") \\";echo -n " MSMessage_(extra, type, _class, name,";for((y=0;y!=x;++y));do if [[ $y -ne 0 ]];then echo -n " ##";fi;echo -n " sel$y ## $";done;echo -n ", ";for((y=0;y!=x;++y));do echo -n "sel$y:";done;echo -n ", (_cls, _old, _spr, self, _cmd";for((y=0;y!=x;++y));do echo -n ", arg$y";done;echo -n ")";for((y=0;y!=x;++y));do echo -n ", type$y arg$y";done;echo ")";} */ 232 | 233 | #define MSMessage0_(extra, type, _class, name, sel0) \ 234 | MSMessage_(extra, type, _class, name, sel0, sel0, (_cls, _old, _spr, self, _cmd)) 235 | #define MSMessage1_(extra, type, _class, name, sel0, type0, arg0) \ 236 | MSMessage_(extra, type, _class, name, sel0 ## $, sel0:, (_cls, _old, _spr, self, _cmd, arg0), type0 arg0) 237 | #define MSMessage2_(extra, type, _class, name, sel0, sel1, type0, arg0, type1, arg1) \ 238 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $, sel0:sel1:, (_cls, _old, _spr, self, _cmd, arg0, arg1), type0 arg0, type1 arg1) 239 | #define MSMessage3_(extra, type, _class, name, sel0, sel1, sel2, type0, arg0, type1, arg1, type2, arg2) \ 240 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $, sel0:sel1:sel2:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2), type0 arg0, type1 arg1, type2 arg2) 241 | #define MSMessage4_(extra, type, _class, name, sel0, sel1, sel2, sel3, type0, arg0, type1, arg1, type2, arg2, type3, arg3) \ 242 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $, sel0:sel1:sel2:sel3:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3), type0 arg0, type1 arg1, type2 arg2, type3 arg3) 243 | #define MSMessage5_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ 244 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $, sel0:sel1:sel2:sel3:sel4:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4) 245 | #define MSMessage6_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ 246 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $, sel0:sel1:sel2:sel3:sel4:sel5:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 247 | #define MSMessage7_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, sel6, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6) \ 248 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $ ## sel6 ## $, sel0:sel1:sel2:sel3:sel4:sel5:sel6:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 249 | #define MSMessage8_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, sel6, sel7, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6, type7, arg7) \ 250 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $ ## sel6 ## $ ## sel7 ## $, sel0:sel1:sel2:sel3:sel4:sel5:sel6:sel7:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 251 | 252 | #define MSInstanceMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, _class *, _class, ## args) 253 | #define MSInstanceMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, _class *, _class, ## args) 254 | #define MSInstanceMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, _class *, _class, ## args) 255 | #define MSInstanceMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, _class *, _class, ## args) 256 | #define MSInstanceMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, _class *, _class, ## args) 257 | #define MSInstanceMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, _class *, _class, ## args) 258 | #define MSInstanceMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, _class *, _class, ## args) 259 | #define MSInstanceMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, _class *, _class, ## args) 260 | #define MSInstanceMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, _class *, _class, ## args) 261 | 262 | #define MSClassMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, Class, $ ## _class, ## args) 263 | #define MSClassMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, Class, $ ## _class, ## args) 264 | #define MSClassMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, Class, $ ## _class, ## args) 265 | #define MSClassMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, Class, $ ## _class, ## args) 266 | #define MSClassMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, Class, $ ## _class, ## args) 267 | #define MSClassMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, Class, $ ## _class, ## args) 268 | #define MSClassMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, Class, $ ## _class, ## args) 269 | #define MSClassMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, Class, $ ## _class, ## args) 270 | #define MSClassMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, Class, $ ## _class, ## args) 271 | 272 | #define MSInstanceMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, _class *, _class, ## args) 273 | #define MSInstanceMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, _class *, _class, ## args) 274 | #define MSInstanceMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, _class *, _class, ## args) 275 | #define MSInstanceMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, _class *, _class, ## args) 276 | #define MSInstanceMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, _class *, _class, ## args) 277 | #define MSInstanceMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, _class *, _class, ## args) 278 | #define MSInstanceMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, _class *, _class, ## args) 279 | #define MSInstanceMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, _class *, _class, ## args) 280 | #define MSInstanceMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, _class *, _class, ## args) 281 | 282 | #define MSClassMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, Class, $ ## _class, ## args) 283 | #define MSClassMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, Class, $ ## _class, ## args) 284 | #define MSClassMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, Class, $ ## _class, ## args) 285 | #define MSClassMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, Class, $ ## _class, ## args) 286 | #define MSClassMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, Class, $ ## _class, ## args) 287 | #define MSClassMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, Class, $ ## _class, ## args) 288 | #define MSClassMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, Class, $ ## _class, ## args) 289 | #define MSClassMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, Class, $ ## _class, ## args) 290 | #define MSClassMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, Class, $ ## _class, ## args) 291 | 292 | #define MSOldCall(args...) \ 293 | _old(self, _cmd, ## args) 294 | #define MSSuperCall(args...) \ 295 | _spr((struct objc_super[1]) {{self, class_getSuperclass(_cls)}}, _cmd, ## args) 296 | 297 | #define MSIvarHook(type, name) \ 298 | type &name(MSHookIvar(self, #name)) 299 | 300 | #define MSClassHook(name) \ 301 | @class name; \ 302 | static Class $ ## name = objc_getClass(#name); 303 | #define MSMetaClassHook(name) \ 304 | @class name; \ 305 | static Class $$ ## name = object_getClass($ ## name); 306 | 307 | #endif/*__APPLE__*/ 308 | 309 | template 310 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) { 311 | return MSHookFunction( 312 | reinterpret_cast(symbol), 313 | reinterpret_cast(replace), 314 | reinterpret_cast(result) 315 | ); 316 | } 317 | 318 | template 319 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace) { 320 | return MSHookFunction(symbol, replace, reinterpret_cast(NULL)); 321 | } 322 | 323 | template 324 | static inline void MSHookSymbol(Type_ *&value, const char *name, MSImageRef image = NULL) { 325 | value = reinterpret_cast(MSFindSymbol(image, name)); 326 | } 327 | 328 | template 329 | static inline void MSHookFunction(const char *name, Type_ *replace, Type_ **result = NULL) { 330 | Type_ *symbol; 331 | MSHookSymbol(symbol, name); 332 | return MSHookFunction(symbol, replace, result); 333 | } 334 | 335 | template 336 | static inline void MSHookFunction(MSImageRef image, const char *name, Type_ *replace, Type_ **result = NULL) { 337 | Type_ *symbol; 338 | MSHookSymbol(symbol, name, image); 339 | return MSHookFunction(symbol, replace, result); 340 | } 341 | 342 | #endif 343 | 344 | // g++ versions before 4.7 define __cplusplus to 1 345 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 346 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) 347 | 348 | #ifdef __ANDROID__ 349 | 350 | template 351 | static inline void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID method, Type_ (*replace)(JNIEnv *, Kind_, Args_...), Type_ (**result)(JNIEnv *, Kind_, ...)) { 352 | return MSJavaHookMethod( 353 | jni, _class, method, 354 | reinterpret_cast(replace), 355 | reinterpret_cast(result) 356 | ); 357 | } 358 | 359 | #endif 360 | 361 | #endif 362 | 363 | #ifdef __ANDROID__ 364 | 365 | #ifdef __cplusplus 366 | 367 | static inline void MSAndroidGetPackage(JNIEnv *jni, jobject global, const char *name, jobject &local, jobject &loader) { 368 | jclass Context(jni->FindClass("android/content/Context")); 369 | jmethodID Context$createPackageContext(jni->GetMethodID(Context, "createPackageContext", "(Ljava/lang/String;I)Landroid/content/Context;")); 370 | jmethodID Context$getClassLoader(jni->GetMethodID(Context, "getClassLoader", "()Ljava/lang/ClassLoader;")); 371 | 372 | jstring string(jni->NewStringUTF(name)); 373 | local = jni->CallObjectMethod(global, Context$createPackageContext, string, 3); 374 | loader = jni->CallObjectMethod(local, Context$getClassLoader); 375 | } 376 | 377 | static inline jclass MSJavaFindClass(JNIEnv *jni, jobject loader, const char *name) { 378 | jclass Class(jni->FindClass("java/lang/Class")); 379 | jmethodID Class$forName(jni->GetStaticMethodID(Class, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;")); 380 | 381 | jstring string(jni->NewStringUTF(name)); 382 | jobject _class(jni->CallStaticObjectMethod(Class, Class$forName, string, JNI_TRUE, loader)); 383 | 384 | if (jni->ExceptionCheck()) { 385 | jni->ExceptionClear(); 386 | return NULL; 387 | } 388 | 389 | return reinterpret_cast(_class); 390 | } 391 | 392 | _disused static void MSJavaCleanWeak(void *data, JNIEnv *jni, void *value) { 393 | jni->DeleteWeakGlobalRef(reinterpret_cast(value)); 394 | } 395 | 396 | #endif 397 | 398 | #endif 399 | 400 | #define MSHook(type, name, args...) \ 401 | _disused static type (*_ ## name)(args); \ 402 | static type $ ## name(args) 403 | 404 | #define MSJavaHook(type, name, arg0, args...) \ 405 | _disused static type (*_ ## name)(JNIEnv *jni, arg0, ...); \ 406 | static type $ ## name(JNIEnv *jni, arg0, ## args) 407 | 408 | #ifdef __cplusplus 409 | #define MSHake(name) \ 410 | &$ ## name, &_ ## name 411 | #else 412 | #define MSHake(name) \ 413 | &$ ## name, (void **) &_ ## name 414 | #endif 415 | 416 | #define SubstrateConcat_(lhs, rhs) \ 417 | lhs ## rhs 418 | #define SubstrateConcat(lhs, rhs) \ 419 | SubstrateConcat_(lhs, rhs) 420 | 421 | #define SubstrateStringize(value) \ 422 | #value 423 | 424 | #ifdef __APPLE__ 425 | #define SubstrateSection \ 426 | __attribute__((__section__("__TEXT, __substrate"))) 427 | #else 428 | #define SubstrateSection \ 429 | __attribute__((__section__(".substrate"))) 430 | #endif 431 | 432 | #ifdef __APPLE__ 433 | #define MSFilterCFBundleID "Filter:CFBundleID" 434 | #define MSFilterObjC_Class "Filter:ObjC.Class" 435 | #endif 436 | 437 | #ifdef __ANDROID__ 438 | #define MSFilterLibrary "Filter:Library" 439 | #endif 440 | 441 | #define MSFilterCFVersion "Filter:CFVersion" 442 | #define MSFilterExecutable "Filter:Executable" 443 | 444 | #define MSConfig(name, value) \ 445 | extern const char SubstrateConcat(_substrate_, __LINE__)[] SubstrateSection; \ 446 | const char SubstrateConcat(_substrate_, __LINE__)[] SubstrateSection = name "=" value; 447 | 448 | #define MSConfigValue(name, value) \ 449 | char SubstrateConcat(_substrate_MSConfigValue_Invalid_, __LINE__)[((double)value, 0)]; \ 450 | const char SubstrateConcat(_substrate_, __LINE__)[] SubstrateSection = name "=" SubstrateStringize(value); 451 | 452 | #define MSConfigRange(name, lo, hi) \ 453 | char SubstrateConcat(_substrate_MSConfigRange_Invalid_, __LINE__)[(double)lo <= (double)hi ? 0 : -1]; \ 454 | MSConfig(name, SubstrateStringize(lo) "," SubstrateStringize(hi)) 455 | 456 | #ifdef __cplusplus 457 | #define MSInitialize \ 458 | static void SubstrateConcat(_MSInitialize, __LINE__)(void); \ 459 | namespace { static class SubstrateConcat($MSInitialize, __LINE__) { public: _finline SubstrateConcat($MSInitialize, __LINE__)() { \ 460 | SubstrateConcat(_MSInitialize, __LINE__)(); \ 461 | } } SubstrateConcat($MSInitialize, __LINE__); } \ 462 | static void SubstrateConcat(_MSInitialize, __LINE__)() 463 | #else 464 | #define MSInitialize \ 465 | __attribute__((__constructor__)) static void SubstrateConcat(_MSInitialize, __LINE__)(void) 466 | #endif 467 | 468 | #define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation" 469 | #define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit" 470 | #define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore" 471 | #define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit" 472 | 473 | #endif//SUBSTRATE_H_ 474 | --------------------------------------------------------------------------------