Help! Crash MonoString

gmaiphio

Rookie
Can anyone help? This code works for me on the Android x86_64 emulator. But as soon as I run it on arm64 android, it crashes when I try to call CreateString . Apk is installed identically only with arm64-v8a libraries. That is, the offsets are correct. The project is compiled from LGL


C++:
typedef struct _myMonoString
{
    void* klass;
    void* monitor;
    int length;
    char16_t chars[1];

    int getLength()
    {
        return length;
    }

    char16_t* getRawChars()
    {
        return chars;
    }

    std::string getString()
    {
        std::u16string u16(chars, length);
        std::string u8_conv = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(u16);
        return u8_conv;
    }

    const char* getChars()
    {
        return getString().c_str();
    }
} myMonoString;


myMonoString *CreateString(const char *str)
{
    myMonoString *(*CreateString)(void *instance, const char *str, int start, int length) = (monoString * (*)(void *, const char *, int, int)) getAbsoluteAddress("libil2cpp.so", 0x2b77650); 
    int length = (int)strlen(str);
    return CreateString(NULL, str, 0, length);
}
 
sorry, i solved this problem. Maybe i used getAbsoluteAddress("libil2cpp.so", 0x2b77650) incorrectly and it calculated the address incorrectly. I finally calculated it another way:

C++:
uintptr_t il2cppBase = 0;
il2cppBase = g_il2cppELF.base();

C++:
myMonoString* CreateString(const char* str)
{
    myMonoString* (*CreateStringFunc)(void* instance, const char* str, int start, int length) =
        (myMonoString * (*)(void*, const char*, int, int))(il2cppBase + str2Offset(OBFUSCATE("0x2B77650")));
    int length = (int)strlen(str);
    return CreateStringFunc(NULL, str, 0, length);
}

I still don't understand why I had this problem on arm64
 
Back
Top Bottom