Skip to content

Commit 7fd18c9

Browse files
sunnamed434claude
andcommitted
Fix crossed deprecated / obfuscation-attribute skip log messages
ProtectionsSorter passed obfuscationAttributeProtections and deprecatedProtections to the ProtectionsSort constructor in the wrong order, so DeprecatedProtections held the obfuscation-attribute-excluded ones and vice versa. ProtectionsNotifier then logged each list under the other's message ('Skip deprecated protection(s)' vs 'Skip protection(s) with obfuscation attribute'). Swap the arguments to match the parameter order, and add a regression test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b137201 commit 7fd18c9

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/BitMono.Obfuscation/Protections/ProtectionsSorter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public ProtectionsSort Sort(List<IProtection> protections, IEnumerable<Protectio
5757
sortedProtections.ToList(),
5858
pipelineProtections.ToList(),
5959
packers.ToList(),
60-
obfuscationAttributeProtections.ToList(),
6160
deprecatedProtections.ToList(),
61+
obfuscationAttributeProtections.ToList(),
6262
configureForNativeCodeProtections.ToList(),
6363
runtimeMonikerProtections.ToList(),
6464
il2cppExcludedProtections,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using BitMono.API.Protections;
5+
using BitMono.Core.Extensions;
6+
using BitMono.Core.Resolvers;
7+
using BitMono.Obfuscation.Protections;
8+
using BitMono.Shared.Models;
9+
10+
namespace BitMono.Obfuscation.Tests.Protections;
11+
12+
public class ProtectionsSorterTests
13+
{
14+
private static ProtectionsSorter CreateSorter()
15+
{
16+
var resolver = new ObfuscationAttributeResolver(new ObfuscationSettings());
17+
var assembly = new AssemblyDefinition("Test", new Version(1, 0, 0, 0));
18+
return new ProtectionsSorter(resolver, assembly);
19+
}
20+
21+
// A deprecated ([Obsolete]) protection must land in DeprecatedProtections, not in
22+
// ObfuscationAttributeExcludeProtections - otherwise the "Skip deprecated" and "Skip ... obfuscation
23+
// attribute" log lines are crossed.
24+
[Fact]
25+
public void DeprecatedProtection_GoesIntoDeprecatedBucket_NotObfuscationAttributeBucket()
26+
{
27+
var sorter = CreateSorter();
28+
#pragma warning disable CS0612
29+
var deprecated = new DeprecatedDouble();
30+
#pragma warning restore CS0612
31+
var protections = new List<IProtection> { new ActiveDouble(), deprecated };
32+
var settings = new List<ProtectionSetting>
33+
{
34+
new() { Name = nameof(ActiveDouble), Enabled = true },
35+
new() { Name = nameof(DeprecatedDouble), Enabled = true },
36+
};
37+
38+
var sort = sorter.Sort(protections, settings);
39+
40+
sort.DeprecatedProtections.Select(p => p.GetName()).Should().Equal(nameof(DeprecatedDouble));
41+
sort.ObfuscationAttributeExcludeProtections.Should().BeEmpty();
42+
sort.SortedProtections.Select(p => p.GetName()).Should().Equal(nameof(ActiveDouble));
43+
}
44+
45+
private class ActiveDouble : IProtection
46+
{
47+
public Task ExecuteAsync() => Task.CompletedTask;
48+
}
49+
50+
[Obsolete]
51+
private class DeprecatedDouble : IProtection
52+
{
53+
public Task ExecuteAsync() => Task.CompletedTask;
54+
}
55+
}

0 commit comments

Comments
 (0)