From 4f074837b73386036d54d7d23c284bb30ece6f14 Mon Sep 17 00:00:00 2001 From: Robert Xiao Date: Tue, 7 Apr 2020 02:11:20 -0700 Subject: [PATCH] Fix fieldOffsetsArePointers logic on 64-bit builds The logic for fieldOffsetsArePointers was always reading 32-bit units even on 64-bits. When fieldOffsetsArePointers is true, fieldOffsets is declared as int32_t**, so each element *must* be a pointer and therefore word-sized (64 bits on 64-bit machines). So it doesn't make sense to only read 32-bit words for this test. This fixes metadata extraction for 64-bit builds from Il2Cpp versions 5.3.7f1, 5.3.8f2, 5.4.1f1, 5.4.2f2, 5.4.3f1, 5.4.4f1, 5.4.5f1 and 5.4.6f3. Notably, 5.4.0f3 is an unusual outlier which uses int32_t * for fieldOffsets. --- Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs index eda8513..7fbf8c6 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs @@ -207,8 +207,7 @@ namespace Il2CppInspector // Some variants of 21 also use an array of pointers if (image.Version == 21) { - // Always 4-byte values even for 64-bit builds when array is NOT pointers - var fieldTest = image.ReadMappedArray(MetadataRegistration.pfieldOffsets, 6); + var fieldTest = image.ReadMappedWordArray(MetadataRegistration.pfieldOffsets, 6); // We detect this by relying on the fact Module, Object, ValueType, Attribute, _Attribute and Int32 // are always the first six defined types, and that all but Int32 have no fields