IL2CPP: Fix edge case where max metadata dest index can be greater than usagesCount (#110)

This commit is contained in:
Katy Coe
2020-12-15 16:13:24 +01:00
parent 64649d9f55
commit a3a06d807a

View File

@@ -151,7 +151,8 @@ namespace Il2CppInspector
// Metadata usages (addresses) // Metadata usages (addresses)
// Unfortunately the value supplied in MetadataRegistration.matadataUsagesCount seems to be incorrect, // Unfortunately the value supplied in MetadataRegistration.matadataUsagesCount seems to be incorrect,
// so we have to calculate the correct number of usages above before reading the usage address list from the binary // so we have to calculate the correct number of usages above before reading the usage address list from the binary
var addresses = Binary.Image.ReadMappedArray<ulong>(Binary.MetadataRegistration.metadataUsages, usages.Count); var count = usages.Keys.Max() + 1;
var addresses = Binary.Image.ReadMappedArray<ulong>(Binary.MetadataRegistration.metadataUsages, (int) count);
foreach (var usage in usages) foreach (var usage in usages)
usage.Value.SetAddress(addresses[usage.Key]); usage.Value.SetAddress(addresses[usage.Key]);