Take the 2-minute tour ×

I'm wondering how to properly read strings from a specific section of a Mach-O binary. (This is a binary for iOS.)

I'm curious about the strings found in the __DATA segment, __cfstring section. These sections appear to contain arrays of simple structures:

    Class class;
    const char *string;
    int length;

The question comes down to: how do you decide the encoding of the string?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It's described in the source of CFString available here. It's either in ASCII or UTF16 (in the processor endian-ness.) Also see the source code of clang, available here. Look for GenerateConstantString. Constant strings are eventually generated by this piece of code, look for GetAddrOfConstantCFString. The source code says that the constant CFString is of the format

  struct __builtin_CFString {
     const int *isa; // point to __CFConstantStringClassReference
     int flags;
     const char *str;
     long length;

(at least on OS X, I'm not sure about iOS.) flags tells you whether it's ASCII or UTF16.

share|improve this answer
Very useful answer. Thanks! –  Dave Peck Dec 2 '10 at 8:58
add comment

Your Answer


