├── .gitignore ├── Frameworks ├── RevealServer.framework │ ├── Info.plist │ ├── Modules │ │ └── module.modulemap │ └── RevealServer ├── libcycript.cy ├── libcycript.db ├── libcycript.dylib └── libsubstrate.dylib ├── LICENSE ├── Librarys └── .gitkeep ├── MFrameworks ├── libsubstitute.dylib └── substrate.h ├── README.md ├── Resource └── TargetApp.app │ ├── AppIcon60x60@2x.png │ ├── AppIcon60x60@3x.png │ ├── Assets.car │ ├── Base.lproj │ ├── LaunchScreen.storyboardc │ │ ├── 01J-lp-oVM-view-Ze5-6b-2t3.nib │ │ ├── Info.plist │ │ └── UIViewController-01J-lp-oVM.nib │ └── Main.storyboardc │ │ ├── BYZ-38-t0r-view-8bC-Xf-vdC.nib │ │ ├── Info.plist │ │ └── UIViewController-BYZ-38-t0r.nib │ ├── Info.plist │ ├── PkgInfo │ └── TargetApp ├── Tools ├── mpack.sh └── pack.sh ├── bin ├── class-dump ├── createIPA.command ├── cycript ├── md ├── md-install ├── md-uninstall ├── md-update └── monkeyparser ├── change.log └── include ├── CaptainHook └── CaptainHook.h └── substrate.h /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /Frameworks/RevealServer.framework/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 17E199 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | RevealServer 11 | CFBundleIdentifier 12 | com.ittybittyapps.RevealServer 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | RevealServer 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 14 21 | CFBundleSignature 22 | ???? 23 | CFBundleSupportedPlatforms 24 | 25 | iPhoneOS 26 | 27 | CFBundleVersion 28 | 10107 29 | DTCompiler 30 | com.apple.compilers.llvm.clang.1_0 31 | DTPlatformBuild 32 | 15E217 33 | DTPlatformName 34 | iphoneos 35 | DTPlatformVersion 36 | 11.3 37 | DTSDKBuild 38 | 15E217 39 | DTSDKName 40 | iphoneos11.3 41 | DTXcode 42 | 0930 43 | DTXcodeBuild 44 | 9E145 45 | MinimumOSVersion 46 | 8.0 47 | UIDeviceFamily 48 | 49 | 1 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Frameworks/RevealServer.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module RevealServer { 2 | umbrella header "RevealServer.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Frameworks/RevealServer.framework/RevealServer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Frameworks/RevealServer.framework/RevealServer -------------------------------------------------------------------------------- /Frameworks/libcycript.cy: -------------------------------------------------------------------------------- 1 | /* Cycript - The Truly Universal Scripting Language 2 | * Copyright (C) 2009-2016 Jay Freeman (saurik) 3 | */ 4 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ 6 | /* 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Affero General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Affero General Public License for more details. 16 | 17 | * You should have received a copy of the GNU Affero General Public License 18 | * along with this program. If not, see . 19 | **/ 20 | /* }}} */ 21 | 22 | (function() { 23 | 24 | Number.prototype.__defineGetter__('$cyt', function() { 25 | if (this.$cyt_) 26 | return this.$cyt_; 27 | if ((this|0) == this) 28 | return int; 29 | }); 30 | 31 | this.typeid = function(object) { 32 | return object.$cyt; 33 | }; 34 | 35 | let $cy_set = function(object, properties) { 36 | for (const name in properties) 37 | if ("defineProperty" in Object) 38 | Object.defineProperty(object, name, { 39 | configurable: true, 40 | enumerable: false, 41 | writable: true, 42 | value: properties[name], 43 | }); else object[name] = properties[name]; 44 | }; 45 | 46 | $cy_set(Boolean.prototype, { 47 | toCYON: function() { 48 | return `new Boolean(${this.toString()})`; 49 | }, 50 | }); 51 | 52 | $cy_set(Date.prototype, { 53 | toCYON: function() { 54 | return `new ${this.constructor.name}(${this.toUTCString().toCYON()})`; 55 | }, 56 | }); 57 | 58 | $cy_set(Error.prototype, { 59 | toCYON: function() { 60 | let stack = this.stack; 61 | if (typeof stack == 'undefined') 62 | stack = ''; 63 | else { 64 | stack = stack.split('\n'); 65 | if (stack.slice(-1)[0] == "global code") 66 | stack = stack.slice(0, -1); 67 | for (let i = 0; i != stack.length; ++i) 68 | stack[i] = '\n ' + stack[i]; 69 | if (stack.length == 0) 70 | stack = ''; 71 | else { 72 | stack = stack.join(''); 73 | stack = ` /*${stack} */`; 74 | } 75 | } 76 | return `new ${this.constructor.name}(${this.message.toCYON()})${stack}`; 77 | }, 78 | }); 79 | 80 | $cy_set(Number.prototype, { 81 | toCYON: function() { 82 | if ("$cyt" in this) 83 | //return `${this.$cyt.toCYON()}(${this.toString()})`; 84 | return this.toString(); 85 | return `new Number(${this.toString()})`; 86 | }, 87 | }); 88 | 89 | $cy_set(RegExp.prototype, { 90 | toCYON: function() { 91 | return this.toString(); 92 | }, 93 | }); 94 | 95 | if ("ObjectiveC" in Cycript) { 96 | $cy_set(NSArray.prototype, { 97 | $cyg: function(key) { 98 | return objc_msgSend(this, "objectAtIndex:", key); 99 | }, 100 | 101 | $cys: function(key, value) { 102 | return objc_msgSend(this, "setObject:atIndex:", value, key); 103 | }, 104 | }); 105 | 106 | $cy_set(NSDictionary.prototype, { 107 | $cyg: function(key) { 108 | return objc_msgSend(this, "objectForKey:", key); 109 | }, 110 | 111 | $cys: function(key, value) { 112 | return objc_msgSend(this, "setObject:forKey:", value, key); 113 | }, 114 | }); 115 | } 116 | 117 | let IsFile = function(path) { 118 | // XXX: this doesn't work on symlinks, but I don't want to fix stat :/ 119 | return access(path, F_OK) == 0 && access(path + '/', F_OK) == -1; 120 | }; 121 | 122 | let StartsWith = function(lhs, rhs) { 123 | return lhs.substring(0, rhs.length) == rhs; 124 | }; 125 | 126 | let ResolveFile = function(exact, name) { 127 | if (exact && IsFile(name)) 128 | return name; 129 | for (let suffix of ['.js', '.json']) 130 | if (IsFile(name + suffix)) 131 | return name + suffix; 132 | return null; 133 | }; 134 | 135 | let GetDocumentPath = function() { 136 | return NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,1,true)[0]; 137 | }; 138 | 139 | let GetLibraryPath = function() { 140 | let handle = dlopen(NULL, RTLD_NOLOAD); 141 | if (handle == null) 142 | return null; 143 | 144 | try { 145 | let CYListenServer = dlsym(handle, "CYListenServer"); 146 | if (CYListenServer == null) 147 | return null; 148 | 149 | let info = new Dl_info; 150 | if (dladdr(CYListenServer, info) == 0) 151 | return null; 152 | 153 | let path = info->dli_fname; 154 | let slash = path.lastIndexOf('/'); 155 | if (slash == -1) 156 | return null; 157 | 158 | path = path.substr(0, slash); 159 | 160 | GetLibraryPath = function() { 161 | return path; 162 | }; 163 | 164 | return GetLibraryPath(); 165 | } finally { 166 | dlclose(handle); 167 | } 168 | }; 169 | 170 | let ResolveFolder = function(name) { 171 | if (access(name + '/', F_OK) == -1) 172 | return null; 173 | 174 | if (IsFile(name + "/package.json")) { 175 | let package = require(name + "/package.json"); 176 | let path = ResolveFile(true, name + "/" + package.main); 177 | if (path != null) 178 | return path; 179 | } 180 | 181 | return ResolveFile(false, name + "/index"); 182 | }; 183 | 184 | let ResolveEither = function(name) { 185 | let path = null; 186 | if (path == null) 187 | path = ResolveFile(true, name); 188 | if (path == null) 189 | path = ResolveFolder(name); 190 | return path; 191 | }; 192 | 193 | require.resolve = function(name) { 194 | if (StartsWith(name, '/')) { 195 | let path = ResolveEither(name); 196 | if (path != null) 197 | return path; 198 | } else { 199 | let cwd = *new (typedef char[1024]); 200 | cwd = getcwd(cwd, cwd.length).toString(); 201 | cwd = cwd.split('/'); 202 | 203 | if (StartsWith(name, './') || StartsWith(name, '../')) { 204 | let path = ResolveEither(cwd + '/' + name); 205 | if (path != null) 206 | return path; 207 | } else { 208 | 209 | for (let i = cwd.length; i != 0; --i) { 210 | let modules = cwd.slice(0, i).concat("node_modules").join('/'); 211 | let path = ResolveEither(modules + "/" + name); 212 | if (path != null) 213 | return path; 214 | } 215 | 216 | let library = GetLibraryPath(); 217 | let path = ResolveFile(true, library + "/" + name + ".cy"); 218 | if (path != null) 219 | return path; 220 | 221 | let document = GetDocumentPath(); 222 | path = ResolveFile(true, document + "/cycript/" + name + ".cy"); 223 | if (path != null) 224 | return path; 225 | } 226 | } 227 | 228 | throw new Error("Cannot find module '" + name + "'"); 229 | }; 230 | 231 | var _syscall = function(value) { 232 | if (value == -1) 233 | throw new Error(strerror(errno)); 234 | }; 235 | 236 | var info = *new (struct stat); 237 | if (false) { 238 | } else if ("st_atim" in info) { 239 | var st_atime = "st_atim"; 240 | var st_mtime = "st_mtim"; 241 | var st_ctime = "st_ctim"; 242 | } else if ("st_atimespec" in info) { 243 | var st_atime = "st_atimespec"; 244 | var st_mtime = "st_mtimespec"; 245 | var st_ctime = "st_ctimespec"; 246 | } else { 247 | var st_atime = "st_atime"; 248 | var st_mtime = "st_mtime"; 249 | var st_ctime = "st_ctime"; 250 | } 251 | 252 | var toDate = function(timespec) { 253 | return new Date(timespec.tv_sec * 1000 + timespec.tv_nsec / 1000); 254 | }; 255 | 256 | var bindings = {}; 257 | 258 | process.binding = function(name) { 259 | let binding = bindings[name]; 260 | if (typeof binding != 'undefined') 261 | return binding; 262 | 263 | switch (name) { 264 | case 'buffer': binding = { 265 | setupBufferJS() { 266 | }, 267 | }; break; 268 | 269 | case 'cares_wrap': binding = { 270 | }; break; 271 | 272 | case 'constants': binding = { 273 | }; break; 274 | 275 | case 'fs': binding = { 276 | FSInitialize() { 277 | }, 278 | 279 | lstat(path) { 280 | var info = new (struct stat); 281 | _syscall(lstat(path, info)); 282 | 283 | return { 284 | dev: info->st_dev, 285 | mode: info->st_mode, 286 | nlink: info->st_nlink, 287 | uid: info->st_uid, 288 | gid: info->st_gid, 289 | rdev: info->st_rdev, 290 | blksize: info->st_blksize, 291 | ino: info->st_ino, 292 | size: info->st_size, 293 | blocks: info->st_blocks, 294 | 295 | atime: toDate(info->[st_atime]), 296 | mtime: toDate(info->[st_mtime]), 297 | ctime: toDate(info->[st_ctime]), 298 | 299 | isSymbolicLink() { 300 | return S_ISLNK(this.mode); 301 | }, 302 | }; 303 | }, 304 | }; break; 305 | 306 | case 'pipe_wrap': binding = { 307 | }; break; 308 | 309 | case 'smalloc': binding = { 310 | alloc() { 311 | }, 312 | }; break; 313 | 314 | case 'stream_wrap': binding = { 315 | }; break; 316 | 317 | case 'tcp_wrap': binding = { 318 | }; break; 319 | 320 | case 'timer_wrap': binding = { 321 | kOnTimeout: 0, 322 | Timer: { 323 | }, 324 | }; break; 325 | 326 | case 'tty_wrap': binding = { 327 | }; break; 328 | 329 | case 'uv': binding = { 330 | }; break; 331 | 332 | default: 333 | throw new Error('No such module: ' + name); 334 | } 335 | 336 | bindings[name] = binding; 337 | return binding; 338 | }; 339 | 340 | process.env = {}; 341 | 342 | let environ = *(typedef char ***)(dlsym(RTLD_DEFAULT, "environ")); 343 | for (let i = 0; environ[i] != null; ++i) { 344 | let assign = environ[i]; 345 | let equal = assign.indexOf('='); 346 | let name = assign.substr(0, equal); 347 | let value = assign.substr(equal + 1); 348 | process.env[name.toString()] = value; 349 | } 350 | 351 | process.cwd = function() { 352 | let cwd = new (typedef char[1024]); 353 | return getcwd(cwd, cwd.length).toString(); 354 | }; 355 | 356 | process.pid = getpid(); 357 | 358 | })(); 359 | -------------------------------------------------------------------------------- /Frameworks/libcycript.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Frameworks/libcycript.db -------------------------------------------------------------------------------- /Frameworks/libcycript.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Frameworks/libcycript.dylib -------------------------------------------------------------------------------- /Frameworks/libsubstrate.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Frameworks/libsubstrate.dylib -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Librarys/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Librarys/.gitkeep -------------------------------------------------------------------------------- /MFrameworks/libsubstitute.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/MFrameworks/libsubstitute.dylib -------------------------------------------------------------------------------- /MFrameworks/substrate.h: -------------------------------------------------------------------------------- 1 | /* Cydia Substrate - Powerful Code Insertion Platform 2 | * Copyright (C) 2008-2011 Jay Freeman (saurik) 3 | */ 4 | 5 | /* Modified from git revision 904d20f414c79a2716680f4d29d833e6ce0dcea2 by comex 6 | * to act as a compatibility shim for libsubstitute; the changes consist of 7 | * removing MSHookMessage, MSHookProcess (for now), and some internal 8 | * functions, and setting custom asm names for all non-inline functions. 9 | * 10 | * The purpose of the custom asm names is to allow the shim to be applied at 11 | * either the source or binary level (the latter mainly for testing purposes). 12 | * Normally, due to two-level name lookup, exposing the regular names in 13 | * libsubstitute.dylib would suffice for this, even if it's loaded in the same 14 | * process as Substrate, but not with DYLD_FORCE_FLAT_NAMESPACE etc. 15 | * Therefore, making a binary use this requires hacking it up with sed. With 16 | * source, just put the directory containing this file in your include path. 17 | */ 18 | 19 | /* GNU Lesser General Public License, Version 3 {{{ */ 20 | /* 21 | * Substrate is free software: you can redistribute it and/or modify it under 22 | * the terms of the GNU Lesser General Public License as published by the 23 | * Free Software Foundation, either version 3 of the License, or (at your 24 | * option) any later version. 25 | * 26 | * Substrate is distributed in the hope that it will be useful, but WITHOUT 27 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 29 | * License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public License 32 | * along with Substrate. If not, see . 33 | **/ 34 | /* }}} */ 35 | 36 | #ifndef SUBSTRATE_H_ 37 | #define SUBSTRATE_H_ 38 | 39 | #ifdef __APPLE__ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | #include 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #include 49 | #include 50 | #endif 51 | 52 | #include 53 | #include 54 | 55 | #define _finline \ 56 | inline __attribute__((__always_inline__)) 57 | #define _disused \ 58 | __attribute__((__unused__)) 59 | 60 | #define _extern \ 61 | extern "C" __attribute__((__visibility__("default"))) 62 | 63 | #ifdef __cplusplus 64 | #define _default(value) = value 65 | #else 66 | #define _default(value) 67 | #endif 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | typedef const void *MSImageRef; 74 | 75 | MSImageRef MSGetImageByName(const char *file) 76 | __asm__("SubGetImageByName"); 77 | void *MSFindSymbol(MSImageRef image, const char *name) 78 | __asm__("SubFindSymbol"); 79 | 80 | void MSHookFunction(void *symbol, void *replace, void **result) 81 | __asm__("SubHookFunction"); 82 | 83 | #ifdef __APPLE__ 84 | void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result) 85 | __asm__("SubHookMessageEx"); 86 | #endif 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #ifdef __cplusplus 93 | 94 | #ifdef __APPLE__ 95 | 96 | namespace etl { 97 | 98 | template 99 | struct Case { 100 | static char value[Case_ + 1]; 101 | }; 102 | 103 | typedef Case Yes; 104 | typedef Case No; 105 | 106 | namespace be { 107 | template 108 | static Yes CheckClass_(void (Checked_::*)()); 109 | 110 | template 111 | static No CheckClass_(...); 112 | } 113 | 114 | template 115 | struct IsClass { 116 | void gcc32(); 117 | 118 | static const bool value = (sizeof(be::CheckClass_(0).value) == sizeof(Yes::value)); 119 | }; 120 | 121 | } 122 | 123 | #ifdef __arm__ 124 | template 125 | __attribute__((__deprecated__)) 126 | static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) { 127 | return reinterpret_cast(MSHookMessage(_class, sel, reinterpret_cast(imp), prefix)); 128 | } 129 | #endif 130 | 131 | template 132 | static inline void MSHookMessage(Class _class, SEL sel, Type_ *imp, Type_ **result) { 133 | return MSHookMessageEx(_class, sel, reinterpret_cast(imp), reinterpret_cast(result)); 134 | } 135 | 136 | template 137 | static inline Type_ &MSHookIvar(id self, const char *name) { 138 | Ivar ivar(class_getInstanceVariable(object_getClass(self), name)); 139 | #if __has_feature(objc_arc) 140 | void *pointer(ivar == NULL ? NULL : reinterpret_cast((__bridge void *)self) + ivar_getOffset(ivar)); 141 | #else 142 | void *pointer(ivar == NULL ? NULL : reinterpret_cast(self) + ivar_getOffset(ivar)); 143 | #endif 144 | return *reinterpret_cast(pointer); 145 | } 146 | 147 | #define MSAddMessage0(_class, type, arg0) \ 148 | class_addMethod($ ## _class, @selector(arg0), (IMP) &$ ## _class ## $ ## arg0, type); 149 | #define MSAddMessage1(_class, type, arg0) \ 150 | class_addMethod($ ## _class, @selector(arg0:), (IMP) &$ ## _class ## $ ## arg0 ## $, type); 151 | #define MSAddMessage2(_class, type, arg0, arg1) \ 152 | class_addMethod($ ## _class, @selector(arg0:arg1:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $, type); 153 | #define MSAddMessage3(_class, type, arg0, arg1, arg2) \ 154 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $, type); 155 | #define MSAddMessage4(_class, type, arg0, arg1, arg2, arg3) \ 156 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $, type); 157 | #define MSAddMessage5(_class, type, arg0, arg1, arg2, arg3, arg4) \ 158 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $, type); 159 | #define MSAddMessage6(_class, type, arg0, arg1, arg2, arg3, arg4, arg5) \ 160 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $, type); 161 | 162 | #define MSHookMessage0(_class, arg0) \ 163 | MSHookMessage($ ## _class, @selector(arg0), MSHake(_class ## $ ## arg0)) 164 | #define MSHookMessage1(_class, arg0) \ 165 | MSHookMessage($ ## _class, @selector(arg0:), MSHake(_class ## $ ## arg0 ## $)) 166 | #define MSHookMessage2(_class, arg0, arg1) \ 167 | MSHookMessage($ ## _class, @selector(arg0:arg1:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $)) 168 | #define MSHookMessage3(_class, arg0, arg1, arg2) \ 169 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $)) 170 | #define MSHookMessage4(_class, arg0, arg1, arg2, arg3) \ 171 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $)) 172 | #define MSHookMessage5(_class, arg0, arg1, arg2, arg3, arg4) \ 173 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $)) 174 | #define MSHookMessage6(_class, arg0, arg1, arg2, arg3, arg4, arg5) \ 175 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $)) 176 | 177 | #define MSRegister_(name, dollar, colon) \ 178 | static class C_$ ## name ## $ ## dollar { public: _finline C_$ ## name ## $ ##dollar() { \ 179 | MSHookMessage($ ## name, @selector(colon), MSHake(name ## $ ## dollar)); \ 180 | } } V_$ ## name ## $ ## dollar; \ 181 | 182 | #define MSIgnore_(name, dollar, colon) 183 | 184 | #define MSMessage_(extra, type, _class, name, dollar, colon, call, args...) \ 185 | static type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args); \ 186 | MSHook(type, name ## $ ## dollar, _class self, SEL _cmd, ## args) { \ 187 | Class const _cls($ ## name); \ 188 | type (* const _old)(_class, SEL, ## args, ...) = reinterpret_cast(_ ## name ## $ ## dollar); \ 189 | typedef type (*msgSendSuper_t)(struct objc_super *, SEL, ## args, ...); \ 190 | msgSendSuper_t const _spr(::etl::IsClass::value ? reinterpret_cast(&objc_msgSendSuper_stret) : reinterpret_cast(&objc_msgSendSuper)); \ 191 | return _$ ## name ## $ ## dollar call; \ 192 | } \ 193 | extra(name, dollar, colon) \ 194 | static _finline type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args) 195 | 196 | /* 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 ")";} */ 197 | 198 | #define MSMessage0_(extra, type, _class, name, sel0) \ 199 | MSMessage_(extra, type, _class, name, sel0, sel0, (_cls, _old, _spr, self, _cmd)) 200 | #define MSMessage1_(extra, type, _class, name, sel0, type0, arg0) \ 201 | MSMessage_(extra, type, _class, name, sel0 ## $, sel0:, (_cls, _old, _spr, self, _cmd, arg0), type0 arg0) 202 | #define MSMessage2_(extra, type, _class, name, sel0, sel1, type0, arg0, type1, arg1) \ 203 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $, sel0:sel1:, (_cls, _old, _spr, self, _cmd, arg0, arg1), type0 arg0, type1 arg1) 204 | #define MSMessage3_(extra, type, _class, name, sel0, sel1, sel2, type0, arg0, type1, arg1, type2, arg2) \ 205 | 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) 206 | #define MSMessage4_(extra, type, _class, name, sel0, sel1, sel2, sel3, type0, arg0, type1, arg1, type2, arg2, type3, arg3) \ 207 | 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) 208 | #define MSMessage5_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ 209 | 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) 210 | #define MSMessage6_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ 211 | 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) 212 | 213 | #define MSInstanceMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, _class *, _class, ## args) 214 | #define MSInstanceMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, _class *, _class, ## args) 215 | #define MSInstanceMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, _class *, _class, ## args) 216 | #define MSInstanceMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, _class *, _class, ## args) 217 | #define MSInstanceMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, _class *, _class, ## args) 218 | #define MSInstanceMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, _class *, _class, ## args) 219 | #define MSInstanceMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, _class *, _class, ## args) 220 | 221 | #define MSClassMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, Class, $ ## _class, ## args) 222 | #define MSClassMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, Class, $ ## _class, ## args) 223 | #define MSClassMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, Class, $ ## _class, ## args) 224 | #define MSClassMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, Class, $ ## _class, ## args) 225 | #define MSClassMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, Class, $ ## _class, ## args) 226 | #define MSClassMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, Class, $ ## _class, ## args) 227 | #define MSClassMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, Class, $ ## _class, ## args) 228 | 229 | #define MSInstanceMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, _class *, _class, ## args) 230 | #define MSInstanceMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, _class *, _class, ## args) 231 | #define MSInstanceMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, _class *, _class, ## args) 232 | #define MSInstanceMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, _class *, _class, ## args) 233 | #define MSInstanceMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, _class *, _class, ## args) 234 | #define MSInstanceMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, _class *, _class, ## args) 235 | #define MSInstanceMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, _class *, _class, ## args) 236 | 237 | #define MSClassMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, Class, $ ## _class, ## args) 238 | #define MSClassMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, Class, $ ## _class, ## args) 239 | #define MSClassMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, Class, $ ## _class, ## args) 240 | #define MSClassMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, Class, $ ## _class, ## args) 241 | #define MSClassMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, Class, $ ## _class, ## args) 242 | #define MSClassMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, Class, $ ## _class, ## args) 243 | #define MSClassMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, Class, $ ## _class, ## args) 244 | 245 | #define MSOldCall(args...) \ 246 | _old(self, _cmd, ## args) 247 | #define MSSuperCall(args...) \ 248 | _spr(& (struct objc_super) {self, class_getSuperclass(_cls)}, _cmd, ## args) 249 | 250 | #define MSIvarHook(type, name) \ 251 | type &name(MSHookIvar(self, #name)) 252 | 253 | #define MSClassHook(name) \ 254 | @class name; \ 255 | static Class $ ## name = objc_getClass(#name); 256 | #define MSMetaClassHook(name) \ 257 | @class name; \ 258 | static Class $$ ## name = object_getClass($ ## name); 259 | 260 | #endif/*__APPLE__*/ 261 | 262 | template 263 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) { 264 | return MSHookFunction( 265 | reinterpret_cast(symbol), 266 | reinterpret_cast(replace), 267 | reinterpret_cast(result) 268 | ); 269 | } 270 | 271 | template 272 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace) { 273 | return MSHookFunction(symbol, replace, reinterpret_cast(NULL)); 274 | } 275 | 276 | template 277 | static inline void MSHookSymbol(Type_ *&value, const char *name, MSImageRef image = NULL) { 278 | value = reinterpret_cast(MSFindSymbol(image, name)); 279 | } 280 | 281 | template 282 | static inline void MSHookFunction(const char *name, Type_ *replace, Type_ **result = NULL) { 283 | Type_ *symbol; 284 | MSHookSymbol(symbol, name); 285 | return MSHookFunction(symbol, replace, result); 286 | } 287 | 288 | #endif 289 | 290 | #define MSHook(type, name, args...) \ 291 | _disused static type (*_ ## name)(args); \ 292 | static type $ ## name(args) 293 | 294 | #ifdef __cplusplus 295 | #define MSHake(name) \ 296 | &$ ## name, &_ ## name 297 | #else 298 | #define MSHake(name) \ 299 | &$ ## name, (void **) &_ ## name 300 | #endif 301 | 302 | #define MSInitialize \ 303 | __attribute__((__constructor__)) static void _MSInitialize(void) 304 | 305 | #define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation" 306 | #define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit" 307 | #define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore" 308 | #define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit" 309 | 310 | #endif//SUBSTRATE_H_ 311 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MonkeyDev 2 | 3 | A modified version of iOSOpenDev 4 | 5 | * easy to install 6 | * support the latest version of theos 7 | * support CaptainHook Tweak、Logos Tweak、Command-line Tool 8 | * support insert dylib、class-dump、restore-symbol、reveal、cycript,patch and debug iOS Apps, without jailbreak. 9 | 10 | Plese Read Wiki: [Wiki](https://github.com/AloneMonkey/MonkeyDev/wiki) 11 | 12 | 13 | 14 | 15 | 16 | 原有iOSOpenDev的升级,非越狱插件开发集成神器! 17 | 18 | * 可以使用Xcode开发CaptainHook Tweak、Logos Tweak 和 Command-line Tool,在越狱机器开发插件,这是原来iOSOpenDev功能的迁移和改进。 19 | * 只需拖入一个砸壳应用,自动集成class-dump、restore-symbol、Reveal、Cycript和注入的动态库并重签名安装到非越狱机器。 20 | * 支持调试自己编写的动态库和第三方App 21 | * 支持通过CocoaPods第三方应用集成SDK以及非越狱插件,简单来说就是通过CocoaPods搭建了一个非越狱插件商店。 22 | 23 | 使用请阅读Wiki文档: [Wiki](https://github.com/AloneMonkey/MonkeyDev/wiki) 24 | 25 | 26 | 非越狱插件CocoaPods私有仓库地址:[MonkeyDevSpecs](https://github.com/AloneMonkey/MonkeyDevSpecs) 27 | 28 | 29 | 30 | **免责声明: 软件仅供技术交流,禁止用于商业及非法用途,如产生法律纠纷与本人无关。** 31 | 32 |
33 | 34 |

