From: Jay Freeman (saurik) Date: Thu, 7 Jan 2016 09:42:12 +0000 (-0800) Subject: Avoid naming functors without symbols as just "1". X-Git-Tag: v0.9.590~41 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/17764b01280ac7cd2e14c82581fd8d185a437fef?ds=inline Avoid naming functors without symbols as just "1". --- diff --git a/Execute.cpp b/Execute.cpp index 229e238..e4ed3d8 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1761,29 +1761,28 @@ static JSValueRef Functor_callAsFunction_valueOf(JSContextRef context, JSObjectR static JSValueRef Functor_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { cy::Functor *internal(reinterpret_cast(JSObjectGetPrivate(_this))); uint8_t *value(reinterpret_cast(internal->value_)); + _assert(value != NULL); CYLocalPool pool; sig::Function function(internal->variadic_); sig::Copy(pool, function.signature, internal->signature_); - CYString *name; + CYPropertyName *name; auto typed(CYDecodeType(pool, &function)); { std::ostringstream str; Dl_info info; - if (internal->value_ == NULL) - str << "NULL"; - else if (dladdr(value, &info) == 0) - str << internal->value_; - else { + if (dladdr(value, &info) == 0) { + str << (void *) value; + name = new(pool) CYNumber(reinterpret_cast(value)); + } else { str << info.dli_sname; off_t offset(value - reinterpret_cast(info.dli_saddr)); if (offset != 0) str << "+0x" << std::hex << offset; + name = new(pool) CYString(pool.strdup(str.str().c_str())); } - - name = new(pool) CYString(pool.strdup(str.str().c_str())); } std::ostringstream str; diff --git a/Parser.ypp.in b/Parser.ypp.in index 9db7666..0d8e87d 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -2031,6 +2031,7 @@ ExportSpecifier TypeSignifier : IdentifierType[name] { $$ = CYNew CYTypedName(@name, $name); } | StringLiteral[name] { $$ = CYNew CYTypedName(@name, $name); } + | NumericLiteral[name] { $$ = CYNew CYTypedName(@name, $name); } | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } ; diff --git a/Replace.cpp b/Replace.cpp index 46dd8bb..c268182 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -394,7 +394,10 @@ CYStatement *CYExternalDefinition::Replace(CYContext &context) { } CYTarget *CYExternalExpression::Replace(CYContext &context) { - return $C1(type_->Replace(context), $C2($V("dlsym"), $V("RTLD_DEFAULT"), name_->PropertyName(context))); + CYExpression *expression(name_->Number(context)); + if (expression == NULL) + expression = $C2($V("dlsym"), $V("RTLD_DEFAULT"), name_->PropertyName(context)); + return $C1(type_->Replace(context), expression); } CYNumber *CYFalse::Number(CYContext &context) { diff --git a/Syntax.hpp b/Syntax.hpp index 5f9d705..ea55a3f 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -121,6 +121,7 @@ struct CYOutput { struct CYExpression; struct CYAssignment; struct CYIdentifier; +struct CYNumber; struct CYPropertyName { virtual bool Computed() const { @@ -135,6 +136,10 @@ struct CYPropertyName { return NULL; } + virtual CYNumber *Number(CYContext &context) { + return NULL; + } + virtual CYExpression *PropertyName(CYContext &context) = 0; virtual void PropertyName(CYOutput &out) const = 0; };