From 579ed52671d7f57366fd37cc90a76668d4b4d70c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 9 Oct 2009 18:35:06 +0000 Subject: [PATCH] Remove system.global temporarily, added libffi Depends:, and setup REPL with _ variable for result. --- Application.mm | 12 +++++++++--- Library.mm | 10 +++++++--- Output.cpp | 3 ++- control | 4 ++-- cycript.hpp | 3 +++ todo.txt | 1 + 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Application.mm b/Application.mm index 31b7a45..4982830 100644 --- a/Application.mm +++ b/Application.mm @@ -24,10 +24,12 @@ static jmp_buf ctrlc_; -void sigint(int) { +static void sigint(int) { longjmp(ctrlc_, 1); } +static JSStringRef Result_; + void Run(const char *code, FILE *fout) { _pooled JSStringRef script(JSStringCreateWithUTF8CString(code)); @@ -50,6 +52,8 @@ void Run(const char *code, FILE *fout) { _pooled if (exception != NULL) goto error; + CYSetProperty(context, CYGetGlobalObject(context), Result_, result); + if (fout != NULL) { fputs(json, fout); fputs("\n", fout); @@ -58,7 +62,7 @@ void Run(const char *code, FILE *fout) { _pooled } } -void Console() { +static void Console() { bool bypass(false); bool debug(false); @@ -160,7 +164,7 @@ void Console() { fflush(fout); } -void *Map(const char *path, size_t *psize) { +static void *Map(const char *path, size_t *psize) { int fd; _syscall(fd = open(path, O_RDONLY)); @@ -187,6 +191,8 @@ int main(int argc, const char *argv[]) { script = argv[1]; } + Result_ = CYCopyJSString("_"); + if (script == NULL || strcmp(script, "-") == 0) Console(); else { diff --git a/Library.mm b/Library.mm index 5f22d29..ef85e4c 100644 --- a/Library.mm +++ b/Library.mm @@ -1725,6 +1725,10 @@ void CYSetArgs(int argc, const char *argv[]) { CYSetProperty(context, System_, CYJSString("args"), array); } +JSObjectRef CYGetGlobalObject(JSContextRef context) { + return JSContextGetGlobalObject(context); +} + MSInitialize { _pooled apr_initialize(); @@ -1807,10 +1811,10 @@ MSInitialize { _pooled JSGlobalContextRef context(JSGlobalContextCreate(Global)); Context_ = context; - JSObjectRef global(JSContextGetGlobalObject(context)); + JSObjectRef global(CYGetGlobalObject(context)); JSObjectSetPrototype(context, global, JSObjectMake(context, Runtime_, NULL)); - CYSetProperty(context, global, CYJSString("obc"), JSObjectMake(context, Runtime_, NULL)); + CYSetProperty(context, global, CYJSString("ObjectiveC"), JSObjectMake(context, Runtime_, NULL)); CYSetProperty(context, global, CYJSString("Selector"), JSObjectMakeConstructor(context, Selector_, &Selector_new)); CYSetProperty(context, global, CYJSString("Functor"), JSObjectMakeConstructor(context, Functor_, &Functor_new)); @@ -1821,7 +1825,7 @@ MSInitialize { _pooled System_ = JSObjectMake(context, NULL, NULL); CYSetProperty(context, global, CYJSString("system"), System_); CYSetProperty(context, System_, CYJSString("args"), CYJSNull(context)); - CYSetProperty(context, System_, CYJSString("global"), global); + //CYSetProperty(context, System_, CYJSString("global"), global); CYSetProperty(context, System_, CYJSString("print"), JSObjectMakeFunctionWithCallback(context, CYJSString("print"), &System_print)); diff --git a/Output.cpp b/Output.cpp index 7eee678..0728e82 100644 --- a/Output.cpp +++ b/Output.cpp @@ -428,7 +428,8 @@ void CYPrefix::Output(std::ostream &out, CYFlags flags) const { } void CYProperty::Output(std::ostream &out) const { - out << *name_ << ':'; + out << *name_; + out << ':'; value_->Output(out, CYPA, CYNoFlags); if (next_ != NULL) { out << ','; diff --git a/control b/control index 9d3aba3..95f40bd 100644 --- a/control +++ b/control @@ -3,10 +3,10 @@ Priority: optional Section: Development Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.3-1 +Version: 0.9.65-1 Description: runtime execution server and disassembler Name: Cycript -Depends: mobilesubstrate (>= 0.9.3005-1), readline +Depends: mobilesubstrate (>= 0.9.3005-1), readline, libffi Author: Jay Freeman (saurik) Depiction: http://cydia.saurik.com/info/cycript/ Tag: purpose::daemon, role::developer diff --git a/cycript.hpp b/cycript.hpp index b73d5c6..3f95725 100644 --- a/cycript.hpp +++ b/cycript.hpp @@ -13,5 +13,8 @@ JSGlobalContextRef CYGetJSContext(); const char *CYPoolJSONString(apr_pool_t *pool, JSContextRef context, JSValueRef value, JSValueRef *exception); void CYSetArgs(int argc, const char *argv[]); +void CYSetProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef value); +JSObjectRef CYGetGlobalObject(JSContextRef context); +JSStringRef CYCopyJSString(const char *value); #endif/*CYCRIPT_HPP*/ diff --git a/todo.txt b/todo.txt index d79c305..53ef7bf 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,5 @@ labelled statements don't get labelled blocks and empty statements are poorly factored +property labels should get minimized functors use both ffiData and ffoData... rename "data" variables to "internal" -- 2.45.2