Skip to content

Commit 152caf1

Browse files
authored
Merge c48abbd into e58a29a
2 parents e58a29a + c48abbd commit 152caf1

File tree

7 files changed

+97
-1
lines changed

7 files changed

+97
-1
lines changed

Confuser.Protections/Constants/EncodePhase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ void ExtractConstants(
283283
if (instrs[i - 2].OpCode != OpCodes.Dup) continue;
284284
if (instrs[i - 3].OpCode != OpCodes.Newarr) continue;
285285
if (instrs[i - 4].OpCode != OpCodes.Ldc_I4) continue;
286+
if (!(instrs[i - 3].Operand is ITypeDefOrRef arrayType)) continue;
287+
if (!arrayType.IsPrimitive) continue;
286288

287289
var dataField = instrs[i - 1].Operand as FieldDef;
288290
if (dataField == null)
@@ -369,4 +371,4 @@ struct RTransform {
369371
[FieldOffset(0)] public readonly uint Lo;
370372
}
371373
}
372-
}
374+
}

Confuser2.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "252_ComplexInterfaceRenamin
100100
EndProject
101101
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "252_ComplexInterfaceRenaming.Test", "Tests\252_ComplexInterfaceRenaming.Test\252_ComplexInterfaceRenaming.Test.csproj", "{C10599E3-5A79-484F-940B-E4B61F256466}"
102102
EndProject
103+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "270_EnumArrayConstantProtection", "Tests\270_EnumArrayConstantProtection\270_EnumArrayConstantProtection.csproj", "{7C6D1CCD-D4DF-426A-B5D6-A6B5F13D0091}"
104+
EndProject
105+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "270_EnumArrayConstantProtection.Test", "Tests\270_EnumArrayConstantProtection.Test\270_EnumArrayConstantProtection.Test.csproj", "{DB234158-233E-4EC4-A2CE-EF02699563A2}"
106+
EndProject
103107
Global
104108
GlobalSection(SolutionConfigurationPlatforms) = preSolution
105109
Debug|Any CPU = Debug|Any CPU
@@ -270,6 +274,14 @@ Global
270274
{C10599E3-5A79-484F-940B-E4B61F256466}.Debug|Any CPU.Build.0 = Debug|Any CPU
271275
{C10599E3-5A79-484F-940B-E4B61F256466}.Release|Any CPU.ActiveCfg = Release|Any CPU
272276
{C10599E3-5A79-484F-940B-E4B61F256466}.Release|Any CPU.Build.0 = Release|Any CPU
277+
{7C6D1CCD-D4DF-426A-B5D6-A6B5F13D0091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
278+
{7C6D1CCD-D4DF-426A-B5D6-A6B5F13D0091}.Debug|Any CPU.Build.0 = Debug|Any CPU
279+
{7C6D1CCD-D4DF-426A-B5D6-A6B5F13D0091}.Release|Any CPU.ActiveCfg = Release|Any CPU
280+
{7C6D1CCD-D4DF-426A-B5D6-A6B5F13D0091}.Release|Any CPU.Build.0 = Release|Any CPU
281+
{DB234158-233E-4EC4-A2CE-EF02699563A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
282+
{DB234158-233E-4EC4-A2CE-EF02699563A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
283+
{DB234158-233E-4EC4-A2CE-EF02699563A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
284+
{DB234158-233E-4EC4-A2CE-EF02699563A2}.Release|Any CPU.Build.0 = Release|Any CPU
273285
EndGlobalSection
274286
GlobalSection(SolutionProperties) = preSolution
275287
HideSolutionNode = FALSE
@@ -308,6 +320,8 @@ Global
308320
{B7FF0EE8-6C68-46C6-AADB-58C0E3309FB2} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
309321
{F233D36D-B64A-4F14-A9F9-B8557C2D4F5D} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
310322
{C10599E3-5A79-484F-940B-E4B61F256466} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
323+
{7C6D1CCD-D4DF-426A-B5D6-A6B5F13D0091} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
324+
{DB234158-233E-4EC4-A2CE-EF02699563A2} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB}
311325
EndGlobalSection
312326
GlobalSection(ExtensibilityGlobals) = postSolution
313327
SolutionGuid = {0D937D9E-E04B-4A68-B639-D4260473A388}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<RootNamespace>EnumArrayConstantProtection.Test</RootNamespace>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Confuser.UnitTest\Confuser.UnitTest.csproj" />
11+
<ProjectReference Include="..\270_EnumArrayConstantProtection\270_EnumArrayConstantProtection.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Confuser.Core;
4+
using Confuser.Core.Project;
5+
using Confuser.UnitTest;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
9+
namespace EnumArrayConstantProtection.Test {
10+
public class ConstantProtectionTest : TestBase {
11+
public ConstantProtectionTest(ITestOutputHelper outputHelper) : base(outputHelper) { }
12+
13+
[Fact]
14+
[Trait("Category", "Protection")]
15+
[Trait("Protection", "constants")]
16+
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/270")]
17+
public async Task ConstantsProtection() =>
18+
await Run(
19+
"270_EnumArrayConstantProtection.exe",
20+
new[] {
21+
"Enum Array OK",
22+
"String Array OK"
23+
},
24+
new SettingItem<Protection>("constants") { { "elements", "SI" } }
25+
);
26+
}
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net461</TargetFramework>
6+
<RootNamespace>ConstantProtection</RootNamespace>
7+
<LangVersion>7.3</LangVersion>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace EnumArrayConstantProtection {
2+
public enum Level : long {
3+
A = 1,
4+
B = 2,
5+
C = 4,
6+
D = 8,
7+
E = 1073741824
8+
}
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
4+
namespace EnumArrayConstantProtection {
5+
public class Program {
6+
[SuppressMessage("Style", "IDE0060:Remove unused parameters", Justification = "Required signature")]
7+
static int Main(string[] args) {
8+
Console.WriteLine("START");
9+
Console.WriteLine(Get(Level.A, Level.E, Level.D));
10+
Console.WriteLine(Get("abc", "def", "ghi"));
11+
Console.WriteLine("END");
12+
return 42;
13+
}
14+
15+
[SuppressMessage("Style", "IDE0060:Remove unused parameters", Justification = "Just for testing.")]
16+
private static string Get(params Level[] levels) => "Enum Array OK";
17+
18+
private static string Get(params string[] texts) => "String Array OK";
19+
}
20+
}

0 commit comments

Comments
 (0)