Unity's IL2CPP/LLVM back-end generates cpp files from C#. You can certainly read these files, and drop breakpoints into them to view variables. However C# strings are transcompiled into a custom class called String_t. Xcode doesn't seem to know how to print the inner strings of these classes and I'm not sure how to read the raw bytes.
Here's the String_t definition:
struct String_t : public Object_t
{
// System.Int32 System.String::length
int32_t ___length;
// System.Char System.String::start_char
uint16_t ___start_char;
};
...can anyone figure out how to read the contained string from an Xcode breakpoint?
You can use p il2cpp::utils::StringUtils::Utf16ToUtf8
. So if the name of the variable is L_3
for example, then you can do this:
p il2cpp::utils::StringUtils::Utf16ToUtf8(&L_3->___start_char_1)
You can see the string in memory if you right-click the string in the locals window and select View Memory of "*foo"
. Then the string starts 12 bytes in. Because of IL2CPP's 16bit characters, the string is printed with dots inbetween. This probably doesn't work for unicode characters!
If anyone has a more robust solution I'd love to accept their answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With