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

SamboyCoding / Cpp2IL / 17216182984

25 Aug 2025 05:35PM UTC coverage: 30.38% (-4.0%) from 34.352%
17216182984

Pull #481

github

web-flow
Merge b82763a24 into d5260685f
Pull Request #481: Decompiler

1804 of 7561 branches covered (23.86%)

Branch coverage included in aggregate %.

100 of 1839 new or added lines in 29 files covered. (5.44%)

41 existing lines in 6 files now uncovered.

4093 of 11850 relevant lines covered (34.54%)

165575.01 hits per line

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

5.23
/Cpp2IL.Core/Extensions/MiscExtensions.cs
1
using System;
2
using System.Collections;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using Gee.External.Capstone.Arm;
7
using Gee.External.Capstone.Arm64;
8
using Iced.Intel;
9
using Instruction = Iced.Intel.Instruction;
10

11
namespace Cpp2IL.Core.Extensions;
12

13
public static class MiscExtensions
14
{
NEW
15
    public static object MakeIndependent(this Register reg) => new ISIL.Register(null, reg.ToString().ToLower());
×
16

17
    public static ulong GetImmediateSafe(this Instruction instruction, int op) => instruction.GetOpKind(op).IsImmediate() ? instruction.GetImmediate(op) : 0;
×
18

19
    public static bool IsJump(this Mnemonic mnemonic) => mnemonic is Mnemonic.Call or >= Mnemonic.Ja and <= Mnemonic.Js;
×
20
    public static bool IsConditionalJump(this Mnemonic mnemonic) => mnemonic.IsJump() && mnemonic != Mnemonic.Jmp && mnemonic != Mnemonic.Call;
×
21

22
    //Arm Extensions
23
    public static ArmRegister? RegisterSafe(this ArmOperand operand) => operand.Type != ArmOperandType.Register ? null : operand.Register;
×
24
    public static bool IsImmediate(this ArmOperand operand) => operand.Type is ArmOperandType.CImmediate or ArmOperandType.Immediate or ArmOperandType.PImmediate;
×
25
    public static int ImmediateSafe(this ArmOperand operand) => operand.IsImmediate() ? operand.Immediate : 0;
×
26
    private static ArmOperand? MemoryOperand(ArmInstruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == ArmOperandType.Memory);
×
27

28
    public static ArmRegister? MemoryBase(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Base;
×
29
    public static ArmRegister? MemoryIndex(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Index;
×
30
    public static int MemoryOffset(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Displacement ?? 0;
×
31

32
    //Arm64 Extensions
33
    public static Arm64Register? RegisterSafe(this Arm64Operand operand) => operand.Type != Arm64OperandType.Register ? null : operand.Register;
×
34
    public static bool IsImmediate(this Arm64Operand operand) => operand.Type is Arm64OperandType.CImmediate or Arm64OperandType.Immediate;
×
35
    public static long ImmediateSafe(this Arm64Operand operand) => operand.IsImmediate() ? operand.Immediate : 0;
×
36
    internal static Arm64Operand? MemoryOperand(this Arm64Instruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == Arm64OperandType.Memory);
×
37

38
    public static Arm64Register? MemoryBase(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Base;
×
39
    public static Arm64Register? MemoryIndex(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Index;
×
40
    public static int MemoryOffset(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Displacement ?? 0;
×
41

42
    public static bool IsConditionalMove(this Instruction instruction)
43
    {
44
        switch (instruction.Mnemonic)
×
45
        {
46
            case Mnemonic.Cmove:
47
            case Mnemonic.Cmovne:
48
            case Mnemonic.Cmovs:
49
            case Mnemonic.Cmovns:
50
            case Mnemonic.Cmovg:
51
            case Mnemonic.Cmovge:
52
            case Mnemonic.Cmovl:
53
            case Mnemonic.Cmovle:
54
            case Mnemonic.Cmova:
55
            case Mnemonic.Cmovae:
56
            case Mnemonic.Cmovb:
57
            case Mnemonic.Cmovbe:
58
                return true;
×
59
            default:
60
                return false;
×
61
        }
62
    }
63

64
    public static Stack<T> Clone<T>(this Stack<T> original)
65
    {
66
        var arr = new T[original.Count];
×
67
        original.CopyTo(arr, 0);
×
68
        Array.Reverse(arr);
×
69
        return new Stack<T>(arr);
×
70
    }
71

72
    public static List<T> Clone<T>(this List<T> original)
73
    {
74
        var arr = new T[original.Count];
×
75
        original.CopyTo(arr, 0);
×
NEW
76
        return [.. arr];
×
77
    }
78

79
    public static Dictionary<T1, T2> Clone<T1, T2>(this Dictionary<T1, T2> original) where T1 : notnull
80
        => new(original);
×
81

82
    public static T[] SubArray<T>(this T[] data, int index, int length) => data.SubArray(index..(index + length));
×
83

84
    public static T RemoveAndReturn<T>(this List<T> data, int index)
85
    {
86
        var result = data[index];
×
87
        data.RemoveAt(index);
×
88
        return result;
×
89
    }
90

91
    public static IEnumerable<T> Repeat<T>(this T t, int count)
92
    {
UNCOV
93
        for (int i = 0; i < count; i++)
×
94
        {
95
            yield return t;
×
96
        }
UNCOV
97
    }
×
98

99
    public static string Repeat(this string source, int count)
100
    {
101
        var res = new StringBuilder();
×
102
        for (var i = 0; i < count; i++)
×
103
        {
104
            res.Append(source);
×
105
        }
106

107
        return res.ToString();
×
108
    }
109

110
    internal static T[] SubArray<T>(this T[] source, Range range)
111
    {
112
        if (!range.Start.IsFromEnd && !range.End.IsFromEnd)
×
113
            if (range.Start.Value > range.End.Value)
×
114
                throw new Exception($"Range {range} - Start must be less than end, when both are fixed offsets");
×
115

116
        var (offset, len) = range.GetOffsetAndLength(source.Length);
×
117
        var dest = new T[len];
×
118

119
        Array.Copy(source, offset, dest, 0, len);
×
120

121
        return dest;
×
122
    }
123

124
    public static T? GetValueSafely<T>(this T[] arr, int i) where T : class
125
    {
126
        if (i >= arr.Length)
×
127
            return null;
×
128

129
        return arr[i];
×
130
    }
131

132
    public static bool IsImmediate(this OpKind opKind) => opKind is >= OpKind.Immediate8 and <= OpKind.Immediate32to64;
×
133

134

135
    public static void TrimEndWhile<T>(this List<T> instructions, Func<T, bool> predicate)
136
    {
137
        var i = instructions.Count - 1;
×
138
        for (; i >= 0; i--)
×
139
        {
140
            if (!predicate(instructions[i]))
×
141
            {
142
                break;
143
            }
144
        }
145

146
        var toRemove = instructions.Count - 1 - i;
×
147

148
        if (toRemove <= 0)
×
149
            return;
×
150

151
        instructions.RemoveRange(i, toRemove);
×
152
    }
×
153

154
    public static IEnumerable<T> Peek<T>(this IEnumerable<T> enumerable, Action<T> action)
155
    {
156
        return enumerable.Select(t =>
6,417✔
157
        {
6,417✔
158
            action(t);
16,788✔
159
            return t;
16,788✔
160
        });
6,417✔
161
    }
162

163
    public static unsafe uint ReadUInt(this Span<byte> span, int start)
164
    {
165
        if (start >= span.Length)
40,719,894!
166
            throw new ArgumentOutOfRangeException(nameof(start), $"start=[{start}], mem.Length=[{span.Length}]");
×
167
        fixed (byte* ptr = &span[start])
40,719,894✔
168
            return *(uint*)ptr;
40,719,894✔
169
    }
170

171
    public static bool BitsAreEqual(this BitArray first, BitArray second)
172
    {
173
        if (first.Count != second.Count)
×
174
            return false;
×
175

176
        bool areDifferent = false;
×
177
        for (int i = 0; i < first.Count && !areDifferent; i++)
×
178
            areDifferent = first.Get(i) != second.Get(i);
×
179

180
        return !areDifferent;
×
181
    }
182

183
    public static bool IsNumeric(this object value)
184
    {
NEW
185
        if (value == null) return false;
×
186

NEW
187
        return Type.GetTypeCode(value.GetType()) switch
×
NEW
188
        {
×
NEW
189
            TypeCode.Byte or TypeCode.SByte or TypeCode.UInt16 or
×
NEW
190
            TypeCode.UInt32 or TypeCode.UInt64 or TypeCode.Int16 or
×
NEW
191
            TypeCode.Int32 or TypeCode.Int64 or TypeCode.Decimal or
×
NEW
192
            TypeCode.Double or TypeCode.Single => true,
×
NEW
193
            _ => false,
×
NEW
194
        };
×
195
    }
196
}
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

© 2025 Coveralls, Inc