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

SamboyCoding / Cpp2IL / 30749432829

02 Aug 2026 01:12PM UTC coverage: 36.382% (+0.2%) from 36.169%
30749432829

push

github

SamboyCoding
Decompiler: Stop having operands be raw `object`-typed

2857 of 8963 branches covered (31.88%)

Branch coverage included in aggregate %.

78 of 217 new or added lines in 31 files covered. (35.94%)

7 existing lines in 3 files now uncovered.

5293 of 13438 relevant lines covered (39.39%)

164513.36 hits per line

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

0.0
/Cpp2IL.Core/Analysis/KeyFunctionRecovery.cs
1
using System.Collections.Generic;
2
using System.Linq;
3
using Cpp2IL.Core.Il2CppApiFunctions;
4
using Cpp2IL.Core.ISIL;
5
using Cpp2IL.Core.Model.Contexts;
6

7
namespace Cpp2IL.Core.Analysis;
8

9
/// <summary>
10
/// Maps calls to KeyFunctionAddresses to their underlying IL opcodes. E.g. il2cpp_codegen_object_new => newobj.
11
/// Eventually will include box/unbox/throw/etc
12
/// </summary>
13
public static class KeyFunctionRecovery
14
{
15
    //All of these have the same params in the same order so we treat them as equal.
16
    private static readonly HashSet<string> ObjectNewFunctions =
×
17
    [
×
18
        "il2cpp_object_new",
×
19
        "il2cpp_vm_object_new",
×
20
        "il2cpp_codegen_object_new",
×
21
    ];
×
22

23
    public static void Run(MethodAnalysisContext method)
24
    {
25
        foreach (var instruction in method.ControlFlowGraph!.Blocks.SelectMany(block => block.Instructions))
×
26
        {
NEW
27
            if (instruction.Operands is not [StringLiteral { Value: var keyFunction }, ..])
×
28
                continue;
29

30
            if (ObjectNewFunctions.Contains(keyFunction))
×
31
                RewriteObjectNew(instruction);
×
32
            else if (keyFunction == nameof(BaseKeyFunctionAddresses.il2cpp_codegen_write_barrier))
×
33
                RemoveWriteBarrier(instruction);
×
34
        }
35
    }
×
36

37
    private static void RemoveWriteBarrier(Instruction instruction)
38
    {
39
        instruction.OpCode = OpCode.Nop;
×
NEW
40
        instruction.SetOperands();
×
41
    }
×
42
    
43
    private static void RewriteObjectNew(Instruction instruction)
44
    {
45
        // Needs the function name, the result, and the class argument.
46
        if (instruction.OpCode != OpCode.Call || instruction.Operands.Count < 3)
×
47
            return;
×
48

49
        var result = instruction.Operands[1];
×
50
        var klass = instruction.Operands[2];
×
51

52
        instruction.OpCode = OpCode.Newobj;
×
NEW
53
        instruction.SetOperands(result, klass);
×
54
    }
×
55
}
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