diff --git a/Il2CppDumper/ExecutableFormats/Elf.cs b/Il2CppDumper/ExecutableFormats/Elf.cs index 21f8dd8..5ef962f 100644 --- a/Il2CppDumper/ExecutableFormats/Elf.cs +++ b/Il2CppDumper/ExecutableFormats/Elf.cs @@ -84,7 +84,11 @@ namespace Il2CppDumper public override ulong MapRTVA(ulong addr) { - var phdr = programSegment.First(x => addr >= x.p_offset && addr <= x.p_offset + x.p_filesz); + var phdr = programSegment.FirstOrDefault(x => addr >= x.p_offset && addr <= x.p_offset + x.p_filesz); + if (phdr == null) + { + return 0; + } return addr - phdr.p_offset + phdr.p_vaddr; } diff --git a/Il2CppDumper/ExecutableFormats/Elf64.cs b/Il2CppDumper/ExecutableFormats/Elf64.cs index 98e0f79..d4b15f4 100644 --- a/Il2CppDumper/ExecutableFormats/Elf64.cs +++ b/Il2CppDumper/ExecutableFormats/Elf64.cs @@ -75,7 +75,11 @@ namespace Il2CppDumper public override ulong MapRTVA(ulong addr) { - var phdr = programSegment.First(x => addr >= x.p_offset && addr <= x.p_offset + x.p_filesz); + var phdr = programSegment.FirstOrDefault(x => addr >= x.p_offset && addr <= x.p_offset + x.p_filesz); + if (phdr == null) + { + return 0; + } return addr - phdr.p_offset + phdr.p_vaddr; } diff --git a/Il2CppDumper/ExecutableFormats/Macho.cs b/Il2CppDumper/ExecutableFormats/Macho.cs index afed7ae..c98fc89 100644 --- a/Il2CppDumper/ExecutableFormats/Macho.cs +++ b/Il2CppDumper/ExecutableFormats/Macho.cs @@ -82,7 +82,11 @@ namespace Il2CppDumper public override ulong MapRTVA(ulong addr) { - var section = sections.First(x => addr >= x.offset && addr <= x.offset + x.size); + var section = sections.FirstOrDefault(x => addr >= x.offset && addr <= x.offset + x.size); + if (section == null) + { + return 0; + } return addr - section.offset + section.addr; } diff --git a/Il2CppDumper/ExecutableFormats/Macho64.cs b/Il2CppDumper/ExecutableFormats/Macho64.cs index 81236a4..516534f 100644 --- a/Il2CppDumper/ExecutableFormats/Macho64.cs +++ b/Il2CppDumper/ExecutableFormats/Macho64.cs @@ -78,7 +78,11 @@ namespace Il2CppDumper public override ulong MapRTVA(ulong addr) { - var section = sections.First(x => addr >= x.offset && addr <= x.offset + x.size); + var section = sections.FirstOrDefault(x => addr >= x.offset && addr <= x.offset + x.size); + if (section == null) + { + return 0; + } if (section.sectname == "__bss") { throw new Exception(); diff --git a/Il2CppDumper/ExecutableFormats/NSO.cs b/Il2CppDumper/ExecutableFormats/NSO.cs index 6ccd35e..93800fd 100644 --- a/Il2CppDumper/ExecutableFormats/NSO.cs +++ b/Il2CppDumper/ExecutableFormats/NSO.cs @@ -98,7 +98,11 @@ namespace Il2CppDumper public override ulong MapRTVA(ulong addr) { - var segment = segments.First(x => addr >= x.FileOffset && addr <= x.FileOffset + x.DecompressedSize); + var segment = segments.FirstOrDefault(x => addr >= x.FileOffset && addr <= x.FileOffset + x.DecompressedSize); + if (segment == null) + { + return 0; + } return addr - segment.FileOffset + segment.MemoryOffset; } diff --git a/Il2CppDumper/Outputs/StructGenerator.cs b/Il2CppDumper/Outputs/StructGenerator.cs index d5833c7..a2850bb 100644 --- a/Il2CppDumper/Outputs/StructGenerator.cs +++ b/Il2CppDumper/Outputs/StructGenerator.cs @@ -261,50 +261,53 @@ namespace Il2CppDumper if (metadataValue == ((usage << 29) | (decodedIndex << 1)) + 1) { var va = il2Cpp.MapRTVA(addr); - switch ((Il2CppMetadataUsage)usage) + if (va > 0) { - case Il2CppMetadataUsage.kIl2CppMetadataUsageInvalid: - break; - case Il2CppMetadataUsage.kIl2CppMetadataUsageTypeInfo: - if (decodedIndex < il2Cpp.types.Length) - { - AddMetadataUsageTypeInfo(json, decodedIndex, va); - } - break; - case Il2CppMetadataUsage.kIl2CppMetadataUsageIl2CppType: - if (decodedIndex < il2Cpp.types.Length) - { - AddMetadataUsageIl2CppType(json, decodedIndex, va); - } - break; - case Il2CppMetadataUsage.kIl2CppMetadataUsageMethodDef: - if (decodedIndex < metadata.methodDefs.Length) - { - AddMetadataUsageMethodDef(json, decodedIndex, va); - } - break; - case Il2CppMetadataUsage.kIl2CppMetadataUsageFieldInfo: - if (decodedIndex < metadata.fieldRefs.Length) - { - AddMetadataUsageFieldInfo(json, decodedIndex, va); - } - break; - case Il2CppMetadataUsage.kIl2CppMetadataUsageStringLiteral: - if (decodedIndex < metadata.stringLiterals.Length) - { - AddMetadataUsageStringLiteral(json, decodedIndex, va); - } - break; - case Il2CppMetadataUsage.kIl2CppMetadataUsageMethodRef: - if (decodedIndex < il2Cpp.methodSpecs.Length) - { - AddMetadataUsageMethodRef(json, decodedIndex, va); - } - break; - } - if (il2Cpp.Position != position) - { - il2Cpp.Position = position; + switch ((Il2CppMetadataUsage)usage) + { + case Il2CppMetadataUsage.kIl2CppMetadataUsageInvalid: + break; + case Il2CppMetadataUsage.kIl2CppMetadataUsageTypeInfo: + if (decodedIndex < il2Cpp.types.Length) + { + AddMetadataUsageTypeInfo(json, decodedIndex, va); + } + break; + case Il2CppMetadataUsage.kIl2CppMetadataUsageIl2CppType: + if (decodedIndex < il2Cpp.types.Length) + { + AddMetadataUsageIl2CppType(json, decodedIndex, va); + } + break; + case Il2CppMetadataUsage.kIl2CppMetadataUsageMethodDef: + if (decodedIndex < metadata.methodDefs.Length) + { + AddMetadataUsageMethodDef(json, decodedIndex, va); + } + break; + case Il2CppMetadataUsage.kIl2CppMetadataUsageFieldInfo: + if (decodedIndex < metadata.fieldRefs.Length) + { + AddMetadataUsageFieldInfo(json, decodedIndex, va); + } + break; + case Il2CppMetadataUsage.kIl2CppMetadataUsageStringLiteral: + if (decodedIndex < metadata.stringLiterals.Length) + { + AddMetadataUsageStringLiteral(json, decodedIndex, va); + } + break; + case Il2CppMetadataUsage.kIl2CppMetadataUsageMethodRef: + if (decodedIndex < il2Cpp.methodSpecs.Length) + { + AddMetadataUsageMethodRef(json, decodedIndex, va); + } + break; + } + if (il2Cpp.Position != position) + { + il2Cpp.Position = position; + } } } } diff --git a/Il2CppDumper/Utils/Il2CppExecutor.cs b/Il2CppDumper/Utils/Il2CppExecutor.cs index e2ee7b0..47c366c 100644 --- a/Il2CppDumper/Utils/Il2CppExecutor.cs +++ b/Il2CppDumper/Utils/Il2CppExecutor.cs @@ -43,8 +43,11 @@ namespace Il2CppDumper { var imageDefName = metadata.GetStringFromIndex(imageDef.nameIndex); var codeGenModule = il2Cpp.codeGenModules[imageDefName]; - var pointers = il2Cpp.ReadClassArray(il2Cpp.MapVATR(codeGenModule.customAttributeCacheGenerator), imageDef.customAttributeCount); - pointers.CopyTo(customAttributeGenerators, imageDef.customAttributeStart); + if (imageDef.customAttributeCount > 0) + { + var pointers = il2Cpp.ReadClassArray(il2Cpp.MapVATR(codeGenModule.customAttributeCacheGenerator), imageDef.customAttributeCount); + pointers.CopyTo(customAttributeGenerators, imageDef.customAttributeStart); + } } } else