Skip to content

Commit

Permalink
#421 Fixed the Obfuscation Attribute marker
Browse files Browse the repository at this point in the history
The marker did not correctly handle the inheritance ob the obfuscation attribute.
This results in members not being excluded correctly, when the attribute asks to do that.
  • Loading branch information
mkaring committed Dec 22, 2021
1 parent a642360 commit 24c7ba2
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Confuser.Core/ObfAttrMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void ApplyInfo(IDnlibDef context, ProtectionSettings settings, IEnumerable<Prote
continue;

if (info.Condition == null && info.Exclude) {
if (type == ApplyInfoType.CurrentInfoOnly ||
if ((type == ApplyInfoType.ParentInfo && info.ApplyToMember) ||
type == ApplyInfoType.CurrentInfoOnly ||
(type == ApplyInfoType.CurrentInfoInherits && info.ApplyToMember)) {
settings.Clear();
}
Expand Down
30 changes: 30 additions & 0 deletions Confuser2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlockingReferencesHelper",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlockingReferences.Test", "Tests\BlockingReferences.Test\BlockingReferences.Test.csproj", "{4FB03AD0-96FF-4730-801A-4F997795D920}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "421_NewtonsoftJsonSerialization", "Tests\421_NewtonsoftJsonSerialization\421_NewtonsoftJsonSerialization.csproj", "{4EF73752-78B0-4E0D-A33B-B6637B6C2177}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "421_NewtonsoftJsonSerialization.Test", "Tests\421_NewtonsoftJsonSerialization.Test\421_NewtonsoftJsonSerialization.Test.csproj", "{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -909,6 +913,30 @@ Global
{4FB03AD0-96FF-4730-801A-4F997795D920}.Release|x64.Build.0 = Release|Any CPU
{4FB03AD0-96FF-4730-801A-4F997795D920}.Release|x86.ActiveCfg = Release|Any CPU
{4FB03AD0-96FF-4730-801A-4F997795D920}.Release|x86.Build.0 = Release|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Debug|x64.ActiveCfg = Debug|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Debug|x64.Build.0 = Debug|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Debug|x86.ActiveCfg = Debug|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Debug|x86.Build.0 = Debug|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Release|Any CPU.Build.0 = Release|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Release|x64.ActiveCfg = Release|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Release|x64.Build.0 = Release|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Release|x86.ActiveCfg = Release|Any CPU
{4EF73752-78B0-4E0D-A33B-B6637B6C2177}.Release|x86.Build.0 = Release|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Debug|x64.Build.0 = Debug|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Debug|x86.Build.0 = Debug|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Release|Any CPU.Build.0 = Release|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Release|x64.ActiveCfg = Release|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Release|x64.Build.0 = Release|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Release|x86.ActiveCfg = Release|Any CPU
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -969,6 +997,8 @@ Global
{F602DAFE-E8A2-4CB2-AF0E-656CD357D821} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
{9EB8DC3B-60DC-451E-8C18-3D7E38D463FD} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
{4FB03AD0-96FF-4730-801A-4F997795D920} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
{4EF73752-78B0-4E0D-A33B-B6637B6C2177} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
{B1CB9A30-FEA6-4467-BEC5-4803CCE9BF78} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0D937D9E-E04B-4A68-B639-D4260473A388}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RootNamespace>NewtonsoftJsonSerialization.Test</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Confuser.UnitTest\Confuser.UnitTest.csproj" />
<ProjectReference Include="..\421_NewtonsoftJsonSerialization\421_NewtonsoftJsonSerialization.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions Tests/421_NewtonsoftJsonSerialization.Test/NewtonsoftJsonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using Confuser.Core;
using Confuser.Core.Project;
using Confuser.UnitTest;
using Xunit;
using Xunit.Abstractions;

namespace NewtonsoftJsonSerialization.Test {
public class NewtonsoftJsonTest : TestBase {
public NewtonsoftJsonTest(ITestOutputHelper outputHelper) : base(outputHelper) { }

[Fact]
[Trait("Category", "Protection")]
[Trait("Protection", "rename")]
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/421")]
public async Task SignatureMismatch() =>
await Run(
new[] {
"421_NewtonsoftJsonSerialization.exe",
"external:Newtonsoft.Json.dll"
},
new [] {
"{\"a\":\"a\",\"b\":\"b\",\"c\":\"c\"}",
"{\"a\":\"a\",\"b\":\"b\",\"c\":\"c\"}"
},
new SettingItem<Protection>("rename")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<RootNamespace>NewtonsoftJsonSerialization</RootNamespace>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions Tests/421_NewtonsoftJsonSerialization/ObfExcluded.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using Newtonsoft.Json;

namespace NewtonsoftJsonSerialization {
[Obfuscation(Exclude = true)]
internal class ObfExcluded {
[JsonProperty("a")] public string a;

[JsonProperty("b")] public string b;

[JsonProperty("c")] public string c;

public ObfExcluded(string a, string b, string c) {
this.a = a;
this.b = b;
this.c = c;
}

public override string ToString() => JsonConvert.SerializeObject(this);
}
}
20 changes: 20 additions & 0 deletions Tests/421_NewtonsoftJsonSerialization/ObfMarkedWithAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;

namespace NewtonsoftJsonSerialization {
[JsonObject]
internal class ObfMarkedWithAttribute {
[JsonProperty("a")] public string a;

[JsonProperty("b")] public string b;

[JsonProperty("c")] public string c;

public ObfMarkedWithAttribute(string a, string b, string c) {
this.a = a;
this.b = b;
this.c = c;
}

public override string ToString() => JsonConvert.SerializeObject(this);
}
}
16 changes: 16 additions & 0 deletions Tests/421_NewtonsoftJsonSerialization/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace NewtonsoftJsonSerialization {
class Program {
static int Main(string[] args) {
Console.WriteLine("START");

Console.WriteLine(new ObfMarkedWithAttribute("a", "b", "c").ToString());
Console.WriteLine(new ObfExcluded("a", "b", "c").ToString());

Console.WriteLine("END");

return 42;
}
}
}

0 comments on commit 24c7ba2

Please sign in to comment.