• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SamboyCoding / Cpp2IL / 10648892934

31 Aug 2024 11:02PM UTC coverage: 29.103% (-0.02%) from 29.124%
10648892934

push

github

SamboyCoding
Core: Support "v29.2"'s isUnmanagedCallersOnly the *correct* way

1227 of 5825 branches covered (21.06%)

Branch coverage included in aggregate %.

1 of 7 new or added lines in 2 files covered. (14.29%)

30 existing lines in 2 files now uncovered.

3314 of 9778 relevant lines covered (33.89%)

104609.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.06
/LibCpp2IL/Metadata/Il2CppMethodDefinition.cs
1
using System;
2
using System.Diagnostics;
3
using System.Linq;
4
using System.Reflection;
5
using LibCpp2IL.BinaryStructures;
6
using LibCpp2IL.Logging;
7
using LibCpp2IL.Reflection;
8

9
namespace LibCpp2IL.Metadata;
10

11
public class Il2CppMethodDefinition : ReadableClass
12
{
13
    public int nameIndex;
14
    public int declaringTypeIdx;
15
    public int returnTypeIdx;
16
    [Version(Min = 31)] public uint returnParameterToken;
17
    public int parameterStart;
18
    [Version(Max = 24)] public int customAttributeIndex;
19
    public int genericContainerIndex;
20
    [Version(Max = 24.15f)] public int methodIndex;
21
    [Version(Max = 24.15f)] public int invokerIndex;
22
    [Version(Max = 24.15f)] public int delegateWrapperIndex;
23
    [Version(Max = 24.15f)] public int rgctxStartIndex;
24
    [Version(Max = 24.15f)] public int rgctxCount;
25
    public uint token;
26
    public ushort flags;
27
    public ushort iflags;
28
    public ushort slot;
29
    public ushort parameterCount;
30

31
    public MethodAttributes Attributes => (MethodAttributes)flags;
173,058✔
32

UNCOV
33
    public bool IsStatic => (Attributes & MethodAttributes.Static) != 0;
×
34

35
    public int MethodIndex => LibCpp2IlReflection.GetMethodIndexFromMethod(this);
178,890✔
36

37
    public string? Name { get; private set; }
828,360✔
38

UNCOV
39
    public string? GlobalKey => DeclaringType == null ? null : DeclaringType.Name + "." + Name + "()";
×
40

UNCOV
41
    public Il2CppType? RawReturnType => LibCpp2IlMain.Binary?.GetType(returnTypeIdx);
×
42

UNCOV
43
    public Il2CppTypeReflectionData? ReturnType => LibCpp2IlMain.Binary == null ? null : LibCpp2ILUtils.GetTypeReflectionData(LibCpp2IlMain.Binary.GetType(returnTypeIdx));
×
44

45
    public Il2CppTypeDefinition? DeclaringType => LibCpp2IlMain.TheMetadata == null ? null : LibCpp2IlMain.TheMetadata.typeDefs[declaringTypeIdx];
627,144!
46

47
    private ulong? _methodPointer = null;
48

49
    public ulong MethodPointer
50
    {
51
        get
52
        {
53
            if (!_methodPointer.HasValue)
888,636✔
54
            {
55
                if (LibCpp2IlMain.Binary == null || LibCpp2IlMain.TheMetadata == null || DeclaringType == null)
178,890!
56
                {
UNCOV
57
                    LibLogger.WarnNewline($"Couldn't get method pointer for {Name}. Binary is {LibCpp2IlMain.Binary}, Meta is {LibCpp2IlMain.TheMetadata}, DeclaringType is {DeclaringType}");
×
58
                    return 0;
×
59
                }
60

61
                var asmIdx = 0; //Not needed pre-24.2
178,890✔
62
                if (LibCpp2IlMain.MetadataVersion >= 27)
178,890✔
63
                {
64
                    asmIdx = LibCpp2IlMain.Binary.GetCodegenModuleIndexByName(DeclaringType!.DeclaringAssembly!.Name!);
74,454✔
65
                }
66
                else if (LibCpp2IlMain.MetadataVersion >= 24.2f)
104,436✔
67
                {
68
                    asmIdx = DeclaringType!.DeclaringAssembly!.assemblyIndex;
104,436✔
69
                }
70

71
                _methodPointer = LibCpp2IlMain.Binary.GetMethodPointer(methodIndex, MethodIndex, asmIdx, token);
178,890✔
72
            }
73

74
            return _methodPointer.Value;
888,636✔
75
        }
76
    }
77

UNCOV
78
    public long MethodOffsetInFile => MethodPointer == 0 || LibCpp2IlMain.Binary == null ? 0 : LibCpp2IlMain.Binary.TryMapVirtualAddressToRaw(MethodPointer, out var ret) ? ret : 0;
×
79

UNCOV
80
    public ulong Rva => MethodPointer == 0 || LibCpp2IlMain.Binary == null ? 0 : LibCpp2IlMain.Binary.GetRva(MethodPointer);
×
81

UNCOV
82
    public string? HumanReadableSignature => ReturnType == null || Parameters == null || Name == null ? null : $"{ReturnType} {Name}({string.Join(", ", Parameters.AsEnumerable())})";
×
83

84
    public Il2CppParameterDefinition[]? InternalParameterData
85
    {
86
        get
87
        {
88
            if (LibCpp2IlMain.TheMetadata == null || LibCpp2IlMain.Binary == null)
599,970!
UNCOV
89
                return null;
×
90

91
            if (parameterStart < 0 || parameterCount == 0)
599,970✔
92
                return [];
69,000✔
93

94
            var ret = new Il2CppParameterDefinition[parameterCount];
530,970✔
95

96
            Array.Copy(LibCpp2IlMain.TheMetadata.parameterDefs, parameterStart, ret, 0, parameterCount);
530,970✔
97

98
            return ret;
530,970✔
99
        }
100
    }
101

UNCOV
102
    public Il2CppType[]? InternalParameterTypes => InternalParameterData == null
×
103
        ? null
×
104
        : InternalParameterData.Select(paramDef => LibCpp2IlMain.Binary!.GetType(paramDef.typeIndex))
×
105
            .ToArray();
×
106

107
    private Il2CppParameterReflectionData[]? _cachedParameters;
108

109
    public Il2CppParameterReflectionData[]? Parameters
110
    {
111
        get
112
        {
UNCOV
113
            if (_cachedParameters == null && InternalParameterData != null)
×
114
            {
UNCOV
115
                _cachedParameters = InternalParameterData
×
116
                    .Select((paramDef, idx) =>
×
117
                    {
×
118
                        var paramType = LibCpp2IlMain.Binary!.GetType(paramDef.typeIndex);
×
119
                        var paramFlags = (ParameterAttributes)paramType.Attrs;
×
120
                        var paramDefaultData = (paramFlags & ParameterAttributes.HasDefault) != 0 ? LibCpp2IlMain.TheMetadata!.GetParameterDefaultValueFromIndex(parameterStart + idx) : null;
×
121
                        return new Il2CppParameterReflectionData
×
122
                        {
×
123
                            Type = LibCpp2ILUtils.GetTypeReflectionData(paramType)!,
×
124
                            ParameterName = LibCpp2IlMain.TheMetadata!.GetStringFromIndex(paramDef.nameIndex),
×
125
                            Attributes = paramFlags,
×
126
                            RawType = paramType,
×
127
                            DefaultValue = paramDefaultData == null ? null : LibCpp2ILUtils.GetDefaultValue(paramDefaultData.dataIndex, paramDefaultData.typeIndex),
×
128
                            ParameterIndex = idx,
×
129
                        };
×
130
                    }).ToArray();
×
131
            }
132

UNCOV
133
            return _cachedParameters;
×
134
        }
135
    }
136

UNCOV
137
    public Il2CppGenericContainer? GenericContainer => genericContainerIndex < 0 ? null : LibCpp2IlMain.TheMetadata?.genericContainers[genericContainerIndex];
×
138

UNCOV
139
    public bool IsUnmanagedCallersOnly => (iflags & 0xF000) != 0;
×
140
    
UNCOV
141
    public MethodImplAttributes MethodImplAttributes => (MethodImplAttributes)(iflags & ~0xF000);
×
142

143
    public override string? ToString()
144
    {
145
        if (LibCpp2IlMain.TheMetadata == null)
×
UNCOV
146
            return base.ToString();
×
147

UNCOV
148
        return $"Il2CppMethodDefinition[Name='{Name}', ReturnType={ReturnType}, DeclaringType={DeclaringType}]";
×
149
    }
150

151
    public override void Read(ClassReadingBinaryReader reader)
152
    {
153
        nameIndex = reader.ReadInt32();
828,342✔
154

155
        //Cache name now
156
        var pos = reader.Position;
828,342✔
157
        Name = ((Il2CppMetadata)reader).ReadStringFromIndexNoReadLock(nameIndex);
828,342✔
158
        reader.Position = pos;
828,342✔
159

160
        declaringTypeIdx = reader.ReadInt32();
828,342✔
161
        returnTypeIdx = reader.ReadInt32();
828,342✔
162

163
        if (IsAtLeast(31))
828,342✔
164
            returnParameterToken = reader.ReadUInt32();
74,454✔
165

166
        parameterStart = reader.ReadInt32();
828,342✔
167

168
        if (IsAtMost(24))
828,342!
UNCOV
169
            customAttributeIndex = reader.ReadInt32();
×
170

171
        genericContainerIndex = reader.ReadInt32();
828,342✔
172

173
        if (IsAtMost(24.15f))
828,342✔
174
        {
175
            methodIndex = reader.ReadInt32();
177,366✔
176
            invokerIndex = reader.ReadInt32();
177,366✔
177
            delegateWrapperIndex = reader.ReadInt32();
177,366✔
178
            rgctxStartIndex = reader.ReadInt32();
177,366✔
179
            rgctxCount = reader.ReadInt32();
177,366✔
180
        }
181

182
        token = reader.ReadUInt32();
828,342✔
183

184
        flags = reader.ReadUInt16();
828,342✔
185
        iflags = reader.ReadUInt16();
828,342✔
186
        slot = reader.ReadUInt16();
828,342✔
187
        parameterCount = reader.ReadUInt16();
828,342✔
188
    }
828,342✔
189
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc