SamboyCoding / Cpp2IL

Work-in-progress tool to reverse unity's IL2CPP toolchain.
MIT License
1.56k stars 178 forks source link

`object` instead of `Type` in Call Analysis Attributes #264

Closed ds5678 closed 6 months ago

ds5678 commented 6 months ago

Currently, Call Analysis generates attributes like this:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class CallsAttribute : Attribute
{
    public Type Type;

    public string TypeFullName;

    public string Member;

    public Type[] MemberTypeParameters;

    public Type[] MemberParameters;
}

//Normal attribute
[Calls(Type = typeof(Path), Member = "Combine", MemberParameters = new Type[] { typeof(string), typeof(string) } )]

//Generic parameter could not be resolved because of deduplication.
[Calls(Type = typeof(List<>), Member = "get_Item", MemberParameters = new Type[] { null })]

//Types are inaccessible at this attribute location.
[CalledBy(TypeFullName = "SomeNamespace.SomeClass", Member = "SomeGenericMethod", MemberTypeParameters = new Type[] { null }, MemberParameters = new Type[] { null, typeof(string) })]

This can be improved:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class CallsAttribute : Attribute
{
    public object Type; //object instead of Type

    //TypeFullName has been removed.

    public string Member;

    public object[] MemberTypeParameters; //object[] instead of Type[]

    public object[] MemberParameters; //object[] instead of Type[]
}

//Normal attribute
[Calls(Type = typeof(Path), Member = "Combine", MemberParameters = new object[] { typeof(string), typeof(string) } )]

//Generic parameter could not be resolved because of deduplication.
[Calls(Type = typeof(List<>), Member = "get_Item", MemberParameters = new object[] { "T" })]

//Types are inaccessible at this attribute location.
[CalledBy(Type = "SomeNamespace.SomeClass", Member = "SomeGenericMethod", MemberTypeParameters = new object[] { "SomeNamespace.SomeOtherType" }, MemberParameters = new object[] { "UnityEngine.GameObject", typeof(string) })]