X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/9fe34350f09babaa8b51243c74b57041255d2a99..bf76f58056b53ca590b619a7488a1648e554fcb4:/ObjectiveC/Library.mm diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 268edcd..b6410c7 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -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(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]; +} }