Mach-O __DATA 段、__cfstring 部分中找到的字符串使用什么编码?

发布于 2024-10-05 11:36:43 字数 288 浏览 1 评论 0原文

我想知道如何从 Mach-O 二进制文件的特定部分正确读取字符串。 (这是 iOS 的二进制文件。)

我对 __DATA 段、__cfstring 部分中找到的字符串感到好奇。这些部分似乎包含简单结构的数组:

NSConstantString
{
    Class class;
    const char *string;
    int length;
}

问题归结为:如何决定字符串的编码?

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:

NSConstantString
{
    Class class;
    const char *string;
    int length;
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷又爱笑 2024-10-12 11:36:43

它在可用的 CFString 源代码中进行了描述在这里。它采用 ASCII 或 UTF16(以处理器字节顺序表示)。
另请参阅clang的源代码,可用这里。查找GenerateConstantString。常量字符串最终由这段代码生成,查找GetAddrOfConstantCFString。源代码说常量 CFString 的格式

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

(至少在 OS X 上,我不确定 iOS 上)。flags 告诉你它是 ASCII 还是 UTF16。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文