]> git.saurik.com Git - cycript.git/blobdiff - Execute.cpp
Try to CYON pointers as the address of their value.
[cycript.git] / Execute.cpp
index 7b39bb94622f05f37dbbbf381021749de4537e1d..61acaf2e8a05f36ca1c3b6114bae8d1c0ab594c5 100644 (file)
@@ -823,9 +823,9 @@ static JSValueRef Pointer_getProperty(JSContextRef context, JSObjectRef object,
         return internal->length_ == _not(size_t) ? CYJSUndefined(context) : CYCastJSValue(context, internal->length_);
 
     Type_privateData *typical(internal->type_);
         return internal->length_ == _not(size_t) ? CYJSUndefined(context) : CYCastJSValue(context, internal->length_);
 
     Type_privateData *typical(internal->type_);
-
     if (typical->type_ == NULL)
         return NULL;
     if (typical->type_ == NULL)
         return NULL;
+    sig::Type &type(*typical->type_);
 
     ssize_t offset;
     if (JSStringIsEqualToUTF8CString(property, "$cyi"))
 
     ssize_t offset;
     if (JSStringIsEqualToUTF8CString(property, "$cyi"))
@@ -833,13 +833,16 @@ static JSValueRef Pointer_getProperty(JSContextRef context, JSObjectRef object,
     else if (!CYGetOffset(pool, context, property, offset))
         return NULL;
 
     else if (!CYGetOffset(pool, context, property, offset))
         return NULL;
 
+    if (type.primitive == sig::function_P)
+        return CYMakeFunctor(context, reinterpret_cast<void (*)()>(internal->value_), type.data.signature);
+
     ffi_type *ffi(typical->GetFFI());
 
     uint8_t *base(reinterpret_cast<uint8_t *>(internal->value_));
     base += ffi->size * offset;
 
     JSObjectRef owner(internal->GetOwner() ?: object);
     ffi_type *ffi(typical->GetFFI());
 
     uint8_t *base(reinterpret_cast<uint8_t *>(internal->value_));
     base += ffi->size * offset;
 
     JSObjectRef owner(internal->GetOwner() ?: object);
-    return CYFromFFI(context, typical->type_, ffi, base, false, owner);
+    return CYFromFFI(context, &type, ffi, base, false, owner);
 } CYCatch(NULL) }
 
 static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
 } CYCatch(NULL) }
 
 static bool Pointer_setProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef value, JSValueRef *exception) { CYTry {
@@ -1245,16 +1248,26 @@ static JSValueRef Pointer_callAsFunction_toCYON(JSContextRef context, JSObjectRe
         JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array_prototype")));
         JSObjectRef toCYON(CYCastJSObject(context, CYGetProperty(context, Array, toCYON_s)));
         return CYCallAsFunction(context, toCYON, _this, count, arguments);
         JSObjectRef Array(CYGetCachedObject(context, CYJSString("Array_prototype")));
         JSObjectRef toCYON(CYCastJSObject(context, CYGetProperty(context, Array, toCYON_s)));
         return CYCallAsFunction(context, toCYON, _this, count, arguments);
-    } else try {
-        CYPool pool;
-        return CYCastJSValue(context, pool.strcat("&", CYPoolCCYON(pool, context, CYGetProperty(context, _this, cyi_s)), NULL));
-    } catch (const CYException &e) {
+    } else if (internal->type_->type_ == NULL) pointer: {
         char string[32];
         sprintf(string, "%p", internal->value_);
         return CYCastJSValue(context, string);
         char string[32];
         sprintf(string, "%p", internal->value_);
         return CYCastJSValue(context, string);
+    } try {
+        JSValueRef value(CYGetProperty(context, _this, cyi_s));
+        if (JSValueIsUndefined(context, value))
+            goto pointer;
+        CYPool pool;
+        return CYCastJSValue(context, pool.strcat("&", CYPoolCCYON(pool, context, value), NULL));
+    } catch (const CYException &e) {
+        goto pointer;
     }
 } CYCatch(NULL) }
 
     }
 } CYCatch(NULL) }
 
+static JSValueRef Pointer_getProperty_type(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
+    Pointer *internal(reinterpret_cast<Pointer *>(JSObjectGetPrivate(object)));
+    return CYMakeType(context, internal->type_->type_);
+} CYCatch(NULL) }
+
 static JSValueRef Functor_getProperty_type(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
     cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(object)));
     return CYMakeType(context, &internal->signature_);
 static JSValueRef Functor_getProperty_type(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
     cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(object)));
     return CYMakeType(context, &internal->signature_);
@@ -1303,6 +1316,11 @@ static JSStaticFunction Pointer_staticFunctions[4] = {
     {NULL, NULL, 0}
 };
 
     {NULL, NULL, 0}
 };
 
+static JSStaticValue Pointer_staticValues[2] = {
+    {"type", &Pointer_getProperty_type, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {NULL, NULL, NULL, 0}
+};
+
 static JSStaticFunction Struct_staticFunctions[2] = {
     {"$cya", &Struct_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {NULL, NULL, 0}
 static JSStaticFunction Struct_staticFunctions[2] = {
     {"$cya", &Struct_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {NULL, NULL, 0}
@@ -1447,6 +1465,7 @@ void CYInitializeDynamic() {
     definition = kJSClassDefinitionEmpty;
     definition.className = "Pointer";
     definition.staticFunctions = Pointer_staticFunctions;
     definition = kJSClassDefinitionEmpty;
     definition.className = "Pointer";
     definition.staticFunctions = Pointer_staticFunctions;
+    definition.staticValues = Pointer_staticValues;
     definition.getProperty = &Pointer_getProperty;
     definition.setProperty = &Pointer_setProperty;
     definition.finalize = &CYFinalize;
     definition.getProperty = &Pointer_getProperty;
     definition.setProperty = &Pointer_setProperty;
     definition.finalize = &CYFinalize;