- (void) webView:(WebView *)sender didReceiveMessage:(NSDictionary *)dictionary {
#if LogBrowser || ForSaurik
- lprintf("Console:%s\n", [[dictionary description] UTF8String]);
+ NSLog(@"Console:%@\n", [dictionary description]);
#endif
if ([document_ respondsToSelector:@selector(webView:didReceiveMessage:)])
[document_ webView:sender didReceiveMessage:dictionary];
}
- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
- fprintf(stderr, "Console:%s\n", [[dictionary description] UTF8String]);
+ NSLog(@"Console:%@\n", [dictionary description]);
}
@end
#include <string>
+struct State {
+ unsigned state;
+};
+
+// State Machine {{{
static bool cycript_;
static bool jscript_;
-static void SetParser(bool cycript, bool jscript) {
- cycript_ = cycript;
- jscript_ = jscript;
+struct ParserSet {
+ bool backup_;
+
+ ParserSet() {
+ backup_ = jscript_;
+ jscript_ = true;
+ cycript_ = false;
+ }
+
+ ~ParserSet() {
+ jscript_ = backup_;
+ }
+};
+
+MSHook(State, _ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, void *_this, State state) {
+ ParserSet set;
+ return __ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE(_this, state);
}
-static bool GetParser0() {
- return cycript_;
+MSHook(void, _ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, void *_this, void *resource) {
+ ParserSet set;
+ return __ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE(_this, resource);
}
-static bool GetParser1() {
- return jscript_;
+MSHook(void, _ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv, void *_this) {
+ ParserSet set;
+ return __ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv(_this);
}
+MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
+ if (!jscript_ || mime != "text/cycript")
+ return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
+
+ static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL));
+ if (handle == NULL)
+ return false;
+
+ cycript_ = true;
+ return true;
+}
+// }}}
+// Script Compiler {{{
static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) {
if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
if (void (*CYParseUChar)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast<void (*)(apr_pool_t *, const uint16_t **, size_t *)>(dlsym(handle, "CydgetPoolParse")))
CYParseUChar(pool, &data, &size);
}
+static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned);
+static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned);
+
+static void Cycriptify(const WebCore::String &source, int *psize = NULL) {
+ const uint16_t *data(source.characters());
+ size_t length(source.length()), size(length);
+
+ apr_pool_t *pool;
+ apr_pool_create(&pool, NULL);
+
+ Cycriptify(pool, data, size);
+
+ WebCore::String &script(const_cast<WebCore::String &>(source));
+
+ _ZN7WebCore6String8truncateEj(&script, 0);
+ _ZN7WebCore6String6appendEPKtj(&script, data, size);
+
+ if (psize != NULL)
+ *psize = size;
+
+ apr_pool_destroy(pool);
+}
+// }}}
+
extern "C" void *_ZN3JSC7UString3Rep14nullBaseStringE __attribute__((__weak_import__));
extern "C" void *_ZN3JSC7UString3Rep7destroyEv __attribute__((__weak_import__));
extern "C" void *_ZN3JSC7UStringC1EPKti __attribute__((__weak_import__));
extern "C" void WTFReportAssertionFailure(const char *, int, const char *, const char *) __attribute__((__weak_import__));
extern "C" void *_ZN3WTF8fastFreeEPv __attribute__((__weak_import__));
-static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned);
-static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned);
-
bool CYWeakHell() {
return
&_ZN3JSC7UString3Rep14nullBaseStringE == NULL ||
}
MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) {
- if (!GetParser0())
+ if (!cycript_)
return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
else {
- SetParser(false, true);
+ cycript_ = false;
JSC::SourceCode *source(*_this);
const uint16_t *data(source->data());
}
MSHook(void, _ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, void *_this, int start, const UChar *code, unsigned length, int *source, int *line, JSC::UString *message) {
- if (!GetParser0())
+ if (!cycript_)
return __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, code, length, source, line, message);
else {
const uint16_t *data(code);
}
}
-MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) {
- if (!GetParser0())
- __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line);
- else {
- const uint16_t *data(source.characters());
- size_t size(source.length());
+static WebCore::String *string;
- apr_pool_t *pool;
- apr_pool_create(&pool, NULL);
+MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) {
+ if (cycript_)
+ Cycriptify(source);
+ return __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line);
+}
- Cycriptify(pool, data, size);
+/*void Log(const WebCore::String &string) {
+ size_t length(string.length());
+ UChar data[length + 1];
+ data[length] = 0;
+ memcpy(data, string.characters(), length * 2);
+ NSLog(@"wtf :%S:", data);
+}*/
- WebCore::String &script(const_cast<WebCore::String &>(source));
- _ZN7WebCore6String8truncateEj(&script, 0);
- _ZN7WebCore6String6appendEPKtj(&script, data, size);
+MSHook(const WebCore::String &, _ZN7WebCore12CachedScript6scriptEv, void *_this) {
+ const WebCore::String &script(__ZN7WebCore12CachedScript6scriptEv(_this));
- apr_pool_destroy(pool);
+ //NSLog(@"wtf evil %s %s -- %p %p", jscript_ ? "true" : "false", cycript_ ? "true" : "false", _this, &script);
+ //Log(script);
- __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line);
- }
+ string = const_cast<WebCore::String *>(&script);
+ return script;
}
-struct State {
- unsigned state;
-};
+MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, void *_this, void *source, State state) {
+ //NSLog(@"wtf tree %s %s %p", jscript_ ? "true" : "false", cycript_ ? "true" : "false", string);
-MSHook(State, _ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, State state) {
- SetParser(false, true);
- state = __ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE(state);
- SetParser(false, false);
- return state;
-}
+ if (cycript_ && string != NULL)
+ Cycriptify(*string, reinterpret_cast<int *>(source) + 3);
-MSHook(void, _ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, void *resource) {
- SetParser(false, true);
- __ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE(resource);
- SetParser(false, false);
-}
+ cycript_ = false;
+ string = NULL;
-MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
- if (!GetParser1() || mime != "text/cycript")
- return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
-
- static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL));
- if (handle == NULL)
- return false;
-
- SetParser(true, true);
- return true;
+ return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE(_this, source, state);
}
/* Cydget:// Protocol {{{ */
if (_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE != NULL)
MSHookFunction(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, MSHake(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE));
- struct nlist nl[7];
+ struct nlist nl[10];
memset(nl, 0, sizeof(nl));
+
nl[0].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE";
nl[1].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE";
- nl[2].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE";
- nl[3].n_un.n_name = (char *) "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi";
- nl[4].n_un.n_name = (char *) "__ZN7WebCore6String6appendEPKtj";
- nl[5].n_un.n_name = (char *) "__ZN7WebCore6String8truncateEj";
+ nl[2].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv";
+ nl[3].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE";
+
+ nl[4].n_un.n_name = (char *) "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi";
+ nl[5].n_un.n_name = (char *) "__ZN7WebCore12CachedScript6scriptEv";
+ nl[6].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE";
+
+ nl[7].n_un.n_name = (char *) "__ZN7WebCore6String6appendEPKtj";
+ nl[8].n_un.n_name = (char *) "__ZN7WebCore6String8truncateEj";
+
nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl);
- State (*_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)(State);
+ State (*_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)(void *, State);
nlset(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, nl, 0);
MSHookFunction(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE));
- void (*_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)(void *);
+ void (*_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)(void *, void *);
nlset(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, nl, 1);
- MSHookFunction(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, MSHake(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE));
+ if (_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE != NULL)
+ MSHookFunction(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, MSHake(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE));
+
+ void (*_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv)(void *);
+ nlset(_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv, nl, 2);
+ if (_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv != NULL)
+ MSHookFunction(_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv, MSHake(_ZN7WebCore13HTMLTokenizer29executeExternalScriptsIfReadyEv));
bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &);
- nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 2);
+ nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 3);
MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE));
if (iOS4) {
void (*_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)(void *, const WebCore::String &, const WebCore::KURL &, int);
- nlset(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, nl, 3);
+ nlset(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, nl, 4);
MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi));
+
+ const WebCore::String &(*_ZN7WebCore12CachedScript6scriptEv)(void *);
+ nlset(_ZN7WebCore12CachedScript6scriptEv, nl, 5);
+ MSHookFunction(_ZN7WebCore12CachedScript6scriptEv, MSHake(_ZN7WebCore12CachedScript6scriptEv));
+
+ State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)(void *, void *, State);
+ nlset(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, nl, 6);
+ MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE));
}
- nlset(_ZN7WebCore6String6appendEPKtj, nl, 4);
- nlset(_ZN7WebCore6String8truncateEj, nl, 5);
+ nlset(_ZN7WebCore6String6appendEPKtj, nl, 7);
+ nlset(_ZN7WebCore6String8truncateEj, nl, 8);
}
+ (id) rootViewController {