Help! How to compare between String method with our Monostring input

VounderS

Platinian
Original poster
Jul 6, 2023
12
4
3
24
your daddy ass
i really want to know this is correct way to do unlink with String get_name ? I try to hook this method but it doesnt work
1715782903143.png


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

    int getLength()
    {
        return length;
    }
    char* getChars()
    {
        return chars;
    }
}monoString;

monoString *CreateString(const char *str) {
    monoString *(*CreateString)(void *_this, const char *str, int start, int length) = (monoString *(*)(void *, const char *, int, int))IL2CPP_H::Il2CppGetMethodOffset(OBFUSCATE("mscorlib.dll"), OBFUSCATE("System"), OBFUSCATE("String"), OBFUSCATE("CreateString"), 3);
    int length = (int)strlen(str);
    return CreateString(NULL, str, 0, length);

}
This is how i hook it
C++:
monoString *(*get_name)(void *inst);
void (*org_EntityListUpdate)(void *object);
void new_EntityListUpdate(void *object) {
    if(player != NULL){
        auto name = get_name(object);
        if(name == CreateString("purple_coin_8")){
            if (!objectFind(object))
            {
                objectList.push_back(object);
            }
        }

    }
    org_EntityListUpdate(object);
}

//hack thread
get_name = (monoString *(*)(void *))IL2CPP_H::Il2CppGetMethodOffset(OBFUSCATE("Scripts.dll"), OBFUSCATE("Oak"), OBFUSCATE("FieldObject"), OBFUSCATE("get_Name"), 0);
DobbyHook((void *)IL2CPP_H::Il2CppGetMethodOffset(OBFUSCATE("Scripts.dll"), OBFUSCATE("Oak"), OBFUSCATE("FieldObject") , OBFUSCATE("get_FieldObjectStatsBehaviour"), 0), (void *) new_EntityListUpdate , (void **) &org_EntityListUpdate);
 
Last edited:
  • Like
Reactions: 4fun88

VounderS

Platinian
Original poster
Jul 6, 2023
12
4
3
24
your daddy ass
How did you solve it?
by using equals function
C++:
bool (*get_equals)(monoString *a, monoString *b, int type);

bool (*old_IsSubUnit)(void *instance);
bool new_IsSubUnit(void *instance)
{
    if(instance != NULL)
    {
        monoString *a = CreateString("Evan");
        monoString *b = get_name(instance);
        if(get_equals(a,b, 5)){
            LOGD("Equals");
        }else{
            LOGD("Not Equals");
        }
    }
    return old_IsSubUnit(instance);
}


//hack thread
get_equals = (bool (*)(monoString *, monoString *, int))Il2CppGetMethodOffset(OBFUSCATE("mscorlib.dll"), OBFUSCATE("System"), OBFUSCATE("String"), OBFUSCATE("Equals"), 3);
oh yeah you can also just hook Equals that has 2 param (string a, string b) i hook this equals cause il2cppgenerator hook diffrent equals
 
  • Like
Reactions: libModz

libModz

Awesome Active Platinian
Jun 2, 2022
173
31
28
UK
by using equals function
C++:
bool (*get_equals)(monoString *a, monoString *b, int type);

bool (*old_IsSubUnit)(void *instance);
bool new_IsSubUnit(void *instance)
{
    if(instance != NULL)
    {
        monoString *a = CreateString("Evan");
        monoString *b = get_name(instance);
        if(get_equals(a,b, 5)){
            LOGD("Equals");
        }else{
            LOGD("Not Equals");
        }
    }
    return old_IsSubUnit(instance);
}


//hack thread
get_equals = (bool (*)(monoString *, monoString *, int))Il2CppGetMethodOffset(OBFUSCATE("mscorlib.dll"), OBFUSCATE("System"), OBFUSCATE("String"), OBFUSCATE("Equals"), 3);
oh yeah you can also just hook Equals that has 2 param (string a, string b) i hook this equals cause il2cppgenerator hook diffrent equals
What is the number 5 int *type parameter for?
 

VounderS

Platinian
Original poster
Jul 6, 2023
12
4
3
24
your daddy ass
What is the number 5 int *type parameter for?
its enum class to comparisontype
C#:
public enum StringComparison
{
    // Fields
    public Int32 value__; // 0x10
    public const StringComparison CurrentCulture = 0; // 0x0
    public const StringComparison CurrentCultureIgnoreCase = 1; // 0x0
    public const StringComparison InvariantCulture = 2; // 0x0
    public const StringComparison InvariantCultureIgnoreCase = 3; // 0x0
    public const StringComparison Ordinal = 4; // 0x0
    public const StringComparison OrdinalIgnoreCase = 5; // 0x0

}
like i said if u using absoluteaddress or BNM that has paramtype just hook Equals(String a, String b) but when i use il2cppgenerator i shoul hook this equals cause it have different param
 
  • Like
Reactions: libModz

libModz

Awesome Active Platinian
Jun 2, 2022
173
31
28
UK
its enum class to comparisontype
C#:
public enum StringComparison
{
    // Fields
    public Int32 value__; // 0x10
    public const StringComparison CurrentCulture = 0; // 0x0
    public const StringComparison CurrentCultureIgnoreCase = 1; // 0x0
    public const StringComparison InvariantCulture = 2; // 0x0
    public const StringComparison InvariantCultureIgnoreCase = 3; // 0x0
    public const StringComparison Ordinal = 4; // 0x0
    public const StringComparison OrdinalIgnoreCase = 5; // 0x0

}
like i said if u using absoluteaddress or BNM that has paramtype just hook Equals(String a, String b) but when i use il2cppgenerator i shoul hook this equals cause it have different param
Okay thanks
 
  • Like
Reactions: VounderS