IL2CPP: Eliminate public BinaryMetadataUsages

This commit is contained in:
Katy Coe
2020-02-02 23:03:38 +01:00
parent c43f92b1e2
commit 3e69784898
3 changed files with 14 additions and 11 deletions

View File

@@ -78,12 +78,11 @@ def SetName(addr, name):
private void writeUsages() { private void writeUsages() {
foreach (var usage in model.Package.MetadataUsages) { foreach (var usage in model.Package.MetadataUsages) {
var escapedName = model.GetMetadataUsageName(usage).ToEscapedString(); var escapedName = model.GetMetadataUsageName(usage).ToEscapedString();
var address = model.Package.BinaryMetadataUsages[usage.DestinationIndex];
if (usage.Type != MetadataUsageType.StringLiteral) if (usage.Type != MetadataUsageType.StringLiteral)
writeLines($"SetName({address.ToAddressString()}, '{usagePrefixes[usage.Type]}${escapedName}')"); writeLines($"SetName({usage.VirtualAddress.ToAddressString()}, '{usagePrefixes[usage.Type]}${escapedName}')");
else else
writeLines($"SetString({address.ToAddressString()}, r'{escapedName}')"); writeLines($"SetString({usage.VirtualAddress.ToAddressString()}, r'{escapedName}')");
} }
} }

View File

@@ -27,7 +27,6 @@ namespace Il2CppInspector
// Merged list of all metadata usage references // Merged list of all metadata usage references
public List<MetadataUsage> MetadataUsages { get; } public List<MetadataUsage> MetadataUsages { get; }
public ulong[] BinaryMetadataUsages { get; } // TODO: Make private
// Shortcuts // Shortcuts
public double Version => Metadata.Version; public double Version => Metadata.Version;
@@ -143,6 +142,14 @@ namespace Il2CppInspector
usages.TryAdd(destinationIndex, new MetadataUsage(usageType, (int)sourceIndex, (int)destinationIndex)); 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<ulong>(Binary.MetadataRegistration.metadataUsages, usages.Count);
foreach (var usage in usages.Values)
usage.SetAddress(addresses[usage.DestinationIndex]);
return usages.Values.ToList(); return usages.Values.ToList();
} }
@@ -221,14 +228,8 @@ namespace Il2CppInspector
} }
// Merge all metadata usage references into a single distinct list // Merge all metadata usage references into a single distinct list
if (Version >= 19) { if (Version >= 19)
MetadataUsages = buildMetadataUsages(); 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<ulong>(Binary.MetadataRegistration.metadataUsages, MetadataUsages.Count);
}
} }
// Get a method pointer if available // Get a method pointer if available

View File

@@ -22,11 +22,14 @@ namespace Il2CppInspector
public MetadataUsageType Type { get; } public MetadataUsageType Type { get; }
public int SourceIndex { get; } public int SourceIndex { get; }
public int DestinationIndex { get; } public int DestinationIndex { get; }
public ulong VirtualAddress { get; private set; }
public MetadataUsage(MetadataUsageType type, int sourceIndex, int destinationIndex) { public MetadataUsage(MetadataUsageType type, int sourceIndex, int destinationIndex) {
Type = type; Type = type;
SourceIndex = sourceIndex; SourceIndex = sourceIndex;
DestinationIndex = destinationIndex; DestinationIndex = destinationIndex;
} }
public void SetAddress(ulong virtualAddress) => VirtualAddress = virtualAddress;
} }
} }