|
| 1 | +using System.IO; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using Confuser.Core; |
| 5 | +using Confuser.Core.Project; |
| 6 | +using Confuser.UnitTest; |
| 7 | +using dnlib.DotNet; |
| 8 | +using Xunit; |
| 9 | +using Xunit.Abstractions; |
| 10 | + |
| 11 | +namespace Watermark.Test { |
| 12 | + public sealed class WatermarkTest : TestBase { |
| 13 | + public WatermarkTest(ITestOutputHelper outputHelper) : base(outputHelper) { } |
| 14 | + |
| 15 | + // Issue #69: the watermark is opt-in. An obfuscation that does not request it must produce |
| 16 | + // output with no ConfusedByAttribute fingerprint. |
| 17 | + [Fact] |
| 18 | + [Trait("Category", "Protection")] |
| 19 | + [Trait("Issue", "https://github.com/mcpolo99/ConfuserExx/issues/69")] |
| 20 | + public Task Watermark_NotRequested_ProducesNoFingerprintAttribute() => |
| 21 | + Run("AntiTamper.exe", |
| 22 | + new[] { "This is a test." }, |
| 23 | + new SettingItem<Protection>("rename"), |
| 24 | + "_wm_off", |
| 25 | + postProcessAction: outputPath => { |
| 26 | + using (var module = ModuleDefMD.Load(Path.Combine(outputPath, "AntiTamper.exe"))) { |
| 27 | + Assert.DoesNotContain(module.CustomAttributes, a => a.TypeFullName == "ConfusedByAttribute"); |
| 28 | + Assert.DoesNotContain(module.GetTypes(), t => t.Name == "ConfusedByAttribute"); |
| 29 | + } |
| 30 | + return Task.CompletedTask; |
| 31 | + }); |
| 32 | + |
| 33 | + // When explicitly enabled with custom text and attribute name, the watermark must use them |
| 34 | + // (so it can be branded or disguised instead of the default ConfuserEx fingerprint). |
| 35 | + [Fact] |
| 36 | + [Trait("Category", "Protection")] |
| 37 | + [Trait("Issue", "https://github.com/mcpolo99/ConfuserExx/issues/69")] |
| 38 | + public Task Watermark_CustomTextAndName_AppliesConfiguredAttribute() => |
| 39 | + Run("AntiTamper.exe", |
| 40 | + new[] { "This is a test." }, |
| 41 | + new SettingItem<Protection>("watermark") { |
| 42 | + { "text", "MyCorp Security" }, |
| 43 | + { "attributeName", "SecurityStampAttribute" } |
| 44 | + }, |
| 45 | + "_wm_custom", |
| 46 | + postProcessAction: outputPath => { |
| 47 | + using (var module = ModuleDefMD.Load(Path.Combine(outputPath, "AntiTamper.exe"))) { |
| 48 | + var attr = module.CustomAttributes.FirstOrDefault(a => a.TypeFullName == "SecurityStampAttribute"); |
| 49 | + Assert.NotNull(attr); |
| 50 | + Assert.Equal("MyCorp Security", attr.ConstructorArguments[0].Value?.ToString()); |
| 51 | + |
| 52 | + // The default fingerprint name must not appear. |
| 53 | + Assert.DoesNotContain(module.CustomAttributes, a => a.TypeFullName == "ConfusedByAttribute"); |
| 54 | + } |
| 55 | + return Task.CompletedTask; |
| 56 | + }); |
| 57 | + } |
| 58 | +} |
0 commit comments