From d3865d294299f1d5404b59f4482ebb116c8fcee0 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 20 Dec 2015 03:57:15 -0800 Subject: [PATCH] Use dladdr to improve toCYON of pointers/functors. --- Execute.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index 1cb8373..3d9d6c4 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1548,9 +1548,20 @@ static JSValueRef CYValue_callAsFunction_toJSON(JSContextRef context, JSObjectRe static JSValueRef CYValue_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { CYValue *internal(reinterpret_cast(JSObjectGetPrivate(_this))); - char string[32]; - sprintf(string, "%p", internal->value_); - return CYCastJSValue(context, string); + std::ostringstream str; + Dl_info info; + if (internal->value_ == NULL) + str << "NULL"; + else if (dladdr(internal->value_, &info) == 0) + str << internal->value_; + else { + str << info.dli_sname; + off_t offset(static_cast(internal->value_) - static_cast(info.dli_saddr)); + if (offset != 0) + str << "+0x" << std::hex << offset; + } + std::string value(str.str()); + return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size()))); } CYCatch(NULL) } static JSValueRef Pointer_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { -- 2.45.2