From: Jay Freeman (saurik) Date: Tue, 21 Jan 2014 23:14:36 +0000 (-0800) Subject: Actually add the modules (kind of important ;P). X-Git-Tag: v0.9.500^0 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/afc574add984e00864b81a3546d71d2e4f825c18 Actually add the modules (kind of important ;P). --- diff --git a/modules/com/saurik/substrate/MS.cy b/modules/com/saurik/substrate/MS.cy new file mode 100644 index 0000000..f3ee4d8 --- /dev/null +++ b/modules/com/saurik/substrate/MS.cy @@ -0,0 +1,86 @@ +/* Cycript - Optimizing JavaScript Compiler/Runtime + * Copyright (C) 2009-2013 Jay Freeman (saurik) +*/ + +/* GNU Lesser General Public License, Version 3 {{{ */ +/* + * Cycript is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Cycript is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Cycript. If not, see . +**/ +/* }}} */ + +(function(exports) { + +var libcycript = dlopen("/usr/lib/libcycript.dylib", RTLD_NOLOAD); +if (libcycript == null) + return; + +var CYHandleServer = dlsym(libcycript, "CYHandleServer"); +if (CYHandleServer == null) + return; + +var info = new Dl_info; +if (dladdr(CYHandleServer, info) == 0) { + free(info); + return; +} + +var path = info->dli_fname; +free(info); + +var slash = path.lastIndexOf('/'); +if (slash == -1) + return; +var libsubstrate = dlopen(path.substr(0, slash) + "/libsubstrate.dylib", RTLD_GLOBAL | RTLD_LAZY); +if (libsubstrate == null) + return; + +MSGetImageByName = @encode(void *(const char *))(dlsym(libsubstrate, "MSGetImageByName")); +MSFindSymbol = @encode(void *(void *, const char *))(dlsym(libsubstrate, "MSFindSymbol")); +MSHookFunction = @encode(void(void *, void *, void **))(dlsym(libsubstrate, "MSHookFunction")); +MSHookMessageEx = @encode(void(Class, SEL, void *, void **))(dlsym(libsubstrate, "MSHookMessageEx")); + +var slice = [].slice; + +exports.getImageByName = MSGetImageByName; +exports.findSymbol = MSFindSymbol; + +exports.hookFunction = function(func, hook, old) { + var type = func.type; + + var pointer; + if (old == null || typeof old === "undefined") + pointer = null; + else { + pointer = new @encode(void **); + *old = function() { return type(*pointer).apply(null, arguments); }; + } + + MSHookFunction(func.valueOf(), type(hook), pointer); +}; + +exports.hookMessage = function(isa, sel, imp, old) { + var type = sel.type(isa); + + var pointer; + if (old == null || typeof old === "undefined") + pointer = null; + else { + pointer = new @encode(void **); + *old = function() { return type(*pointer).apply(null, [this, sel].concat(slice.call(arguments))); }; + } + + MSHookMessageEx(isa, sel, type(function(self, sel) { return imp.apply(self, slice.call(arguments, 2)); }), pointer); +}; + +})(exports); diff --git a/modules/org/cycript/NSLog.cy b/modules/org/cycript/NSLog.cy new file mode 100644 index 0000000..651619a --- /dev/null +++ b/modules/org/cycript/NSLog.cy @@ -0,0 +1,28 @@ +/* Cycript - Optimizing JavaScript Compiler/Runtime + * Copyright (C) 2009-2013 Jay Freeman (saurik) +*/ + +/* GNU Lesser General Public License, Version 3 {{{ */ +/* + * Cycript is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Cycript is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Cycript. If not, see . +**/ +/* }}} */ + +var NSLog = dlsym(RTLD_DEFAULT, "NSLog"); +var slice = [].slice; + +module.exports = function(format) { + var args = slice.call(arguments); + new Functor(NSLog, "v" + ["@" for (x in args)].join("")).apply(null, args); +};