]> git.saurik.com Git - cycript.git/commitdiff
Added runloop detection support, ported Handler back to the iPhone, setup RunLoop...
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 31 Oct 2009 21:48:05 +0000 (21:48 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 31 Oct 2009 21:48:05 +0000 (21:48 +0000)
Bridge.def
Handler.mm
Library.cpp
Mach/Inject.cpp

index 7ce9cda654416cbf722285c7beedc52a70c11d02..26797e3dc113bf53c159fc6ee0b003b6244c36b5 100644 (file)
@@ -19,6 +19,9 @@ T boolean B
 T float f
 T double d
 
+T Boolean B
+T SInt32 {int}
+
 S CGPoint "x"f"y"f
 S CGRect "origin"{CGPoint}"size"{CGSize}
 S CGSize "width"f"height"f
@@ -756,6 +759,24 @@ f CoreFoundation
 
 F CFRangeMake {CFRange}{CFIndex}{CFIndex}
 
+# Time Utilities
+
+T CFAbsoluteTime {CFTimeInterval}
+S CFGregorianDate "year"{SInt32}"month"{SInt8}"day"{SInt8}"hour"{SInt8}"minute"{SInt8}"second"{double}
+S CFGregorianUnits "years"{SInt32}"months"{SInt32}"days"{SInt32}"hours"{SInt32}"minutes"{SInt32}"second"{double}
+T CFTimeInterval {double}
+
+C kCFGregorianUnitsYears 1<<0
+C kCFGregorianUnitsMonths 1<<1
+C kCFGregorianUnitsDays 1<<2
+C kCFGregorianUnitsHours 1<<3
+C kCFGregorianUnitsMinutes 1<<4
+C kCFGregorianUnitsSeconds 1<<5
+C kCFGregorianAllUnits 0x00FFFFFF
+
+V kCFAbsoluteTimeIntervalSince1970 {CFTimeInterval}
+V kCFAbsoluteTimeIntervalSince1904 {CFTimeInterval}
+
 # CFComparatorFunction
 
 T CFIndex l
@@ -857,6 +878,68 @@ V kCFAllocatorMallocZone {CFAllocatorRef}
 V kCFAllocatorNull {CFAllocatorRef}
 V kCFAllocatorUseContext {CFAllocatorRef}
 
+# CFByteOrderUtils
+
+E __CFByteOrder
+C CFByteOrderUnknown 0
+C CFByteOrderLittleEndian 1
+C CFByteOrderBigEndian 2
+T CFByteOrder __CFByteOrder
+
+# CFArray
+
+T CFArrayRef @
+
+# CFRunLoop
+
+F CFRunLoopGetCurrent {CFRunLoopRef}
+F CFRunLoopGetMain {CFRunLoopRef}
+
+F CFRunLoopRun v
+F CFRunLoopRunInMode {SInt32}{CFStringRef}{CFTimeInterval}{Boolean}
+F CFRunLoopWakeUp v{CFRunLoopRef}
+F CFRunLoopStop v{CFRunLoopRef}
+F CFRunLoopIsWaiting {Boolean}{CFRunLoopRef}
+
+F CFRunLoopAddSource v{CFRunLoopRef}{CFRunLoopSourceRef}{CFStringRef}
+F CFRunLoopContainsSource {Boolean}{CFRunLoopRef}{CFRunLoopSourceRef}{CFStringRef}
+F CFRunLoopRemoveSource v{CFRunLoopRef}{CFRunLoopSourceRef}{CFStringRef}
+
+F CFRunLoopAddObserver v{CFRunLoopRef}{CFRunLoopObserverRef}{CFStringRef}
+F CFRunLoopContainsObserver {Boolean}{CFRunLoopRef}{CFRunLoopObserverRef}{CFStringRef}
+F CFRunLoopRemoveObserver v{CFRunLoopRef}{CFRunLoopObserverRef}{CFStringRef}
+
+F CFRunLoopAddCommonMode v{CFRunLoopRef}{CFStringRef}
+F CFRunLoopCopyAllModes {CFArrayRef}{CFRunLoopRef}
+F CFRunLoopCopyCurrentMode {CFStringRef}{CFRunLoopRef}
+
+F CFRunLoopAddTimer v{CFRunLoopRef}{CFRunLoopTimerRef}{CFStringRef}
+F CFRunLoopGetNextTimerFireDate {CFAbsoluteTime}{CFRunLoopRef}{CFStringRef}
+F CFRunLoopRemoveTimer v{CFRunLoopRef}{CFRunLoopTimerRef}{CFStringRef}
+F CFRunLoopContainsTimer {Boolean}{CFRunLoopRef}{CFRunLoopTimerRef}{CFStringRef}
+
+# F CFRunLoopPerformBlock
+
+F CFRunLoopGetTypeID {CFTypeID}
+
+T CFRunLoopRef @
+
+C kCFRunLoopRunFinished 1
+C kCFRunLoopRunStopped 2
+C kCFRunLoopRunTimedOut 3
+C kCFRunLoopRunHandledSource 4
+
+V kCFRunLoopCommonModes {CFStringRef}
+V kCFRunLoopDefaultMode {CFStringRef}
+
+# CFRunLoopTimer
+
+T CFRunLoopTimerRef @
+
+# CFString
+
+T CFStringRef @
+
 # CFType
 
 F CFGetAllocator {CFAllocatorRef}{CFTypeRef}
@@ -885,14 +968,6 @@ f CoreGraphics
 
 T CGFloat f
 
-# CFByteOrderUtils
-
-E __CFByteOrder
-C CFByteOrderUnknown 0
-C CFByteOrderLittleEndian 1
-C CFByteOrderBigEndian 2
-T CFByteOrder __CFByteOrder
-
 # CGAffineTransform
 
 F CGAffineTransformMake {CGAffineTransform}{CGFloat}{CGFloat}{CGFloat}{CGFloat}{CGFloat}{CGFloat}
index 2a42ef0893fd920e5c76f809bd34576a38606284..79528c447723723f1eaeb383031d35c0c8a50974 100644 (file)
 #include <unistd.h>
 #include <sstream>
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+
 struct CYExecute_ {
     apr_pool_t *pool_;
     const char * volatile data_;
@@ -93,6 +98,13 @@ struct CYClient :
 
         CYClient_ *client = [[[CYClient_ alloc] init] autorelease];
 
+        bool dispatch;
+        if (CFStringRef mode = CFRunLoopCopyCurrentMode(CFRunLoopGetMain())) {
+            dispatch = true;
+            CFRelease(mode);
+        } else
+            dispatch = false;
+
         for (;;) {
             size_t size;
             if (!CYRecvAll(socket_, &size, sizeof(size)))
@@ -115,6 +127,8 @@ struct CYClient :
                 json = NULL;
                 size = _not(size_t);
             } else {
+                NSAutoreleasePool *ar = [[NSAutoreleasePool alloc] init];
+
                 CYContext context(driver.pool_);
                 driver.program_->Replace(context);
                 std::ostringstream str;
@@ -122,9 +136,15 @@ struct CYClient :
                 out << *driver.program_;
                 std::string code(str.str());
                 CYExecute_ execute = {pool, code.c_str()};
-                [client performSelectorOnMainThread:@selector(execute:) withObject:[NSValue valueWithPointer:&execute] waitUntilDone:YES];
+                NSValue *value([NSValue valueWithPointer:&execute]);
+                if (dispatch)
+                    [client performSelectorOnMainThread:@selector(execute:) withObject:value waitUntilDone:YES];
+                else
+                    [client execute:value];
                 json = execute.data_;
                 size = json == NULL ? _not(size_t) : strlen(json);
+
+                [ar release];
             }
 
             if (!CYSendAll(socket_, &size, sizeof(size)))
index 34763fb94afae3f24773720bffc081175c960f16..a981b2bcb8281322f68e62c41d591641a13cb9d3 100644 (file)
 #include <sstream>
 #include <cmath>
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
-
 #include "Parser.hpp"
 #include "Cycript.tab.hh"
 
index a2c5f045c3abee148259ec3d255c43596f1c38cb..6eb9dad11246bc8d71bdc8652a275f031e6413b2 100644 (file)
@@ -42,6 +42,7 @@ void InjectLibrary(pid_t pid) {
     nl[0].n_un.n_name = (char *) "__pthread_set_self";
     nlist("/usr/lib/libSystem.B.dylib", nl);
     nlset(baton->_pthread_set_self, nl, 0);
+    _assert(baton->_pthread_set_self != NULL);
 
     baton->pthread_create = &pthread_create;
     baton->pthread_join = &pthread_join;