From 3e69784898b354cdcf347a18c1dd161486c7256a Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sun, 2 Feb 2020 23:03:38 +0100 Subject: [PATCH] IL2CPP: Eliminate public BinaryMetadataUsages --- Il2CppDumper/Il2CppIDAScriptDumper.cs | 5 ++--- Il2CppInspector/IL2CPP/Il2CppInspector.cs | 17 +++++++++-------- Il2CppInspector/IL2CPP/MetadataUsage.cs | 3 +++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Il2CppDumper/Il2CppIDAScriptDumper.cs b/Il2CppDumper/Il2CppIDAScriptDumper.cs index a73dd23..5c9b8c1 100644 --- a/Il2CppDumper/Il2CppIDAScriptDumper.cs +++ b/Il2CppDumper/Il2CppIDAScriptDumper.cs @@ -78,12 +78,11 @@ def SetName(addr, name): private void writeUsages() { foreach (var usage in model.Package.MetadataUsages) { var escapedName = model.GetMetadataUsageName(usage).ToEscapedString(); - var address = model.Package.BinaryMetadataUsages[usage.DestinationIndex]; if (usage.Type != MetadataUsageType.StringLiteral) - writeLines($"SetName({address.ToAddressString()}, '{usagePrefixes[usage.Type]}${escapedName}')"); + writeLines($"SetName({usage.VirtualAddress.ToAddressString()}, '{usagePrefixes[usage.Type]}${escapedName}')"); else - writeLines($"SetString({address.ToAddressString()}, r'{escapedName}')"); + writeLines($"SetString({usage.VirtualAddress.ToAddressString()}, r'{escapedName}')"); } } diff --git a/Il2CppInspector/IL2CPP/Il2CppInspector.cs b/Il2CppInspector/IL2CPP/Il2CppInspector.cs index dae3f3a..3f2a329 100644 --- a/Il2CppInspector/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector/IL2CPP/Il2CppInspector.cs @@ -27,7 +27,6 @@ namespace Il2CppInspector // Merged list of all metadata usage references public List MetadataUsages { get; } - public ulong[] BinaryMetadataUsages { get; } // TODO: Make private // Shortcuts public double Version => Metadata.Version; @@ -143,6 +142,14 @@ namespace Il2CppInspector usages.TryAdd(destinationIndex, new MetadataUsage(usageType, (int)sourceIndex, (int)destinationIndex)); } } + + // Metadata usages (addresses) + // 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 + var addresses = Binary.Image.ReadMappedArray(Binary.MetadataRegistration.metadataUsages, usages.Count); + foreach (var usage in usages.Values) + usage.SetAddress(addresses[usage.DestinationIndex]); + return usages.Values.ToList(); } @@ -221,14 +228,8 @@ namespace Il2CppInspector } // Merge all metadata usage references into a single distinct list - if (Version >= 19) { + if (Version >= 19) MetadataUsages = buildMetadataUsages(); - - // Metadata usages (addresses) - // 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 - BinaryMetadataUsages = Binary.Image.ReadMappedArray(Binary.MetadataRegistration.metadataUsages, MetadataUsages.Count); - } } // Get a method pointer if available diff --git a/Il2CppInspector/IL2CPP/MetadataUsage.cs b/Il2CppInspector/IL2CPP/MetadataUsage.cs index 2966111..fa24fdc 100644 --- a/Il2CppInspector/IL2CPP/MetadataUsage.cs +++ b/Il2CppInspector/IL2CPP/MetadataUsage.cs @@ -22,11 +22,14 @@ namespace Il2CppInspector public MetadataUsageType Type { get; } public int SourceIndex { get; } public int DestinationIndex { get; } + public ulong VirtualAddress { get; private set; } public MetadataUsage(MetadataUsageType type, int sourceIndex, int destinationIndex) { Type = type; SourceIndex = sourceIndex; DestinationIndex = destinationIndex; } + + public void SetAddress(ulong virtualAddress) => VirtualAddress = virtualAddress; } } \ No newline at end of file