+/* 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.
+*/
+/* }}} */
+
#include "Replace.hpp"
#include "ObjectiveC.hpp"
#include <objc/runtime.h>
#include <sstream>
+/* Objective-C Output {{{ */
void CYCategory::Output(CYOutput &out, CYFlags flags) const {
out << "(function($cys,$cyp,$cyc,$cyn,$cyt){";
out << "$cyp=object_getClass($cys);";
}
void CYSend::Output(CYOutput &out, CYFlags flags) const {
- out << '[';
-
- self_->Output(out, CYPA, CYNoFlags);
-
for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
if (argument->name_ != NULL) {
out << ' ' << *argument->name_;
if (argument->value_ != NULL)
out << ':' << *argument->value_;
}
+}
+void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
+ out << '[';
+ self_->Output(out, CYPA, CYNoFlags);
+ CYSend::Output(out, flags);
out << ']';
}
+void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
+ out << '[' << "super";
+ CYSend::Output(out, flags);
+ out << ']';
+}
+/* }}} */
+/* Objective-C Replace {{{ */
CYStatement *CYCategory::Replace(CYContext &context) {
CYVariable *cyc($V("$cyc")), *cys($V("$cys"));
CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NULL)
CYVariable *cyn($V("$cyn"));
CYVariable *cyt($V("$cyt"));
+ CYVariable *self($V("self"));
+ CYVariable *_class($V(instance_ ? "$cys" : "$cyp"));
return $ CYBlock($$->*
next_->Replace(context, replace)->*
$E($ CYAssign(cyn, parameters_->Selector(context)))->*
- $E($ CYAssign(cyt, $C1($M(cyn, $S("type")), $V(instance_ ? "$cys" : "$cyp"))))->*
+ $E($ CYAssign(cyt, $C1($M(cyn, $S("type")), _class)))->*
$E($C4($V(replace ? "class_replaceMethod" : "class_addMethod"),
$V(instance_ ? "$cyc" : "$cym"),
cyn,
$N2($V("Functor"), $F(NULL, $P2("self", "_cmd", parameters_->Parameters(context)), $$->*
- $ CYReturn($C1($M($F(NULL, NULL, code_), $S("call")), $V("self")))
+ $ CYVar($ CYDeclarations($ CYDeclaration($I("$cyr"), $N2($V("Super"), self, _class))))->*
+ $ CYReturn($C1($M($F(NULL, NULL, code_), $S("call")), self))
), cyt),
cyt
))
return $S(apr_pstrdup(context.pool_, str.str().c_str()));
}
-CYExpression *CYSend::Replace(CYContext &context) {
+CYExpression *CYSendDirect::Replace(CYContext &context) {
std::ostringstream name;
CYArgument **argument(&arguments_);
return $C2($V("objc_msgSend"), self_, $D(address), arguments_);
}
+
+CYExpression *CYSendSuper::Replace(CYContext &context) {
+ return $ CYSendDirect($V("$cyr"), arguments_);
+}
+/* }}} */