]> git.saurik.com Git - cycript.git/commitdiff
Changed console commands to start with ? and added ?expand to unescape strings.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 16 Oct 2009 18:04:26 +0000 (18:04 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 16 Oct 2009 18:04:26 +0000 (18:04 +0000)
Application.cpp
Library.mm

index 725e2461dcd502b08c8aafcb32a612574005d49f..25f624efb3bf8426660fcacfae29897cfe72bf05 100644 (file)
@@ -72,13 +72,15 @@ static void sigint(int) {
     longjmp(ctrlc_, 1);
 }
 
-void Run(int socket, const char *data, size_t size, FILE *fout) {
+void Run(int socket, const char *data, size_t size, FILE *fout, bool expand = false) {
     CYPool pool;
 
     const char *json;
-    if (socket == -1)
+    if (socket == -1) {
         json = CYExecute(pool, data);
-    else {
+        if (json != NULL)
+            size = strlen(json);
+    } else {
         CYSendAll(socket, &size, sizeof(size));
         CYSendAll(socket, data, size);
         CYRecvAll(socket, &size, sizeof(size));
@@ -93,19 +95,39 @@ void Run(int socket, const char *data, size_t size, FILE *fout) {
     }
 
     if (json != NULL && fout != NULL) {
-        fputs(json, fout);
+        if (!expand || json[0] != '"' && json[0] != '\'')
+            fputs(json, fout);
+        else for (size_t i(0); i != size; ++i)
+            if (json[i] != '\\')
+                fputc(json[i], fout);
+            else switch(json[++i]) {
+                case '\0': goto done;
+                case '\\': fputc('\\', fout); break;
+                case '\'': fputc('\'', fout); break;
+                case '"': fputc('"', fout); break;
+                case 'b': fputc('\b', fout); break;
+                case 'f': fputc('\f', fout); break;
+                case 'n': fputc('\n', fout); break;
+                case 'r': fputc('\r', fout); break;
+                case 't': fputc('\t', fout); break;
+                case 'v': fputc('\v', fout); break;
+                default: fputc('\\', fout); --i; break;
+            }
+
+      done:
         fputs("\n", fout);
         fflush(fout);
     }
 }
 
-void Run(int socket, std::string &code, FILE *fout) {
-    Run(socket, code.c_str(), code.size(), fout);
+void Run(int socket, std::string &code, FILE *fout, bool expand = false) {
+    Run(socket, code.c_str(), code.size(), fout, expand);
 }
 
 static void Console(int socket) {
     bool bypass(false);
     bool debug(false);
+    bool expand(false);
 
     FILE *fout(stdout);
 
@@ -137,7 +159,7 @@ static void Console(int socket) {
 
         if (!extra) {
             extra = true;
-            if (line[0] == '\\') {
+            if (line[0] == '?') {
                 std::string data(line + 1);
                 if (data == "bypass") {
                     bypass = !bypass;
@@ -147,6 +169,10 @@ static void Console(int socket) {
                     debug = !debug;
                     fprintf(fout, "debug == %s\n", debug ? "true" : "false");
                     fflush(fout);
+                } else if (data == "expand") {
+                    expand = !expand;
+                    fprintf(fout, "expand == %s\n", expand ? "true" : "false");
+                    fflush(fout);
                 }
                 add_history(line);
                 goto restart;
@@ -216,7 +242,7 @@ static void Console(int socket) {
         if (debug)
             std::cout << code << std::endl;
 
-        Run(socket, code, fout);
+        Run(socket, code, fout, expand);
     }
 
     fputs("\n", fout);
index 7a1872cebaea2cdc7ac2cd62b2767d79f8ee460a..2eeb1c7738a6ba44052506c8d82cdcb2b9ec8dff 100644 (file)
@@ -1378,6 +1378,7 @@ NSString *CYCopyNSCYON(id value) {
             string = @"_NSZombie_";
         else if (_class == NSZombie_)
             string = [NSString stringWithFormat:@"<_NSZombie_: %p>", value];
+        // XXX: frowny /in/ the pants
         else if (value == NSMessageBuilder_ || value == Object_)
             string = nil;
         else