《iOS应用逆向与安全》出版啦!!!

35 | 36 | # 购书链接 37 | 38 | #### 京东: [https://item.jd.com/12361729.html](https://item.jd.com/12361729.html) 39 | 40 | #### 天猫: [https://detail.tmall.com/item.htm?id=570691214072](https://detail.tmall.com/item.htm?id=570691214072) 41 | 42 | #### 当当: [http://product.dangdang.com/25283164.html](http://product.dangdang.com/25283164.html) 43 | 44 | #### 亚马逊: [https://www.amazon.cn/dp/B07D5952BR/](https://www.amazon.cn/dp/B07D5952BR/) 45 | 46 |

请大家多多支持正版哦~

47 | -------------------------------------------------------------------------------- /Resource/TargetApp.app/AppIcon60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/AppIcon60x60@2x.png -------------------------------------------------------------------------------- /Resource/TargetApp.app/AppIcon60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/AppIcon60x60@3x.png -------------------------------------------------------------------------------- /Resource/TargetApp.app/Assets.car: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Assets.car -------------------------------------------------------------------------------- /Resource/TargetApp.app/Base.lproj/LaunchScreen.storyboardc/01J-lp-oVM-view-Ze5-6b-2t3.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Base.lproj/LaunchScreen.storyboardc/01J-lp-oVM-view-Ze5-6b-2t3.nib -------------------------------------------------------------------------------- /Resource/TargetApp.app/Base.lproj/LaunchScreen.storyboardc/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Base.lproj/LaunchScreen.storyboardc/Info.plist -------------------------------------------------------------------------------- /Resource/TargetApp.app/Base.lproj/LaunchScreen.storyboardc/UIViewController-01J-lp-oVM.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Base.lproj/LaunchScreen.storyboardc/UIViewController-01J-lp-oVM.nib -------------------------------------------------------------------------------- /Resource/TargetApp.app/Base.lproj/Main.storyboardc/BYZ-38-t0r-view-8bC-Xf-vdC.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Base.lproj/Main.storyboardc/BYZ-38-t0r-view-8bC-Xf-vdC.nib -------------------------------------------------------------------------------- /Resource/TargetApp.app/Base.lproj/Main.storyboardc/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Base.lproj/Main.storyboardc/Info.plist -------------------------------------------------------------------------------- /Resource/TargetApp.app/Base.lproj/Main.storyboardc/UIViewController-BYZ-38-t0r.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Base.lproj/Main.storyboardc/UIViewController-BYZ-38-t0r.nib -------------------------------------------------------------------------------- /Resource/TargetApp.app/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/Info.plist -------------------------------------------------------------------------------- /Resource/TargetApp.app/PkgInfo: -------------------------------------------------------------------------------- 1 | APPL???? -------------------------------------------------------------------------------- /Resource/TargetApp.app/TargetApp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/Resource/TargetApp.app/TargetApp -------------------------------------------------------------------------------- /Tools/mpack.sh: -------------------------------------------------------------------------------- 1 | MONKEYDEV_PATH="/opt/MonkeyDev" 2 | 3 | function panic() # args: exitCode, message... 4 | { 5 | local exitCode=$1 6 | set +e 7 | 8 | shift 9 | [[ "$@" == "" ]] || \ 10 | echo "$@" >&2 11 | 12 | exit $exitCode 13 | } 14 | 15 | echo "packing..." 16 | # environment 17 | monkeyparser="$MONKEYDEV_PATH/bin/monkeyparser" 18 | substrate="$MONKEYDEV_PATH/MFrameworks/libsubstitute.dylib" 19 | 20 | #exename 21 | TARGET_APP_PATH=$(find "$SRCROOT/$TARGET_NAME/TargetApp" -type d | grep ".app$" | head -n 1) 22 | 23 | if [[ "$TARGET_APP_PATH" == "" ]]; then 24 | panic 1 "cannot find target app" 25 | fi 26 | 27 | APP_BINARY_NAME=`plutil -convert xml1 -o - "$TARGET_APP_PATH/Contents/Info.plist" | grep -A1 CFBundleExecutable | tail -n1 | cut -f2 -d\> | cut -f1 -d\<` 28 | APP_BINARY_PATH="$TARGET_APP_PATH/Contents/MacOS/$APP_BINARY_NAME" 29 | 30 | #restoresymbol 31 | if [[ ! -f "$APP_BINARY_PATH".symbol ]]; then 32 | "$monkeyparser" restoresymbol -t "$APP_BINARY_PATH" -o "$APP_BINARY_PATH"_with_symbol 33 | mv "$APP_BINARY_PATH"_with_symbol "$APP_BINARY_PATH" 34 | echo "restoresymbol" >> "$APP_BINARY_PATH".symbol 35 | fi 36 | 37 | #unsign 38 | if [[ ! -f "$APP_BINARY_PATH".unsigned ]]; then 39 | "$monkeyparser" strip -t "$APP_BINARY_PATH" -o "$APP_BINARY_PATH".unsigned 40 | mv "$APP_BINARY_PATH".unsigned "$APP_BINARY_PATH" 41 | echo "unsigned" >> "$APP_BINARY_PATH".unsigned 42 | fi 43 | 44 | #insert dylib 45 | BUILD_DYLIB_PATH="$BUILT_PRODUCTS_DIR/lib$TARGET_NAME.dylib" 46 | 47 | if [[ ! -f "$APP_BINARY_PATH".insert ]]; then 48 | cp -rf "$substrate" "$TARGET_APP_PATH/Contents/MacOS/" 49 | "$monkeyparser" install -c load -p "@executable_path/lib$TARGET_NAME.dylib" -t "$APP_BINARY_PATH" 50 | echo "insert" >> "$APP_BINARY_PATH".insert 51 | fi 52 | 53 | cp -rf "$BUILD_DYLIB_PATH" "$TARGET_APP_PATH/Contents/MacOS/" 54 | 55 | chmod +x "$APP_BINARY_PATH" 56 | 57 | "$APP_BINARY_PATH" 58 | -------------------------------------------------------------------------------- /Tools/pack.sh: -------------------------------------------------------------------------------- 1 | MONKEYDEV_PATH="/opt/MonkeyDev" 2 | 3 | # temp path 4 | TEMP_PATH="${SRCROOT}/${TARGET_NAME}/tmp" 5 | 6 | # monkeyparser 7 | MONKEYPARSER="${MONKEYDEV_PATH}/bin/monkeyparser" 8 | 9 | # create ipa script 10 | CREATE_IPA="${MONKEYDEV_PATH}/bin/createIPA.command" 11 | 12 | # build app path 13 | BUILD_APP_PATH="${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app" 14 | 15 | # default demo app 16 | DEMOTARGET_APP_PATH="${MONKEYDEV_PATH}/Resource/TargetApp.app" 17 | 18 | # link framework path 19 | FRAMEWORKS_TO_INJECT_PATH="${MONKEYDEV_PATH}/Frameworks/" 20 | 21 | # target app placed 22 | TARGET_APP_PUT_PATH="${SRCROOT}/${TARGET_NAME}/TargetApp" 23 | 24 | # Compatiable old version 25 | MONKEYDEV_INSERT_DYLIB=${MONKEYDEV_INSERT_DYLIB:=YES} 26 | MONKEYDEV_TARGET_APP=${MONKEYDEV_TARGET_APP:=Optional} 27 | MONKEYDEV_ADD_SUBSTRATE=${MONKEYDEV_ADD_SUBSTRATE:=YES} 28 | MONKEYDEV_DEFAULT_BUNDLEID=${MONKEYDEV_DEFAULT_BUNDLEID:=NO} 29 | 30 | function isRelease() { 31 | if [[ "${CONFIGURATION}" = "Release" ]]; then 32 | true 33 | else 34 | false 35 | fi 36 | } 37 | 38 | function panic() { # args: exitCode, message... 39 | local exitCode=$1 40 | set +e 41 | 42 | shift 43 | [[ "$@" == "" ]] || \ 44 | echo "$@" >&2 45 | 46 | exit ${exitCode} 47 | } 48 | 49 | function checkApp(){ 50 | local TARGET_APP_PATH="$1" 51 | 52 | # remove Plugin an Watch 53 | rm -rf "${TARGET_APP_PATH}/PlugIns" || true 54 | rm -rf "${TARGET_APP_PATH}/Watch" || true 55 | 56 | /usr/libexec/PlistBuddy -c 'Delete UISupportedDevices' "${TARGET_APP_PATH}/Info.plist" 2>/dev/null 57 | 58 | VERIFY_RESULT=`export MONKEYDEV_CLASS_DUMP=${MONKEYDEV_CLASS_DUMP};MONKEYDEV_RESTORE_SYMBOL=${MONKEYDEV_RESTORE_SYMBOL};"$MONKEYPARSER" verify -t "${TARGET_APP_PATH}" -o "${SRCROOT}/${TARGET_NAME}"` 59 | 60 | if [[ $? -eq 16 ]]; then 61 | panic 1 "${VERIFY_RESULT}" 62 | else 63 | echo "${VERIFY_RESULT}" 64 | fi 65 | } 66 | 67 | function pack(){ 68 | TARGET_INFO_PLIST=${SRCROOT}/${TARGET_NAME}/Info.plist 69 | # environment 70 | CURRENT_EXECUTABLE=$(/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" "${TARGET_INFO_PLIST}" 2>/dev/null) 71 | 72 | # create tmp dir 73 | rm -rf "${TEMP_PATH}" || true 74 | mkdir -p "${TEMP_PATH}" || true 75 | 76 | # latestbuild 77 | ln -fhs "${BUILT_PRODUCTS_DIR}" "${PROJECT_DIR}"/LatestBuild 78 | cp -rf "${CREATE_IPA}" "${PROJECT_DIR}"/LatestBuild/ 79 | 80 | # deal ipa or app 81 | TARGET_APP_PATH=$(find "${SRCROOT}/${TARGET_NAME}" -type d | grep "\.app$" | head -n 1) 82 | TARGET_IPA_PATH=$(find "${SRCROOT}/${TARGET_NAME}" -type f | grep "\.ipa$" | head -n 1) 83 | 84 | if [[ ${TARGET_APP_PATH} ]]; then 85 | cp -rf "${TARGET_APP_PATH}" "${TARGET_APP_PUT_PATH}" 86 | fi 87 | 88 | if [[ ! ${TARGET_APP_PATH} ]] && [[ ! ${TARGET_IPA_PATH} ]] && [[ ${MONKEYDEV_TARGET_APP} != "Optional" ]]; then 89 | echo "pulling decrypted ipa from jailbreak device......." 90 | PYTHONIOENCODING=utf-8 ${MONKEYDEV_PATH}/bin/dump.py ${MONKEYDEV_TARGET_APP} -o "${TARGET_APP_PUT_PATH}/TargetApp.ipa" || panic 1 "dump.py error" 91 | TARGET_IPA_PATH=$(find "${TARGET_APP_PUT_PATH}" -type f | grep "\.ipa$" | head -n 1) 92 | fi 93 | 94 | if [[ ! ${TARGET_APP_PATH} ]] && [[ ${TARGET_IPA_PATH} ]]; then 95 | unzip -oqq "${TARGET_IPA_PATH}" -d "${TEMP_PATH}" 96 | cp -rf "${TEMP_PATH}/Payload/"*.app "${TARGET_APP_PUT_PATH}" 97 | fi 98 | 99 | if [ -f "${BUILD_APP_PATH}/embedded.mobileprovision" ]; then 100 | mv "${BUILD_APP_PATH}/embedded.mobileprovision" "${BUILD_APP_PATH}"/.. 101 | fi 102 | 103 | TARGET_APP_PATH=$(find "${TARGET_APP_PUT_PATH}" -type d | grep "\.app$" | head -n 1) 104 | 105 | if [[ -f "${TARGET_APP_PUT_PATH}"/.current_put_app ]]; then 106 | if [[ $(cat ${TARGET_APP_PUT_PATH}/.current_put_app) != "${TARGET_APP_PATH}" ]]; then 107 | rm -rf "${BUILD_APP_PATH}" || true 108 | mkdir -p "${BUILD_APP_PATH}" || true 109 | rm -rf "${TARGET_APP_PUT_PATH}"/.current_put_app 110 | echo "${TARGET_APP_PATH}" >> "${TARGET_APP_PUT_PATH}"/.current_put_app 111 | fi 112 | fi 113 | 114 | COPY_APP_PATH=${TARGET_APP_PATH} 115 | 116 | if [[ "${TARGET_APP_PATH}" = "" ]]; then 117 | COPY_APP_PATH=${DEMOTARGET_APP_PATH} 118 | cp -rf "${COPY_APP_PATH}/" "${BUILD_APP_PATH}/" 119 | checkApp "${BUILD_APP_PATH}" 120 | else 121 | checkApp "${COPY_APP_PATH}" 122 | cp -rf "${COPY_APP_PATH}/" "${BUILD_APP_PATH}/" 123 | fi 124 | 125 | if [ -f "${BUILD_APP_PATH}/../embedded.mobileprovision" ]; then 126 | mv "${BUILD_APP_PATH}/../embedded.mobileprovision" "${BUILD_APP_PATH}" 127 | fi 128 | 129 | # get target info 130 | ORIGIN_BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "${COPY_APP_PATH}/Info.plist" 2>/dev/null) 131 | TARGET_EXECUTABLE=$(/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" "${COPY_APP_PATH}/Info.plist" 2>/dev/null) 132 | 133 | if [[ ${CURRENT_EXECUTABLE} != ${TARGET_EXECUTABLE} ]]; then 134 | cp -rf "${COPY_APP_PATH}/Info.plist" "${TARGET_INFO_PLIST}" 135 | fi 136 | 137 | TARGET_DISPLAY_NAME=$(/usr/libexec/PlistBuddy -c "Print CFBundleDisplayName" "${TARGET_INFO_PLIST}" 2>/dev/null) 138 | 139 | # copy default framewrok 140 | TARGET_APP_FRAMEWORKS_PATH="${BUILD_APP_PATH}/Frameworks/" 141 | 142 | if [ ! -d "${TARGET_APP_FRAMEWORKS_PATH}" ]; then 143 | mkdir -p "${TARGET_APP_FRAMEWORKS_PATH}" 144 | fi 145 | 146 | if [[ ${MONKEYDEV_INSERT_DYLIB} == "YES" ]];then 147 | cp -rf "${BUILT_PRODUCTS_DIR}/lib""${TARGET_NAME}""Dylib.dylib" "${TARGET_APP_FRAMEWORKS_PATH}" 148 | cp -rf "${FRAMEWORKS_TO_INJECT_PATH}" "${TARGET_APP_FRAMEWORKS_PATH}" 149 | if [[ ${MONKEYDEV_ADD_SUBSTRATE} != "YES" ]];then 150 | rm -rf "${TARGET_APP_FRAMEWORKS_PATH}/libsubstrate.dylib" 151 | fi 152 | if isRelease; then 153 | rm -rf "${TARGET_APP_FRAMEWORKS_PATH}"/RevealServer.framework 154 | rm -rf "${TARGET_APP_FRAMEWORKS_PATH}"/libcycript* 155 | fi 156 | fi 157 | 158 | if [[ -d "$SRCROOT/${TARGET_NAME}/Resources" ]]; then 159 | for file in "$SRCROOT/${TARGET_NAME}/Resources"/*; do 160 | extension="${file#*.}" 161 | filename="${file##*/}" 162 | if [[ "$extension" == "storyboard" ]]; then 163 | ibtool --compile "${BUILD_APP_PATH}/$filename"c "$file" 164 | else 165 | cp -rf "$file" "${BUILD_APP_PATH}/" 166 | fi 167 | done 168 | fi 169 | 170 | # Inject the Dynamic Lib 171 | APP_BINARY=`plutil -convert xml1 -o - ${BUILD_APP_PATH}/Info.plist | grep -A1 Exec | tail -n1 | cut -f2 -d\> | cut -f1 -d\<` 172 | 173 | if [[ ${MONKEYDEV_INSERT_DYLIB} == "YES" ]];then 174 | "$MONKEYPARSER" install -c load -p "@executable_path/Frameworks/lib""${TARGET_NAME}""Dylib.dylib" -t "${BUILD_APP_PATH}/${APP_BINARY}" 175 | "$MONKEYPARSER" unrestrict -t "${BUILD_APP_PATH}/${APP_BINARY}" 176 | 177 | chmod +x "${BUILD_APP_PATH}/${APP_BINARY}" 178 | fi 179 | 180 | # Update Info.plist for Target App 181 | if [[ "${TARGET_DISPLAY_NAME}" != "" ]]; then 182 | for file in `ls "${BUILD_APP_PATH}"`; 183 | do 184 | extension="${file#*.}" 185 | if [[ -d "${BUILD_APP_PATH}/$file" ]]; then 186 | if [[ "${extension}" == "lproj" ]]; then 187 | if [[ -f "${BUILD_APP_PATH}/${file}/InfoPlist.strings" ]];then 188 | /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName ${TARGET_DISPLAY_NAME}" "${BUILD_APP_PATH}/${file}/InfoPlist.strings" 189 | fi 190 | fi 191 | fi 192 | done 193 | fi 194 | 195 | if [[ ${MONKEYDEV_DEFAULT_BUNDLEID} = NO ]];then 196 | /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${PRODUCT_BUNDLE_IDENTIFIER}" "${TARGET_INFO_PLIST}" 197 | else 198 | /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${ORIGIN_BUNDLE_ID}" "${TARGET_INFO_PLIST}" 199 | fi 200 | 201 | /usr/libexec/PlistBuddy -c "Delete :CFBundleIconFiles" "${TARGET_INFO_PLIST}" 202 | /usr/libexec/PlistBuddy -c "Add :CFBundleIconFiles array" "${TARGET_INFO_PLIST}" 203 | /usr/libexec/PlistBuddy -c "Add :CFBundleIconFiles: string ${TARGET_NAME}/icon.png" "${TARGET_INFO_PLIST}" 204 | 205 | cp -rf "${TARGET_INFO_PLIST}" "${BUILD_APP_PATH}/Info.plist" 206 | 207 | #cocoapods 208 | if [[ -f "${SRCROOT}/Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-frameworks.sh" ]]; then 209 | source "${SRCROOT}/Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-frameworks.sh" 210 | fi 211 | 212 | if [[ -f "${SRCROOT}/Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-resources.sh" ]]; then 213 | source "${SRCROOT}/Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-resources.sh" 214 | fi 215 | 216 | if [[ -f "${SRCROOT}/../Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-frameworks.sh" ]]; then 217 | source "${SRCROOT}/../Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-frameworks.sh" 218 | fi 219 | 220 | if [[ -f "${SRCROOT}/../Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-resources.sh" ]]; then 221 | source "${SRCROOT}/../Pods/Target Support Files/Pods-""${TARGET_NAME}""Dylib/Pods-""${TARGET_NAME}""Dylib-resources.sh" 222 | fi 223 | } 224 | 225 | if [[ "$1" == "codesign" ]]; then 226 | ${MONKEYPARSER} codesign -i "${EXPANDED_CODE_SIGN_IDENTITY}" -t "${BUILD_APP_PATH}" 227 | if [[ ${MONKEYDEV_INSERT_DYLIB} == "NO" ]];then 228 | rm -rf "${BUILD_APP_PATH}/Frameworks/lib${TARGET_NAME}Dylib.dylib" 229 | fi 230 | else 231 | pack 232 | fi 233 | -------------------------------------------------------------------------------- /bin/class-dump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/bin/class-dump -------------------------------------------------------------------------------- /bin/createIPA.command: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 3 | 4 | if [[ ${DIR} = "/opt/MonkeyDev/bin" ]]; then 5 | DIR="$PWD" 6 | fi 7 | 8 | function run { 9 | echo "Executing command: $@" 10 | $@ 11 | if [[ $? != "0" ]]; then 12 | echo "Executing the above command has failed!" 13 | exit 1 14 | fi 15 | } 16 | 17 | function run_at { 18 | pushd $1 19 | shift 20 | run $@ 21 | popd 22 | } 23 | 24 | echo "==================MonkeyDev(create ipa file...)==================" 25 | 26 | run "rm -rf ${DIR}/Target.ipa ${DIR}/Payload" 27 | run "mkdir ${DIR}/Payload" 28 | 29 | APP=$(find ${DIR} -type d | grep ".app$" | head -n 1) 30 | 31 | run "cp -rf ${APP} ${DIR}/Payload" 32 | run_at ${DIR} "zip -qr Target.ipa Payload" 33 | run "rm -rf ${DIR}/Payload" 34 | 35 | echo "==================MonkeyDev(done)==================" 36 | 37 | exit; -------------------------------------------------------------------------------- /bin/cycript: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/bin/cycript -------------------------------------------------------------------------------- /bin/md: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export setCmd="set -eo pipefail" 4 | $setCmd 5 | 6 | export PATH=/opt/MonkeyDev/bin:$MonkeyDevTheosPath/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH 7 | 8 | export scriptName="${0##*/}" 9 | export scriptVer="4.4" 10 | export originalArguments=("$@") 11 | export activeActionArg 12 | 13 | export MonkeyDevPath="/opt/MonkeyDev" 14 | #默认设备ip 15 | export DefaultDeviceIP="localhost" 16 | #默认端口号 17 | export DefaultDevicePort="22" 18 | 19 | export userName="${SUDO_USER-$USER}" 20 | export userGroup=`id -g $userName` 21 | export userHome=`eval echo ~$userName` 22 | export bashProfileFiles=("$userHome/.zshrc" "$userHome/.bash_profile" "$userHome/.bashrc" "$userHome/.bash_login" "$userHome/.profile") 23 | 24 | export tempDirsFile="`mktemp -d -t $scriptName`/tempdirs" 25 | touch "$tempDirsFile" 26 | 27 | unset LANG 28 | 29 | export ActionNames=("XcodeBuildPhase" "XcodeBuildPhaseLogos" "Help") 30 | export ActionProperty_ShortArg=0 31 | export ActionProperty_ShortUsage=1 32 | export ActionProperty_Options=2 33 | export ActionProperty_MinArgs=3 34 | export ActionProperty_MaxArgs=4 35 | export ActionProperty_Function=5 36 | export ActionProperty_RequireSudo=6 37 | export ActionProperty_LongUsage=7 38 | 39 | export Action_XcodeBuildPhaseLogos=("--xcbp-logos" "" "" 0 0 xcodeBuildPhase_Logos false \ 40 | " DO NOT USE. For use by Xcode as a Build Phase for projects created from 41 | MonkeyDev templates only.") 42 | 43 | export Action_XcodeBuildPhase=("--xcbp" "" "" 0 0 xcodeBuildPhase false \ 44 | " DO NOT USE. For use by Xcode as a Build Phase for projects created from 45 | MonkeyDev templates only.") 46 | 47 | export Action_Help=("--help" "" "" 0 0 "" false \ 48 | " Show this help.") 49 | 50 | function cleanup() # no args 51 | { 52 | local exitCode=$? 53 | set +e 54 | trap - $signals 55 | 56 | removeTempData 57 | 58 | exit $exitCode 59 | } 60 | export signals="0 1 2 3 15" 61 | trap cleanup $signals 62 | 63 | function panic() # args: exitCode, message... 64 | { 65 | local exitCode=$1 66 | set +e 67 | 68 | shift 69 | [[ "$@" == "" ]] || \ 70 | echo "$@" >&2 71 | 72 | exit $exitCode 73 | } 74 | 75 | function determineBashProfileFile() 76 | { 77 | $setCmd 78 | 79 | local f 80 | local filePath 81 | 82 | for f in "${bashProfileFiles[@]}"; do 83 | if [[ -f "$f" ]]; then 84 | if [[ -n `perl -ne 'print $1 if /^(?:export)? *'"MonkeyDevPath"'=(.*)$/' "$f"` ]]; then 85 | filePath="$f" 86 | break 87 | fi 88 | fi 89 | done 90 | 91 | if [[ $filePath == "" ]]; then 92 | 93 | filePath="$bashProfileFiles" # use first array item 94 | 95 | touch "$filePath" || \ 96 | panic $? "Failed to touch $filePath" 97 | 98 | changeOwn "$userName:$userGroup" "$filePath" 99 | changeMode 0600 "$filePath" 100 | fi 101 | 102 | # return # 103 | echo "$filePath" 104 | } 105 | 106 | function removeTempData() # no args 107 | { 108 | local tempDirs 109 | 110 | if [[ -f "$tempDirsFile" ]]; then 111 | tempDirs=(`cat "$tempDirsFile"`) 112 | 113 | for td in "${tempDirs[@]}"; do 114 | rm -rf "$td" || true # forget abou' it. 115 | done 116 | 117 | rm -rf "`dirname \"$tempDirsFile\"`" || true # forget abou' it. 118 | fi 119 | } 120 | 121 | function requireDir() # args: dirPath [, makeDirIfNotFound] 122 | { 123 | local dirPath="$1" 124 | local makeDirIfNotFound="$2" 125 | 126 | if [[ ! -d "$dirPath" ]]; then 127 | if [[ $makeDirIfNotFound == "true" ]]; then 128 | 129 | mkdir -p "$dirPath" || \ 130 | panic $? "Failed to create directory $dirPath" 131 | 132 | else 133 | panic 1 "Directory $dirPath not found" 134 | fi 135 | fi 136 | } 137 | 138 | function copyFile() # args: sourceFile, targetDirOrFile 139 | { 140 | local sourceFile="$1" 141 | local targetDirOrFile="$2" 142 | 143 | cp -fR "$sourceFile" "$targetDirOrFile" || \ 144 | panic $? "Failed to copy file $sourceFile to $targetDirOrFile" 145 | } 146 | 147 | function changeMode() # args: mode, target 148 | { 149 | local mode="$1" 150 | local target="$2" 151 | 152 | if [[ -e "$target" ]]; then 153 | 154 | chmod $mode "$target" || \ 155 | panic $? "Failed to change mode to $mode on $target" 156 | fi 157 | } 158 | 159 | function changeOwn() # args: ownerAndOrGroup, target 160 | { 161 | local ownerAndOrGroup="$1" 162 | local target="$2" 163 | 164 | if [[ -e "$target" ]]; then 165 | 166 | chown "$ownerAndOrGroup" "$target" || \ 167 | panic $? "Failed to change ownership to $ownerAndOrGroup on $target" 168 | fi 169 | } 170 | 171 | function requireFile() # args: filePath [, touchFileIfNotFound] 172 | { 173 | local filePath="$1" 174 | local touchFileIfNotFound="$2" 175 | 176 | if [[ ! -f "$filePath" ]]; then 177 | if [[ $touchFileIfNotFound == "true" ]]; then 178 | 179 | touch "$filePath" || \ 180 | panic $? "Failed to touch $filePath" 181 | 182 | else 183 | panic 1 "File $filePath not found" 184 | fi 185 | fi 186 | } 187 | 188 | function requireExportedVariable() # args: envVarName[, message] 189 | { 190 | local envVarName="$1" 191 | local message="$2" 192 | local value 193 | 194 | if [[ ${!envVarName} == "" ]]; then 195 | value=`getBashProfileEnvVarValue "$envVarName"` 196 | 197 | [[ $value != "" ]] || \ 198 | panic 1 "Environment variable $envVarName is not set or is empty" 199 | 200 | eval $envVarName='$value' 201 | export $envVarName 202 | fi 203 | } 204 | 205 | function createSymlink() # args: sourcePath, linkPath 206 | { 207 | local sourcePath="$1" 208 | local linkPath="$2" 209 | 210 | ln -fhs "$sourcePath" "$linkPath" || \ 211 | panic $? "Failed to create symbolic link $linkPath -> $sourcePath" 212 | } 213 | 214 | function runCmdOnDevice() # args: command message 215 | { 216 | local command="$1" 217 | local message="$1" 218 | local final="$1" 219 | 220 | if [[ "$MonkeyDevDevicePassword" != "" ]]; then 221 | final="sshpass -p $MonkeyDevDevicePassword $command" 222 | fi 223 | 224 | eval "$final" || \ 225 | panic $? "$message" 226 | } 227 | 228 | #拷贝文件到设备 229 | function copyFileToDevice() # args: sourceFile, targetDir, hostAddress, hostPort 230 | { 231 | local sourceFile="$1" 232 | local targetDir="$2" 233 | local hostAddress="$3" 234 | local hostPort="$4" 235 | local targetFilePath 236 | 237 | runCmdOnDevice "ssh -p$hostPort root@$hostAddress mkdir -p \"$targetDir\"" "Failed to create directory $targetDir on device $hostAddress" 238 | 239 | targetFilePath="$targetDir/`basename \"$sourceFile\"`" || \ 240 | panic $? "Failed to build target file path" 241 | 242 | runCmdOnDevice "ssh -p$hostPort root@$hostAddress rm -f \"$targetFilePath\"" "Failed to remove existing file $targetFilePath on device $hostAddress" 243 | 244 | runCmdOnDevice "scp -P$hostPort \"$sourceFile\" root@$hostAddress:\"$targetFilePath\"" "Failed to copy file $sourceFile to device $hostAddress at directory $targetDir" 245 | } 246 | 247 | function getBashProfileEnvVarValue() # args: envVarName 248 | { 249 | $setCmd 250 | 251 | local envVarName="$1" 252 | local perlValue 253 | local bashProfileFile 254 | 255 | bashProfileFile=`determineBashProfileFile` 256 | 257 | perlValue=`perl -ne 'print $1 if /^(?:export)? *'"$envVarName"'=(.*)$/' "$bashProfileFile"` || \ 258 | panic $? "Failed to perl" 259 | 260 | # return # 261 | echo "$perlValue" 262 | } 263 | 264 | function getTempDir() # no args 265 | { 266 | $setCmd 267 | 268 | local tempDir 269 | 270 | tempDir=`mktemp -d -t $scriptName` || \ 271 | panic $? "Failed to create temporary directory" 272 | 273 | # remember the temp dir path; in cleanup() these are rm'd # 274 | 275 | echo "$tempDir" >> "$tempDirsFile" || \ 276 | panic $? "Failed to echo into temporary file $tempDirsFile" 277 | 278 | # return # 279 | echo "$tempDir" 280 | } 281 | 282 | #签名 283 | function signCode() # args: executableToSign, identityToSignWith 284 | { 285 | local executableToSign="$1" 286 | local identityToSignWith="$2" 287 | local cmdBin 288 | local cmdArg 289 | local codesignAllocatePath 290 | local entitlements="$CODE_SIGN_ENTITLEMENTS" 291 | 292 | # process arguments # 293 | 294 | requireFile "$executableToSign" false 295 | 296 | if [[ "$identityToSignWith" == "" || "$identityToSignWith" == "-" ]]; then 297 | 298 | # use ldid # 299 | cmdBin="ldid" 300 | 301 | if [[ "$entitlements" == "" ]]; then 302 | cmdArg=("-S") 303 | else 304 | cmdArg=("-S${PROJECT_DIR}/${entitlements}") 305 | fi 306 | 307 | else 308 | # use codesign # 309 | codesignAllocatePath=`xcodebuild -sdk iphoneos -find codesign_allocate` || \ 310 | panic $? "Failed to get codesign_allocate path" 311 | 312 | export CODESIGN_ALLOCATE="$codesignAllocatePath" 313 | 314 | cmdBin=`xcodebuild -sdk iphoneos -find codesign` || \ 315 | panic $? "Failed to get codesign path" 316 | 317 | if [[ "$entitlements" == "" ]]; then 318 | cmdArg=("-fs" "$identityToSignWith") 319 | else 320 | cmdArg=("-fs" "$identityToSignWith" "--entitlements" "${PROJECT_DIR}/${entitlements}") 321 | fi 322 | fi 323 | 324 | echo -n "Signing $executableToSign with `basename \"$cmdBin\"`... " 325 | 326 | "$cmdBin" "${cmdArg[@]}" "$executableToSign" || \ 327 | panic $? "Failed." 328 | 329 | # success # 330 | echo "Done." 331 | } 332 | 333 | 334 | #从plist读取 335 | function readDefaultsValue() # args: plistPath, propertyName 336 | { 337 | $setCmd 338 | 339 | local plistPath="$1" 340 | local propertyName="$2" 341 | local value 342 | 343 | value=`defaults read "${plistPath%.*}" "$propertyName"` || \ 344 | panic $? "Failed to read defaults property $propertyName from $plistPath" 345 | 346 | # return # 347 | echo "$value" 348 | } 349 | 350 | #获取control文件信息 351 | function getControlFieldValue() # args: controlFile, fieldName [, isRequired] 352 | { 353 | $setCmd 354 | 355 | local controlFile="$1" 356 | local fieldName="$2" 357 | local isRequired="$3" 358 | local perlValue 359 | 360 | perlValue=`perl -ne 'print $1 if /^'"$fieldName"': *(.*) *$/' "$controlFile"` || \ 361 | panic $? "Failed perl command using $controlFile" 362 | 363 | if [[ "$perlValue" == "" ]] && [[ "$isRequired" == "true" ]]; then 364 | panic 1 "Missing control field: $fieldName" 365 | fi 366 | 367 | # return # 368 | echo "$perlValue" 369 | } 370 | 371 | #获取pkg信息 372 | function getPackageFileNameUsingControlFile() # args: controlFile 373 | { 374 | $setCmd 375 | 376 | local controlFile="$1" 377 | local pkgId 378 | local pkgVer 379 | local pkgArch 380 | 381 | pkgId=`getControlFieldValue "$controlFile" Package true` 382 | pkgVer=`getControlFieldValue "$controlFile" Version true` 383 | pkgArch=`getControlFieldValue "$controlFile" Architecture true` 384 | 385 | # return # 386 | echo "${pkgId}_${pkgVer}_${pkgArch}" 387 | } 388 | 389 | #打包 390 | function buildPackage() # args: packageDir, outputDir [, useZOption] 391 | { 392 | local packageDir="$1" 393 | local outputDir="$2" 394 | local useZOption="$3" 395 | local subFilesToRemove=(".DS_Store" "0xdeadfa11") 396 | local packageFileName 397 | local packageName 398 | local zipFileName 399 | 400 | echo "Preparing to build package..." 401 | 402 | # verify arguments # 403 | requireDir "$packageDir" 404 | 405 | requireDir "$outputDir" true 406 | 407 | for f in "${subFilesToRemove[@]}"; do 408 | find "$packageDir" -type f -name "$f" -exec rm -f '{}' \; || \ 409 | panic $? "Failed to remove file $f" 410 | done 411 | 412 | #循环去除掉文件的@属性 413 | xattr -crs "$packageDir" || true # forget abou' it (does not work on 10.6) 414 | 415 | changeMode 0644 "$packageDir/DEBIAN/control" 416 | changeMode 0755 "$packageDir/DEBIAN/preinst" 417 | changeMode 0755 "$packageDir/DEBIAN/postinst" 418 | changeMode 0755 "$packageDir/DEBIAN/prerm" 419 | changeMode 0755 "$packageDir/DEBIAN/postrm" 420 | 421 | # determine package name # 422 | packageName=`getPackageFileNameUsingControlFile "$packageDir/DEBIAN/control"` 423 | 424 | # create package # 425 | createDebianPackage "$packageDir" "$packageName" "$outputDir" 426 | 427 | # create zip # 428 | if [[ $useZOption == "true" ]]; then 429 | 430 | zipFileName="$outputDir/${packageName}.zip" 431 | 432 | echo -n "Creating zip $zipFileName... " 433 | 434 | rm -f "$zipFileName" || \ 435 | panic $? "Failed to remove $zipFileName" 436 | 437 | pushd "$packageDir" 1> /dev/null 438 | 439 | zip -qrX "$zipFileName" * || \ 440 | panic $? "Failed." 441 | 442 | popd 1> /dev/null 443 | 444 | echo "Done." 445 | fi 446 | } 447 | 448 | #创建deb 449 | function createDebianPackage() # args: sourceDir, packageName [, outputDir] 450 | { 451 | $setCmd 452 | 453 | local sourceDir="$1" 454 | local packageName="$2" 455 | local outputDir="$3" 456 | 457 | local packageFile="${outputDir:-.}/$packageName.deb" 458 | 459 | echo -n "Building package $packageFileName... " 460 | 461 | local tempDir="`getTempDir`" 462 | 463 | createTarForDebianPackage "$sourceDir/DEBIAN" "$tempDir" "control" "-n" 464 | createTarForDebianPackage "$sourceDir" "$tempDir" "data" "--exclude" "DEBIAN/*" "--exclude" "DEBIAN" 465 | 466 | echo "2.0" > "$tempDir/debian-binary" || \ 467 | panic $? "Failed to create debian-binary file" 468 | 469 | ar -rc "$packageFile" "$tempDir/debian-binary" "$tempDir/control.tar.gz" "$tempDir/data.tar.gz" || \ 470 | panic $? "Failed to create Debian archive" 471 | 472 | echo "Done." 473 | } 474 | 475 | #创建tar.gz 476 | function createTarForDebianPackage() # args: sourceDir, outputDir, tarName [, options] 477 | { 478 | $setCmd 479 | 480 | local sourceDir="$1" 481 | local outputDir="$2" 482 | local tarName="$3" 483 | shift 3 484 | 485 | pushd "$sourceDir" 1> /dev/null 486 | 487 | tar -cLpz --disable-copyfile --exclude ".*" "$@" -f "$outputDir/$tarName.tar.gz" * || \ 488 | panic $? "Failed to create $tarName archive" 489 | 490 | popd 1> /dev/null 491 | } 492 | 493 | #deb包管理 494 | function managePackageOnDevice() # args: manageAction, packageFileOrName, hostAddress, hostPort 495 | { 496 | local manageAction="$1" 497 | local packageFileOrName="$2" 498 | local hostAddress="$3" 499 | local hostPort="$4" 500 | local doingWhat 501 | local direction 502 | local didWhat 503 | local cmdBin="dpkg" 504 | local cmdArg 505 | local devicePackagesDir 506 | 507 | if [[ "$manageAction" == "install" ]]; then 508 | doingWhat="Installing" 509 | direction="on" 510 | didWhat="installed" 511 | cmdArg="--install" 512 | elif [[ "$manageAction" == "remove" ]]; then 513 | doingWhat="Removing" 514 | direction="from" 515 | didWhat="removed" 516 | cmdArg="--remove" 517 | elif [[ "$manageAction" == "purge" ]]; then 518 | doingWhat="Purging" 519 | direction="from" 520 | didWhat="purged" 521 | cmdArg="--purge" 522 | else 523 | panic 1 "Invalid manage action: $manageAction" 524 | fi 525 | 526 | if [[ $hostAddress == "" ]]; then 527 | 528 | requireExportedVariable "MonkeyDevDeviceIP" 529 | 530 | hostAddress="$MonkeyDevDeviceIP" 531 | 532 | [[ $hostAddress != "" ]] || \ 533 | hostAddress="$DefaultDeviceIP" && echo "Host address not provided and environment variable MonkeyDevDeviceIP is not set or is empty, use default $DefaultDeviceIP" 534 | fi 535 | 536 | if [[ $hostPort == "" ]]; then 537 | 538 | hostPort="$MonkeyDevDevicePort" 539 | 540 | [[ $hostPort != "" ]] || hostPort="$MonkeyDevDevicePort" 541 | 542 | fi 543 | 544 | # if installing, copy package to device # 545 | if [[ $manageAction == "install" ]]; then 546 | 547 | requireFile "$packageFileOrName" false 548 | 549 | devicePackagesDir="/var/root/MonkeyDevPackages" 550 | 551 | copyFileToDevice "$packageFileOrName" "$devicePackagesDir" "$hostAddress" "$hostPort" 552 | 553 | packageFileOrName="$devicePackagesDir/`basename \"$packageFileOrName\"`" 554 | fi 555 | 556 | # install, remove or purge package # 557 | echo "$doingWhat package `basename \"$packageFileOrName\"` $direction device $hostAddress... " 558 | 559 | runCmdOnDevice "ssh -p$hostPort root@$hostAddress $cmdBin $cmdArg $packageFileOrName" "Failed." 560 | 561 | # success # 562 | echo "Done." 563 | } 564 | 565 | #在设备执行方法 566 | function runFuncOnDevice() # args: function, hostAddress, hostPort 567 | { 568 | local func="$1" 569 | local hostAddress="$2" 570 | local hostPort="$3" 571 | local cmd 572 | 573 | if [[ $hostAddress == "" ]]; then 574 | 575 | requireExportedVariable "MonkeyDevDeviceIP" 576 | 577 | hostAddress="$MonkeyDevDeviceIP" 578 | 579 | [[ $hostAddress != "" ]] || \ 580 | hostAddress="$DefaultDeviceIP" && echo "Host address not provided and environment variable MonkeyDevDeviceIP is not set or is empty, use default $DefaultDeviceIP" 581 | fi 582 | 583 | if [[ $hostPort == "" ]]; then 584 | 585 | hostPort="$MonkeyDevDevicePort" 586 | 587 | [[ $hostPort != "" ]] || \ 588 | hostPort="$DefaultDevicePort" 589 | 590 | fi 591 | 592 | case "$func" in 593 | reboot) 594 | cmd="reboot" 595 | ;; 596 | respring) 597 | cmd="killall -9 SpringBoard" 598 | ;; 599 | uicache) 600 | cmd="su mobile -c uicache" 601 | ;; 602 | *) 603 | # panic $? "Invalid function: $func" 604 | cmd="$func" 605 | ;; 606 | esac 607 | 608 | runCmdOnDevice "ssh -p$hostPort root@$hostAddress $cmd" "Failed to perform function $func on device $hostAddress" 609 | } 610 | 611 | #sudo 612 | function requireSudo() # args: ... 613 | { 614 | if [[ $EUID != 0 ]]; then 615 | 616 | removeTempData 617 | 618 | exec sudo "$0" "$@" || \ 619 | panic $? "Failed to re-execute as root" 620 | fi 621 | } 622 | 623 | #从文件匹配内容 624 | function doesFileContain() # args: filePath, pattern 625 | { 626 | $setCmd 627 | 628 | local filePath="$1" 629 | local pattern="$2" 630 | local perlValue 631 | local funcReturn 632 | 633 | perlValue=`perl -ne 'if (/'"$pattern"'/) { print "true"; exit; }' "$filePath"` || \ 634 | panic $? "Failed to perl" 635 | 636 | if [[ $perlValue == "true" ]]; then 637 | funcReturn="true" 638 | else 639 | funcReturn="false" 640 | fi 641 | 642 | # return # 643 | echo $funcReturn 644 | } 645 | 646 | #预处理xm、x文件 647 | function Processor() 648 | { 649 | local logosProcessor="$1" 650 | local currentDirectory="$2" 651 | 652 | if [[ $currentDirectory =~ "Build/Products" ]] || [[ $currentDirectory =~ "Build/Intermediates" ]] || [[ $currentDirectory =~ "Index/DataStore" ]] || [[ $currentDirectory =~ "/LatestBuild/" ]]; then 653 | return 654 | fi 655 | 656 | for file in `ls "$currentDirectory"`; 657 | do 658 | extension="${file#*.}" 659 | filename="${file##*/}" 660 | if [[ -d "$currentDirectory/$file" ]]; then 661 | Processor "$logosProcessor" "$currentDirectory/$file" 662 | elif [[ "$extension" == "xm" ]]; then 663 | if [[ ! -f "$currentDirectory/${file%.*}.mm" ]] || [[ `ls -l "$currentDirectory/${file%.*}.mm" | awk '{ print $5 }'` < 10 ]] || [[ `stat -f %c "$currentDirectory/$file"` > `stat -f %c "$currentDirectory/${file%.*}.mm"` ]]; then 664 | echo "Logos Processor: $filename -> ${filename%.*}.mm..." 665 | logosStdErr=$(("$logosProcessor" "$currentDirectory/$file" > "$currentDirectory/${file%.*}.mm") 2>&1) || \ 666 | panic $? "Failed Logos Processor: $logosStdErr" 667 | fi 668 | 669 | elif [[ "$extension" == "x" ]]; then 670 | if [[ ! -f "$currentDirectory/${file%.*}.m" ]] || [[ `ls -l "$currentDirectory/${file%.*}.m" | awk '{ print $5 }'` < 10 ]] || [[ `stat -f %c "$currentDirectory/$file"` > `stat -f %c "$currentDirectory/${file%.*}.m"` ]]; then 671 | echo "Logos Processor: $filename -> ${filename%.*}.m..." 672 | logosStdErr=$(("$logosProcessor" "$currentDirectory/$file" > "$currentDirectory/${file%.*}.m") 2>&1) || \ 673 | panic $? "Failed Logos Processor: $logosStdErr" 674 | fi 675 | 676 | fi 677 | done 678 | } 679 | 680 | # --xcbp-logos 681 | function xcodeBuildPhase_Logos() # no args 682 | { 683 | [[ "$ACTION" == "build" ]] || \ 684 | panic 1 "For Xcode Build Phase use only, Not support Archive, Please use LatestBuild/createIPA.command to generate ipa." 685 | 686 | echo "Preparing to run Xcode Build Phase for Logos Processor..." 687 | 688 | local pbxProjectFilePath="$PROJECT_FILE_PATH/project.pbxproj" 689 | local logosProcessor 690 | local projectFileModified=false 691 | local projectContainsXmFiles 692 | local projectContainsXFiles 693 | local lastKnownXmFileTypeNotObjCpp 694 | local lastKnownXFileTypeNotObjC 695 | local xmFileLangSpecNotObjCpp 696 | local xFileLangSpecNotObjC 697 | local projectXmFiles 698 | local projectXFiles 699 | local logosStdErr 700 | local logosErr=0 701 | 702 | [[ -f "$pbxProjectFilePath" ]] || \ 703 | panic 1 "Xcode project file not found: $pbxProjectFilePath" 704 | 705 | #没有安装Theos? 706 | logosProcessor=`which logos.pl` || \ 707 | panic $? "Failed to locate Logos Processor. Is Theos installed? If not, see https://github.com/theos/theos/wiki/Installation." 708 | 709 | # for each *.xm project file, use Logos Processor to generate *.mm file 710 | 711 | Processor "$logosProcessor" "$PROJECT_DIR" 712 | 713 | echo "Note: If any *.xm or *.x file generated above by the Logos Processor (${projectXmFiles[@]}) is not being compiled below, then you must add it to the Xcode project to be compiled." 714 | 715 | echo "Xcode Build Phase for Logos Processor complete." 716 | } 717 | 718 | # --xcbp 719 | function xcodeBuildPhase() # no args 720 | { 721 | [[ "$ACTION" == "build" ]] || \ 722 | panic 1 "For Xcode Build Phase use only" 723 | 724 | echo "Preparing to run Xcode Build Phase..." 725 | 726 | #编译可执行文件路径 727 | local builtExecutable="$TARGET_BUILD_DIR/$EXECUTABLE_PATH" 728 | #deb打包文件夹目录 729 | local packageDirectory="$PROJECT_DIR/$TARGET_NAME/Package" 730 | #安装的目录 731 | local packageInstallPath="$packageDirectory$INSTALL_PATH" 732 | #存放所有deb目录 733 | local allPackagesDir="$PROJECT_DIR/Packages" 734 | #编译产品输出目录 735 | local builtProductsDir="$BUILT_PRODUCTS_DIR" 736 | #最新的编译版本 737 | local latestBuildSymlink="$PROJECT_DIR/LatestBuild" 738 | local stripBin 739 | local stripOption 740 | local packageFileName 741 | 742 | #目标文件路径 743 | local packageInstallSource 744 | if [[ $SHALLOW_BUNDLE != "YES" ]]; then 745 | packageInstallSource="$TARGET_BUILD_DIR/$EXECUTABLE_PATH" 746 | else 747 | packageInstallSource="$TARGET_BUILD_DIR/$EXECUTABLE_FOLDER_PATH" 748 | fi 749 | 750 | #如果编译设置里面MonkeyDevDeviceIP为空的话,就从用户的profile里面去拿,否则使用默认值 751 | [[ $MonkeyDevDeviceIP != "" ]] || \ 752 | MonkeyDevDeviceIP=`getBashProfileEnvVarValue "MonkeyDevDeviceIP"` 753 | [[ $MonkeyDevDeviceIP != "" ]] || \ 754 | MonkeyDevDeviceIP="$DefaultDeviceIP" && echo "use default $DefaultDeviceIP" 755 | 756 | #如果编译设置里面MonkeyDevDevicePort为空的话,就从用户的profile里面去拿,否则使用默认值 757 | [[ $MonkeyDevDevicePort != "" ]] || \ 758 | MonkeyDevDevicePort=`getBashProfileEnvVarValue "MonkeyDevDevicePort"` 759 | 760 | [[ $MonkeyDevDevicePort != "" ]] || \ 761 | MonkeyDevDevicePort="$DefaultDevicePort" 762 | 763 | #验证必要文件的存在 764 | requireFile "$builtExecutable" false 765 | 766 | #创建最后一个编译的符号链接 767 | createSymlink "$builtProductsDir" "$latestBuildSymlink" 768 | 769 | #如果是Profile,strip可执行文件 770 | if [[ "$CONFIGURATION" == "Release" && "$VALIDATE_PRODUCT" == "YES" ]]; then 771 | if [[ "$STRIP_INSTALLED_PRODUCT" == "YES" ]]; then 772 | 773 | stripBin=`xcodebuild -sdk iphoneos -find strip` || \ 774 | panic $? "Failed to get strip path" 775 | 776 | echo "$stripBin" 777 | 778 | [[ "$STRIP_STYLE" != "debugging" ]] || stripOption="-S" 779 | 780 | echo "Stripping $builtExecutable..." 781 | 782 | "$stripBin" $stripOption "$builtExecutable" || \ 783 | panic $? "Failed to strip $builtExecutable" 784 | fi 785 | fi 786 | 787 | #静态库跳过签名 788 | if [[ "$MACH_O_TYPE" == "staticlib" && "$CODE_SIGN_IDENTITY" == "" ]]; then 789 | echo "Skipping signing (since ldid would be used and it fails on static libraries)" 790 | elif [[ "$PLATFORM_NAME" != "iphoneos" ]]; then 791 | echo "Skipping signing (since platform is not iphoneos)" 792 | else 793 | signCode "$builtExecutable" "$EXPANDED_CODE_SIGN_IDENTITY" 794 | fi 795 | 796 | changeMode "$INSTALL_MODE_FLAG" "$builtExecutable" 797 | 798 | if [[ "$MonkeyDevDevicePassword" != "" ]]; then 799 | sshpassProcessor=`which sshpass` || \ 800 | panic $? "Failed to locate sshpass. Is sshpass installed? If not, brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb" 801 | fi 802 | 803 | #是否需要拷贝到设备 804 | if [[ "$MonkeyDevCopyOnBuild" == "YES" ]]; then 805 | 806 | #拷贝到设备的/var/root/MonkeyDevBuilds/ 807 | if [[ "$MonkeyDevDeviceIP" != "" ]]; then 808 | copyFileToDevice "$builtExecutable" "/var/root/MonkeyDevBuilds/$PROJECT_NAME" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort" 809 | else 810 | # build setting MonkeyDevDeviceIP is empty # 811 | panic 1 "Unable to copy executable to device since build setting MonkeyDevDeviceIP is not set or is empty and it is not exported in your Bash personal initialization file" 812 | fi 813 | 814 | fi 815 | 816 | #如果是profie或者用户设置了每次build都install或package,生成deb 817 | if [[ "$CONFIGURATION" == "Release" && "$VALIDATE_PRODUCT" == "YES" ]] || [[ "$MonkeyDevInstallOnAnyBuild" == "YES" ]] || [[ "$MonkeyDevBuildPackageOnAnyBuild" == "YES" ]]; then 818 | requireDir "$packageDirectory" 819 | #准备打包 820 | echo "Copying $packageInstallSource to package directory at $packageInstallPath..." 821 | 822 | requireDir "$packageInstallPath" true 823 | 824 | #拷贝目标文件到/Package/Library/MobileSubstrate/DynamicLibraries 825 | copyFile "$packageInstallSource" "$packageInstallPath" 826 | 827 | buildPackage "$packageDirectory" "$allPackagesDir" true 828 | 829 | #profile或者用户设置了build安装 830 | if [[ "$CONFIGURATION" == "Release" && "$VALIDATE_PRODUCT" == "YES" ]] || [[ "$MonkeyDevInstallOnAnyBuild" == "YES" ]]; then 831 | 832 | if [[ "$DEPLOYMENT_POSTPROCESSING" == "NO" || "$MonkeyDevInstallOnAnyBuild" == "YES" ]]; then 833 | 834 | # if build setting MonkeyDevInstallOnProfiling is enabled, installation of package is enabled... 835 | if [[ "$MonkeyDevInstallOnProfiling" == "YES" || "$MonkeyDevInstallOnAnyBuild" == "YES" ]]; then 836 | 837 | # if MonkeyDevDeviceIP has a value, install package on device... 838 | if [[ "$MonkeyDevDeviceIP" != "" ]]; then 839 | 840 | # get package file name # 841 | packageFileName="`getPackageFileNameUsingControlFile \"$packageDirectory/DEBIAN/control\"`.deb" 842 | 843 | # install package on device # 844 | managePackageOnDevice "install" "$allPackagesDir/$packageFileName" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort" 845 | 846 | if [[ "$MonkeyDevkillProcessOnInstall" != "" ]]; then 847 | if [[ "$MonkeyDevkillProcessOnInstall" == "SpringBoard" ]]; then 848 | echo "respring device..." 849 | runFuncOnDevice "respring" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort" 850 | else 851 | echo "killall -9 $MonkeyDevkillProcessOnInstall" 852 | runFuncOnDevice "killall -9 $MonkeyDevkillProcessOnInstall || echo skip" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort" 853 | fi 854 | fi 855 | 856 | if [[ "$MonkeyDevClearUiCacheOnInstall" == "YES" ]]; then 857 | echo "Clearing uicache device..." 858 | runFuncOnDevice "uicache" "$MonkeyDevDeviceIP" "$MonkeyDevDevicePort" 859 | fi 860 | else 861 | # build setting MonkeyDevDeviceIP is empty # 862 | panic 1 "Unable to install package on device since build setting MonkeyDevDeviceIP is not set or is empty and it is not exported in your Bash personal initialization file" 863 | fi 864 | else 865 | # build setting MonkeyDevInstallOnProfiling is disabled # 866 | echo "Installation of package on device is disabled. To enable, set build setting MonkeyDevInstallOnProfiling to YES." 867 | fi 868 | fi 869 | fi 870 | fi 871 | 872 | echo "Xcode Build Phase complete." 873 | } 874 | 875 | #用法 876 | function showUsageAndExit() # args: showEverything 877 | { 878 | local showEverything="$1" 879 | local n 880 | 881 | echo "$scriptName (v$scriptVer) -- MonkeyDev Command-line Tool" 882 | echo "Usages:" 883 | 884 | for n in "${ActionNames[@]}"; do 885 | eval echo "\" $scriptName \${Action_$n[$ActionProperty_ShortArg]} \${Action_$n[$ActionProperty_ShortUsage]}\"" 886 | done 887 | 888 | if [[ $showEverything == "true" ]]; then 889 | echo 890 | echo "Actions:" 891 | 892 | for n in "${ActionNames[@]}"; do 893 | eval echo "\" \${Action_$n[$ActionProperty_ShortArg]} \${Action_$n[$ActionProperty_ShortUsage]}\"" 894 | eval echo "\"\${Action_$n[$ActionProperty_LongUsage]}\"" 895 | echo 896 | done 897 | fi 898 | 899 | panic 1 900 | } 901 | 902 | function showSingleUsageAndExit() 903 | { 904 | panic 1 "Usage: $scriptName ${activeActionArg[$ActionProperty_ShortArg]} ${activeActionArg[$ActionProperty_ShortUsage]} 905 | 906 | ${activeActionArg[$ActionProperty_LongUsage]} 907 | " 908 | 909 | } 910 | 911 | #脚本开始 912 | [[ $1 != "" ]] || showUsageAndExit false 913 | [[ $1 != "--help" ]] || showUsageAndExit true 914 | 915 | #寻找有没有对应的参数 916 | for n in "${ActionNames[@]}"; do 917 | foundArg=false 918 | eval [[ "\$1" != "\${Action_$n[$ActionProperty_ShortArg]}" ]] || \ 919 | foundArg=true 920 | 921 | if [[ $foundArg == true ]]; then 922 | eval activeActionArg=("\"\${Action_$n[@]}\"") 923 | break; 924 | fi 925 | done 926 | 927 | [[ $foundArg == true ]] || \ 928 | panic 1 "Invalid argument: $1" 929 | 930 | [[ "$#" != 1 || ${activeActionArg[$ActionProperty_MinArgs]} == 0 ]] || \ 931 | showSingleUsageAndExit 932 | 933 | shift 1 934 | 935 | while getopts ":${activeActionArg[$ActionProperty_Options]}" opt; do 936 | case "$opt" in 937 | \?) 938 | panic 1 "Invalid option: -$OPTARG" 939 | ;; 940 | *) 941 | [[ $opt != ":" ]] || \ 942 | panic 1 "Option missing value: -$OPTARG" 943 | 944 | eval Opt_$opt="\"${OPTARG-true}\"" #可选参数赋值 945 | ;; 946 | esac 947 | done 948 | 949 | shift $(($OPTIND - 1)) # shift out options 950 | 951 | (( "$#" >= ${activeActionArg[$ActionProperty_MinArgs]} && "$#" <= ${activeActionArg[$ActionProperty_MaxArgs]} )) || \ 952 | showSingleUsageAndExit 953 | 954 | #执行Action 955 | [[ ${activeActionArg[$ActionProperty_RequireSudo]} == false ]] || \ 956 | requireSudo "${originalArguments[@]}" 957 | 958 | case "${activeActionArg[$ActionProperty_ShortArg]}" in 959 | ${Action_XcodeBuildPhase[$ActionProperty_ShortArg]}) 960 | "${activeActionArg[$ActionProperty_Function]}" 961 | ;; 962 | ${Action_XcodeBuildPhaseLogos[$ActionProperty_ShortArg]}) 963 | "${activeActionArg[$ActionProperty_Function]}" 964 | ;; 965 | esac 966 | 967 | exit 0 968 | -------------------------------------------------------------------------------- /bin/md-install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -e表示一旦脚本中有命令的返回值为非0,则脚本立即退出,后续命令不再执行; 4 | #set -o pipefail表示在管道连接的命令序列中,只要有任何一个命令返回非0值,则整个管道返回非0值,即使最后一个命令返回0. 5 | export setCmd="set -eo pipefail" 6 | $setCmd 7 | 8 | #导出环境变量 9 | export PATH=/opt/MonkeyDev/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH 10 | 11 | #脚本名称和版本 12 | export scriptName="${0##*/}" 13 | export scriptVer="2.0" 14 | 15 | #本地存储文件的目录 16 | export MonkeyDevPath="/opt/MonkeyDev" 17 | export backupFileExt=".MonkeyDev" 18 | 19 | #获取用户名、用户组、用户目录、和profile文件 20 | export userName="${SUDO_USER-$USER}" 21 | export userGroup=`id -g $userName` 22 | export userHome=`eval echo ~$userName` 23 | 24 | #用户可能存在的profile文件 25 | export bashProfileFiles=("$userHome/.zshrc" "$userHome/.bash_profile" "$userHome/.bashrc" "$userHome/.bash_login" "$userHome/.profile") 26 | 27 | #获取临时文件名 28 | export tempDirsFile="`mktemp -d -t $scriptName`/tempdirs" 29 | touch "$tempDirsFile" 30 | 31 | #把LANG变量从当前环境中删除 32 | unset LANG 33 | 34 | #出错退出 35 | function cleanup() 36 | { 37 | local exitCode=$? 38 | set +e 39 | trap - $signals 40 | removeTempData 41 | exit $exitCode 42 | } 43 | 44 | function panic() 45 | { 46 | local exitCode=$1 47 | set +e 48 | shift 49 | [[ "$@" == "" ]] || echo "$@" >&2 50 | exit $exitCode 51 | } 52 | 53 | export signals="0 1 2 3 15" 54 | #当shell接收到signals指定的信号时,执行cleanup命令 55 | trap cleanup $signals 56 | 57 | function removeTempData() 58 | { 59 | local tempDirs 60 | if [[ -f "$tempDirsFile" ]]; then 61 | tempDirs=(`cat "$tempDirsFile"`) 62 | for td in "${tempDirs[@]}"; do 63 | rm -rf "$td" || true 64 | done 65 | rm -rf "`dirname $tempDirsFile`" || true 66 | fi 67 | } 68 | function getTempDir() 69 | { 70 | $setCmd 71 | local tempDir 72 | tempDir=`mktemp -d -t $scriptName` || \ 73 | panic $? "Failed to create temporary directory" 74 | echo "$tempDir" >> "$tempDirsFile" || \ 75 | panic $? "Failed to echo into $tempDirsFile" 76 | echo "$tempDir" 77 | } 78 | 79 | function copyFile() 80 | { 81 | cp -f "$1" "$2" || \ 82 | panic $? "Failed to copy file $1 to $2" 83 | } 84 | 85 | #备份原文件 86 | function requireBackup() 87 | { 88 | [[ ! -f "$1" || -f "${1}${backupFileExt}" ]] || \ 89 | copyFile "$1" "${1}${backupFileExt}" 90 | } 91 | 92 | #获取SDK信息 93 | function getSdkProperty() 94 | { 95 | $setCmd 96 | 97 | local sdk="$1" 98 | local propertyName="$2" 99 | 100 | propertyValue=`xcodebuild -version -sdk $sdk $propertyName` || \ 101 | panic $? "Failed to get $sdk SDK property $propertyName" 102 | 103 | [[ $propertyValue != "" ]] || \ 104 | panic 1 "Value of $sdk SDK property $propertyName cannot be empty" 105 | 106 | # return # 107 | echo "$propertyValue" 108 | } 109 | 110 | #下载文件 111 | function downloadFile() # args: sourceUrl, targetPath 112 | { 113 | local sourceUrl="$1" 114 | local targetPath="$2" 115 | local curlPath 116 | 117 | mkdir -p "${targetPath%/*}" || \ 118 | panic $? "Failed to make directory: ${targetPath%/*}" 119 | 120 | curlPath=`which curl` || \ 121 | panic $? "Failed to get curl path" 122 | 123 | "$curlPath" --output "$targetPath" "$sourceUrl" || \ 124 | panic $? "Failed to download $sourceUrl to $targetPath" 125 | } 126 | 127 | #解压文件 128 | function extractTar() # args: tarPath, outputPath 129 | { 130 | local tarPath="$1" 131 | local outputPath="$2" 132 | 133 | tar -C "$outputPath" -zxf "$tarPath" || \ 134 | panic $? "Failed to extract $tarPath to $outputPath" 135 | } 136 | 137 | #下载github文件 138 | function downloadGithubTarball() # args: url, outputDir, title 139 | { 140 | $setcmd 141 | 142 | local url="$1" 143 | local outputDir="$2" 144 | local title="$3" 145 | local tempDirForTar 146 | local tempDirForFiles 147 | local untardDir 148 | local tarFile="file.tar.gz" 149 | 150 | echo "Downloading $title from Github..." 151 | 152 | tempDirForTar=`getTempDir` 153 | tempDirForFiles=`getTempDir` 154 | 155 | downloadFile "$url" "$tempDirForTar/$tarFile" 156 | 157 | extractTar "$tempDirForTar/$tarFile" "$tempDirForFiles" 158 | 159 | untardDir=`find "$tempDirForFiles/"* -type d -depth 0` || \ 160 | panic $? "Failed to get untar'ed directory name of $tempDirForTar/$tarFile" 161 | 162 | mkdir -p "$outputDir" || \ 163 | panic $? "Failed to make directory: $outputDir" 164 | 165 | cp -fR "$untardDir/"* "$outputDir/" 166 | } 167 | 168 | #修改文件权限 169 | function changeMode() 170 | { 171 | local mode="$1" 172 | local target="$2" 173 | local recursive="$3" 174 | local options 175 | 176 | [[ $recursive != "true" ]] || \ 177 | options="-R" 178 | 179 | if [[ -e "$target" ]]; then 180 | chmod $options "$mode" "$target" || \ 181 | panic $? "Failed to change mode to $mode on $target" 182 | fi 183 | } 184 | 185 | #获取用户profile文件 186 | function determineUserBashProfileFile() 187 | { 188 | $setCmd 189 | 190 | local f 191 | local filePath 192 | 193 | for f in "${bashProfileFiles[@]}"; do 194 | if [[ -f "$f" ]]; then 195 | filePath="$f" 196 | echo "" >> "$f" || \ 197 | panic $? "Failed to echo into $f" 198 | break 199 | fi 200 | done 201 | 202 | if [[ $filePath == "" ]]; then 203 | filePath="$bashProfileFiles" 204 | 205 | touch "$filePath" || \ 206 | panic $? "Failed to touch $filePath" 207 | 208 | chown "$userName:$userGroup" "$filePath" || \ 209 | panic $? "Failed to change owner-group of $filePath" 210 | 211 | changeMode 0600 "$filePath" 212 | fi 213 | 214 | # return # 215 | echo "$filePath" 216 | } 217 | 218 | #验证是否存在文件 219 | function requireFile() # args: filePath [, touchFileIfNotFound] 220 | { 221 | local filePath="$1" 222 | local touchFileIfNotFound="$2" 223 | 224 | if [[ ! -f "$filePath" ]]; then 225 | if [[ $touchFileIfNotFound == "true" ]]; then 226 | 227 | touch "$filePath" || \ 228 | panic $? "Failed to touch $filePath" 229 | 230 | else 231 | panic 1 "File $filePath not found" 232 | fi 233 | fi 234 | } 235 | 236 | #增加内容到文件 237 | function addToFileIfMissing() # args: filePath, pattern, value 238 | { 239 | local filePath="$1" 240 | local pattern="$2" 241 | local value="$3" 242 | local doesContain 243 | 244 | doesContain=`doesFileContain "$filePath" "$pattern"` 245 | 246 | [[ $doesContain == "true" ]] || \ 247 | echo "$value" >> "$filePath" || \ 248 | panic $? "Failed to echo into $filePath" 249 | } 250 | 251 | #判断文件是否包含内容 252 | function doesFileContain() # args: filePath, pattern 253 | { 254 | $setCmd 255 | 256 | local filePath="$1" 257 | local pattern="$2" 258 | local perlValue 259 | local funcReturn 260 | 261 | perlValue=`perl -ne 'if (/'"$pattern"'/) { print "true"; exit; }' "$filePath"` || \ 262 | panic $? "Failed to perl" 263 | 264 | if [[ $perlValue == "true" ]]; then 265 | funcReturn="true" 266 | else 267 | funcReturn="false" 268 | fi 269 | 270 | # return # 271 | echo $funcReturn 272 | } 273 | 274 | #从spec读取内容 275 | function readXcodeSpecificationById(){ #args: filePath, id 276 | local filePath="$1" 277 | local id="$2" 278 | content=`/usr/libexec/PlistBuddy -x -c Print "$filePath"` || \ 279 | panic $? "Failed to get $filePath content" 280 | for (( i=0; i<=1; i++)); do 281 | dict=`/usr/libexec/PlistBuddy -x -c "Print $i" "$filePath"` 282 | if echo $dict | grep -qE "$id"; then 283 | echo "$dict" 284 | fi 285 | done 286 | } 287 | 288 | #往spec文件写入内容 289 | function writeDictToSpecification(){ #args: filePath, content 290 | local filePath="$1" 291 | local content="$2" 292 | tempfile=`getTempDir`/dictfile 293 | echo "$content" >> $tempfile 294 | /usr/libexec/PlistBuddy -x -c 'add 0 dict' "$filePath" > /dev/null 295 | /usr/libexec/PlistBuddy -x -c "merge $tempfile 0" "$filePath" > /dev/null 296 | } 297 | 298 | # start it 299 | # 创建/opt/MonkeyDev 300 | mkdir -p "$MonkeyDevPath" || \ 301 | panic $? "Failed to make directory: $MonkeyDevPath" 302 | 303 | branch="master" 304 | 305 | if [[ "$1" ]]; then 306 | branch="$1" 307 | fi 308 | 309 | #下载一些基础文件和模板文件 310 | downloadGithubTarball "https://codeload.github.com/AloneMonkey/MonkeyDev/tar.gz/$branch" "$MonkeyDevPath" "MonkeyDev base" 311 | downloadGithubTarball "https://codeload.github.com/AloneMonkey/MonkeyDev-Xcode-Templates/tar.gz/$branch" "$MonkeyDevPath/templates" "Xcode templates" 312 | 313 | #下载frida-ios-dump 314 | echo "Downloading frida-ios-dump from Github..." 315 | downloadFile "https://raw.githubusercontent.com/AloneMonkey/frida-ios-dump/3.x/dump.py" "$MonkeyDevPath/bin/dump.py" 316 | downloadFile "https://raw.githubusercontent.com/AloneMonkey/frida-ios-dump/3.x/dump.js" "$MonkeyDevPath/bin/dump.js" 317 | 318 | chmod +x "$MonkeyDevPath/bin/dump.py" 319 | 320 | #创建符号链接 321 | echo "Creating symlink to Xcode templates..." 322 | 323 | #$userHome/Library/Developer/Xcode/Templates/MonkeyDev linkto $MonkeyDevPath/templates 324 | userDevDir="$userHome/Library/Developer" 325 | userTemplatesDir="$userDevDir/Xcode/Templates" 326 | 327 | if [[ ! -d "$userTemplatesDir" ]]; then 328 | mkdir -p "$userTemplatesDir" || \ 329 | panic $? "Failed to make directory: $userTemplatesDir" 330 | 331 | chown -R "$userName:$userGroup" "$userDevDir" || \ 332 | panic $? "Failed to change ownership-group of $userDevDir" 333 | fi 334 | 335 | ln -fhs "$MonkeyDevPath/templates" "$userTemplatesDir/MonkeyDev" 336 | 337 | #修改用户profile文件 338 | echo "Modifying Bash personal initialization file..." 339 | 340 | userBashProfileFile=`determineUserBashProfileFile` 341 | 342 | addToFileIfMissing "$userBashProfileFile" "^(export)? *MonkeyDevPath=.*" "export MonkeyDevPath=$MonkeyDevPath" 343 | addToFileIfMissing "$userBashProfileFile" "^(export)? *MonkeyDevDeviceIP=.*" "export MonkeyDevDeviceIP=" 344 | addToFileIfMissing "$userBashProfileFile" "^(export)? *PATH=.*(\\\$MonkeyDevPath\\/bin|${MonkeyDevPath//\//\\/}\\/bin).*" "export PATH=$MonkeyDevPath/bin:\$PATH" 345 | 346 | #支持iphoneos command line tools 347 | iosSdkPlatformPath=`getSdkProperty iphoneos PlatformPath` 348 | macosSdkPlatformPath=`getSdkProperty macosx PlatformPath` 349 | 350 | specificationFile=$(cd $iosSdkPlatformPath/../../.. && pwd)/PlugIns/IDEiOSSupportCore.ideplugin/Contents/Resources/Embedded-Device.xcspec 351 | 352 | requireFile "$specificationFile" false 353 | 354 | #backup 355 | requireBackup "$specificationFile" 356 | 357 | hasPackageTypeForCommandLineTool=`doesFileContain "$specificationFile" 'com.apple.package-type.mach-o-executable'` 358 | hasProductTypeForCommandLineTool=`doesFileContain "$specificationFile" 'com.apple.product-type.tool'` 359 | 360 | macosxSDKSpecificationsPath=$macosSdkPlatformPath/Developer/Library/Xcode/Specifications 361 | packageTypesForMacOSXPath="$macosxSDKSpecificationsPath/MacOSX Package Types.xcspec" 362 | productTypesForMacOSXPath="$macosxSDKSpecificationsPath/MacOSX Product Types.xcspec" 363 | 364 | requireFile "$packageTypesForMacOSXPath" false 365 | requireFile "$productTypesForMacOSXPath" false 366 | 367 | if [[ $hasPackageTypeForCommandLineTool != "true" ]]; then 368 | machoDict=`readXcodeSpecificationById "$packageTypesForMacOSXPath" "com.apple.package-type.mach-o-executable"` 369 | writeDictToSpecification "$specificationFile" "$machoDict" 370 | fi 371 | 372 | if [[ $hasProductTypeForCommandLineTool != "true" ]]; then 373 | toolDict=`readXcodeSpecificationById "$productTypesForMacOSXPath" "com.apple.product-type.tool"` 374 | writeDictToSpecification "$specificationFile" "$toolDict" 375 | fi 376 | 377 | exit 0 378 | -------------------------------------------------------------------------------- /bin/md-uninstall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export setCmd="set -eo pipefail" 4 | $setCmd 5 | 6 | export PATH=/opt/MonkeyDev/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH 7 | 8 | export scriptName="${0##*/}" 9 | export scriptVer="2.0" 10 | 11 | export MonkeyDevPath="/opt/MonkeyDev" 12 | export backupFileExt=".MonkeyDev" 13 | 14 | export userName="${SUDO_USER-$USER}" 15 | export userGroup=`id -g $userName` 16 | export userHome=`eval echo ~$userName` 17 | export bashProfileFiles=("$userHome/.zshrc" "$userHome/.bash_profile" "$userHome/.bashrc" "$userHome/.bash_login" "$userHome/.profile") 18 | 19 | export tempDirsFile="`mktemp -d -t $scriptName`/tempdirs" 20 | touch "$tempDirsFile" 21 | 22 | unset LANG 23 | 24 | function cleanup() 25 | { 26 | local exitCode=$? 27 | set +e 28 | trap - $signals 29 | removeTempData 30 | exit $exitCode 31 | } 32 | function panic() 33 | { 34 | local exitCode=$1 35 | set +e 36 | shift 37 | [[ "$@" == "" ]] || echo "$@" >&2 38 | exit $exitCode 39 | } 40 | export signals="0 1 2 3 15" 41 | trap cleanup $signals 42 | 43 | function removeTempData() 44 | { 45 | local tempDirs 46 | if [[ -f "$tempDirsFile" ]]; then 47 | tempDirs=(`cat "$tempDirsFile"`) 48 | for td in "${tempDirs[@]}"; do 49 | rm -rf "$td" || true 50 | done 51 | rm -rf "`dirname $tempDirsFile`" || true 52 | fi 53 | } 54 | 55 | function copyFile() 56 | { 57 | cp -f "$1" "$2" || \ 58 | panic $? "Failed to copy file $1 to $2" 59 | } 60 | 61 | #还原文件 62 | function restoreFile() 63 | { 64 | local filePath="$1" 65 | local backedUpFilePath="${filePath}${backupFileExt}" 66 | 67 | if [[ -f "$backedUpFilePath" ]]; then 68 | copyFile "$backedUpFilePath" "$filePath" 69 | rm -f "$backedUpFilePath" 70 | fi 71 | } 72 | 73 | #获取SDK信息 74 | function getSdkProperty() 75 | { 76 | $setCmd 77 | 78 | local sdk="$1" 79 | local propertyName="$2" 80 | 81 | propertyValue=`xcodebuild -version -sdk $sdk $propertyName` || \ 82 | panic $? "Failed to get $sdk SDK property $propertyName" 83 | 84 | [[ $propertyValue != "" ]] || \ 85 | panic 1 "Value of $sdk SDK property $propertyName cannot be empty" 86 | 87 | # return # 88 | echo "$propertyValue" 89 | } 90 | 91 | echo "Uninstalling MonkeyDev base, Xcode templates and framework header files..." 92 | 93 | #删除文件夹 94 | rm -rf "$MonkeyDevPath" || \ 95 | panic $? "Failed to remove directory: $MonkeyDevPath" 96 | 97 | #移除模块符号链接 98 | userDevDir="$userHome/Library/Developer" 99 | userTemplatesDir="$userDevDir/Xcode/Templates" 100 | symlinkPath="$userTemplatesDir/MonkeyDev" 101 | 102 | rm -f "$symlinkPath" || \ 103 | panic $? "Failed to remove file: $symlinkPath" 104 | 105 | #移除profile环境变量 106 | for f in "${bashProfileFiles[@]}"; do 107 | if [[ -f "$f" ]]; then 108 | userBashProfileFile="$f" 109 | break 110 | fi 111 | done 112 | 113 | if [[ $userBashProfileFile != "" ]]; then 114 | sed -i "" "s/^export MonkeyDevPath=.*$//g" "$userBashProfileFile" 115 | sed -i "" "s/^export MonkeyDevDeviceIP=.*$//g" "$userBashProfileFile" 116 | sed -i "" "s/^export PATH=.*${MonkeyDevPath//\//\\/}\\/bin:.*$//g" "$userBashProfileFile" 117 | sed -i "" "s/^export PATH=.*\$MonkeyDevPath\\/bin:.*$//g" "$userBashProfileFile" 118 | fi 119 | 120 | iosSdkPlatformPath=`getSdkProperty iphoneos PlatformPath` 121 | 122 | specificationFile=$(cd $iosSdkPlatformPath/../../.. && pwd)/PlugIns/IDEiOSSupportCore.ideplugin/Contents/Resources/Embedded-Device.xcspec 123 | 124 | #还原文件 125 | restoreFile "$specificationFile" 126 | 127 | exit 0 -------------------------------------------------------------------------------- /bin/md-update: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -e表示一旦脚本中有命令的返回值为非0,则脚本立即退出,后续命令不再执行; 4 | #set -o pipefail表示在管道连接的命令序列中,只要有任何一个命令返回非0值,则整个管道返回非0值,即使最后一个命令返回0. 5 | export setCmd="set -eo pipefail" 6 | $setCmd 7 | 8 | #导出环境变量 9 | export PATH=/opt/MonkeyDev/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH 10 | 11 | #脚本名称和版本 12 | export scriptName="${0##*/}" 13 | export scriptVer="2.0" 14 | 15 | #本地存储文件的目录 16 | export MonkeyDevPath="/opt/MonkeyDev" 17 | 18 | #获取用户名、用户组、用户目录、和profile文件 19 | export userName="${SUDO_USER-$USER}" 20 | export userGroup=`id -g $userName` 21 | export userHome=`eval echo ~$userName` 22 | 23 | #获取临时文件名 24 | export tempDirsFile="`mktemp -d -t $scriptName`/tempdirs" 25 | touch "$tempDirsFile" 26 | 27 | #把LANG变量从当前环境中删除 28 | unset LANG 29 | 30 | #出错退出 31 | function cleanup() 32 | { 33 | local exitCode=$? 34 | set +e 35 | trap - $signals 36 | removeTempData 37 | exit $exitCode 38 | } 39 | 40 | function panic() 41 | { 42 | local exitCode=$1 43 | set +e 44 | shift 45 | [[ "$@" == "" ]] || echo "$@" >&2 46 | exit $exitCode 47 | } 48 | 49 | export signals="0 1 2 3 15" 50 | #当shell接收到signals指定的信号时,执行cleanup命令 51 | trap cleanup $signals 52 | 53 | function removeTempData() 54 | { 55 | local tempDirs 56 | if [[ -f "$tempDirsFile" ]]; then 57 | tempDirs=(`cat "$tempDirsFile"`) 58 | for td in "${tempDirs[@]}"; do 59 | rm -rf "$td" || true 60 | done 61 | rm -rf "`dirname $tempDirsFile`" || true 62 | fi 63 | } 64 | function getTempDir() 65 | { 66 | $setCmd 67 | local tempDir 68 | tempDir=`mktemp -d -t $scriptName` || \ 69 | panic $? "Failed to create temporary directory" 70 | echo "$tempDir" >> "$tempDirsFile" || \ 71 | panic $? "Failed to echo into $tempDirsFile" 72 | echo "$tempDir" 73 | } 74 | 75 | #下载文件 76 | function downloadFile() # args: sourceUrl, targetPath 77 | { 78 | local sourceUrl="$1" 79 | local targetPath="$2" 80 | local curlPath 81 | 82 | mkdir -p "${targetPath%/*}" || \ 83 | panic $? "Failed to make directory: ${targetPath%/*}" 84 | 85 | curlPath=`which curl` || \ 86 | panic $? "Failed to get curl path" 87 | 88 | "$curlPath" --output "$targetPath" "$sourceUrl" || \ 89 | panic $? "Failed to download $sourceUrl to $targetPath" 90 | } 91 | 92 | #解压文件 93 | function extractTar() # args: tarPath, outputPath 94 | { 95 | local tarPath="$1" 96 | local outputPath="$2" 97 | 98 | tar -C "$outputPath" -zxf "$tarPath" || \ 99 | panic $? "Failed to extract $tarPath to $outputPath" 100 | } 101 | 102 | #下载github文件 103 | function downloadGithubTarball() # args: url, outputDir, title 104 | { 105 | $setcmd 106 | 107 | local url="$1" 108 | local outputDir="$2" 109 | local title="$3" 110 | local tempDirForTar 111 | local tempDirForFiles 112 | local untardDir 113 | local tarFile="file.tar.gz" 114 | 115 | echo "Downloading $title from Github..." 116 | 117 | tempDirForTar=`getTempDir` 118 | tempDirForFiles=`getTempDir` 119 | 120 | downloadFile "$url" "$tempDirForTar/$tarFile" 121 | 122 | extractTar "$tempDirForTar/$tarFile" "$tempDirForFiles" 123 | 124 | untardDir=`find "$tempDirForFiles/"* -type d -depth 0` || \ 125 | panic $? "Failed to get untar'ed directory name of $tempDirForTar/$tarFile" 126 | 127 | rm -rf "$outputDir" || \ 128 | panic $? "Failed to remove directory: $outputDir" 129 | 130 | mkdir -p "$outputDir" || \ 131 | panic $? "Failed to make directory: $outputDir" 132 | 133 | cp -fR "$untardDir/"* "$outputDir/" 134 | } 135 | 136 | branch="master" 137 | 138 | if [[ "$1" ]]; then 139 | branch="$1" 140 | fi 141 | 142 | #更新一些基础文件和模板文件 143 | downloadGithubTarball "https://codeload.github.com/AloneMonkey/MonkeyDev/tar.gz/$branch" "$MonkeyDevPath" "MonkeyDev base" 144 | downloadGithubTarball "https://codeload.github.com/AloneMonkey/MonkeyDev-Xcode-Templates/tar.gz/$branch" "$MonkeyDevPath/templates" "Xcode templates" 145 | 146 | #更新frida-ios-dump 147 | echo "Downloading frida-ios-dump from Github..." 148 | downloadFile "https://raw.githubusercontent.com/AloneMonkey/frida-ios-dump/3.x/dump.py" "$MonkeyDevPath/bin/dump.py" 149 | downloadFile "https://raw.githubusercontent.com/AloneMonkey/frida-ios-dump/3.x/dump.js" "$MonkeyDevPath/bin/dump.js" 150 | 151 | chmod +x "$MonkeyDevPath/bin/dump.py" 152 | 153 | exit 0 154 | -------------------------------------------------------------------------------- /bin/monkeyparser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AloneMonkey/MonkeyDev/c37b5cc5e9a4184d80eb18fb9ae8c48bb8689442/bin/monkeyparser -------------------------------------------------------------------------------- /change.log: -------------------------------------------------------------------------------- 1 | /opt/MonkeyDev/bin/md 2 | 3 | - 3.0 使用monkeyparser替换restore-symbol、optool、unsign 4 | - 3.3 重命名FrameworksForMac为MFrameworks 5 | - 3.3 增加sshpass,支持自己设置设备密码 6 | - 3.5 增加monkeyparser verify验证App、framework是否砸壳 7 | - 3.6 shell写的太丑了,class-dump和restore-symobl都交给monkeyparser去做 8 | - 3.7 二进制文件瘦身,减少下载文件大小 9 | - 3.8 可以选择Debug和Release,Release下不集成Cycript和Reveal 10 | - 4.0 优化目录结构,增加快速重签脚本 11 | - 4.1 集成frida-ios-dump,直接在TargetApp目录下执行dump.py xxx即可 12 | - 4.2 集成新的cycript,支持从网络下载cy脚本,直接@import 13 | - 4.3 优化部分代码,使用MDConfig.plist来配置 14 | - 4.4 支持通过代码执行cycript脚本以及使用脚本编写hook代码 -------------------------------------------------------------------------------- /include/CaptainHook/CaptainHook.h: -------------------------------------------------------------------------------- 1 | // Possible defines: 2 | // CHDebug if defined, CHDebugLog is equivalent to CHLog; else, emits no code 3 | // CHUseSubstrate if defined, uses MSMessageHookEx to hook methods, otherwise uses internal hooking routines. Warning! super call closures are only available on ARM platforms for recent releases of MobileSubstrate 4 | // CHEnableProfiling if defined, enables calls to CHProfileScope() 5 | // CHAppName should be set to the name of the application (if not, defaults to "CaptainHook"); used for logging and profiling 6 | 7 | #import 8 | #import 9 | #import 10 | #import 11 | 12 | #ifndef CHAppName 13 | #define CHAppName "CaptainHook" 14 | #endif 15 | 16 | #ifdef __clang__ 17 | #if __has_feature(objc_arc) 18 | #define CHHasARC 19 | #endif 20 | #endif 21 | 22 | // Some Debugging/Logging Commands 23 | 24 | #define CHStringify_(x) #x 25 | #define CHStringify(x) CHStringify_(x) 26 | #define CHConcat_(a, b) a ## b 27 | #define CHConcat(a, b) CHConcat_(a, b) 28 | 29 | #define CHNothing() do { } while(0) 30 | 31 | #define CHLocationInSource [NSString stringWithFormat:@CHStringify(__LINE__) " in %s", __FUNCTION__] 32 | 33 | #define CHLog(args...) NSLog(@CHAppName ": %@", [NSString stringWithFormat:args]) 34 | #define CHLogSource(args...) NSLog(@CHAppName " @ " CHStringify(__LINE__) " in %s: %@", __FUNCTION__, [NSString stringWithFormat:args]) 35 | 36 | #ifdef CHDebug 37 | #define CHDebugLog(args...) CHLog(args) 38 | #define CHDebugLogSource(args...) CHLogSource(args) 39 | #else 40 | #define CHDebugLog(args...) CHNothing() 41 | #define CHDebugLogSource(args...) CHNothing() 42 | #endif 43 | 44 | // Constructor 45 | #define CHConstructor static __attribute__((constructor)) void CHConcat(CHConstructor, __LINE__)() 46 | #define CHInline inline __attribute__((always_inline)) 47 | 48 | // Cached Class Declaration (allows hooking methods, and fast lookup of classes) 49 | struct CHClassDeclaration_ { 50 | Class class_; 51 | Class metaClass_; 52 | Class superClass_; 53 | }; 54 | typedef struct CHClassDeclaration_ CHClassDeclaration_; 55 | #define CHDeclareClass(name) \ 56 | @class name; \ 57 | static CHClassDeclaration_ name ## $; 58 | 59 | // Loading Cached Classes (use CHLoadClass when class is linkable, CHLoadLateClass when it isn't) 60 | static inline Class CHLoadClass_(CHClassDeclaration_ *declaration, Class value) 61 | { 62 | declaration->class_ = value; 63 | declaration->metaClass_ = object_getClass(value); 64 | declaration->superClass_ = class_getSuperclass(value); 65 | return value; 66 | } 67 | #define CHLoadLateClass(name) CHLoadClass_(&name ## $, objc_getClass(#name)) 68 | #define CHLoadClass(name) CHLoadClass_(&name ## $, [name class]) 69 | 70 | // Quick Lookup of cached classes, and common methods on them 71 | #define CHClass(name) name ## $.class_ 72 | #define CHMetaClass(name) name ## $.metaClass_ 73 | #define CHSuperClass(name) name ## $.superClass_ 74 | #define CHAlloc(name) ((name *)[CHClass(name) alloc]) 75 | #define CHSharedInstance(name) ((name *)[CHClass(name) sharedInstance]) 76 | #define CHIsClass(obj, name) [obj isKindOfClass:CHClass(name)] 77 | #define CHRespondsTo(obj, sel) [obj respondsToSelector:@selector(sel)] 78 | 79 | // Replacement Method Definition 80 | #define CHDeclareSig0_(return_type) \ 81 | const char *return_ = @encode(return_type); \ 82 | size_t return_len = __builtin_strlen(return_); \ 83 | char sig[return_len+2+1]; \ 84 | __builtin_memcpy(sig, return_, return_len); \ 85 | sig[return_len] = _C_ID; \ 86 | sig[return_len+1] = _C_SEL; \ 87 | sig[return_len+2] = '\0'; 88 | #define CHDeclareSig1_(return_type, type1) \ 89 | const char *return_ = @encode(return_type); \ 90 | size_t return_len = __builtin_strlen(return_); \ 91 | const char *type1_ = @encode(type1); \ 92 | size_t type1_len = __builtin_strlen(type1_); \ 93 | char sig[return_len+2+type1_len+1]; \ 94 | __builtin_memcpy(sig, return_, return_len); \ 95 | sig[return_len] = _C_ID; \ 96 | sig[return_len+1] = _C_SEL; \ 97 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 98 | sig[return_len+type1_len+2] = '\0'; 99 | #define CHDeclareSig2_(return_type, type1, type2) \ 100 | const char *return_ = @encode(return_type); \ 101 | size_t return_len = __builtin_strlen(return_); \ 102 | const char *type1_ = @encode(type1); \ 103 | size_t type1_len = __builtin_strlen(type1_); \ 104 | const char *type2_ = @encode(type2); \ 105 | size_t type2_len = __builtin_strlen(type2_); \ 106 | char sig[return_len+2+type1_len+type2_len+1]; \ 107 | __builtin_memcpy(sig, return_, return_len); \ 108 | sig[return_len] = _C_ID; \ 109 | sig[return_len+1] = _C_SEL; \ 110 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 111 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 112 | sig[return_len+type1_len+type2_len+2] = '\0'; 113 | #define CHDeclareSig3_(return_type, type1, type2, type3) \ 114 | const char *return_ = @encode(return_type); \ 115 | size_t return_len = __builtin_strlen(return_); \ 116 | const char *type1_ = @encode(type1); \ 117 | size_t type1_len = __builtin_strlen(type1_); \ 118 | const char *type2_ = @encode(type2); \ 119 | size_t type2_len = __builtin_strlen(type2_); \ 120 | const char *type3_ = @encode(type3); \ 121 | size_t type3_len = __builtin_strlen(type3_); \ 122 | char sig[return_len+2+type1_len+type2_len+type3_len+1]; \ 123 | __builtin_memcpy(sig, return_, return_len); \ 124 | sig[return_len] = _C_ID; \ 125 | sig[return_len+1] = _C_SEL; \ 126 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 127 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 128 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 129 | sig[return_len+type1_len+type2_len+type3_len+2] = '\0'; 130 | #define CHDeclareSig4_(return_type, type1, type2, type3, type4) \ 131 | const char *return_ = @encode(return_type); \ 132 | size_t return_len = __builtin_strlen(return_); \ 133 | const char *type1_ = @encode(type1); \ 134 | size_t type1_len = __builtin_strlen(type1_); \ 135 | const char *type2_ = @encode(type2); \ 136 | size_t type2_len = __builtin_strlen(type2_); \ 137 | const char *type3_ = @encode(type3); \ 138 | size_t type3_len = __builtin_strlen(type3_); \ 139 | const char *type4_ = @encode(type4); \ 140 | size_t type4_len = __builtin_strlen(type4_); \ 141 | char sig[return_len+2+type1_len+type2_len+type3_len+type4_len+1]; \ 142 | __builtin_memcpy(sig, return_, return_len); \ 143 | sig[return_len] = _C_ID; \ 144 | sig[return_len+1] = _C_SEL; \ 145 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 146 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 147 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 148 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len], type4_, type4_len); \ 149 | sig[return_len+type1_len+type2_len+type3_len+type4_len+2] = '\0'; 150 | #define CHDeclareSig5_(return_type, type1, type2, type3, type4, type5) \ 151 | const char *return_ = @encode(return_type); \ 152 | size_t return_len = __builtin_strlen(return_); \ 153 | const char *type1_ = @encode(type1); \ 154 | size_t type1_len = __builtin_strlen(type1_); \ 155 | const char *type2_ = @encode(type2); \ 156 | size_t type2_len = __builtin_strlen(type2_); \ 157 | const char *type3_ = @encode(type3); \ 158 | size_t type3_len = __builtin_strlen(type3_); \ 159 | const char *type4_ = @encode(type4); \ 160 | size_t type4_len = __builtin_strlen(type4_); \ 161 | const char *type5_ = @encode(type5); \ 162 | size_t type5_len = __builtin_strlen(type5_); \ 163 | char sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+1]; \ 164 | __builtin_memcpy(sig, return_, return_len); \ 165 | sig[return_len] = _C_ID; \ 166 | sig[return_len+1] = _C_SEL; \ 167 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 168 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 169 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 170 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len], type4_, type4_len); \ 171 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len], type5_, type5_len); \ 172 | sig[return_len+type1_len+type2_len+type3_len+type4_len+type5_len+2] = '\0'; 173 | #define CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6) \ 174 | const char *return_ = @encode(return_type); \ 175 | size_t return_len = __builtin_strlen(return_); \ 176 | const char *type1_ = @encode(type1); \ 177 | size_t type1_len = __builtin_strlen(type1_); \ 178 | const char *type2_ = @encode(type2); \ 179 | size_t type2_len = __builtin_strlen(type2_); \ 180 | const char *type3_ = @encode(type3); \ 181 | size_t type3_len = __builtin_strlen(type3_); \ 182 | const char *type4_ = @encode(type4); \ 183 | size_t type4_len = __builtin_strlen(type4_); \ 184 | const char *type5_ = @encode(type5); \ 185 | size_t type5_len = __builtin_strlen(type5_); \ 186 | const char *type6_ = @encode(type6); \ 187 | size_t type6_len = __builtin_strlen(type6_); \ 188 | char sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+1]; \ 189 | __builtin_memcpy(sig, return_, return_len); \ 190 | sig[return_len] = _C_ID; \ 191 | sig[return_len+1] = _C_SEL; \ 192 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 193 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 194 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 195 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len], type4_, type4_len); \ 196 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len], type5_, type5_len); \ 197 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len], type6_, type6_len); \ 198 | sig[return_len+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+2] = '\0'; 199 | #define CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7) \ 200 | const char *return_ = @encode(return_type); \ 201 | size_t return_len = __builtin_strlen(return_); \ 202 | const char *type1_ = @encode(type1); \ 203 | size_t type1_len = __builtin_strlen(type1_); \ 204 | const char *type2_ = @encode(type2); \ 205 | size_t type2_len = __builtin_strlen(type2_); \ 206 | const char *type3_ = @encode(type3); \ 207 | size_t type3_len = __builtin_strlen(type3_); \ 208 | const char *type4_ = @encode(type4); \ 209 | size_t type4_len = __builtin_strlen(type4_); \ 210 | const char *type5_ = @encode(type5); \ 211 | size_t type5_len = __builtin_strlen(type5_); \ 212 | const char *type6_ = @encode(type6); \ 213 | size_t type6_len = __builtin_strlen(type6_); \ 214 | const char *type7_ = @encode(type7); \ 215 | size_t type7_len = __builtin_strlen(type7_); \ 216 | char sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+1]; \ 217 | __builtin_memcpy(sig, return_, return_len); \ 218 | sig[return_len] = _C_ID; \ 219 | sig[return_len+1] = _C_SEL; \ 220 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 221 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 222 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 223 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len], type4_, type4_len); \ 224 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len], type5_, type5_len); \ 225 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len], type6_, type6_len); \ 226 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len], type7_, type7_len); \ 227 | sig[return_len+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+2] = '\0'; 228 | #define CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8) \ 229 | const char *return_ = @encode(return_type); \ 230 | size_t return_len = __builtin_strlen(return_); \ 231 | const char *type1_ = @encode(type1); \ 232 | size_t type1_len = __builtin_strlen(type1_); \ 233 | const char *type2_ = @encode(type2); \ 234 | size_t type2_len = __builtin_strlen(type2_); \ 235 | const char *type3_ = @encode(type3); \ 236 | size_t type3_len = __builtin_strlen(type3_); \ 237 | const char *type4_ = @encode(type4); \ 238 | size_t type4_len = __builtin_strlen(type4_); \ 239 | const char *type5_ = @encode(type5); \ 240 | size_t type5_len = __builtin_strlen(type5_); \ 241 | const char *type6_ = @encode(type6); \ 242 | size_t type6_len = __builtin_strlen(type6_); \ 243 | const char *type7_ = @encode(type7); \ 244 | size_t type7_len = __builtin_strlen(type7_); \ 245 | const char *type8_ = @encode(type8); \ 246 | size_t type8_len = __builtin_strlen(type8_); \ 247 | char sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+type8_len+1]; \ 248 | __builtin_memcpy(sig, return_, return_len); \ 249 | sig[return_len] = _C_ID; \ 250 | sig[return_len+1] = _C_SEL; \ 251 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 252 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 253 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 254 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len], type4_, type4_len); \ 255 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len], type5_, type5_len); \ 256 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len], type6_, type6_len); \ 257 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len], type7_, type7_len); \ 258 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len], type8_, type8_len); \ 259 | sig[return_len+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+type8_len+2] = '\0'; 260 | #define CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9) \ 261 | const char *return_ = @encode(return_type); \ 262 | size_t return_len = __builtin_strlen(return_); \ 263 | const char *type1_ = @encode(type1); \ 264 | size_t type1_len = __builtin_strlen(type1_); \ 265 | const char *type2_ = @encode(type2); \ 266 | size_t type2_len = __builtin_strlen(type2_); \ 267 | const char *type3_ = @encode(type3); \ 268 | size_t type3_len = __builtin_strlen(type3_); \ 269 | const char *type4_ = @encode(type4); \ 270 | size_t type4_len = __builtin_strlen(type4_); \ 271 | const char *type5_ = @encode(type5); \ 272 | size_t type5_len = __builtin_strlen(type5_); \ 273 | const char *type6_ = @encode(type6); \ 274 | size_t type6_len = __builtin_strlen(type6_); \ 275 | const char *type7_ = @encode(type7); \ 276 | size_t type7_len = __builtin_strlen(type7_); \ 277 | const char *type8_ = @encode(type8); \ 278 | size_t type8_len = __builtin_strlen(type8_); \ 279 | const char *type9_ = @encode(type9); \ 280 | size_t type9_len = __builtin_strlen(type9_); \ 281 | char sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+type8_len+type9_len+1]; \ 282 | __builtin_memcpy(sig, return_, return_len); \ 283 | sig[return_len] = _C_ID; \ 284 | sig[return_len+1] = _C_SEL; \ 285 | __builtin_memcpy(&sig[return_len+2], type1_, type1_len); \ 286 | __builtin_memcpy(&sig[return_len+2+type1_len], type2_, type2_len); \ 287 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len], type3_, type3_len); \ 288 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len], type4_, type4_len); \ 289 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len], type5_, type5_len); \ 290 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len], type6_, type6_len); \ 291 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len], type7_, type7_len); \ 292 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len], type8_, type8_len); \ 293 | __builtin_memcpy(&sig[return_len+2+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+type8_len], type9_, type9_len); \ 294 | sig[return_len+type1_len+type2_len+type3_len+type4_len+type5_len+type6_len+type7_len+type8_len+type9_len+2] = '\0'; 295 | 296 | #ifdef CHUseSubstrate 297 | #import 298 | #define CHMethod_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 299 | static return_type (*$ ## class_name ## _ ## name ## _super)(class_type self, SEL _cmd, ##args); \ 300 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 301 | __attribute__((always_inline)) \ 302 | static inline void $ ## class_name ## _ ## name ## _register() { \ 303 | if (class_val) { \ 304 | MSHookMessageEx(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, (IMP *)&$ ## class_name ## _ ## name ## _super); \ 305 | if (!$ ## class_name ## _ ## name ## _super) { \ 306 | sigdef; \ 307 | class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \ 308 | } \ 309 | } \ 310 | } \ 311 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 312 | #define CHMethod_new_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 313 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 314 | __attribute__((always_inline)) \ 315 | static inline void $ ## class_name ## _ ## name ## _register() { \ 316 | sigdef; \ 317 | class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \ 318 | } \ 319 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 320 | #define CHMethod_super_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 321 | static return_type (*$ ## class_name ## _ ## name ## _super)(class_type self, SEL _cmd, ##args); \ 322 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 323 | __attribute__((always_inline)) \ 324 | static inline void $ ## class_name ## _ ## name ## _register() { \ 325 | if (class_val) { \ 326 | MSHookMessageEx(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, (IMP *)&$ ## class_name ## _ ## name ## _super); \ 327 | } \ 328 | } \ 329 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 330 | #define CHMethod_self_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 331 | static return_type (*$ ## class_name ## _ ## name ## _super)(class_type self, SEL _cmd, ##args); \ 332 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 333 | __attribute__((always_inline)) \ 334 | static inline void $ ## class_name ## _ ## name ## _register() { \ 335 | if (class_val) { \ 336 | MSHookMessageEx(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, (IMP *)&$ ## class_name ## _ ## name ## _super); \ 337 | } \ 338 | } \ 339 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 340 | #else 341 | #define CHMethod_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 342 | static return_type (*$ ## class_name ## _ ## name ## _super)(class_type self, SEL _cmd, ##args); \ 343 | static return_type $ ## class_name ## _ ## name ## _closure(class_type self, SEL _cmd, ##args) { \ 344 | typedef return_type (*supType)(class_type, SEL, ## args); \ 345 | supType supFn = (supType)class_getMethodImplementation(super_class_val, _cmd); \ 346 | return supFn supercall; \ 347 | } \ 348 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 349 | __attribute__((always_inline)) \ 350 | static inline void $ ## class_name ## _ ## name ## _register() { \ 351 | Method method = class_getInstanceMethod(class_val, @selector(sel)); \ 352 | if (method) { \ 353 | $ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \ 354 | if (class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, method_getTypeEncoding(method))) { \ 355 | $ ## class_name ## _ ## name ## _super = &$ ## class_name ## _ ## name ## _closure; \ 356 | } else { \ 357 | method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \ 358 | } \ 359 | } else { \ 360 | sigdef; \ 361 | class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \ 362 | } \ 363 | } \ 364 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 365 | #define CHMethod_new_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 366 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 367 | __attribute__((always_inline)) \ 368 | static inline void $ ## class_name ## _ ## name ## _register() { \ 369 | sigdef; \ 370 | class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, sig); \ 371 | } \ 372 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 373 | #define CHMethod_super_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 374 | static return_type (*$ ## class_name ## _ ## name ## _super)(class_type self, SEL _cmd, ##args); \ 375 | static return_type $ ## class_name ## _ ## name ## _closure(class_type self, SEL _cmd, ##args) { \ 376 | typedef return_type (*supType)(class_type, SEL, ## args); \ 377 | supType supFn = (supType)class_getMethodImplementation(super_class_val, _cmd); \ 378 | return supFn supercall; \ 379 | } \ 380 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 381 | __attribute__((always_inline)) \ 382 | static inline void $ ## class_name ## _ ## name ## _register() { \ 383 | Method method = class_getInstanceMethod(class_val, @selector(sel)); \ 384 | if (method) { \ 385 | $ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \ 386 | if (class_addMethod(class_val, @selector(sel), (IMP)&$ ## class_name ## _ ## name ## _method, method_getTypeEncoding(method))) { \ 387 | $ ## class_name ## _ ## name ## _super = &$ ## class_name ## _ ## name ## _closure; \ 388 | } else { \ 389 | method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \ 390 | } \ 391 | } \ 392 | } \ 393 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 394 | #define CHMethod_self_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 395 | static return_type (*$ ## class_name ## _ ## name ## _super)(class_type self, SEL _cmd, ##args); \ 396 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args); \ 397 | __attribute__((always_inline)) \ 398 | static inline void $ ## class_name ## _ ## name ## _register() { \ 399 | Method method = class_getInstanceMethod(class_val, @selector(sel)); \ 400 | if (method) { \ 401 | $ ## class_name ## _ ## name ## _super = (__typeof__($ ## class_name ## _ ## name ## _super))method_getImplementation(method); \ 402 | method_setImplementation(method, (IMP)&$ ## class_name ## _ ## name ## _method); \ 403 | } \ 404 | } \ 405 | static return_type $ ## class_name ## _ ## name ## _method(class_type self, SEL _cmd, ##args) 406 | #endif 407 | #define CHMethod(count, args...) \ 408 | CHMethod ## count(args) 409 | #define CHMethod0(return_type, class_type, name) \ 410 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name, name, CHDeclareSig0_(return_type), (self, _cmd)) 411 | #define CHMethod1(return_type, class_type, name1, type1, arg1) \ 412 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $, name1:, CHDeclareSig1_(return_type, type1), (self, _cmd, arg1), type1 arg1) 413 | #define CHMethod2(return_type, class_type, name1, type1, arg1, name2, type2, arg2) \ 414 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $, name1:name2:, CHDeclareSig2_(return_type, type1, type2), (self, _cmd, arg1, arg2), type1 arg1, type2 arg2) 415 | #define CHMethod3(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3) \ 416 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $, name1:name2:name3:, CHDeclareSig3_(return_type, type1, type2, type3), (self, _cmd, arg1, arg2, arg3), type1 arg1, type2 arg2, type3 arg3) 417 | #define CHMethod4(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4) \ 418 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, name1:name2:name3:name4:, CHDeclareSig4_(return_type, type1, type2, type3, type4), (self, _cmd, arg1, arg2, arg3, arg4), type1 arg1, type2 arg2, type3 arg3, type4 arg4) 419 | #define CHMethod5(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5) \ 420 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $, name1:name2:name3:name4:name5:, CHDeclareSig5_(return_type, type1, type2, type3, type4, type5), (self, _cmd, arg1, arg2, arg3, arg4, arg5), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 421 | #define CHMethod6(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6) \ 422 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, name1:name2:name3:name4:name5:name6:, CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 423 | #define CHMethod7(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7) \ 424 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, name1:name2:name3:name4:name5:name6:name7:, CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 425 | #define CHMethod8(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8) \ 426 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, name1:name2:name3:name4:name5:name6:name7:name8:, CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8) 427 | #define CHMethod9(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8, name9, type9, arg9) \ 428 | CHMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, name1:name2:name3:name4:name5:name6:name7:name8:name9:, CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8, type9 arg9) 429 | #define CHClassMethod(count, args...) \ 430 | CHClassMethod ## count(args) 431 | #define CHClassMethod0(return_type, class_type, name) \ 432 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name, name, CHDeclareSig0_(return_type), (self, _cmd)) 433 | #define CHClassMethod1(return_type, class_type, name1, type1, arg1) \ 434 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $, name1:, CHDeclareSig1_(return_type, type1), (self, _cmd, arg1), type1 arg1) 435 | #define CHClassMethod2(return_type, class_type, name1, type1, arg1, name2, type2, arg2) \ 436 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $, name1:name2:, CHDeclareSig2_(return_type, type1, type2), (self, _cmd, arg1, arg2), type1 arg1, type2 arg2) 437 | #define CHClassMethod3(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3) \ 438 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $, name1:name2:name3:, CHDeclareSig3_(return_type, type1, type2, type3), (self, _cmd, arg1, arg2, arg3), type1 arg1, type2 arg2, type3 arg3) 439 | #define CHClassMethod4(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4) \ 440 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, name1:name2:name3:name4:, CHDeclareSig4_(return_type, type1, type2, type3, type4), (self, _cmd, arg1, arg2, arg3, arg4), type1 arg1, type2 arg2, type3 arg3, type4 arg4) 441 | #define CHClassMethod5(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5) \ 442 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $, name1:name2:name3:name4:name5:, CHDeclareSig5_(return_type, type1, type2, type3, type4, type5), (self, _cmd, arg1, arg2, arg3, arg4, arg5), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 443 | #define CHClassMethod6(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6) \ 444 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, name1:name2:name3:name4:name5:name6:, CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 445 | #define CHClassMethod7(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7) \ 446 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, name1:name2:name3:name4:name5:name6:name7:, CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 447 | #define CHClassMethod8(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8) \ 448 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, name1:name2:name3:name4:name5:name6:name7:name8:, CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8) 449 | #define CHClassMethod9(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8, name9, type9, arg9) \ 450 | CHMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, name1:name2:name3:name4:name5:name6:name7:name8:name9:, CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8, type9 arg9) 451 | #define CHOptimizedMethod(count, args...) \ 452 | CHOptimizedMethod ## count(args) 453 | #define CHOptimizedMethod0(optimization, return_type, class_type, name) \ 454 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name, name, CHDeclareSig0_(return_type), (self, _cmd)) 455 | #define CHOptimizedMethod1(optimization, return_type, class_type, name1, type1, arg1) \ 456 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $, name1:, CHDeclareSig1_(return_type, type1), (self, _cmd, arg1), type1 arg1) 457 | #define CHOptimizedMethod2(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2) \ 458 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $, name1:name2:, CHDeclareSig2_(return_type, type1, type2), (self, _cmd, arg1, arg2), type1 arg1, type2 arg2) 459 | #define CHOptimizedMethod3(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3) \ 460 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $, name1:name2:name3:, CHDeclareSig3_(return_type, type1, type2, type3), (self, _cmd, arg1, arg2, arg3), type1 arg1, type2 arg2, type3 arg3) 461 | #define CHOptimizedMethod4(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4) \ 462 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, name1:name2:name3:name4:, CHDeclareSig4_(return_type, type1, type2, type3, type4), (self, _cmd, arg1, arg2, arg3, arg4), type1 arg1, type2 arg2, type3 arg3, type4 arg4) 463 | #define CHOptimizedMethod5(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5) \ 464 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $, name1:name2:name3:name4:name5:, CHDeclareSig5_(return_type, type1, type2, type3, type4, type5), (self, _cmd, arg1, arg2, arg3, arg4, arg5), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 465 | #define CHOptimizedMethod6(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6) \ 466 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, name1:name2:name3:name4:name5:name6:, CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 467 | #define CHOptimizedMethod7(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7) \ 468 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, name1:name2:name3:name4:name5:name6:name7:, CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 469 | #define CHOptimizedMethod8(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8) \ 470 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, name1:name2:name3:name4:name5:name6:name7:name8:, CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8) 471 | #define CHOptimizedMethod9(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8, name9, type9, arg9) \ 472 | CHMethod_ ## optimization ## _(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, name1:name2:name3:name4:name5:name6:name7:name8:name9:, CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8, type9 arg9) 473 | #define CHOptimizedClassMethod(count, args...) \ 474 | CHOptimizedClassMethod ## count(args) 475 | #define CHOptimizedClassMethod0(optimization, return_type, class_type, name) \ 476 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name, name, CHDeclareSig0_(return_type), (self, _cmd)) 477 | #define CHOptimizedClassMethod1(optimization, return_type, class_type, name1, type1, arg1) \ 478 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $, name1:, CHDeclareSig1_(return_type, type1), (self, _cmd, arg1), type1 arg1) 479 | #define CHOptimizedClassMethod2(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2) \ 480 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $, name1:name2:, CHDeclareSig2_(return_type, type1, type2), (self, _cmd, arg1, arg2), type1 arg1, type2 arg2) 481 | #define CHOptimizedClassMethod3(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3) \ 482 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $, name1:name2:name3:, CHDeclareSig3_(return_type, type1, type2, type3), (self, _cmd, arg1, arg2, arg3), type1 arg1, type2 arg2, type3 arg3) 483 | #define CHOptimizedClassMethod4(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4) \ 484 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, name1:name2:name3:name4:, CHDeclareSig4_(return_type, type1, type2, type3, type4), (self, _cmd, arg1, arg2, arg3, arg4), type1 arg1, type2 arg2, type3 arg3, type4 arg4) 485 | #define CHOptimizedClassMethod5(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5) \ 486 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $, name1:name2:name3:name4:name5:, CHDeclareSig5_(return_type, type1, type2, type3, type4, type5), (self, _cmd, arg1, arg2, arg3, arg4, arg5), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 487 | #define CHOptimizedClassMethod6(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6) \ 488 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, name1:name2:name3:name4:name5:name6:, CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 489 | #define CHOptimizedClassMethod7(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7) \ 490 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, name1:name2:name3:name4:name5:name6:name7:, CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 491 | #define CHOptimizedClassMethod8(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8) \ 492 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, name1:name2:name3:name4:name5:name6:name7:name8:, CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8) 493 | #define CHOptimizedClassMethod9(optimization, return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8, name9, type9, arg9) \ 494 | CHMethod_ ## optimization ## _(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, name1:name2:name3:name4:name5:name6:name7:name8:name9:, CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8, type9 arg9) 495 | 496 | // Replacement Method Registration 497 | #define CHHook_(class_name, name) \ 498 | $ ## class_name ## _ ## name ## _register() 499 | #define CHHook(count, args...) CHHook ## count(args) 500 | #define CHHook0(class, name) CHHook_(class, name) 501 | #define CHHook1(class, name1) CHHook_(class, name1 ## $) 502 | #define CHHook2(class, name1, name2) CHHook_(class, name1 ## $ ## name2 ## $) 503 | #define CHHook3(class, name1, name2, name3) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $) 504 | #define CHHook4(class, name1, name2, name3, name4) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $) 505 | #define CHHook5(class, name1, name2, name3, name4, name5) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $) 506 | #define CHHook6(class, name1, name2, name3, name4, name5, name6) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $) 507 | #define CHHook7(class, name1, name2, name3, name4, name5, name6, name7) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $) 508 | #define CHHook8(class, name1, name2, name3, name4, name5, name6, name7, name8) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $) 509 | #define CHHook9(class, name1, name2, name3, name4, name5, name6, name7, name8, name9) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $) 510 | #define CHClassHook(count, args...) CHClassHook ## count(args) 511 | #define CHClassHook0(class, name) CHHook_(class, name) 512 | #define CHClassHook1(class, name1) CHHook_(class, name1 ## $) 513 | #define CHClassHook2(class, name1, name2) CHHook_(class, name1 ## $ ## name2 ## $) 514 | #define CHClassHook3(class, name1, name2, name3) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $) 515 | #define CHClassHook4(class, name1, name2, name3, name4) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $) 516 | #define CHClassHook5(class, name1, name2, name3, name4, name5) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $) 517 | #define CHClassHook6(class, name1, name2, name3, name4, name5, name6) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $) 518 | #define CHClassHook7(class, name1, name2, name3, name4, name5, name6, name7) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $) 519 | #define CHClassHook8(class, name1, name2, name3, name4, name5, name6, name7, name8) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $) 520 | #define CHClassHook9(class, name1, name2, name3, name4, name5, name6, name7, name8, name9) CHHook_(class, name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $) 521 | 522 | // Declarative style methods (automatically calls CHHook) 523 | #define CHDeclareMethod_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, args...) \ 524 | static inline void $ ## class_name ## _ ## name ## _register(); \ 525 | __attribute__((constructor)) \ 526 | static inline void $ ## class_name ## _ ## name ## _constructor() { \ 527 | CHLoadLateClass(class_name); \ 528 | $ ## class_name ## _ ## name ## _register(); \ 529 | } \ 530 | CHMethod_(return_type, class_type, class_name, class_val, super_class_val, name, sel, sigdef, supercall, ##args) 531 | #define CHDeclareMethod(count, args...) \ 532 | CHDeclareMethod ## count(args) 533 | #define CHDeclareMethod0(return_type, class_type, name) \ 534 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name, name, CHDeclareSig0_(return_type), (self, _cmd)) 535 | #define CHDeclareMethod1(return_type, class_type, name1, type1, arg1) \ 536 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $, name1:, CHDeclareSig1_(return_type, type1), (self, _cmd, arg1), type1 arg1) 537 | #define CHDeclareMethod2(return_type, class_type, name1, type1, arg1, name2, type2, arg2) \ 538 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $, name1:name2:, CHDeclareSig2_(return_type, type1, type2), (self, _cmd, arg1, arg2), type1 arg1, type2 arg2) 539 | #define CHDeclareMethod3(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3) \ 540 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $, name1:name2:name3:, CHDeclareSig3_(return_type, type1, type2, type3), (self, _cmd, arg1, arg2, arg3), type1 arg1, type2 arg2, type3 arg3) 541 | #define CHDeclareMethod4(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4) \ 542 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, name1:name2:name3:name4:, CHDeclareSig4_(return_type, type1, type2, type3, type4), (self, _cmd, arg1, arg2, arg3, arg4), type1 arg1, type2 arg2, type3 arg3, type4 arg4) 543 | #define CHDeclareMethod5(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5) \ 544 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## arg5 ## $, name1:name2:name3:name4:name5:, CHDeclareSig5_(return_type, type1, type2, type3, type4, type5), (self, _cmd, arg1, arg2, arg3, arg4, arg5), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 545 | #define CHDeclareMethod6(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6) \ 546 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, name1:name2:name3:name4:name5:name6:, CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 547 | #define CHDeclareMethod7(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7) \ 548 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, name1:name2:name3:name4:name5:name6:name7:, CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 549 | #define CHDeclareMethod8(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8) \ 550 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, name1:name2:name3:name4:name5:name6:name7:name8:, CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8) 551 | #define CHDeclareMethod9(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8, name9, type9, arg9) \ 552 | CHDeclareMethod_(return_type, class_type *, class_type, CHClass(class_type), CHSuperClass(class_type), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, name1:name2:name3:name4:name5:name6:name7:name8:name9:, CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8, type9 arg9) 553 | #define CHDeclareClassMethod(count, args...) \ 554 | CHDeclareClassMethod ## count(args) 555 | #define CHDeclareClassMethod0(return_type, class_type, name) \ 556 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name, name, CHDeclareSig0_(return_type), (self, _cmd)) 557 | #define CHDeclareClassMethod1(return_type, class_type, name1, type1, arg1) \ 558 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $, name1:, CHDeclareSig1_(return_type, type1), (self, _cmd, arg1), type1 arg1) 559 | #define CHDeclareClassMethod2(return_type, class_type, name1, type1, arg1, name2, type2, arg2) \ 560 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $, name1:name2:, CHDeclareSig2_(return_type, type1, type2), (self, _cmd, arg1, arg2), type1 arg1, type2 arg2) 561 | #define CHDeclareClassMethod3(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3) \ 562 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $, name1:name2:name3:, CHDeclareSig3_(return_type, type1, type2, type3), (self, _cmd, arg1, arg2, arg3), type1 arg1, type2 arg2, type3 arg3) 563 | #define CHDeclareClassMethod4(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4) \ 564 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, name1:name2:name3:name4:, CHDeclareSig4_(return_type, type1, type2, type3, type4), (self, _cmd, arg1, arg2, arg3, arg4), type1 arg1, type2 arg2, type3 arg3, type4 arg4) 565 | #define CHDeclareClassMethod5(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5) \ 566 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $, name1:name2:name3:name4:name5:, CHDeclareSig5_(return_type, type1, type2, type3, type4, type5), (self, _cmd, arg1, arg2, arg3, arg4, arg5), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 567 | #define CHDeclareClassMethod6(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6) \ 568 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, name1:name2:name3:name4:name5:name6:, CHDeclareSig6_(return_type, type1, type2, type3, type4, type5, type6), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 569 | #define CHDeclareClassMethod7(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7) \ 570 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, name1:name2:name3:name4:name5:name6:name7:, CHDeclareSig7_(return_type, type1, type2, type3, type4, type5, type6, type7), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 571 | #define CHDeclareClassMethod8(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8) \ 572 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, name1:name2:name3:name4:name5:name6:name7:name8:, CHDeclareSig8_(return_type, type1, type2, type3, type4, type5, type6, type7, type8), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8) 573 | #define CHDeclareClassMethod9(return_type, class_type, name1, type1, arg1, name2, type2, arg2, name3, type3, arg3, name4, type4, arg4, name5, type5, arg5, name6, type6, arg6, name7, type7, arg7, name8, type8, arg8, name9, type9, arg9) \ 574 | CHDeclareMethod_(return_type, id, class_type, CHMetaClass(class_type), object_getClass(CHMetaClass(class_type)), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, name1:name2:name3:name4:name5:name6:name7:name8:name9:, CHDeclareSig9_(return_type, type1, type2, type3, type4, type5, type6, type7, type8, type9), (self, _cmd, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7, type8 arg8, type9 arg9) 575 | 576 | // Calling super class (or the old method as the case may be) 577 | #define CHSuper_(class_type, _cmd, name, args...) \ 578 | $ ## class_type ## _ ## name ## _super(self, _cmd, ##args) 579 | #define CHSuper(count, args...) \ 580 | CHSuper ## count(args) 581 | #define CHSuper0(class_type, name) \ 582 | CHSuper_(class_type, @selector(name), name) 583 | #define CHSuper1(class_type, name1, val1) \ 584 | CHSuper_(class_type, @selector(name1:), name1 ## $, val1) 585 | #define CHSuper2(class_type, name1, val1, name2, val2) \ 586 | CHSuper_(class_type, @selector(name1:name2:), name1 ## $ ## name2 ## $, val1, val2) 587 | #define CHSuper3(class_type, name1, val1, name2, val2, name3, val3) \ 588 | CHSuper_(class_type, @selector(name1:name2:name3:), name1 ## $ ## name2 ## $ ## name3 ## $, val1, val2, val3) 589 | #define CHSuper4(class_type, name1, val1, name2, val2, name3, val3, name4, val4) \ 590 | CHSuper_(class_type, @selector(name1:name2:name3:name4:), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $, val1, val2, val3, val4) 591 | #define CHSuper5(class_type, name1, val1, name2, val2, name3, val3, name4, val4, name5, val5) \ 592 | CHSuper_(class_type, @selector(name1:name2:name3:name4:name5:), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $, val1, val2, val3, val4, val5) 593 | #define CHSuper6(class_type, name1, val1, name2, val2, name3, val3, name4, val4, name5, val5, name6, val6) \ 594 | CHSuper_(class_type, @selector(name1:name2:name3:name4:name5:name6:), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $, val1, val2, val3, val4, val5, val6) 595 | #define CHSuper7(class_type, name1, val1, name2, val2, name3, val3, name4, val4, name5, val5, name6, val6, name7, val7) \ 596 | CHSuper_(class_type, @selector(name1:name2:name3:name4:name5:name6:name7:), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $, val1, val2, val3, val4, val5, val6, val7) 597 | #define CHSuper8(class_type, name1, val1, name2, val2, name3, val3, name4, val4, name5, val5, name6, val6, name7, val7, name8, val8) \ 598 | CHSuper_(class_type, @selector(name1:name2:name3:name4:name5:name6:name7:name8:), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $, val1, val2, val3, val4, val5, val6, val7, val8) 599 | #define CHSuper9(class_type, name1, val1, name2, val2, name3, val3, name4, val4, name5, val5, name6, val6, name7, val7, name8, val8, name9, val9) \ 600 | CHSuper_(class_type, @selector(name1:name2:name3:name4:name5:name6:name7:name8:name9:), name1 ## $ ## name2 ## $ ## name3 ## $ ## name4 ## $ ## name5 ## $ ## name6 ## $ ## name7 ## $ ## name8 ## $ ## name9 ## $, val1, val2, val3, val4, val5, val6, val7, val8, val9) 601 | 602 | // Create Class at Runtime (useful for creating subclasses of classes that can't be linked) 603 | #define CHRegisterClass(name, superName) for (int _tmp = ({ CHClass(name) = objc_allocateClassPair(CHClass(superName), #name, 0); CHMetaClass(name) = object_getClass(CHClass(name)); CHSuperClass(name) = class_getSuperclass(CHClass(name)); 1; }); _tmp; _tmp = ({ objc_registerClassPair(CHClass(name)), 0; })) 604 | #define CHAlignmentForSize_(size) ({ \ 605 | size_t s = size; \ 606 | __builtin_constant_p(s) ? ( \ 607 | (s) & (1 << 31) ? 31 : \ 608 | (s) & (1 << 30) ? 30 : \ 609 | (s) & (1 << 29) ? 29 : \ 610 | (s) & (1 << 28) ? 28 : \ 611 | (s) & (1 << 27) ? 27 : \ 612 | (s) & (1 << 26) ? 26 : \ 613 | (s) & (1 << 25) ? 25 : \ 614 | (s) & (1 << 24) ? 24 : \ 615 | (s) & (1 << 23) ? 23 : \ 616 | (s) & (1 << 22) ? 22 : \ 617 | (s) & (1 << 21) ? 21 : \ 618 | (s) & (1 << 20) ? 20 : \ 619 | (s) & (1 << 19) ? 19 : \ 620 | (s) & (1 << 18) ? 18 : \ 621 | (s) & (1 << 17) ? 17 : \ 622 | (s) & (1 << 16) ? 16 : \ 623 | (s) & (1 << 15) ? 15 : \ 624 | (s) & (1 << 14) ? 14 : \ 625 | (s) & (1 << 13) ? 13 : \ 626 | (s) & (1 << 12) ? 12 : \ 627 | (s) & (1 << 11) ? 11 : \ 628 | (s) & (1 << 10) ? 10 : \ 629 | (s) & (1 << 9) ? 9 : \ 630 | (s) & (1 << 8) ? 8 : \ 631 | (s) & (1 << 7) ? 7 : \ 632 | (s) & (1 << 6) ? 6 : \ 633 | (s) & (1 << 5) ? 5 : \ 634 | (s) & (1 << 4) ? 4 : \ 635 | (s) & (1 << 3) ? 3 : \ 636 | (s) & (1 << 2) ? 2 : \ 637 | (s) & (1 << 1) ? 1 : \ 638 | (s) & (1 << 0) ? 0 : \ 639 | 0 \ 640 | ) : (uint32_t)log2f(s); \ 641 | }) 642 | #define CHAddIvar(targetClass, name, type) \ 643 | class_addIvar(targetClass, #name, sizeof(type), CHAlignmentForSize_(sizeof(type)), @encode(type)) 644 | 645 | // Retrieve reference to an Ivar value (can read and assign) 646 | __attribute__((unused)) CHInline 647 | static void *CHIvar_(id object, const char *name) 648 | { 649 | Ivar ivar = class_getInstanceVariable(object_getClass(object), name); 650 | if (ivar) 651 | #ifdef CHHasARC 652 | return (void *)&((char *)(__bridge void *)object)[ivar_getOffset(ivar)]; 653 | #else 654 | return (void *)&((char *)object)[ivar_getOffset(ivar)]; 655 | #endif 656 | return NULL; 657 | } 658 | #define CHIvarRef(object, name, type) \ 659 | ((type *)CHIvar_(object, #name)) 660 | #define CHIvar(object, name, type) \ 661 | (*CHIvarRef(object, name, type)) 662 | // Warning: Dereferences NULL if object is nil or name isn't found. To avoid this save CHIvarRef(...) and test if != NULL 663 | 664 | #define CHDeclareProperty(class, name) static const char k ## class ## _ ## name = '\0'; 665 | #define CHPropertyGetValue(class, name) objc_getAssociatedObject(self, &k ## class ## _ ## name ) 666 | #define CHPropertySetValue(class, name, value, policy) objc_setAssociatedObject(self, &k ## class ## _ ## name , value, policy) 667 | 668 | #define CHPropertyGetter(class, getter, type) CHOptimizedMethod0(new, type, class, getter) 669 | #define CHPropertySetter(class, setter, type, value) CHOptimizedMethod1(new, void, class, setter, type, value) 670 | 671 | // Obj-C dynamic property declaration (objects) 672 | #define CHProperty(class, type, getter, setter, policy) \ 673 | CHDeclareProperty(class, getter) \ 674 | CHPropertyGetter(class, getter, type) { \ 675 | return CHPropertyGetValue(class, getter); \ 676 | } \ 677 | CHPropertySetter(class, setter, type, getter) { \ 678 | CHPropertySetValue(class, getter, getter, policy); \ 679 | } 680 | #define CHPropertyRetain(class, type, getter, setter) CHProperty(class, type, getter, setter, OBJC_ASSOCIATION_RETAIN) 681 | #define CHPropertyRetainNonatomic(class, type, getter, setter) CHProperty(class, type, getter, setter, OBJC_ASSOCIATION_RETAIN_NONATOMIC) 682 | #define CHPropertyCopy(class, type, getter, setter) CHProperty(class, type, getter, setter, OBJC_ASSOCIATION_COPY) 683 | #define CHPropertyCopyNonatomic(class, type, getter, setter) CHProperty(class, type, getter, setter, OBJC_ASSOCIATION_COPY_NONATOMIC) 684 | #define CHPropertyAssign(class, type, getter, setter) CHProperty(class, type, getter, setter, OBJC_ASSOCIATION_ASSIGN) 685 | 686 | #define CHPrimitivePropertyGetValue(class, name, type, val, default) \ 687 | type val = default; \ 688 | do { \ 689 | NSNumber * objVal = CHPropertyGetValue(class, name); \ 690 | [objVal getValue:& val ]; \ 691 | } while(0) 692 | #define CHPrimitivePropertySetValue(class, name, type, val) \ 693 | do { \ 694 | NSValue *objVal = [NSValue value:& val withObjCType:@encode( type )]; \ 695 | CHPropertySetValue(class, name, objVal, OBJC_ASSOCIATION_RETAIN_NONATOMIC); \ 696 | } while(0) 697 | 698 | // Primitive property equivalent (ie. BOOL, int, structs) 699 | #define CHPrimitiveProperty(class, type, getter, setter, default) \ 700 | CHDeclareProperty(class, getter) \ 701 | CHOptimizedMethod0(new, type, class, getter) { \ 702 | CHPrimitivePropertyGetValue( class , getter , type , val , default ); \ 703 | return val; \ 704 | } \ 705 | CHOptimizedMethod1(new, void, class, setter, type, getter) { \ 706 | CHPrimitivePropertySetValue( class , getter, type , getter ); \ 707 | } 708 | 709 | #define CHHookProperty(class, getter, setter) \ 710 | do { \ 711 | CHHook0(class, getter); \ 712 | CHHook1(class, setter); \ 713 | } while(0) 714 | 715 | #ifndef CHHasARC 716 | // Scope Autorelease 717 | __attribute__((unused)) CHInline 718 | static void CHScopeReleased(id *sro) 719 | { 720 | [*sro release]; 721 | } 722 | #define CHScopeReleased \ 723 | __attribute__((cleanup(CHScopeReleased))) 724 | 725 | #define CHAutoreleasePoolForScope() \ 726 | NSAutoreleasePool *CHAutoreleasePoolForScope __attribute__((unused)) CHScopeReleased = [[NSAutoreleasePool alloc] init] 727 | #endif 728 | 729 | // Build Assertion 730 | #define CHBuildAssert(condition) \ 731 | ((void)sizeof(char[1 - 2*!!(condition)])) 732 | 733 | // Profiling 734 | #ifdef CHEnableProfiling 735 | #import 736 | struct CHProfileData 737 | { 738 | NSString *message; 739 | uint64_t startTime; 740 | }; 741 | __attribute__((unused)) CHInline 742 | static void CHProfileCalculateDurationAndLog_(struct CHProfileData *profileData) 743 | { 744 | uint64_t duration = mach_absolute_time() - profileData->startTime; 745 | mach_timebase_info_data_t info; 746 | mach_timebase_info(&info); 747 | duration = (duration * info.numer) / info.denom; 748 | CHLog(@"Profile time: %lldns; %@", duration, profileData->message); 749 | } 750 | #define CHProfileScopeWithString(string) \ 751 | struct CHProfileData _profileData __attribute__((cleanup(CHProfileCalculateDurationAndLog_))) = ({ struct CHProfileData _tmp; _tmp.message = (string); _tmp.startTime = mach_absolute_time(); _tmp; }) 752 | #else 753 | #define CHProfileScopeWithString(string) \ 754 | CHNothing() 755 | #endif 756 | #define CHProfileScopeWithFormat(args...) \ 757 | CHProfileScopeWithString(([NSString stringWithFormat:args])) 758 | #define CHProfileScope() \ 759 | CHProfileScopeWithFormat(@CHStringify(__LINE__) " in %s", __FUNCTION__) 760 | -------------------------------------------------------------------------------- /include/substrate.h: -------------------------------------------------------------------------------- 1 | /* Cydia Substrate - Powerful Code Insertion Platform 2 | * Copyright (C) 2008-2012 Jay Freeman (saurik) 3 | */ 4 | 5 | /* GNU Lesser General Public License, Version 3 {{{ */ 6 | /* 7 | * Substrate is free software: you can redistribute it and/or modify it under 8 | * the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Substrate is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | * License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser 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 | 41 | #define _finline \ 42 | inline __attribute__((__always_inline__)) 43 | #define _disused \ 44 | __attribute__((__unused__)) 45 | 46 | #define _extern \ 47 | extern "C" __attribute__((__visibility__("default"))) 48 | 49 | #ifdef __cplusplus 50 | #define _default(value) = value 51 | #else 52 | #define _default(value) 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | bool MSHookProcess(pid_t pid, const char *library); 60 | 61 | typedef const void *MSImageRef; 62 | 63 | MSImageRef MSGetImageByName(const char *file); 64 | void *MSFindSymbol(MSImageRef image, const char *name); 65 | 66 | void MSHookFunction(void *symbol, void *replace, void **result); 67 | 68 | #ifdef __APPLE__ 69 | #ifdef __arm__ 70 | __attribute__((__deprecated__)) 71 | IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL)); 72 | #endif 73 | void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result); 74 | #endif 75 | 76 | #ifdef SubstrateInternal 77 | typedef void *SubstrateAllocatorRef; 78 | typedef struct __SubstrateProcess *SubstrateProcessRef; 79 | typedef struct __SubstrateMemory *SubstrateMemoryRef; 80 | 81 | SubstrateProcessRef SubstrateProcessCreate(SubstrateAllocatorRef allocator, pid_t pid); 82 | void SubstrateProcessRelease(SubstrateProcessRef process); 83 | 84 | SubstrateMemoryRef SubstrateMemoryCreate(SubstrateAllocatorRef allocator, SubstrateProcessRef process, void *data, size_t size); 85 | void SubstrateMemoryRelease(SubstrateMemoryRef memory); 86 | #endif 87 | 88 | #ifdef __ANDROID__ 89 | #include 90 | _extern void MSJavaHookClassLoad(JNIEnv *jni, const char *name, void (*callback)(JNIEnv *, jclass, void *), void *data _default(NULL)); 91 | _extern void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID methodID, void *function, void **result); 92 | _extern void MSJavaBlessClassLoader(JNIEnv *jni, jobject loader); 93 | 94 | typedef struct MSJavaObjectKey_ *MSJavaObjectKey; 95 | _extern MSJavaObjectKey MSJavaNewObjectKey(); 96 | _extern void MSJavaDeleteObjectKey(MSJavaObjectKey key); 97 | _extern void *MSJavaGetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key); 98 | _extern void MSJavaSetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key, void *value, void (*clean)(void *, JNIEnv *, void *) _default(NULL), void *data _default(NULL)); 99 | #endif 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #ifdef __cplusplus 106 | 107 | #ifdef SubstrateInternal 108 | struct SubstrateHookMemory { 109 | SubstrateMemoryRef handle_; 110 | 111 | SubstrateHookMemory(SubstrateProcessRef process, void *data, size_t size) : 112 | handle_(SubstrateMemoryCreate(NULL, NULL, data, size)) 113 | { 114 | } 115 | 116 | ~SubstrateHookMemory() { 117 | if (handle_ != NULL) 118 | SubstrateMemoryRelease(handle_); 119 | } 120 | }; 121 | #endif 122 | 123 | #ifdef __APPLE__ 124 | 125 | namespace etl { 126 | 127 | template 128 | struct Case { 129 | static char value[Case_ + 1]; 130 | }; 131 | 132 | typedef Case Yes; 133 | typedef Case No; 134 | 135 | namespace be { 136 | template 137 | static Yes CheckClass_(void (Checked_::*)()); 138 | 139 | template 140 | static No CheckClass_(...); 141 | } 142 | 143 | template 144 | struct IsClass { 145 | void gcc32(); 146 | 147 | static const bool value = (sizeof(be::CheckClass_(0).value) == sizeof(Yes::value)); 148 | }; 149 | 150 | } 151 | 152 | #ifdef __arm__ 153 | template 154 | __attribute__((__deprecated__)) 155 | static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) { 156 | return reinterpret_cast(MSHookMessage(_class, sel, reinterpret_cast(imp), prefix)); 157 | } 158 | #endif 159 | 160 | template 161 | static inline void MSHookMessage(Class _class, SEL sel, Type_ *imp, Type_ **result) { 162 | return MSHookMessageEx(_class, sel, reinterpret_cast(imp), reinterpret_cast(result)); 163 | } 164 | 165 | template 166 | static inline Type_ &MSHookIvar(id self, const char *name) { 167 | Ivar ivar(class_getInstanceVariable(object_getClass(self), name)); 168 | #if __has_feature(objc_arc) 169 | void *pointer(ivar == NULL ? NULL : reinterpret_cast((__bridge void *)self) + ivar_getOffset(ivar)); 170 | #else 171 | void *pointer(ivar == NULL ? NULL : reinterpret_cast(self) + ivar_getOffset(ivar)); 172 | #endif 173 | return *reinterpret_cast(pointer); 174 | } 175 | 176 | #define MSAddMessage0(_class, type, arg0) \ 177 | class_addMethod($ ## _class, @selector(arg0), (IMP) &$ ## _class ## $ ## arg0, type); 178 | #define MSAddMessage1(_class, type, arg0) \ 179 | class_addMethod($ ## _class, @selector(arg0:), (IMP) &$ ## _class ## $ ## arg0 ## $, type); 180 | #define MSAddMessage2(_class, type, arg0, arg1) \ 181 | class_addMethod($ ## _class, @selector(arg0:arg1:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $, type); 182 | #define MSAddMessage3(_class, type, arg0, arg1, arg2) \ 183 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $, type); 184 | #define MSAddMessage4(_class, type, arg0, arg1, arg2, arg3) \ 185 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $, type); 186 | #define MSAddMessage5(_class, type, arg0, arg1, arg2, arg3, arg4) \ 187 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $, type); 188 | #define MSAddMessage6(_class, type, arg0, arg1, arg2, arg3, arg4, arg5) \ 189 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $, type); 190 | #define MSAddMessage7(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ 191 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $, type); 192 | #define MSAddMessage8(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ 193 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $ ## arg7 ## $, type); 194 | 195 | #define MSHookMessage0(_class, arg0) \ 196 | MSHookMessage($ ## _class, @selector(arg0), MSHake(_class ## $ ## arg0)) 197 | #define MSHookMessage1(_class, arg0) \ 198 | MSHookMessage($ ## _class, @selector(arg0:), MSHake(_class ## $ ## arg0 ## $)) 199 | #define MSHookMessage2(_class, arg0, arg1) \ 200 | MSHookMessage($ ## _class, @selector(arg0:arg1:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $)) 201 | #define MSHookMessage3(_class, arg0, arg1, arg2) \ 202 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $)) 203 | #define MSHookMessage4(_class, arg0, arg1, arg2, arg3) \ 204 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $)) 205 | #define MSHookMessage5(_class, arg0, arg1, arg2, arg3, arg4) \ 206 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $)) 207 | #define MSHookMessage6(_class, arg0, arg1, arg2, arg3, arg4, arg5) \ 208 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $)) 209 | #define MSHookMessage7(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ 210 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $)) 211 | #define MSHookMessage8(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ 212 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $ ## arg7 ## $)) 213 | 214 | #define MSRegister_(name, dollar, colon) \ 215 | namespace { static class C_$ ## name ## $ ## dollar { public: _finline C_$ ## name ## $ ##dollar() { \ 216 | MSHookMessage($ ## name, @selector(colon), MSHake(name ## $ ## dollar)); \ 217 | } } V_$ ## name ## $ ## dollar; } \ 218 | 219 | #define MSIgnore_(name, dollar, colon) 220 | 221 | #define MSMessage_(extra, type, _class, name, dollar, colon, call, args...) \ 222 | static type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args); \ 223 | MSHook(type, name ## $ ## dollar, _class self, SEL _cmd, ## args) { \ 224 | Class const _cls($ ## name); \ 225 | type (* const _old)(_class, SEL, ## args, ...) = reinterpret_cast(_ ## name ## $ ## dollar); \ 226 | typedef type (*msgSendSuper_t)(struct objc_super *, SEL, ## args, ...); \ 227 | msgSendSuper_t const _spr(::etl::IsClass::value ? reinterpret_cast(&objc_msgSendSuper_stret) : reinterpret_cast(&objc_msgSendSuper)); \ 228 | return _$ ## name ## $ ## dollar call; \ 229 | } \ 230 | extra(name, dollar, colon) \ 231 | static _finline type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args) 232 | 233 | /* 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 ")";} */ 234 | 235 | #define MSMessage0_(extra, type, _class, name, sel0) \ 236 | MSMessage_(extra, type, _class, name, sel0, sel0, (_cls, _old, _spr, self, _cmd)) 237 | #define MSMessage1_(extra, type, _class, name, sel0, type0, arg0) \ 238 | MSMessage_(extra, type, _class, name, sel0 ## $, sel0:, (_cls, _old, _spr, self, _cmd, arg0), type0 arg0) 239 | #define MSMessage2_(extra, type, _class, name, sel0, sel1, type0, arg0, type1, arg1) \ 240 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $, sel0:sel1:, (_cls, _old, _spr, self, _cmd, arg0, arg1), type0 arg0, type1 arg1) 241 | #define MSMessage3_(extra, type, _class, name, sel0, sel1, sel2, type0, arg0, type1, arg1, type2, arg2) \ 242 | 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) 243 | #define MSMessage4_(extra, type, _class, name, sel0, sel1, sel2, sel3, type0, arg0, type1, arg1, type2, arg2, type3, arg3) \ 244 | 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) 245 | #define MSMessage5_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ 246 | 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) 247 | #define MSMessage6_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ 248 | 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) 249 | #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) \ 250 | 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) 251 | #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) \ 252 | 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) 253 | 254 | #define MSInstanceMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, _class *, _class, ## args) 255 | #define MSInstanceMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, _class *, _class, ## args) 256 | #define MSInstanceMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, _class *, _class, ## args) 257 | #define MSInstanceMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, _class *, _class, ## args) 258 | #define MSInstanceMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, _class *, _class, ## args) 259 | #define MSInstanceMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, _class *, _class, ## args) 260 | #define MSInstanceMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, _class *, _class, ## args) 261 | #define MSInstanceMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, _class *, _class, ## args) 262 | #define MSInstanceMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, _class *, _class, ## args) 263 | 264 | #define MSClassMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, Class, $ ## _class, ## args) 265 | #define MSClassMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, Class, $ ## _class, ## args) 266 | #define MSClassMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, Class, $ ## _class, ## args) 267 | #define MSClassMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, Class, $ ## _class, ## args) 268 | #define MSClassMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, Class, $ ## _class, ## args) 269 | #define MSClassMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, Class, $ ## _class, ## args) 270 | #define MSClassMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, Class, $ ## _class, ## args) 271 | #define MSClassMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, Class, $ ## _class, ## args) 272 | #define MSClassMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, Class, $ ## _class, ## args) 273 | 274 | #define MSInstanceMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, _class *, _class, ## args) 275 | #define MSInstanceMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, _class *, _class, ## args) 276 | #define MSInstanceMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, _class *, _class, ## args) 277 | #define MSInstanceMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, _class *, _class, ## args) 278 | #define MSInstanceMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, _class *, _class, ## args) 279 | #define MSInstanceMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, _class *, _class, ## args) 280 | #define MSInstanceMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, _class *, _class, ## args) 281 | #define MSInstanceMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, _class *, _class, ## args) 282 | #define MSInstanceMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, _class *, _class, ## args) 283 | 284 | #define MSClassMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, Class, $ ## _class, ## args) 285 | #define MSClassMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, Class, $ ## _class, ## args) 286 | #define MSClassMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, Class, $ ## _class, ## args) 287 | #define MSClassMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, Class, $ ## _class, ## args) 288 | #define MSClassMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, Class, $ ## _class, ## args) 289 | #define MSClassMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, Class, $ ## _class, ## args) 290 | #define MSClassMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, Class, $ ## _class, ## args) 291 | #define MSClassMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, Class, $ ## _class, ## args) 292 | #define MSClassMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, Class, $ ## _class, ## args) 293 | 294 | #define MSOldCall(args...) \ 295 | _old(self, _cmd, ## args) 296 | #define MSSuperCall(args...) \ 297 | _spr(& (struct objc_super) {self, class_getSuperclass(_cls)}, _cmd, ## args) 298 | 299 | #define MSIvarHook(type, name) \ 300 | type &name(MSHookIvar(self, #name)) 301 | 302 | #define MSClassHook(name) \ 303 | @class name; \ 304 | static Class $ ## name = objc_getClass(#name); 305 | #define MSMetaClassHook(name) \ 306 | @class name; \ 307 | static Class $$ ## name = object_getClass($ ## name); 308 | 309 | #endif/*__APPLE__*/ 310 | 311 | template 312 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) { 313 | return MSHookFunction( 314 | reinterpret_cast(symbol), 315 | reinterpret_cast(replace), 316 | reinterpret_cast(result) 317 | ); 318 | } 319 | 320 | template 321 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace) { 322 | return MSHookFunction(symbol, replace, reinterpret_cast(NULL)); 323 | } 324 | 325 | template 326 | static inline void MSHookSymbol(Type_ *&value, const char *name, MSImageRef image = NULL) { 327 | value = reinterpret_cast(MSFindSymbol(image, name)); 328 | } 329 | 330 | template 331 | static inline void MSHookFunction(const char *name, Type_ *replace, Type_ **result = NULL) { 332 | Type_ *symbol; 333 | MSHookSymbol(symbol, name); 334 | return MSHookFunction(symbol, replace, result); 335 | } 336 | 337 | template 338 | static inline void MSHookFunction(MSImageRef image, const char *name, Type_ *replace, Type_ **result = NULL) { 339 | Type_ *symbol; 340 | MSHookSymbol(symbol, name, image); 341 | return MSHookFunction(symbol, replace, result); 342 | } 343 | 344 | #endif 345 | 346 | #ifdef __ANDROID__ 347 | 348 | #ifdef __cplusplus 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 | static inline void MSAndroidGetPackage(JNIEnv *jni, jobject global, const char *name, jobject &local, jobject &loader) { 362 | jclass Context(jni->FindClass("android/content/Context")); 363 | jmethodID Context$createPackageContext(jni->GetMethodID(Context, "createPackageContext", "(Ljava/lang/String;I)Landroid/content/Context;")); 364 | jmethodID Context$getClassLoader(jni->GetMethodID(Context, "getClassLoader", "()Ljava/lang/ClassLoader;")); 365 | 366 | jstring string(jni->NewStringUTF(name)); 367 | local = jni->CallObjectMethod(global, Context$createPackageContext, string, 3); 368 | loader = jni->CallObjectMethod(local, Context$getClassLoader); 369 | } 370 | 371 | static inline jclass MSJavaFindClass(JNIEnv *jni, jobject loader, const char *name) { 372 | jclass Class(jni->FindClass("java/lang/Class")); 373 | jmethodID Class$forName(jni->GetStaticMethodID(Class, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;")); 374 | 375 | jstring string(jni->NewStringUTF(name)); 376 | jobject _class(jni->CallStaticObjectMethod(Class, Class$forName, string, JNI_TRUE, loader)); 377 | if (jni->ExceptionCheck()) 378 | return NULL; 379 | 380 | return reinterpret_cast(_class); 381 | } 382 | 383 | _disused static void MSJavaCleanWeak(void *data, JNIEnv *jni, void *value) { 384 | jni->DeleteWeakGlobalRef(reinterpret_cast(value)); 385 | } 386 | 387 | #endif 388 | 389 | #define MSHook(type, name, args...) \ 390 | _disused static type (*_ ## name)(args); \ 391 | static type $ ## name(args) 392 | 393 | #define MSJavaHook(type, name, arg0, args...) \ 394 | _disused static type (*_ ## name)(JNIEnv *jni, arg0, ...); \ 395 | static type $ ## name(JNIEnv *jni, arg0, ## args) 396 | 397 | #ifdef __cplusplus 398 | #define MSHake(name) \ 399 | &$ ## name, &_ ## name 400 | #else 401 | #define MSHake(name) \ 402 | &$ ## name, (void **) &_ ## name 403 | #endif 404 | 405 | #define SubstrateConcat_(lhs, rhs) \ 406 | lhs ## rhs 407 | #define SubstrateConcat(lhs, rhs) \ 408 | SubstrateConcat_(lhs, rhs) 409 | 410 | #ifdef __APPLE__ 411 | #define SubstrateSection \ 412 | __attribute__((__section__("__TEXT, __substrate"))) 413 | #else 414 | #define SubstrateSection \ 415 | __attribute__((__section__(".substrate"))) 416 | #endif 417 | 418 | #ifdef __APPLE__ 419 | #define MSFilterCFBundleID "Filter:CFBundleID" 420 | #define MSFilterObjC_Class "Filter:ObjC.Class" 421 | #endif 422 | 423 | #define MSFilterLibrary "Filter:Library" 424 | #define MSFilterExecutable "Filter:Executable" 425 | 426 | #define MSConfig(name, value) \ 427 | extern const char SubstrateConcat(_substrate_, __LINE__)[] SubstrateSection = name "=" value; 428 | 429 | #ifdef __cplusplus 430 | #define MSInitialize \ 431 | static void _MSInitialize(void); \ 432 | namespace { static class $MSInitialize { public: _finline $MSInitialize() { \ 433 | _MSInitialize(); \ 434 | } } $MSInitialize; } \ 435 | static void _MSInitialize() 436 | #else 437 | #define MSInitialize \ 438 | __attribute__((__constructor__)) static void _MSInitialize(void) 439 | #endif 440 | 441 | #define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation" 442 | #define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit" 443 | #define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore" 444 | #define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit" 445 | 446 | #endif//SUBSTRATE_H_ 447 | 448 | --------------------------------------------------------------------------------