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

SamboyCoding / Cpp2IL / 20488056168

24 Dec 2025 02:19PM UTC coverage: 34.361% (+0.05%) from 34.31%
20488056168

Pull #499

github

web-flow
Merge 482cdd13f into 3a72c253a
Pull Request #499: Add ResolveContextForMethod overload taking Cpp2IlMethodRef as a parameter

1811 of 6624 branches covered (27.34%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 1 file covered. (0.0%)

187 existing lines in 10 files now uncovered.

4208 of 10893 relevant lines covered (38.63%)

201355.63 hits per line

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

69.12
/Cpp2IL.Core/Model/Contexts/AssemblyAnalysisContext.cs
1
using System;
2
using System.Collections.Concurrent;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Reflection;
6
using Cpp2IL.Core.Extensions;
7
using Cpp2IL.Core.Utils;
8
using LibCpp2IL.BinaryStructures;
9
using LibCpp2IL.Metadata;
10

11
namespace Cpp2IL.Core.Model.Contexts;
12

13
/// <summary>
14
/// Represents a single Assembly that was converted using IL2CPP.
15
/// </summary>
16
public class AssemblyAnalysisContext : HasCustomAttributesAndName
17
{
18
    /// <summary>
19
    /// The raw assembly metadata, such as its name, version, etc.
20
    /// </summary>
21
    public Il2CppAssemblyDefinition? Definition { get; set; }
3,492,979✔
22

23
    /// <summary>
24
    /// The analysis context objects for all types contained within the assembly, including those nested within a parent type.
25
    /// </summary>
26
    public List<TypeAnalysisContext> Types = [];
1,267✔
27

28
    /// <summary>
29
    /// The analysis context objects for all types contained within the assembly which are not nested within a parent type.
30
    /// </summary>
31
    public IEnumerable<TypeAnalysisContext> TopLevelTypes => Types.Where(t => t.DeclaringType == null);
14,840✔
32

33
    /// <summary>
34
    /// The code gen module for this assembly.
35
    ///
36
    /// Null prior to 24.2
37
    /// </summary>
38
    public Il2CppCodeGenModule? CodeGenModule;
39

40
    public virtual Version DefaultVersion
41
    {
42
        get
43
        {
44
            //handle __Generated assembly on v29, which has a version of 0.0.-1.-1
45
            return Definition is null || Definition.AssemblyName.build < 0
210!
46
                ? new(0,0,0,0)
210✔
47
                : new(Definition.AssemblyName.major, Definition.AssemblyName.minor, Definition.AssemblyName.build, Definition.AssemblyName.revision);
210✔
48
        }
49
    }
50
    public Version? OverrideVersion { get; set; }
210✔
51
    public Version Version
52
    {
53
        get => OverrideVersion ?? DefaultVersion;
210✔
UNCOV
54
        set => OverrideVersion = value;
×
55
    }
56

57
    public virtual uint DefaultHashAlgorithm => Definition?.AssemblyName.hash_alg ?? default;
210!
58
    public uint? OverrideHashAlgorithm { get; set; }
210✔
59
    public uint HashAlgorithm
60
    {
61
        get => OverrideHashAlgorithm ?? DefaultHashAlgorithm;
210!
UNCOV
62
        set => OverrideHashAlgorithm = value;
×
63
    }
64

65
    public virtual uint DefaultFlags => Definition?.AssemblyName.flags ?? default;
210!
66
    public uint? OverrideFlags { get; set; }
210✔
67
    public uint Flags
68
    {
69
        get => OverrideFlags ?? DefaultFlags;
210!
UNCOV
70
        set => OverrideFlags = value;
×
71
    }
72

73
    public virtual string? DefaultCulture => Definition?.AssemblyName.Culture;
210!
74
    /// <summary>
75
    /// Override <see cref="Culture"/>
76
    /// </summary>
77
    /// <remarks>
78
    /// <see langword="null""/> indicates no override, while an empty string indicates an explicit override to "no culture".
79
    /// </remarks>
80
    public string? OverrideCulture { get; set; }
210✔
81
    /// <summary>
82
    /// Gets or sets the culture
83
    /// </summary>
84
    /// <remarks>
85
    /// The get method will never return an empty string.
86
    /// </remarks>
87
    public string? Culture
88
    {
89
        get
90
        {
91
            var culture = OverrideCulture ?? DefaultCulture;
210✔
92
            return string.IsNullOrEmpty(culture) ? null : culture;
210!
93
        }
94
        set
95
        {
UNCOV
96
            OverrideCulture = value is null ? "" : value;
×
UNCOV
97
        }
×
98
    }
99

UNCOV
100
    public virtual byte[]? DefaultPublicKeyToken => Definition?.AssemblyName.PublicKeyToken;
×
101
    /// <summary>
102
    /// Override <see cref="PublicKeyToken"/>
103
    /// </summary>
104
    /// <remarks>
105
    /// <see langword="null""/> indicates no override, while an empty array indicates an explicit override to "no public key token".
106
    /// </remarks>
UNCOV
107
    public byte[]? OverridePublicKeyToken { get; set; }
×
108
    /// <summary>
109
    /// Gets or sets the public key token
110
    /// </summary>
111
    /// <remarks>
112
    /// The get method will never return an empty array.
113
    /// </remarks>
114
    public byte[]? PublicKeyToken
115
    {
116
        get
117
        {
UNCOV
118
            var data = OverridePublicKeyToken ?? DefaultPublicKeyToken;
×
UNCOV
119
            return data is null || data.Length == 0 ? null : data;
×
120
        }
121
        set
122
        {
UNCOV
123
            OverridePublicKeyToken = value is null ? [] : value;
×
UNCOV
124
        }
×
125
    }
126

127
    public virtual byte[]? DefaultPublicKey => Definition?.AssemblyName.PublicKey;
210!
128
    /// <summary>
129
    /// Override <see cref="PublicKey"/>
130
    /// </summary>
131
    /// <remarks>
132
    /// <see langword="null""/> indicates no override, while an empty array indicates an explicit override to "no public key".
133
    /// </remarks>
134
    public byte[]? OverridePublicKey { get; set; }
210✔
135
    /// <summary>
136
    /// Gets or sets the public key
137
    /// </summary>
138
    /// <remarks>
139
    /// The get method will never return an empty array.
140
    /// </remarks>
141
    public byte[]? PublicKey
142
    {
143
        get
144
        {
145
            var data = OverridePublicKey ?? DefaultPublicKey;
210✔
146
            return data is null || data.Length == 0 ? null : data;
210✔
147
        }
148
        set
149
        {
UNCOV
150
            OverridePublicKey = value is null ? [] : value;
×
UNCOV
151
        }
×
152
    }
153

154
    protected override int CustomAttributeIndex => Definition?.CustomAttributeIndex ?? -1;
1,050!
155

156
    public override AssemblyAnalysisContext CustomAttributeAssembly => this;
2,748✔
157

158
    private readonly Dictionary<string, TypeAnalysisContext> TypesByName = new();
1,267✔
159

160
    private readonly Dictionary<Il2CppTypeDefinition, TypeAnalysisContext> TypesByDefinition = new();
1,267✔
161

162
    /// <summary>
163
    /// Cache for <see cref="GenericInstanceTypeAnalysisContext.GetOrCreate(Il2CppType, AssemblyAnalysisContext)"/>
164
    /// </summary>
165
    internal readonly ConcurrentDictionary<Il2CppType, GenericInstanceTypeAnalysisContext> GenericInstanceTypesByIl2CppType = new();
1,267✔
166

167
    public override string DefaultName => Definition?.AssemblyName.Name ?? throw new($"Injected assemblies should override {nameof(DefaultName)}");
635!
168

169
    protected override bool IsInjected => Definition is null;
1,266✔
170

171
    /// <summary>
172
    /// Get assembly name without the extension and with any invalid path characters or elements removed.
173
    /// </summary>
174
    public string CleanAssemblyName => MiscUtils.CleanPathElement(Name);
210✔
175

176
    public AssemblyAnalysisContext(Il2CppAssemblyDefinition? assemblyDefinition, ApplicationAnalysisContext appContext) : base(assemblyDefinition?.Token ?? 0, appContext)
1,267✔
177
    {
178
        if (assemblyDefinition is null)
1,267✔
179
            return;
1✔
180

181
        Definition = assemblyDefinition;
1,266✔
182

183
        if (AppContext.MetadataVersion >= 24.2f)
1,266✔
184
            CodeGenModule = AppContext.Binary.GetCodegenModuleByName(Definition.Image.Name!);
1,266✔
185

186
        InitCustomAttributeData();
1,266✔
187

188
        foreach (var il2CppTypeDefinition in Definition.Image.Types!)
178,448✔
189
        {
190
            var typeContext = new TypeAnalysisContext(il2CppTypeDefinition, this);
87,958✔
191
            Types.Add(typeContext);
87,958✔
192
            TypesByName[il2CppTypeDefinition.FullName!] = typeContext;
87,958✔
193
            TypesByDefinition[il2CppTypeDefinition] = typeContext;
87,958✔
194
        }
195

196
        foreach (var type in Types)
178,448✔
197
        {
198
            if (type.Definition!.NestedTypeCount < 1)
87,958✔
199
                continue;
200

201
            type.NestedTypes = type.Definition.NestedTypes!.Select(n => GetTypeByFullName(n.FullName!) ?? throw new($"Unable to find nested type by name {n.FullName}"))
26,713!
202
                .Peek(t => t.DeclaringType = type)
19,324✔
203
                .ToList();
7,389✔
204
        }
205
    }
1,266✔
206

207
    public InjectedTypeAnalysisContext InjectType(string ns, string name, TypeAnalysisContext? baseType, TypeAttributes typeAttributes)
208
    {
209
        var ret = new InjectedTypeAnalysisContext(this, ns, name, baseType, typeAttributes);
336✔
210
        InjectType(ret);
336✔
211
        return ret;
336✔
212
    }
213

214
    internal void InjectType(InjectedTypeAnalysisContext ret)
215
    {
216
        Types.Add(ret);
379✔
217
        TypesByName[ret.FullName] = ret;
379✔
218
    }
379✔
219

220
    public TypeAnalysisContext? GetTypeByFullName(string fullName) => TypesByName.TryGetValue(fullName, out var typeContext) ? typeContext : null;
20,016✔
221

222
    public TypeAnalysisContext? GetTypeByDefinition(Il2CppTypeDefinition typeDefinition) => TypesByDefinition.TryGetValue(typeDefinition, out var typeContext) ? typeContext : null;
3,067,188!
223

UNCOV
224
    public override string ToString() => "Assembly: " + Name;
×
225
}
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