From afc574add984e00864b81a3546d71d2e4f825c18 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 21 Jan 2014 15:14:36 -0800 Subject: [PATCH] Actually add the modules (kind of important ;P). --- modules/com/saurik/substrate/MS.cy | 86 ++++++++++++++++++++++++++++++ modules/org/cycript/NSLog.cy | 28 ++++++++++ 2 files changed, 114 insertions(+) create mode 100644 modules/com/saurik/substrate/MS.cy create mode 100644 modules/org/cycript/NSLog.cy 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); +}; -- 2.45.2