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

SamboyCoding / Cpp2IL / 30751767570

02 Aug 2026 02:17PM UTC coverage: 35.984% (-0.4%) from 36.382%
30751767570

push

github

SamboyCoding
Decompiler: Remove implicit null checks, resolve fields on generics, resolve generic methods which aren't in the metadata by address if we can

2857 of 9122 branches covered (31.32%)

Branch coverage included in aggregate %.

0 of 108 new or added lines in 4 files covered. (0.0%)

2 existing lines in 2 files now uncovered.

5293 of 13527 relevant lines covered (39.13%)

163430.95 hits per line

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

0.0
/Cpp2IL.Core/Analysis/GenericInstanceFieldLayout.cs
1
using System.Linq;
2
using Cpp2IL.Core.Model.Contexts;
3

4
namespace Cpp2IL.Core.Analysis;
5

6
//Resolves field offsets on generic instances, which are all 0 in the metadata.
7
public static class GenericInstanceFieldLayout
8
{
9
    public static FieldAnalysisContext? FindFieldAtOffset(GenericInstanceTypeAnalysisContext type, long targetOffset)
10
    {
NEW
11
        var definition = type.GenericType;
×
NEW
12
        var pointerSize = type.AppContext.Binary.PointerSizeBytes;
×
13

14
        // TODO Support anything outside the trivial case.
NEW
15
        for (var baseType = definition.BaseType; baseType != null; baseType = baseType.BaseType)
×
NEW
16
            if (baseType.Fields.Any(f => !f.IsStatic))
×
NEW
17
                return null;
×
18

NEW
19
        var offset = 2L * pointerSize;
×
20

NEW
21
        foreach (var field in definition.Fields)
×
22
        {
NEW
23
            if (field.IsStatic)
×
24
                continue;
25

NEW
26
            if (GetSizeAndAlignment(field.FieldType, pointerSize) is not var (size, alignment))
×
NEW
27
                return null;
×
28

NEW
29
            offset = (offset + alignment - 1) & ~(alignment - 1);
×
30

NEW
31
            if (offset == targetOffset)
×
NEW
32
                return field;
×
33

NEW
34
            offset += size;
×
35
        }
36

NEW
37
        return null;
×
NEW
38
    }
×
39

40
    private static (long Size, long Alignment)? GetSizeAndAlignment(TypeAnalysisContext fieldType, int pointerSize)
41
    {
42
        // TODO support user-defined value types
NEW
43
        if (fieldType is GenericParameterTypeAnalysisContext or PointerTypeAnalysisContext || !fieldType.IsValueType)
×
NEW
44
            return (pointerSize, pointerSize);
×
45

NEW
46
        if (fieldType.IsEnumType && fieldType.Fields.FirstOrDefault(f => !f.IsStatic) is { } underlying)
×
NEW
47
            return GetSizeAndAlignment(underlying.FieldType, pointerSize);
×
48

NEW
49
        return fieldType.FullName switch
×
NEW
50
        {
×
NEW
51
            "System.Boolean" or "System.Byte" or "System.SByte" => (1, 1),
×
NEW
52
            "System.Int16" or "System.UInt16" or "System.Char" => (2, 2),
×
NEW
53
            "System.Int32" or "System.UInt32" or "System.Single" => (4, 4),
×
NEW
54
            "System.Int64" or "System.UInt64" or "System.Double" => (8, 8),
×
NEW
55
            "System.IntPtr" or "System.UIntPtr" => (pointerSize, pointerSize),
×
NEW
56
            _ => null // an arbitrary struct needs its own layout computed, bail rather than guess
×
NEW
57
        };
×
58
    }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc