From: Jay Freeman (saurik) Date: Tue, 19 Aug 2014 19:08:20 +0000 (-0700) Subject: Replace -any.dylib with a check in the trampoline. X-Git-Tag: v0.9.502~5 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/3d1db6b99542cb51e0114b1a9c18f8490a6c3e52?ds=inline Replace -any.dylib with a check in the trampoline. --- diff --git a/Handler.mm b/Handler.mm index e9a8903..3298148 100644 --- a/Handler.mm +++ b/Handler.mm @@ -140,7 +140,7 @@ extern "C" void CYHandleClient(int socket) { _assert(pthread_create(&client->thread_, NULL, &OnClient, client) == 0); } -extern "C" void CYHandleServer(pid_t pid, char *data, size_t size) { +extern "C" void CYHandleServer(pid_t pid) { CYInitializeDynamic(); int socket(_syscall(::socket(PF_UNIX, SOCK_STREAM, 0))); try { diff --git a/Mach/Inject.cpp b/Mach/Inject.cpp index 7d80599..a017a5b 100644 --- a/Mach/Inject.cpp +++ b/Mach/Inject.cpp @@ -58,7 +58,7 @@ void InjectLibrary(pid_t pid) { library[flength] = '\0'; _assert(strcmp(library + flength - 6, ".dylib") == 0); #if !TARGET_OS_IPHONE - strcpy(library + flength - 6, "-any.dylib"); + strcpy(library + flength - 6, "-###.dylib"); #endif mach_port_t self(mach_task_self()), task; diff --git a/Makefile.am b/Makefile.am index 757ca29..0397377 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,13 +32,6 @@ CY_LDFLAGS = -no-undefined -avoid-version -export-dynamic lib_LTLIBRARIES = -if CY_MACH -lib_LTLIBRARIES += libcycript-any.la -libcycript_any_la_SOURCES = Select.cpp -libcycript_any_la_LDFLAGS = $(CY_LDFLAGS) -libcycript_any_la_LIBADD = -ldl -endif - lib_LTLIBRARIES += libcycript.la libcycript_la_LDFLAGS = $(CY_LDFLAGS) libcycript_la_LIBADD = $(LTLIBFFI) $(LTLIBGCC) -ldl diff --git a/Makefile.in b/Makefile.in index ac610b9..e74b205 100644 --- a/Makefile.in +++ b/Makefile.in @@ -98,22 +98,21 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -@CY_MACH_TRUE@am__append_1 = libcycript-any.la @CY_CONSOLE_TRUE@bin_PROGRAMS = cycript$(EXEEXT) -@CY_EXECUTE_TRUE@am__append_2 = sig/ffi_type.cpp sig/parse.cpp \ +@CY_EXECUTE_TRUE@am__append_1 = sig/ffi_type.cpp sig/parse.cpp \ @CY_EXECUTE_TRUE@ sig/copy.cpp Bridge.cpp Execute.cpp \ @CY_EXECUTE_TRUE@ JavaScriptCore.cpp -@CY_EXECUTE_TRUE@am__append_3 = $(LTJAVASCRIPTCORE) -@CY_EXECUTE_TRUE@am__append_4 = -DCY_EXECUTE -@CY_EXECUTE_TRUE@am__append_5 = C -@CY_EXECUTE_TRUE@am__append_6 = Bridge.gperf Bridge.hpp -@CY_OBJECTIVEC_TRUE@am__append_7 = ObjectiveC -@CY_OBJECTIVEC_TRUE@am__append_8 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm -@CY_OBJECTIVEC_TRUE@am__append_9 = $(LTOBJECTIVEC) -@CY_MACH_TRUE@am__append_10 = Handler.mm -@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_11 = Mach/Inject.cpp -@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_12 = -DCY_ATTACH -@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_13 = Trampoline.t.lo \ +@CY_EXECUTE_TRUE@am__append_2 = $(LTJAVASCRIPTCORE) +@CY_EXECUTE_TRUE@am__append_3 = -DCY_EXECUTE +@CY_EXECUTE_TRUE@am__append_4 = C +@CY_EXECUTE_TRUE@am__append_5 = Bridge.gperf Bridge.hpp +@CY_OBJECTIVEC_TRUE@am__append_6 = ObjectiveC +@CY_OBJECTIVEC_TRUE@am__append_7 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm +@CY_OBJECTIVEC_TRUE@am__append_8 = $(LTOBJECTIVEC) +@CY_MACH_TRUE@am__append_9 = Handler.mm +@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_10 = Mach/Inject.cpp +@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_11 = -DCY_ATTACH +@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_12 = Trampoline.t.lo \ @CY_CONSOLE_TRUE@@CY_MACH_TRUE@ libTrampoline.t.la \ @CY_CONSOLE_TRUE@@CY_MACH_TRUE@ Trampoline.t.hpp subdir = . @@ -165,19 +164,6 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" LTLIBRARIES = $(lib_LTLIBRARIES) -libcycript_any_la_DEPENDENCIES = -am__libcycript_any_la_SOURCES_DIST = Select.cpp -@CY_MACH_TRUE@am_libcycript_any_la_OBJECTS = Select.lo -libcycript_any_la_OBJECTS = $(am_libcycript_any_la_OBJECTS) -AM_V_lt = $(am__v_lt_@AM_V@) -am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) -am__v_lt_0 = --silent -am__v_lt_1 = -libcycript_any_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ - $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ - $(AM_CXXFLAGS) $(CXXFLAGS) $(libcycript_any_la_LDFLAGS) \ - $(LDFLAGS) -o $@ -@CY_MACH_TRUE@am_libcycript_any_la_rpath = -rpath $(libdir) am__DEPENDENCIES_1 = @CY_EXECUTE_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) @CY_OBJECTIVEC_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) @@ -203,6 +189,10 @@ am_libcycript_la_OBJECTS = ConvertUTF.lo Decode.lo Driver.lo \ Replace.lo Cycript.tab.lo lex.cy.lo $(am__objects_1) \ $(am__objects_2) $(am__objects_3) libcycript_la_OBJECTS = $(am_libcycript_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = libcycript_la_LINK = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(OBJCXXLD) $(AM_OBJCXXFLAGS) \ $(OBJCXXFLAGS) $(libcycript_la_LDFLAGS) $(LDFLAGS) -o $@ @@ -285,10 +275,9 @@ AM_V_OBJCXXLD = $(am__v_OBJCXXLD_@AM_V@) am__v_OBJCXXLD_ = $(am__v_OBJCXXLD_@AM_DEFAULT_V@) am__v_OBJCXXLD_0 = @echo " OBJCXXLD" $@; am__v_OBJCXXLD_1 = -SOURCES = $(libcycript_any_la_SOURCES) $(libcycript_la_SOURCES) \ - $(cycript_SOURCES) -DIST_SOURCES = $(am__libcycript_any_la_SOURCES_DIST) \ - $(am__libcycript_la_SOURCES_DIST) $(am__cycript_SOURCES_DIST) +SOURCES = $(libcycript_la_SOURCES) $(cycript_SOURCES) +DIST_SOURCES = $(am__libcycript_la_SOURCES_DIST) \ + $(am__cycript_SOURCES_DIST) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -534,28 +523,25 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects -CLEANFILES = $(am__append_6) $(am__append_13) Cycript.yy Cycript.l \ +CLEANFILES = $(am__append_5) $(am__append_12) Cycript.yy Cycript.l \ lex.cy.cpp Cycript.tab.cc Cycript.tab.hh location.hh \ position.hh stack.hh Cycript.output SUBDIRS = ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = -I$(srcdir)/include -DYYDEBUG=1 -include config.h \ - -include $(srcdir)/unconfig.h $(am__append_4) $(am__append_12) + -include $(srcdir)/unconfig.h $(am__append_3) $(am__append_11) CY_LDFLAGS = -no-undefined -avoid-version -export-dynamic -lib_LTLIBRARIES = $(am__append_1) libcycript.la -@CY_MACH_TRUE@libcycript_any_la_SOURCES = Select.cpp -@CY_MACH_TRUE@libcycript_any_la_LDFLAGS = $(CY_LDFLAGS) -@CY_MACH_TRUE@libcycript_any_la_LIBADD = -ldl +lib_LTLIBRARIES = libcycript.la libcycript_la_LDFLAGS = $(CY_LDFLAGS) -libcycript_la_LIBADD = $(LTLIBFFI) $(LTLIBGCC) -ldl $(am__append_3) \ - $(am__append_9) +libcycript_la_LIBADD = $(LTLIBFFI) $(LTLIBGCC) -ldl $(am__append_2) \ + $(am__append_8) libcycript_la_SOURCES = ConvertUTF.c Decode.cpp Driver.cpp \ Highlight.cpp Library.cpp Network.cpp Output.cpp Parser.cpp \ - Replace.cpp Cycript.tab.cc lex.cy.cpp $(am__append_2) \ - $(am__append_8) $(am__append_10) -filters = $(CY_FILTERS) $(am__append_5) $(am__append_7) + Replace.cpp Cycript.tab.cc lex.cy.cpp $(am__append_1) \ + $(am__append_7) $(am__append_9) +filters = $(CY_FILTERS) $(am__append_4) $(am__append_6) @CY_CONSOLE_TRUE@cycript_SOURCES = Console.cpp Display.cpp \ -@CY_CONSOLE_TRUE@ $(am__append_11) +@CY_CONSOLE_TRUE@ $(am__append_10) @CY_CONSOLE_TRUE@cycript_LDADD = libcycript.la $(LTLIBAPR) $(LTLIBREADLINE) $(LTLIBTERMCAP) $(LTLIBGCC) -ldl @CY_CONSOLE_TRUE@ldid = true @CY_CONSOLE_TRUE@entitle = $(ldid) -S$(srcdir)/cycript.xml @@ -648,9 +634,6 @@ clean-libLTLIBRARIES: echo rm -f $${locs}; \ rm -f $${locs}; \ } - -libcycript-any.la: $(libcycript_any_la_OBJECTS) $(libcycript_any_la_DEPENDENCIES) $(EXTRA_libcycript_any_la_DEPENDENCIES) - $(AM_V_CXXLD)$(libcycript_any_la_LINK) $(am_libcycript_any_la_rpath) $(libcycript_any_la_OBJECTS) $(libcycript_any_la_LIBADD) $(LIBS) sig/$(am__dirstamp): @$(MKDIR_P) sig @: > sig/$(am__dirstamp) @@ -764,7 +747,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Output.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Parser.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Replace.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Select.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lex.cy.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@Mach/$(DEPDIR)/Inject.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ObjectiveC/$(DEPDIR)/Library.Plo@am__quote@ diff --git a/Select.cpp b/Select.cpp deleted file mode 100644 index fc49e7c..0000000 --- a/Select.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2013 Jay Freeman (saurik) -*/ - -/* GNU General Public License, Version 3 {{{ */ -/* - * Cycript is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cycript. If not, see . -**/ -/* }}} */ - -#include - -#include - -#include -#include -#include - -#include - -extern "C" void CYHandleServer(pid_t pid, char *data, size_t size) { - Dl_info addr; - if (dladdr(reinterpret_cast(&CYHandleServer), &addr) == 0) - return; - - const char *fname(addr.dli_fname); - size_t length(strlen(fname)); - - const char *target; -#ifdef __APPLE__ - // XXX: THIS IS HORRIBLE OMG I NEED TO FIX THIS ASAP - bool simulator(false); - for (uint32_t i(0), e(_dyld_image_count()); i != e; ++i) { - if (strstr(_dyld_get_image_name(i), "/SDKs/iPhoneSimulator") != NULL) - simulator = true; - } - if (simulator) - target = "sim"; - else -#endif - // someone threw a fit about dangling #endif + else - // the idea that this bothers someone gives me glee - target = "sys"; - - char library[length + 1]; - memcpy(library, fname, length); - memcpy(library + length - 6 - 3, target, 3); - library[length] = '\0'; - - void *handle(dlopen(library, RTLD_LOCAL | RTLD_LAZY)); - if (handle == NULL) { - strlcpy(data, dlerror(), size); - return; - } - - void *symbol(dlsym(handle, "CYHandleServer")); - if (symbol == NULL) { - strlcpy(data, dlerror(), size); - return; - } - - reinterpret_cast(symbol)(pid); -} diff --git a/Trampoline.t.cpp b/Trampoline.t.cpp index ab821e8..71d6cba 100644 --- a/Trampoline.t.cpp +++ b/Trampoline.t.cpp @@ -44,6 +44,12 @@ static void $bzero(void *data, size_t size) { bytes[i] = 0; } +__attribute__((__unused__)) +static void $memcpy(char *dst, const char *src, size_t size) { + for (size_t i(0); i != size; ++i) + dst[i] = src[i]; +} + static int $strcmp(const char *lhs, const char *rhs) { while (*lhs == *rhs) { if (*lhs == '\0') @@ -66,6 +72,26 @@ static void $strlcpy(char *dst, const char *src, size_t size) { } dst[i] = '\0'; } +__attribute__((__unused__)) +static char *$strstr(const char *haystack, const char *needle) { + if (*needle == '\0') + return NULL; + for (; *haystack != '\0'; ++haystack) + for (size_t i(0); ; ++i) + if (needle[i] == '\0') + return const_cast(haystack); + else if (needle[i] != haystack[i]) + break; + return NULL; +} + +__attribute__((__unused__)) +static size_t $strlen(const char *data) { + for (size_t i(0); ; ++i) + if (data[i] == '\0') + return i; +} + __attribute__((__unused__)) static void $snprintfp(char *dst, size_t size, const void *pointer) { uintptr_t value(reinterpret_cast(pointer)); @@ -192,6 +218,22 @@ static _finline const mach_header_xx *Library(Baton *baton, const char *name) { return Library(infos, name); } +#if defined(__i386__) || defined(__x86_64__) +static bool Simulator(struct dyld_all_image_infos *infos) { + for (uint32_t i(0); i != infos->infoArrayCount; ++i) { + const dyld_image_info &info(infos->infoArray[i]); + const char *path(info.imageFilePath); + if ($strstr(path, "/SDKs/iPhoneSimulator") != NULL) + return true; + } return false; +} + +static bool Simulator(Baton *baton) { + struct dyld_all_image_infos *infos(reinterpret_cast(baton->dyld)); + return Simulator(infos); +} +#endif + void *Routine(void *arg) { Baton *baton(reinterpret_cast(arg)); @@ -207,6 +249,12 @@ void *Routine(void *arg) { void *(*$dlopen)(const char *, int); cyset($dlopen, "_dlopen", dyld); +#if defined(__i386__) || defined(__x86_64__) + size_t length($strlen(baton->library)); + if (length >= 10 && $strcmp(baton->library + length - 10, "-###.dylib") == 0) + $memcpy(baton->library + length - 10, Simulator(baton) ? "-sim" : "-sys", 4); +#endif + void *handle($dlopen(baton->library, RTLD_LAZY | RTLD_LOCAL)); if (handle == NULL) { $strlcpy(baton->error, $dlerror(), sizeof(baton->error)); @@ -216,14 +264,14 @@ void *Routine(void *arg) { void *(*$dlsym)(void *, const char *); cyset($dlsym, "_dlsym", dyld); - void (*CYHandleServer)(pid_t, char *, size_t); - CYHandleServer = reinterpret_cast($dlsym(handle, "CYHandleServer")); + void (*CYHandleServer)(pid_t); + CYHandleServer = reinterpret_cast($dlsym(handle, "CYHandleServer")); if (CYHandleServer == NULL) { $strlcpy(baton->error, $dlerror(), sizeof(baton->error)); return NULL; } - CYHandleServer(baton->pid, baton->error, sizeof(baton->error)); + CYHandleServer(baton->pid); return NULL; } diff --git a/ios.mk b/ios.mk index 7c40211..7a1850e 100644 --- a/ios.mk +++ b/ios.mk @@ -1,6 +1,6 @@ binary := Cycript_/cycript -$(deb): $(binary) $(patsubst %,Cycript_/libcycript%dylib,. -any. -sim. -sys.) control +$(deb): $(binary) $(patsubst %,Cycript_/libcycript%dylib,. -sim. -sys.) control rm -rf package mkdir -p package/DEBIAN cp -pR control package/DEBIAN diff --git a/xcode.mk b/xcode.mk index 35f0a4f..c6db97a 100644 --- a/xcode.mk +++ b/xcode.mk @@ -32,7 +32,6 @@ cycript := cycript += Cycript.lib/cycript cycript += Cycript.lib/cycript0.9 cycript += Cycript.lib/libcycript.dylib -cycript += Cycript.lib/libcycript-any.dylib cycript += Cycript.lib/libcycript-sys.dylib cycript += Cycript.lib/libcycript-sim.dylib @@ -107,8 +106,6 @@ $(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch)))) define build_sim $(call build_any,sim,$(1)) $(call build_lib,sim,$(1)) -build.sim-$(1)/.libs/libcycript-any.dylib: build-sim-$(1) - @ endef $(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch)))) @@ -126,11 +123,6 @@ endef $(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch)))) -Cycript.lib/libcycript-any.dylib: build.sim-i386/.libs/libcycript-any.dylib build.sim-x86_64/.libs/libcycript-any.dylib - @mkdir -p $(dir $@) - $(lipo) -create -output $@ $^ - codesign -s $(codesign) $@ - Cycript.lib/libcycript.dylib: build.mac-i386/.libs/libcycript.dylib build.mac-x86_64/.libs/libcycript.dylib build.ios-armv6/.libs/libcycript.dylib build.ios-arm64/.libs/libcycript.dylib @mkdir -p $(dir $@) $(lipo) -create -output $@ $^ @@ -181,7 +173,7 @@ cycript: cycript.in cp -af $< $@ chmod 755 $@ -install: Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript-sys.dylib Cycript.lib/libcycript-any.dylib Cycript.lib/libcycript-sim.dylib +install: Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript-sys.dylib Cycript.lib/libcycript-sim.dylib sudo cp -af $(filter-out %.dylib,$^) /usr/bin sudo cp -af $(filter %.dylib,$^) /usr/lib