0

I have arg1 which is an IMessage. IMessage is defined as:

struct IMessage {
    ...
    struct CFString _field2;
    ...
};

and CFString is defined as:

    struct CFString {
    void **_vptr$CFObject;
    struct __CFString *mCFRef;
    _Bool mIsMutable;
};

and __CFString is defined as:

struct __CFString;

My goal is to get a string of some sort be it NSString or CFStringRef from arg1, so how can i do it? Thanks.

Here is the error I get when I try to nslog mCFRef:

Thread 0 crashed:

#  1  0x97b41edb in _objc_msgSend + 0x0000001B (libobjc.A.dylib + 0x00005edb)
#  2  0x9610b5f2 in __CFStringAppendFormatAndArgumentsAux + 0x00000C42 (CoreFoundation + 0x0002c5f2)
#  3  0x9610a979 in __CFStringCreateWithFormatAndArgumentsAux + 0x00000069 (CoreFoundation + 0x0002b979)
#  4  0x961b3a3e in __CFLogvEx + 0x0000008E (CoreFoundation + 0x000d4a3e)
#  5  0x9415387c in _NSLogv + 0x0000008F (Foundation + 0x0009487c)
#  6  0x941537eb in _NSLog + 0x0000001B (Foundation + 0x000947eb)
user635064
  • 6,219
  • 12
  • 54
  • 100
  • 1
    You should change the declaration of `mCFRef` in that structure. It should be `CFStringRef mCFRef;`. The `CFStringRef` type, like all the other `BlahBlahRef` types, exists to emphasize that the pointer is meant to be opaque, not a pointer to a structure that is open to you. – Peter Hosey Mar 23 '11 at 11:28
  • I did that and still get the EXC BAD ACCESS error, please check the original question for the error. thanks! – user635064 Mar 23 '11 at 17:00
  • Perhaps the underlying CFStringRef is the void pointer? I tried dereferencing the void point and casting it to CFStringRef but still no luck... – user635064 Mar 23 '11 at 17:17
  • 1
    @user635064: What I said in my comment on Chuck's answer stands unchanged; what you're describing is the symptom of trying to use something as a pointer to a CF object that isn't a pointer to a CF object. Either it never was, or it was but all its owners released it. You need to continue debugging from there. – Peter Hosey Mar 23 '11 at 21:45
  • 1
    @user635064: As for whether `vptr` or `mCFRef` is the string: Well, `vptr` looks like a pointer to some pointers, whereas `mCFRef` bears the (internal definition of the) type of a CFString pointer. See my first comment on this question. Whether the third-party library that's sending you this `IMessage` structure is putting the CFString in the wrong place or hasn't given it to you yet or whatever is the problem, that is an issue with the third-party library, not with Core Foundation. You should ask the library's developer what's up. – Peter Hosey Mar 23 '11 at 21:48

1 Answers1

1

I don't know where you're getting this from, but CFStringRef is defined as struct __CFString *const, so you already have something that looks equivalent.

Chuck
  • 234,037
  • 30
  • 302
  • 389
  • Thanks for the answer. So if i want to get CFSstringRef from arg1, would I do: CFStringRef s = (arg1->_field2).mCFRef; this results in the program crashing. – user635064 Mar 22 '11 at 20:28
  • 2
    @user635064: Yes, though that has nothing to do with CF; it's a problem in your program and/or whatever other library you're using. Either `arg1` is not a pointer to anything, or it is a pointer to not enough storage, or `mCFRef` has not been filled in with a pointer to a CFString object, or something did set `mCFRef` to a pointer to a CFString object but that object has been released by everything that owned it (and possibly one more—an over-release). If it's the last one, Instruments's Zombies template will help. – Peter Hosey Mar 23 '11 at 11:20
  • hey, thats for the input. This is what i get in console when I try to nslog it, maybe you can guess what going on? I put it in my original question with formatting (much easier to read). thanks – user635064 Mar 23 '11 at 16:51