Esempio n. 1
0
        internal static string GetGenericTypeParamNames(Il2CppMetadata metadata, PE.PE cppAssembly, Il2CppGenericInst genericInst)
        {
            var typeNames = new List <string>();
            var pointers  = cppAssembly.ReadClassArrayAtVirtualAddress <ulong>(genericInst.pointerStart, (long)genericInst.pointerCount);

            for (uint i = 0; i < genericInst.pointerCount; ++i)
            {
                var oriType = cppAssembly.GetIl2CppTypeFromPointer(pointers[i]);
                typeNames.Add(GetTypeName(metadata, cppAssembly, oriType));
            }

            return($"<{string.Join(", ", typeNames)}>");
        }
Esempio n. 2
0
        public static string GetTypeName(Il2CppMetadata metadata, PE.PE cppAssembly, Il2CppType type, bool fullName = false)
        {
            string ret;

            switch (type.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            {
                var typeDef = metadata.typeDefs[type.data.classIndex];
                ret = string.Empty;

                ret += GetTypeName(metadata, cppAssembly, typeDef, fullName);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                var genericClass = cppAssembly.ReadClassAtVirtualAddress <Il2CppGenericClass>(type.data.generic_class);
                var typeDef      = metadata.typeDefs[genericClass.typeDefinitionIndex];
                ret = metadata.GetStringFromIndex(typeDef.nameIndex);
                var genericInst = cppAssembly.ReadClassAtVirtualAddress <Il2CppGenericInst>(genericClass.context.class_inst);
                ret  = ret.Replace($"`{genericInst.pointerCount}", "");
                ret += GetGenericTypeParamNames(metadata, cppAssembly, genericInst);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                var param = metadata.genericParameters[type.data.genericParameterIndex];
                ret = metadata.GetStringFromIndex(param.nameIndex);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            {
                var arrayType = cppAssembly.ReadClassAtVirtualAddress <Il2CppArrayType>(type.data.array);
                var oriType   = cppAssembly.GetIl2CppTypeFromPointer(arrayType.etype);
                ret = $"{GetTypeName(metadata, cppAssembly, oriType)}[{new string(',', arrayType.rank - 1)}]";
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                var oriType = cppAssembly.GetIl2CppTypeFromPointer(type.data.type);
                ret = $"{GetTypeName(metadata, cppAssembly, oriType)}[]";
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var oriType = cppAssembly.GetIl2CppTypeFromPointer(type.data.type);
                ret = $"{GetTypeName(metadata, cppAssembly, oriType)}*";
                break;
            }

            default:
                ret = TypeString[(int)type.type];
                break;
            }

            return(ret);
        }