This is the AMP version of this page.
If you want to load the real page instead, click this text.

Help! Helping with Strings hooking in Unity

Kaorin333

Solid & Active Platinian
Hello first of all, i was reading now some tutorials about string hooking and modifying, but sadly it doesnt help me much from what i see on my output.

I followed his tutorial
ARM64 Unity String Function Hooking LGL Menu



C++:
[Token(Token = "0x600669D")]
[Address(RVA = "0x2612AA4", Offset = "0x2612AA4", VA = "0x2612AA4")]
public static string get_version()
{
    return null;
}

my code:

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

    int getLength() {
        return length;
    }

    char* getChars() {
        return chars;
    }
} monoString;

monoString* (*String_CreateString)(void* _this, const char* str);
void(*get_StringInstance);

monoString* (*get_version)(void* instance);
char* (*get_version_str)(void* instance);

void (*old_Update)(void *instance);
void Update(void *instance) {
    if(instance != NULL){

        monoString* a = get_version(instance);
        LOGI("Version: %s", a);

        char* b = get_version_str(instance);
        LOGI("Version: %s", b);
     
    }
    old_Update(instance);
}

void* hack_thread(){
    String_CreateString = (monoString * (*)(void*, const char*))getAbsoluteAddress(targetLibName, 0x1125790);
    get_StringInstance = (void(*))getAbsoluteAddress(targetLibName, 0x1125790);
 
 
    get_version = (monoString* (*) (void*)) getAbsoluteAddress(targetLibName, 0x2612AA4);
    get_version_str = (char* (*) (void*)) getAbsoluteAddress(targetLibName, 0x2612AA4);
 
}

none are working i also tried one different way but also its simply not giving me the correct output.

output from example
Code:
06-27 01:21:54.571 17173 17238 I Mod_Menu: Version: Ç╨ⁿ¬
06-27 01:21:54.571 17173 17238 I Mod_Menu: Version: Ç╨ⁿ¬

would be nice if someone could enlight me.
 
IL2CPP/Mono strings are UTF-16, meaning they are 2 bytes per character, while C strings are UTF-8, meaning they are 1 byte per character. You can use some C++ libraries to help, here's an example.
C++:
#include <codecvt>
#include <string>
#include <locale>

std::string FromUTF16(monoString* str) {
    std::u16string u16(reinterpret_cast<const char16_t*>(str->chars));
    return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(u16);
}

void (*old_Update)(void *instance);
void Update(void *instance) {
    if(instance != NULL){
        LOGI("Version: %s", FromUTF16(get_version()).c_str());
    }
   
    old_Update(instance);
}