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

SamboyCoding / Cpp2IL / 30166321939

25 Jul 2026 04:47PM UTC coverage: 37.297% (-0.2%) from 37.493%
30166321939

push

github

SamboyCoding
Decompiler: Find and remove write barriers

2875 of 8674 branches covered (33.15%)

Branch coverage included in aggregate %.

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

2 existing lines in 1 file now uncovered.

5271 of 13167 relevant lines covered (40.03%)

167893.48 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
        {
27
            if (instruction.Operands is not [string keyFunction, ..])
×
28
                continue;
29

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

37
    private static void RemoveWriteBarrier(Instruction instruction)
38
    {
NEW
39
        instruction.OpCode = OpCode.Nop;
×
NEW
40
        instruction.Operands = [];
×
NEW
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;
×
53
        instruction.Operands = [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