+/* Cycript - Remove Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#include <substrate.h>
#include "cycript.hpp"
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
/* Objective-C Strings {{{ */
JSStringRef CYCopyJSString_(NSString *value) {
#ifdef __APPLE__
- return JSStringCreateWithCFString(reinterpret_cast<CFStringRef>(string));
+ return JSStringCreateWithCFString(reinterpret_cast<CFStringRef>(value));
#else
return CYCopyJSString([value UTF8String]);
#endif
static JSObjectRef CYMakeType(JSContextRef context, const char *type) {
Type_privateData *internal(new Type_privateData(NULL, type));
- return JSObjectMake(context, Type_, internal);
+ return JSObjectMake(context, Type_privateData::Class, internal);
}
static JSObjectRef CYMakeType(JSContextRef context, sig::Type *type) {
Type_privateData *internal(new Type_privateData(type));
- return JSObjectMake(context, Type_, internal);
+ return JSObjectMake(context, Type_privateData::Class, internal);
}
static JSValueRef Runtime_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
definition.callAsFunction = &Type_callAsFunction;
definition.callAsConstructor = &Type_callAsConstructor;
definition.finalize = &Finalize;
- Type_privateData::Class = JSClassCreate(&definition);
+ // XXX: dude: just rename the damned variable
+ (Type_privateData::Class) = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
definition.className = "Runtime";
CYSetProperty(context, global, CYJSString("Instance"), Instance);
CYSetProperty(context, global, CYJSString("Pointer"), JSObjectMakeConstructor(context, Pointer_, &Pointer_new));
CYSetProperty(context, global, CYJSString("Selector"), Selector);
- CYSetProperty(context, global, CYJSString("Type"), JSObjectMakeConstructor(context, Type_, &Type_new));
+ CYSetProperty(context, global, CYJSString("Type"), JSObjectMakeConstructor(context, Type_privateData::Class, &Type_new));
MSHookFunction(&objc_registerClassPair, MSHake(objc_registerClassPair));
#include "cycript.hpp"
+/* Cycript - Remove Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#include <sys/types.h>
#include <sys/socket.h>
+/* Cycript - Remote Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#ifndef CYCRIPT_OBJECTIVEC_HPP
#define CYCRIPT_OBJECTIVEC_HPP
bool instance_;
CYExpression *type_;
CYMessageParameter *parameters_;
- CYStatement *statements_;
+ CYBlock code_;
CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
instance_(instance),
type_(type),
parameters_(parameter),
- statements_(statements)
+ code_(statements)
{
}
}
void CYField::Output(CYOutput &out) const {
- // XXX: implement!
}
void CYMessage::Output(CYOutput &out, bool replace) const {
- if (next_ != NULL)
- next_->Output(out, replace);
- out << "$cyn=new Selector(\"";
+ out << (instance_ ? '-' : '+');
+
for (CYMessageParameter *parameter(parameters_); parameter != NULL; parameter = parameter->next_)
if (parameter->tag_ != NULL) {
- out << *parameter->tag_;
+ out << ' ' << *parameter->tag_;
if (parameter->name_ != NULL)
- out << ':';
+ out << ':' << *parameter->name_;
}
- out << "\");";
- out << "$cyt=$cyn.type($cy" << (instance_ ? 's' : 'p') << ')' << ';';
- out << (replace ? "class_replaceMethod" : "class_addMethod") << '(' << (instance_ ? "$cyc" : "$cym") << ',' << "$cyn" << ',';
- out << "new Functor(function(self,_cmd";
- for (CYMessageParameter *parameter(parameters_); parameter != NULL; parameter = parameter->next_)
- if (parameter->name_ != NULL)
- out << ',' << *parameter->name_;
- out << "){return function(){";
- if (statements_ != NULL)
- statements_->Multiple(out);
- out << "}.call(self);},$cyt),$cyt);";
+
+ out << code_;
}
void CYSelector::Output(CYOutput &out, CYFlags flags) const {
void CYSend::Output(CYOutput &out, CYFlags flags) const {
out << '[';
+
self_->Output(out, CYPA, CYNoFlags);
- out << ']';
- std::ostringstream name;
for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
if (argument->name_ != NULL) {
- name << *argument->name_;
+ out << ' ' << *argument->name_;
if (argument->value_ != NULL)
- name << ':';
+ out << ':' << *argument->value_;
}
- out.out_ << reinterpret_cast<void *>(sel_registerName(name.str().c_str()));
- for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
- if (argument->value_ != NULL) {
- out << ',';
- argument->value_->Output(out, CYPA, CYNoFlags);
- }
- out << ')';
+ out << ']';
}
CYStatement *CYCategory::Replace(CYContext &context) {
$V(instance_ ? "$cyc" : "$cym"),
cyn,
$N2($V("Functor"), $F(NULL, $P2("self", "_cmd", parameters_->Parameters(context)), $$->*
- $ CYReturn($C1($M($F(NULL, NULL, statements_), $S("call")), $V("self")))
+ $ CYReturn($C1($M($F(NULL, NULL, code_), $S("call")), $V("self")))
), cyt),
cyt
))
+/* Cycript - Remove Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#include "Parser.hpp"
#include <iomanip>
}
void CYArrayComprehension::Output(CYOutput &out, CYFlags flags) const {
- // XXX: I don't necc. need the ()s
- out << "(function($cyv";
- for (CYComprehension *comprehension(comprehensions_); comprehension != NULL; comprehension = comprehension->next_)
- if (const char *name = comprehension->Name())
- out << ',' << name;
- out << "){";
- out << "$cyv=[];";
- comprehensions_->Output(out);
- out << "$cyv.push(";
- expression_->Output(out, CYPA, CYNoFlags);
- out << ");";
- for (CYComprehension *comprehension(comprehensions_); comprehension != NULL; comprehension = comprehension->next_)
- comprehension->End_(out);
- out << "return $cyv;";
- out << "}())";
+ out << '[' << *expression_ << ' ' << *comprehensions_ << ']';
}
void CYAssignment::Output(CYOutput &out, CYFlags flags) const {
expression->Output(out, flags);
}
-void CYComprehension::Output(CYOutput &out) const {
- Begin_(out);
- out << next_;
-}
-
void CYCondition::Output(CYOutput &out, CYFlags flags) const {
test_->Output(out, Precedence() - 1, CYLeft(flags));
out << ' ' << '?' << ' ';
Output(out, CYRight(flags));
}
-void CYDeclaration::ForEachIn(CYOutput &out) const {
- out << *identifier_;
-}
-
void CYDeclaration::Output(CYOutput &out, CYFlags flags) const {
out << *identifier_;
if (initialiser_ != NULL) {
Output(out, CYNoIn);
}
-void CYExpression::ForEachIn(CYOutput &out) const {
- Output(out, CYPA, CYNoRightHand);
-}
-
void CYExpression::ForIn(CYOutput &out, CYFlags flags) const {
Output(out, flags | CYNoRightHand);
}
}
void CYForEachIn::Output(CYOutput &out, CYFlags flags) const {
- out << "with({$cys:0,$cyt:0}){";
-
- out << "$cys=";
- set_->Output(out, CYPA, CYNoFlags);
- out << ';';
-
- out << "for($cyt in $cys){";
-
- initialiser_->ForEachIn(out);
- out << "=$cys[$cyt];";
-
- code_->Multiple(out);
-
- out << '}';
-
- out << '}';
-}
-
-void CYForEachInComprehension::Begin_(CYOutput &out) const {
- out << "(function($cys){";
- out << "$cys=";
- set_->Output(out, CYPA, CYNoFlags);
- out << ';';
-
- out << "for(" << *name_ << " in $cys){";
- out << *name_ << "=$cys[" << *name_ << "];";
+ out << "for" << ' ' << "each" << ' ' << '(';
+ initialiser_->ForIn(out, CYNoIn);
+ out << "in" << *set_ << ')';
+ code_->Single(out, CYRight(flags));
}
-void CYForEachInComprehension::End_(CYOutput &out) const {
- out << "}}());";
+void CYForEachInComprehension::Output(CYOutput &out) const {
+ out << "for" << ' ' << "each" << ' ' << '(' << *name_ << ' ' << "in" << ' ' << *set_ << ')' << next_;
}
void CYForIn::Output(CYOutput &out, CYFlags flags) const {
code_->Single(out, CYRight(flags));
}
-void CYForInComprehension::Begin_(CYOutput &out) const {
- out << "for" << ' ' << '(' << *name_ << "in" << *set_ << ')';
+void CYForInComprehension::Output(CYOutput &out) const {
+ out << "for" << ' ' << '(' << *name_ << ' ' << "in" << ' ' << *set_ << ')';
}
void CYFunction::Output(CYOutput &out, CYFlags flags) const {
out << '}';
}
-void CYIfComprehension::Begin_(CYOutput &out) const {
- out << "if" << '(' << *test_ << ')';
+void CYIfComprehension::Output(CYOutput &out) const {
+ out << "if" << ' ' << '(' << *test_ << ')' << next_;
}
void CYIndirectMember::Output(CYOutput &out, CYFlags flags) const {
void CYNumber::Output(CYOutput &out, CYFlags flags) const {
char value[32];
+ // XXX: I want this to print 1e3 rather than 1000
sprintf(value, "%.17g", Value());
out << value;
}
+/* Cycript - Remove Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#include "Parser.hpp"
#include "Cycript.tab.hh"
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
{
}
+ operator CYStatement *() const {
+ return statements_;
+ }
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
struct CYForInInitialiser {
virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
virtual const char *ForEachIn() const = 0;
- virtual void ForEachIn(CYOutput &out) const = 0;
virtual CYExpression *ForEachIn(CYContext &out) = 0;
};
+struct CYNumber;
+struct CYString;
+
struct CYExpression :
CYNext<CYExpression>,
CYForInitialiser,
virtual void ForIn(CYOutput &out, CYFlags flags) const;
virtual const char *ForEachIn() const;
- virtual void ForEachIn(CYOutput &out) const;
virtual CYExpression *ForEachIn(CYContext &out);
virtual void Output(CYOutput &out) const;
virtual CYExpression *Replace(CYContext &context) = 0;
+ virtual CYExpression *Primitive(CYContext &context) {
+ return this;
+ }
+
+ virtual CYNumber *Number(CYContext &context) {
+ return NULL;
+ }
+
+ virtual CYString *String(CYContext &context) {
+ return NULL;
+ }
+
virtual const char *Word() const {
return NULL;
}
CYNext<CYComprehension>,
CYThing
{
- void Output(CYOutput &out) const;
virtual const char *Name() const = 0;
- virtual void Begin_(CYOutput &out) const = 0;
-
- virtual void End_(CYOutput &out) const {
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
CYFunctionParameter *Parameters(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
+ virtual void Output(CYOutput &out) const = 0;
};
struct CYForInComprehension :
return name_->Value();
}
- virtual void Begin_(CYOutput &out) const;
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
+ virtual void Output(CYOutput &out) const;
};
struct CYForEachInComprehension :
return name_->Value();
}
- virtual void Begin_(CYOutput &out) const;
- virtual void End_(CYOutput &out) const;
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
+ virtual void Output(CYOutput &out) const;
};
struct CYIfComprehension :
return NULL;
}
- virtual void Begin_(CYOutput &out) const;
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
+ virtual void Output(CYOutput &out) const;
};
struct CYArrayComprehension :
virtual const char *Word() const;
+ virtual CYNumber *Number(CYContext &context);
+ virtual CYString *String(CYContext &context);
+
+ virtual CYString *Concat(CYContext &out, CYString *rhs) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
virtual void PropertyName(CYOutput &out) const;
};
return value_;
}
+ virtual CYNumber *Number(CYContext &context);
+ virtual CYString *String(CYContext &context);
+
virtual void Output(CYOutput &out, CYFlags flags) const;
virtual void PropertyName(CYOutput &out) const;
};
{
}
+ virtual CYNumber *Number(CYContext &context);
+ virtual CYString *String(CYContext &context);
+
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual bool Value() const {
return false;
}
+
+ virtual CYNumber *Number(CYContext &context);
+ virtual CYString *String(CYContext &context);
};
struct CYTrue :
virtual bool Value() const {
return true;
}
+
+ virtual CYNumber *Number(CYContext &context);
+ virtual CYString *String(CYContext &context);
};
struct CYVariable :
virtual void ForIn(CYOutput &out, CYFlags flags) const;
virtual const char *ForEachIn() const;
- virtual void ForEachIn(CYOutput &out) const;
virtual CYExpression *ForEachIn(CYContext &out);
void Replace(CYContext &context);
virtual CYExpression *Replace(CYContext &context);
};
-#define CYPostfix_(op, name) \
+#define CYReplace \
+ virtual CYExpression *Replace(CYContext &context);
+
+#define CYPostfix_(op, name, args...) \
struct CY ## name : \
CYPostfix \
- { \
+ { args \
CY ## name(CYExpression *lhs) : \
CYPostfix(lhs) \
{ \
} \
};
-#define CYPrefix_(alphabetic, op, name) \
+#define CYPrefix_(alphabetic, op, name, args...) \
struct CY ## name : \
CYPrefix \
- { \
+ { args \
CY ## name(CYExpression *rhs) : \
CYPrefix(rhs) \
{ \
} \
};
-#define CYInfix_(alphabetic, precedence, op, name) \
+#define CYInfix_(alphabetic, precedence, op, name, args...) \
struct CY ## name : \
CYInfix \
- { \
+ { args \
CY ## name(CYExpression *lhs, CYExpression *rhs) : \
CYInfix(lhs, rhs) \
{ \
} \
};
-#define CYAssignment_(op, name) \
+#define CYAssignment_(op, name, args...) \
struct CY ## name ## Assign : \
CYAssignment \
- { \
+ { args \
CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
CYAssignment(lhs, rhs) \
{ \
CYInfix_(false, 5, "*", Multiply)
CYInfix_(false, 5, "/", Divide)
CYInfix_(false, 5, "%", Modulus)
-CYInfix_(false, 6, "+", Add)
+CYInfix_(false, 6, "+", Add, CYReplace)
CYInfix_(false, 6, "-", Subtract)
CYInfix_(false, 7, "<<", ShiftLeft)
CYInfix_(false, 7, ">>", ShiftRightSigned)
+/* Cycript - Remote Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#ifndef CYPOOLING_HPP
#define CYPOOLING_HPP
+/* Cycript - Remove Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#include "Parser.hpp"
#include <iomanip>
#include "Replace.hpp"
+CYExpression *CYAdd::Replace(CYContext &context) {
+ CYInfix::Replace(context);
+
+ CYExpression *lhp(lhs_->Primitive(context));
+ CYExpression *rhp(rhs_->Primitive(context));
+
+ CYString *lhs(dynamic_cast<CYString *>(lhp));
+ CYString *rhs(dynamic_cast<CYString *>(rhp));
+
+ if (lhs != NULL || rhs != NULL) {
+ if (lhs == NULL) {
+ lhs = lhp->String(context);
+ if (lhs == NULL)
+ return NULL;
+ } else if (rhs == NULL) {
+ rhs = rhp->String(context);
+ if (rhs == NULL)
+ return NULL;
+ }
+
+ return lhs->Concat(context, rhs);
+ }
+
+ if (CYNumber *lhn = lhp->Number(context))
+ if (CYNumber *rhn = rhp->Number(context))
+ return $D(lhn->Value() + rhn->Value());
+
+ return NULL;
+}
+
CYExpression *CYAddressOf::Replace(CYContext &context) {
CYPrefix::Replace(context);
return $C0($M(rhs_, $S("$cya")));
return replace;
}
+CYNumber *CYFalse::Number(CYContext &context) {
+ return $D(0);
+}
+
+CYString *CYFalse::String(CYContext &context) {
+ return $S("false");
+}
+
void CYFinally::Replace(CYContext &context) { $T()
code_.Replace(context);
}
return NULL;
}
+CYNumber *CYNull::Number(CYContext &context) {
+ return $D(0);
+}
+
+CYString *CYNull::String(CYContext &context) {
+ return $S("null");
+}
+
+CYNumber *CYNumber::Number(CYContext &context) {
+ return this;
+}
+
+CYString *CYNumber::String(CYContext &context) {
+ // XXX: there is a precise algorithm for this
+ return $S(apr_psprintf(context.pool_, "%.17g", Value()));
+}
+
CYExpression *CYObject::Replace(CYContext &context) {
properties_->Replace(context);
return NULL;
return replace;
}
+CYString *CYString::Concat(CYContext &context, CYString *rhs) const {
+ size_t size(size_ + rhs->size_);
+ char *value(new(context.pool_) char[size + 1]);
+ memcpy(value, value_, size_);
+ memcpy(value + size_, rhs->value_, rhs->size_);
+ value[size] = '\0';
+ return $S(value);
+}
+
+CYNumber *CYString::Number(CYContext &context) {
+ // XXX: there is a precise algorithm for this
+ return NULL;
+}
+
+CYString *CYString::String(CYContext &context) {
+ return this;
+}
+
CYStatement *CYSwitch::Replace(CYContext &context) {
context.Replace(value_);
clauses_->Replace(context);
return NULL;
}
+CYNumber *CYTrue::Number(CYContext &context) {
+ return $D(1);
+}
+
+CYString *CYTrue::String(CYContext &context) {
+ return $S("true");
+}
+
CYStatement *CYTry::Replace(CYContext &context) {
code_.Replace(context);
catch_->Replace(context);
+/* Cycript - Remote Execution Server and Disassembler
+ * Copyright (C) 2009 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
#ifndef REPLACE_HPP
#define REPLACE_HPP
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Remote Execution Server and Disassembler
* Copyright (C) 2009 Jay Freeman (saurik)
*/