Beispiel #1
0
        private ulong FindCodeRegistration32Bit()
        {
            foreach (var section in data)
            {
                il2Cpp.Position = section.offset;
                while (il2Cpp.Position < section.offsetEnd)
                {
                    var addr = il2Cpp.Position;
                    if (il2Cpp.ReadUInt32() == methodCount)
                    {
                        try {
                            var pointer = il2Cpp.MapVATR(il2Cpp.ReadUInt32());
                            if (CheckPointerRangeDataRa(pointer))
                            {
                                var pointers = il2Cpp.ReadClassArray <uint>(pointer, methodCount);
                                if (CheckPointerRangeExecVa(pointers))
                                {
                                    return(addr - section.offset + section.address);
                                }
                            }
                        } catch {
                            // ignored
                        }
                    }
                    il2Cpp.Position = addr + 4;
                }
            }

            return(0ul);
        }
        public string GetTypeName(Il2CppType il2CppType, bool addNamespace, bool is_nested)
        {
            switch (il2CppType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY: {
                var arrayType   = il2Cpp.MapVATR <Il2CppArrayType>(il2CppType.data.array);
                var elementType = il2Cpp.GetIl2CppType(arrayType.etype);
                return($"{GetTypeName(elementType, addNamespace, false)}[{new string(',', arrayType.rank - 1)}]");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY: {
                var elementType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return($"{GetTypeName(elementType, addNamespace, false)}[]");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR: {
                var oriType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return($"{GetTypeName(oriType, addNamespace, false)}*");
            }

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

            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST: {
                string str = string.Empty;
                Il2CppTypeDefinition typeDef;
                bool wasUsed = false;
                Il2CppGenericClass genericClass = default(Il2CppGenericClass);
                if (il2CppType.type == Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
                {
                    genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class);
                    typeDef      = metadata.typeDefs[genericClass.typeDefinitionIndex];
                    wasUsed      = true;
                }
                else
                {
                    typeDef = metadata.typeDefs[il2CppType.data.klassIndex];
                }
                if (typeDef.declaringTypeIndex != -1)
                {
                    str += GetTypeName(il2Cpp.types[typeDef.declaringTypeIndex], addNamespace, true);
                    str += '.';
                }
                else if (addNamespace)
                {
                    var @namespace = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                    if (@namespace != "")
                    {
                        str += @namespace + ".";
                    }
                }

                var typeName = metadata.GetStringFromIndex(typeDef.nameIndex);
                var index    = typeName.IndexOf("`");
                if (index != -1)
                {
                    str += typeName.Substring(0, index);
                }
                else
                {
                    str += typeName;
                }

                if (is_nested)
                {
                    return(str);
                }

                if (wasUsed)
                {
                    var genericInst = il2Cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst);
                    str += GetGenericInstParams(genericInst);
                }
                else if (typeDef.genericContainerIndex >= 0)
                {
                    var genericContainer      = metadata.genericContainers[typeDef.genericContainerIndex];
                    var genericParameterNames = new List <string>();
                    for (int i = 0; i < genericContainer.type_argc; i++)
                    {
                        var genericParameterIndex = genericContainer.genericParameterStart + i;
                        var param = metadata.genericParameters[genericParameterIndex];
                        genericParameterNames.Add(metadata.GetStringFromIndex(param.nameIndex));
                    }
                    str += $"<{string.Join(", ", genericParameterNames)}>";
                }

                return(str);
            }

            default:
                return(TypeString[(int)il2CppType.type]);
            }
        }