]> git.saurik.com Git - cycript.git/blobdiff - sig/parse.cpp
Fix pointer crashes and round-trip const void *.
[cycript.git] / sig / parse.cpp
index 1bbd7a4b2bb603ec578be5ed80b699491a1d505f..d95af2fa57e053ccaac778fd97c9c9a0ac78b803 100644 (file)
@@ -25,6 +25,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#include <sstream>
 
 namespace sig {
 
@@ -148,14 +149,11 @@ Type *Parse_(CYPool &pool, const char **name, char eos, bool named, Callback cal
 
         case '^':
             type->primitive = pointer_P;
-            if (**name == '"') {
+            if (**name == '"')
+                // XXX: why is this here?
                 type->data.data.type = NULL;
-            } else {
+            else
                 type->data.data.type = Parse_(pool, name, eos, named, callback);
-                sig::Type *&target(type->data.data.type);
-                if (target != NULL && target->primitive == void_P)
-                    target = NULL;
-            }
         break;
 
         case 'b':
@@ -172,6 +170,12 @@ Type *Parse_(CYPool &pool, const char **name, char eos, bool named, Callback cal
         case 's': type->primitive = short_P; break;
         case 'v': type->primitive = void_P; break;
 
+#ifdef __LP64__
+        case 'F': type->primitive = double_P; break;
+#else
+        case 'F': type->primitive = float_P; break;
+#endif
+
         case '{':
             type->primitive = struct_P;
             next = '}';
@@ -241,6 +245,19 @@ const char *Unparse(CYPool &pool, struct Signature *signature) {
 
 const char *Unparse_(CYPool &pool, struct Type *type) {
     switch (type->primitive) {
+        case function_P: {
+            if (type->data.signature.count == 0)
+                return "?";
+            std::ostringstream out;
+            for (size_t i(0); i != type->data.signature.count; ++i) {
+                Element &element(type->data.signature.elements[i]);
+                out << Unparse(pool, element.type);
+                if (element.offset != _not(size_t))
+                    out << pool.itoa(element.offset);
+            }
+            return pool.strdup(out.str().c_str());
+        } break;
+
         case typename_P: return "#";
         case union_P: return pool.strcat("(", Unparse(pool, &type->data.signature), ")", NULL);
         case string_P: return "*";
@@ -259,7 +276,15 @@ const char *Unparse_(CYPool &pool, struct Type *type) {
             return pool.strcat("[", pool.itoa(type->data.data.size), value, "]", NULL);
         } break;
 
-        case pointer_P: return pool.strcat("^", type->data.data.type == NULL ? "v" : Unparse(pool, type->data.data.type), NULL);
+        case pointer_P: {
+            // XXX: protect against the weird '"' check in Parse_
+            _assert(type->data.data.type != NULL);
+            if (type->data.data.type->primitive == function_P)
+                return "^?";
+            else
+                return pool.strcat("^", Unparse(pool, type->data.data.type), NULL);
+        } break;
+
         case bit_P: return pool.strcat("b", pool.itoa(type->data.data.size), NULL);
         case char_P: return "c";
         case double_P: return "d";