public PlusSearch(PE.PE pe, int methodCount, int typeDefinitionsCount, long maxMetadataUsages) { _pe = pe; this.methodCount = methodCount; this.typeDefinitionsCount = typeDefinitionsCount; this.maxMetadataUsages = maxMetadataUsages; }
internal static void MapGlobalIdentifiers(Il2CppMetadata metadata, PE.PE cppAssembly) { //Type references TypeRefs = metadata.metadataUsageDic[1] .Select(kvp => new { kvp, type = cppAssembly.types[kvp.Value] }) .Select(t => new GlobalIdentifier { Name = LibCpp2ILUtils.GetTypeName(metadata, cppAssembly, t.type, true), Value = LibCpp2ILUtils.GetTypeReflectionData(t.type) !, Offset = cppAssembly.metadataUsages[t.kvp.Key], IdentifierType = GlobalIdentifier.Type.TYPEREF }).ToList();
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)}>"); }
internal static string GetTypeName(Il2CppMetadata metadata, PE.PE cppAssembly, Il2CppTypeDefinition typeDef, bool fullName = false) { var ret = string.Empty; if (fullName) { ret = typeDef.Namespace; if (ret != string.Empty) { ret += "."; } } if (typeDef.declaringTypeIndex != -1) { ret += GetTypeName(metadata, cppAssembly, cppAssembly.types[typeDef.declaringTypeIndex]) + "."; } ret += metadata.GetStringFromIndex(typeDef.nameIndex); var names = new List <string>(); if (typeDef.genericContainerIndex < 0) { return(ret); } var genericContainer = metadata.genericContainers[typeDef.genericContainerIndex]; for (var i = 0; i < genericContainer.type_argc; i++) { var genericParameterIndex = genericContainer.genericParameterStart + i; var param = metadata.genericParameters[genericParameterIndex]; names.Add(metadata.GetStringFromIndex(param.nameIndex)); } ret = ret.Replace($"`{genericContainer.type_argc}", ""); ret += $"<{string.Join(", ", names)}>"; return(ret); }
internal static object?GetDefaultValue(int dataIndex, int typeIndex, Il2CppMetadata metadata, PE.PE theDll) { var pointer = metadata.GetDefaultValueFromIndex(dataIndex); if (pointer <= 0) { return(null); } var defaultValueType = theDll.types[typeIndex]; metadata.Position = pointer; switch (defaultValueType.type) { case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: return(metadata.ReadBoolean()); case Il2CppTypeEnum.IL2CPP_TYPE_U1: return(metadata.ReadByte()); case Il2CppTypeEnum.IL2CPP_TYPE_I1: return(metadata.ReadSByte()); case Il2CppTypeEnum.IL2CPP_TYPE_CHAR: return(BitConverter.ToChar(metadata.ReadBytes(2), 0)); case Il2CppTypeEnum.IL2CPP_TYPE_U2: return(metadata.ReadUInt16()); case Il2CppTypeEnum.IL2CPP_TYPE_I2: return(metadata.ReadInt16()); case Il2CppTypeEnum.IL2CPP_TYPE_U4: return(metadata.ReadUInt32()); case Il2CppTypeEnum.IL2CPP_TYPE_I4: return(metadata.ReadInt32()); case Il2CppTypeEnum.IL2CPP_TYPE_U8: return(metadata.ReadUInt64()); case Il2CppTypeEnum.IL2CPP_TYPE_I8: return(metadata.ReadInt64()); case Il2CppTypeEnum.IL2CPP_TYPE_R4: return(metadata.ReadSingle()); case Il2CppTypeEnum.IL2CPP_TYPE_R8: return(metadata.ReadDouble()); case Il2CppTypeEnum.IL2CPP_TYPE_STRING: var len = metadata.ReadInt32(); return(Encoding.UTF8.GetString(metadata.ReadBytes(len))); default: return(null); } }
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); }