diff --git a/Il2CppDumper/Utils/DummyAssemblyGenerator.cs b/Il2CppDumper/Utils/DummyAssemblyGenerator.cs index ff57885..2c59b19 100644 --- a/Il2CppDumper/Utils/DummyAssemblyGenerator.cs +++ b/Il2CppDumper/Utils/DummyAssemblyGenerator.cs @@ -551,67 +551,74 @@ namespace Il2CppDumper var attributeIndex = metadata.GetCustomAttributeIndex(imageDef, customAttributeIndex, token); if (attributeIndex >= 0) { - if (il2Cpp.Version < 29) + try { - var attributeTypeRange = metadata.attributeTypeRanges[attributeIndex]; - for (int i = 0; i < attributeTypeRange.count; i++) + if (il2Cpp.Version < 29) { - var attributeTypeIndex = metadata.attributeTypes[attributeTypeRange.start + i]; - var attributeType = il2Cpp.types[attributeTypeIndex]; - var typeDef = executor.GetTypeDefinitionFromIl2CppType(attributeType); - var typeDefinition = typeDefinitionDic[typeDef]; - if (!TryRestoreCustomAttribute(typeDefinition, moduleDefinition, customAttributes)) + var attributeTypeRange = metadata.attributeTypeRanges[attributeIndex]; + for (int i = 0; i < attributeTypeRange.count; i++) { - var methodPointer = executor.customAttributeGenerators[attributeIndex]; - var fixedMethodPointer = il2Cpp.GetRVA(methodPointer); - var customAttribute = new CustomAttribute(moduleDefinition.ImportReference(attributeAttribute)); - var name = new CustomAttributeNamedArgument("Name", new CustomAttributeArgument(stringType, typeDefinition.Name)); - var rva = new CustomAttributeNamedArgument("RVA", new CustomAttributeArgument(stringType, $"0x{fixedMethodPointer:X}")); - var offset = new CustomAttributeNamedArgument("Offset", new CustomAttributeArgument(stringType, $"0x{il2Cpp.MapVATR(methodPointer):X}")); - customAttribute.Fields.Add(name); - customAttribute.Fields.Add(rva); - customAttribute.Fields.Add(offset); - customAttributes.Add(customAttribute); + var attributeTypeIndex = metadata.attributeTypes[attributeTypeRange.start + i]; + var attributeType = il2Cpp.types[attributeTypeIndex]; + var typeDef = executor.GetTypeDefinitionFromIl2CppType(attributeType); + var typeDefinition = typeDefinitionDic[typeDef]; + if (!TryRestoreCustomAttribute(typeDefinition, moduleDefinition, customAttributes)) + { + var methodPointer = executor.customAttributeGenerators[attributeIndex]; + var fixedMethodPointer = il2Cpp.GetRVA(methodPointer); + var customAttribute = new CustomAttribute(moduleDefinition.ImportReference(attributeAttribute)); + var name = new CustomAttributeNamedArgument("Name", new CustomAttributeArgument(stringType, typeDefinition.Name)); + var rva = new CustomAttributeNamedArgument("RVA", new CustomAttributeArgument(stringType, $"0x{fixedMethodPointer:X}")); + var offset = new CustomAttributeNamedArgument("Offset", new CustomAttributeArgument(stringType, $"0x{il2Cpp.MapVATR(methodPointer):X}")); + customAttribute.Fields.Add(name); + customAttribute.Fields.Add(rva); + customAttribute.Fields.Add(offset); + customAttributes.Add(customAttribute); + } + } + } + else + { + var startRange = metadata.attributeDataRanges[attributeIndex]; + var endRange = metadata.attributeDataRanges[attributeIndex + 1]; + metadata.Position = metadata.header.attributeDataOffset + startRange.startOffset; + var buff = metadata.ReadBytes((int)(endRange.startOffset - startRange.startOffset)); + var reader = new CustomAttributeDataReader(executor, buff); + if (reader.Count != 0) + { + for (var i = 0; i < reader.Count; i++) + { + var visitor = reader.VisitCustomAttributeData(); + var methodDefinition = methodDefinitionDic[visitor.CtorIndex]; + var customAttribute = new CustomAttribute(moduleDefinition.ImportReference(methodDefinition)); + foreach (var argument in visitor.Arguments) + { + var parameterDefinition = methodDefinition.Parameters[argument.Index]; + var customAttributeArgument = CreateCustomAttributeArgument(parameterDefinition.ParameterType, argument.Value, methodDefinition); + customAttribute.ConstructorArguments.Add(customAttributeArgument); + } + foreach (var field in visitor.Fields) + { + var fieldDefinition = fieldDefinitionDic[field.Index]; + var customAttributeArgument = CreateCustomAttributeArgument(fieldDefinition.FieldType, field.Value, fieldDefinition); + var customAttributeNamedArgument = new CustomAttributeNamedArgument(fieldDefinition.Name, customAttributeArgument); + customAttribute.Fields.Add(customAttributeNamedArgument); + } + foreach (var property in visitor.Properties) + { + var propertyDefinition = propertyDefinitionDic[property.Index]; + var customAttributeArgument = CreateCustomAttributeArgument(propertyDefinition.PropertyType, property.Value, propertyDefinition); + var customAttributeNamedArgument = new CustomAttributeNamedArgument(propertyDefinition.Name, customAttributeArgument); + customAttribute.Properties.Add(customAttributeNamedArgument); + } + customAttributes.Add(customAttribute); + } } } } - else + catch { - var startRange = metadata.attributeDataRanges[attributeIndex]; - var endRange = metadata.attributeDataRanges[attributeIndex + 1]; - metadata.Position = metadata.header.attributeDataOffset + startRange.startOffset; - var buff = metadata.ReadBytes((int)(endRange.startOffset - startRange.startOffset)); - var reader = new CustomAttributeDataReader(executor, buff); - if (reader.Count != 0) - { - for (var i = 0; i < reader.Count; i++) - { - var visitor = reader.VisitCustomAttributeData(); - var methodDefinition = methodDefinitionDic[visitor.CtorIndex]; - var customAttribute = new CustomAttribute(moduleDefinition.ImportReference(methodDefinition)); - foreach (var argument in visitor.Arguments) - { - var parameterDefinition = methodDefinition.Parameters[argument.Index]; - var customAttributeArgument = CreateCustomAttributeArgument(parameterDefinition.ParameterType, argument.Value, methodDefinition); - customAttribute.ConstructorArguments.Add(customAttributeArgument); - } - foreach (var field in visitor.Fields) - { - var fieldDefinition = fieldDefinitionDic[field.Index]; - var customAttributeArgument = CreateCustomAttributeArgument(fieldDefinition.FieldType, field.Value, fieldDefinition); - var customAttributeNamedArgument = new CustomAttributeNamedArgument(fieldDefinition.Name, customAttributeArgument); - customAttribute.Fields.Add(customAttributeNamedArgument); - } - foreach (var property in visitor.Properties) - { - var propertyDefinition = propertyDefinitionDic[property.Index]; - var customAttributeArgument = CreateCustomAttributeArgument(propertyDefinition.PropertyType, property.Value, propertyDefinition); - var customAttributeNamedArgument = new CustomAttributeNamedArgument(propertyDefinition.Name, customAttributeArgument); - customAttribute.Properties.Add(customAttributeNamedArgument); - } - customAttributes.Add(customAttribute); - } - } + Console.WriteLine($"ERROR: Error while restoring attributeIndex {attributeIndex}"); } } } @@ -651,7 +658,11 @@ namespace Il2CppDumper private CustomAttributeArgument CreateCustomAttributeArgument(TypeReference typeReference, BlobValue blobValue, MemberReference memberReference) { var val = blobValue.Value; - if (typeReference.FullName == "System.Object") + if (val == null) + { + return new CustomAttributeArgument(typeReference, val); + } + else if (typeReference.FullName == "System.Object") { val = new CustomAttributeArgument(GetBlobValueTypeReference(blobValue, memberReference), val); } diff --git a/Il2CppDumper/Utils/Il2CppExecutor.cs b/Il2CppDumper/Utils/Il2CppExecutor.cs index d27f8ec..eaa2afd 100644 --- a/Il2CppDumper/Utils/Il2CppExecutor.cs +++ b/Il2CppDumper/Utils/Il2CppExecutor.cs @@ -444,7 +444,14 @@ namespace Il2CppDumper return true; case Il2CppTypeEnum.IL2CPP_TYPE_IL2CPP_TYPE_INDEX: var typeIndex = reader.ReadCompressedInt32(); - value.Value = il2Cpp.types[typeIndex]; + if (typeIndex == -1) + { + value.Value = null; + } + else + { + value.Value = il2Cpp.types[typeIndex]; + } return true; default: value = null; diff --git a/Il2CppDumper/Utils/SectionHelper.cs b/Il2CppDumper/Utils/SectionHelper.cs index 3ae8b32..1e93b58 100644 --- a/Il2CppDumper/Utils/SectionHelper.cs +++ b/Il2CppDumper/Utils/SectionHelper.cs @@ -335,7 +335,7 @@ namespace Il2CppDumper { if (il2Cpp.Version >= 27) { - for (int i = imageCount; i >= 0; i--) + for (int i = imageCount - 1; i >= 0; i--) { var va2 = FindReference(va - (ulong)i * il2Cpp.PointerSize); if (va2 != 0ul)