Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in HasCustomAttribute affecting performance #405

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
private (long blobStart, long blobEnd)? GetV29BlobOffsets()
{
var target = new Il2CppCustomAttributeDataRange() { token = Token };
var caIndex = AppContext.Metadata.AttributeDataRanges.BinarySearch

Check warning on line 114 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build - Windows .NET Framework Zip

Dereference of a possibly null reference.

Check warning on line 114 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (osx-x64, Cpp2IL)

Dereference of a possibly null reference.

Check warning on line 114 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (linux-x64, Cpp2IL)

Dereference of a possibly null reference.

Check warning on line 114 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (win-x64, Cpp2IL)

Dereference of a possibly null reference.
(
CustomAttributeAssembly.Definition.Image.customAttributeStart,
(int)CustomAttributeAssembly.Definition.Image.customAttributeCount,
Expand All @@ -137,6 +137,13 @@
{
ulong generatorPtr;
if (AppContext.MetadataVersion < 27)
{
if (rangeIndex < 0)
{
RawIl2CppCustomAttributeData = Array.Empty<byte>();
return;
}

try
{
generatorPtr = AppContext.Binary.GetCustomAttributeGenerator(rangeIndex);
Expand All @@ -147,6 +154,7 @@
RawIl2CppCustomAttributeData = Array.Empty<byte>();
return;
}
}
else
{
var baseAddress = CustomAttributeAssembly.CodeGenModule!.customAttributeCacheGenerator;
Expand All @@ -157,7 +165,7 @@

if (generatorPtr == 0 || !AppContext.Binary.TryMapVirtualAddressToRaw(generatorPtr, out _))
{
Logger.WarnNewline($"Supposedly had custom attributes ({string.Join(", ", AttributeTypes)}), but generator was null for " + this, "CA Restore");

Check warning on line 168 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (osx-x64, Cpp2IL)

Possible null reference argument for parameter 'values' in 'string string.Join<Il2CppType>(string? separator, IEnumerable<Il2CppType> values)'.

Check warning on line 168 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (linux-x64, Cpp2IL)

Possible null reference argument for parameter 'values' in 'string string.Join<Il2CppType>(string? separator, IEnumerable<Il2CppType> values)'.

Check warning on line 168 in Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (win-x64, Cpp2IL)

Possible null reference argument for parameter 'values' in 'string string.Join<Il2CppType>(string? separator, IEnumerable<Il2CppType> values)'.
RawIl2CppCustomAttributeData = Memory<byte>.Empty;
return;
}
Expand Down Expand Up @@ -204,7 +212,7 @@

//Basically, extract actions from the analysis, and compare with the type list we have to resolve parameters and populate the CustomAttributes list.

foreach (var il2CppType in AttributeTypes!) //Assert nonnull because we're pre-29 at this point
foreach (var il2CppType in AttributeTypes ?? []) //Can be null for injected objects
{
var typeDef = il2CppType.AsClass();
var attributeTypeContext = AppContext.ResolveContextForType(typeDef) ?? throw new("Unable to find type " + typeDef.FullName);
Expand Down
Loading