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, int startIndex, int length);
void (*get_StringInstance);
#include <codecvt>
#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);
}
bool isGetNickname;
monoString* (*get_Nickname)(void *instance);
void (*old_Update)(void *instance);
void Update(void *instance) {
if (instance != NULL) {
if (isGetNickname) {
LOGI("Nickname: %s", FromUTF16(get_Nickname(instance)).c_str());
}
}
return old_Update(instance);
}
bool isSetNickname;
const char *Nickname;
monoString* (*old_getNickname)(void* instance);
monoString* getNickname(void* instance) {
if (instance != NULL && isSetNickname) {
return String_CreateString(get_StringInstance, Nickname, 0, (int)strlen(Nickname));
}
return old_getNickname(instance);
}
#if defined(__aarch64__) //To compile this code for arm64 lib only. Do not worry about greyed out highlighting code, it still works
A64HookFunction((void*)getAbsoluteAddress(targetLibName, 0xFFC538), (void*)Update, (void**)&old_Update);
A64HookFunction((void*)getAbsoluteAddress(targetLibName, 0x233574C), (void*)getNickname, (void**)&old_getNickname);
String_CreateString = (monoString *(*)(void *, const char *, int startIndex, int length))getAbsoluteAddress(targetLibName, 0x2066CB0);
get_StringInstance = (void (*))getAbsoluteAddress(targetLibName, 0x2066CB0);
get_Nickname = (monoString* (*)(void *))getAbsoluteAddress(targetLibName, 0x233574C);
const char *features[] = {
OBFUSCATE("30_CollapseAdd_Toggle_Get Nickname"),
OBFUSCATE("37_CollapseAdd_InputText_Nickname"),
OBFUSCATE("38_CollapseAdd_Toggle_Set Nickname"),
};
switch (featNum) {
case 30:
isGetNickname = boolean;
break;
case 37:
Nickname = env->GetStringUTFChars(str, 0);
break;
case 38:
isSetNickname = boolean;
break;
}