steven-michaud / HookCase

Tool for reverse engineering macOS/OS X

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LogWithFormat() displays some strings incorrectly

steven-michaud opened this issue · comments

LogWithFormat() in the hook library template can display strings incorrectly that contain characters with different encodings. Sometimes it fails to display any part of the string. This happens when the first "preferred language" in the Language & Region pref panel doesn't use the kCFStringEncodingMacRoman string encoding -- in other words, when that language doesn't use a Latin script. Examples are Russian, Greek and Chinese.

The cause is a bug or design flaw in the CFStringCreateWithFormatAndArguments() function used by LogWithFormatV(): Unlike similar functions (for example CFStringCreateWithCString() and CFStringGetBytes()), it doesn't allow you to specify a string encoding. Instead it always uses the string encoding associated with the "preferred language".

For languages that use Latin scripts, this is always kCFStringEncodingMacRoman. This encoding can handle strings that combine characters from many different encodings, and is in fact used by macOS itself at the most basic level (the LC_C_LOCALE). But the encodings associated with languages that use non-Latin scripts are specific to a particular language, and generally don't allow you to add characters to a string from any other encoding system.

I will work around this Apple bug by adding a hook to the HookCase interpose library template.

I just landed 0517b28 to fix this issue.