]> git.saurik.com Git - cycript.git/blobdiff - ObjectiveC/Library.mm
Move Cydget* to ObjectiveC and @throw exceptions.
[cycript.git] / ObjectiveC / Library.mm
index 268edcd87741811534fb09bd0cd7b9c304aa7dea..b6410c7471507cddbd3e158379ab6861bcac5ca2 100644 (file)
@@ -2988,3 +2988,25 @@ struct CYObjectiveC {
         _assert(hooks_ != NULL);
     }
 } CYObjectiveC;
+
+extern "C" void CydgetSetupContext(JSGlobalContextRef context) { CYObjectiveTry_ {
+    CYSetupContext(context);
+} CYObjectiveCatch }
+
+extern "C" void CydgetMemoryParse(const uint16_t **data, size_t *size) { try {
+    CYPool pool;
+
+    CYUTF8String utf8(CYPoolUTF8String(pool, CYUTF16String(*data, *size)));
+    utf8 = CYPoolCode(pool, utf8);
+
+    CYUTF16String utf16(CYPoolUTF16String(pool, CYUTF8String(utf8.data, utf8.size)));
+    size_t bytes(utf16.size * sizeof(uint16_t));
+    uint16_t *copy(reinterpret_cast<uint16_t *>(malloc(bytes)));
+    memcpy(copy, utf16.data, bytes);
+
+    *data = copy;
+    *size = utf16.size;
+} catch (const CYException &exception) {
+    CYPool pool;
+    @throw [NSException exceptionWithName:NSRangeException reason:[NSString stringWithFormat:@"%s", exception.PoolCString(pool)] userInfo:nil];
+} }