]> git.saurik.com Git - cycript.git/blobdiff - Trampoline.t.cpp
Embed Cycript git version in zip package filename.
[cycript.git] / Trampoline.t.cpp
index 7c6b388bb491a23f36491a93d1ccfba4a0c54866..ab821e88d013d1b0c00aa69c7371129eb8fc28a4 100644 (file)
@@ -53,6 +53,8 @@ static int $strcmp(const char *lhs, const char *rhs) {
 }
 
 static void $strlcpy(char *dst, const char *src, size_t size) {
+    if (src == NULL)
+        src = "(null)";
     if (size == 0)
         return;
     size_t i(0);
@@ -64,6 +66,24 @@ static void $strlcpy(char *dst, const char *src, size_t size) {
     } dst[i] = '\0';
 }
 
+__attribute__((__unused__))
+static void $snprintfp(char *dst, size_t size, const void *pointer) {
+    uintptr_t value(reinterpret_cast<uintptr_t>(pointer));
+    char buffer[32];
+    char *end(buffer + sizeof(buffer));
+    *--end = '\0';
+    if (value == 0)
+        *--end = '0';
+    else do {
+        unsigned digit(value & 0xf);
+        value >>= 4;
+        *--end = (digit < 10 ? '0' : 'a' - 10) + digit;
+    } while (value != 0);
+    *--end = 'x';
+    *--end = '0';
+    $strlcpy(dst, end, size);
+}
+
 #ifdef __LP64__
 typedef struct mach_header_64 mach_header_xx;
 typedef struct nlist_64 nlist_xx;
@@ -88,11 +108,11 @@ static const uint32_t MH_MAGIC_XX = MH_MAGIC;
                     lcp->cmdsize % sizeof(long) != 0 || lcp->cmdsize <= 0 || \
                     reinterpret_cast<const uint8_t *>(lcp) + lcp->cmdsize > reinterpret_cast<const uint8_t *>(load_commands) + mach->sizeofcmds \
                 ) \
-                    return NULL; \
+                    break; \
                 else if (lcp->cmd != lc) \
                     continue; \
                 else if (lcp->cmdsize < sizeof(type)) \
-                    return NULL; \
+                    break; \
                 else if (const type *command = reinterpret_cast<const type *>(lcp))
 
 static const mach_header_xx *Library(struct dyld_all_image_infos *infos, const char *name) {