Skip to content

Commit

Permalink
Fix metadata usage issues caused by it being a value type now
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeFZ committed Nov 8, 2024
1 parent 5715760 commit 08431b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
17 changes: 8 additions & 9 deletions Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ private List<MetadataUsage> buildMetadataUsages()
return buildLateBindingMetadataUsages();

// Version >= 19 && < 27
var usages = new Dictionary<uint, MetadataUsage>();
var usages = new Dictionary<uint, uint>();
foreach (var metadataUsageList in Metadata.MetadataUsageLists)
{
for (var i = 0; i < metadataUsageList.Count; i++)
{
var metadataUsagePair = Metadata.MetadataUsagePairs[metadataUsageList.Start + i];
usages.TryAdd(metadataUsagePair.DestinationIndex, MetadataUsage.FromEncodedIndex(this, metadataUsagePair.EncodedSourceIndex));
usages.TryAdd(metadataUsagePair.DestinationIndex, metadataUsagePair.EncodedSourceIndex);
}
}

Expand All @@ -123,10 +123,12 @@ private List<MetadataUsage> buildMetadataUsages()
// so we have to calculate the correct number of usages above before reading the usage address list from the binary
var count = usages.Keys.Max() + 1;
var addresses = Binary.Image.ReadMappedUWordArray(Binary.MetadataRegistration.MetadataUsages, (int) count);
foreach (var usage in usages)
usage.Value.SetAddress(addresses[usage.Key]);

return usages.Values.ToList();
var metadataUsages = new List<MetadataUsage>();
foreach (var (index, encodedUsage) in usages)
metadataUsages.Add(MetadataUsage.FromEncodedIndex(this, encodedUsage, addresses[index]));

return metadataUsages;
}

private List<MetadataUsage> buildLateBindingMetadataUsages()
Expand All @@ -149,10 +151,7 @@ private List<MetadataUsage> buildLateBindingMetadataUsages()

if (CheckMetadataUsageSanity(usage)
&& BinaryImage.TryMapFileOffsetToVA(i * ((uint)BinaryImage.Bits / 8), out var va))
{
usage.SetAddress(va);
usages.Add(usage);
}
usages.Add(MetadataUsage.FromEncodedIndex(this, encodedToken, va));
}
}

Expand Down
4 changes: 1 addition & 3 deletions Il2CppInspector.Common/IL2CPP/MetadataUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public record struct MetadataUsage
{
public MetadataUsageType Type { get; }
public int SourceIndex { get; }
public ulong VirtualAddress { get; private set; }
public ulong VirtualAddress { get; }

public readonly bool IsValid => Type != 0;

Expand Down Expand Up @@ -55,7 +55,5 @@ public static MetadataUsage FromEncodedIndex(Il2CppInspector package, uint encod
}
return new MetadataUsage(usageType, (int)index, virtualAddress);
}

public void SetAddress(ulong virtualAddress) => VirtualAddress = virtualAddress;
}
}
3 changes: 2 additions & 1 deletion Il2CppInspector.Common/Model/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private string Group {
}

// Initialize
public AppModel(TypeModel model, bool makeDefaultBuild = true) {
public AppModel(TypeModel model, bool makeDefaultBuild = true)
{
// Save .NET type model
TypeModel = model;

Expand Down

0 comments on commit 08431b7

Please sign in to comment.