Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing contents of IL2CPP's string_t in xcode's debugger

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?

like image 684
tenpn Avatar asked Mar 20 '15 16:03

tenpn


2 Answers

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)
like image 85
Daniel Avatar answered Oct 05 '22 23:10

Daniel


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.

like image 25
tenpn Avatar answered Oct 05 '22 23:10

tenpn