Perfare / Il2CppDumper

Unity il2cpp reverse engineer
MIT License
6.98k stars 1.37k forks source link

Wrong function signature when the class is defined as a struct #699

Open kotori2 opened 1 year ago

kotori2 commented 1 year ago

Note: if you do not provide all of the following information I will directly ignore and close this issue

kotori2 commented 1 year ago

I think this rule only applies to this pointer. For other function calls / returns, it will still keep the structure in stack. Here is an example:

namespace DefaultNamespace
{
    public class StructCaller
    {
        public Structure Call()
        { 
            uint[] arr = new uint[0];
            var s = new Structure(arr, 0);
            return s;
        }

        public Structure MeaninglessPass(Structure s)
        {
            return s;
        }
    }
}
// DefaultNamespace.Structure DefaultNamespace.StructCaller::Call()
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Structure_t360561EF943FEF121944803824E6A238E5BADE61 StructCaller_Call_m83B7AA5633ED4B24D7005681747CFC914398ADC1 (StructCaller_t1862CAAC6E3464E8DEE388A421709BC0CBE38DCF* __this, const RuntimeMethod* method) 
{
    static bool s_Il2CppMethodInitialized;
    if (!s_Il2CppMethodInitialized)
    {
        il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA_il2cpp_TypeInfo_var);
        s_Il2CppMethodInitialized = true;
    }
    UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* V_0 = NULL;
    {
        // uint[] arr = new uint[0];
        UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* L_0 = (UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA*)(UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA*)SZArrayNew(UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA_il2cpp_TypeInfo_var, (uint32_t)0);
        V_0 = L_0;
        // var s = new Structure(arr, 0);
        UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* L_1 = V_0;
        Structure_t360561EF943FEF121944803824E6A238E5BADE61 L_2;
        memset((&L_2), 0, sizeof(L_2));
        Structure__ctor_m6D54596E55D081B9E3821988795275D8A0540958((&L_2), L_1, 0, /*hidden argument*/NULL);
        // return s;
        return L_2;
    }
}
// DefaultNamespace.Structure DefaultNamespace.StructCaller::MeaninglessPass(DefaultNamespace.Structure)
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Structure_t360561EF943FEF121944803824E6A238E5BADE61 StructCaller_MeaninglessPass_mF7C123782870858D21D994DBEECB1C02F31BFAB5 (StructCaller_t1862CAAC6E3464E8DEE388A421709BC0CBE38DCF* __this, Structure_t360561EF943FEF121944803824E6A238E5BADE61 ___s0, const RuntimeMethod* method) 
{
    {
        // return s;
        Structure_t360561EF943FEF121944803824E6A238E5BADE61 L_0 = ___s0;
        return L_0;
    }
}