Skip to content

Commit dd0c015

Browse files
authored
Merge f7e1360 into 20c04ac
2 parents 20c04ac + f7e1360 commit dd0c015

File tree

8 files changed

+655
-6
lines changed

8 files changed

+655
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!--
2+
This file as to be present, otherwise the Microsoft.DiaSymReader.Native package does not copy it's files to the output.
3+
The content of this file does not matter.
4+
-->
5+
<appSettings />

Confuser.Protections/AntiTamper/NormalMode.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ public void HandleMD(AntiTamperProtection parent, ConfuserContext context, Prote
100100
}
101101

102102
void WriterEvent(object sender, ModuleWriterEventArgs e) {
103-
var writer = (ModuleWriterBase)sender;
104-
if (e.Event == ModuleWriterEvent.MDEndCreateTables) {
105-
CreateSections(writer);
106-
}
107-
else if (e.Event == ModuleWriterEvent.BeginStrongNameSign) {
108-
EncryptSection(writer);
103+
switch (e.Event)
104+
{
105+
case ModuleWriterEvent.Begin when e.Writer is NativeModuleWriter nativeWriter:
106+
// disable the optimization of the image size for the native writer, so the method bodies can be protected.
107+
nativeWriter.Options = new NativeModuleWriterOptions(nativeWriter.ModuleDefMD, false);
108+
break;
109+
case ModuleWriterEvent.MDEndCreateTables:
110+
CreateSections(e.Writer);
111+
break;
112+
case ModuleWriterEvent.BeginStrongNameSign:
113+
EncryptSection(e.Writer);
114+
break;
109115
}
110116
}
111117

Confuser2.sln

Lines changed: 394 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<RootNamespace>ClrProtection.Test</RootNamespace>
6+
<IsPackable>false</IsPackable>
7+
<PlatformTarget>x86</PlatformTarget>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\244_ClrProtection\244_ClrProtection.vcxproj" />
12+
<ProjectReference Include="..\Confuser.UnitTest\Confuser.UnitTest.csproj" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 ClrProtection.Test {
10+
public class ProtectClrAssemblyTest : TestBase {
11+
public ProtectClrAssemblyTest(ITestOutputHelper outputHelper) : base(outputHelper) { }
12+
13+
[Fact]
14+
[Trait("Category", "Protection")]
15+
[Trait("Protection", "anti tamper")]
16+
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/244")]
17+
public Task AntiTamperProtection() => Run(
18+
"244_ClrProtection.exe",
19+
Array.Empty<String>(),
20+
new SettingItem<Protection>("anti tamper"),
21+
$"_{nameof(AntiTamperProtection)}");
22+
23+
[Fact]
24+
[Trait("Category", "Protection")]
25+
[Trait("Protection", "resources")]
26+
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/244")]
27+
public Task ResourceProtection() => Run(
28+
"244_ClrProtection.exe",
29+
Array.Empty<String>(),
30+
new SettingItem<Protection>("resources"),
31+
$"_{nameof(ResourceProtection)}");
32+
33+
[Fact]
34+
[Trait("Category", "Protection")]
35+
[Trait("Protection", "typescramble")]
36+
[Trait("Issue", "https://github.com/mkaring/ConfuserEx/issues/244")]
37+
public Task TypeScrambleProtection() => Run(
38+
"244_ClrProtection.exe",
39+
Array.Empty<String>(),
40+
new SettingItem<Protection>("typescramble"),
41+
$"_{nameof(TypeScrambleProtection)}");
42+
}
43+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{73f11ee8-f565-479e-8366-bd74ee467ce8}</ProjectGuid>
25+
<RootNamespace>My244ClrProtection</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
31+
<ConfigurationType>Application</ConfigurationType>
32+
<UseDebugLibraries>true</UseDebugLibraries>
33+
<PlatformToolset>v142</PlatformToolset>
34+
<CharacterSet>Unicode</CharacterSet>
35+
<CLRSupport>true</CLRSupport>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>false</UseDebugLibraries>
40+
<PlatformToolset>v142</PlatformToolset>
41+
<WholeProgramOptimization>true</WholeProgramOptimization>
42+
<CharacterSet>Unicode</CharacterSet>
43+
<CLRSupport>true</CLRSupport>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
46+
<ConfigurationType>Application</ConfigurationType>
47+
<UseDebugLibraries>true</UseDebugLibraries>
48+
<PlatformToolset>v142</PlatformToolset>
49+
<CharacterSet>Unicode</CharacterSet>
50+
<CLRSupport>true</CLRSupport>
51+
</PropertyGroup>
52+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
53+
<ConfigurationType>Application</ConfigurationType>
54+
<UseDebugLibraries>false</UseDebugLibraries>
55+
<PlatformToolset>v142</PlatformToolset>
56+
<WholeProgramOptimization>true</WholeProgramOptimization>
57+
<CharacterSet>Unicode</CharacterSet>
58+
<CLRSupport>true</CLRSupport>
59+
</PropertyGroup>
60+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
61+
<ImportGroup Label="ExtensionSettings">
62+
</ImportGroup>
63+
<ImportGroup Label="Shared">
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
72+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
73+
</ImportGroup>
74+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
75+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
76+
</ImportGroup>
77+
<PropertyGroup Label="UserMacros" />
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
79+
<LinkIncremental>true</LinkIncremental>
80+
</PropertyGroup>
81+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
82+
<LinkIncremental>false</LinkIncremental>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
85+
<LinkIncremental>true</LinkIncremental>
86+
</PropertyGroup>
87+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
88+
<LinkIncremental>false</LinkIncremental>
89+
</PropertyGroup>
90+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
91+
<ClCompile>
92+
<WarningLevel>Level3</WarningLevel>
93+
<SDLCheck>true</SDLCheck>
94+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
95+
<ConformanceMode>false</ConformanceMode>
96+
</ClCompile>
97+
<Link>
98+
<SubSystem>Console</SubSystem>
99+
<GenerateDebugInformation>false</GenerateDebugInformation>
100+
<EntryPointSymbol>main</EntryPointSymbol>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
104+
<ClCompile>
105+
<WarningLevel>Level3</WarningLevel>
106+
<FunctionLevelLinking>true</FunctionLevelLinking>
107+
<IntrinsicFunctions>true</IntrinsicFunctions>
108+
<SDLCheck>true</SDLCheck>
109+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
110+
<ConformanceMode>false</ConformanceMode>
111+
</ClCompile>
112+
<Link>
113+
<SubSystem>Console</SubSystem>
114+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
115+
<OptimizeReferences>true</OptimizeReferences>
116+
<GenerateDebugInformation>false</GenerateDebugInformation>
117+
<EntryPointSymbol>main</EntryPointSymbol>
118+
</Link>
119+
</ItemDefinitionGroup>
120+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
121+
<ClCompile>
122+
<WarningLevel>Level3</WarningLevel>
123+
<SDLCheck>true</SDLCheck>
124+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
<ConformanceMode>false</ConformanceMode>
126+
</ClCompile>
127+
<Link>
128+
<SubSystem>Console</SubSystem>
129+
<GenerateDebugInformation>false</GenerateDebugInformation>
130+
<EntryPointSymbol>main</EntryPointSymbol>
131+
</Link>
132+
</ItemDefinitionGroup>
133+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
134+
<ClCompile>
135+
<WarningLevel>Level3</WarningLevel>
136+
<FunctionLevelLinking>true</FunctionLevelLinking>
137+
<IntrinsicFunctions>true</IntrinsicFunctions>
138+
<SDLCheck>true</SDLCheck>
139+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
140+
<ConformanceMode>false</ConformanceMode>
141+
</ClCompile>
142+
<Link>
143+
<SubSystem>Console</SubSystem>
144+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
145+
<OptimizeReferences>true</OptimizeReferences>
146+
<GenerateDebugInformation>false</GenerateDebugInformation>
147+
<EntryPointSymbol>main</EntryPointSymbol>
148+
</Link>
149+
</ItemDefinitionGroup>
150+
<ItemGroup>
151+
<ClCompile Include="Program.cpp" />
152+
</ItemGroup>
153+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
154+
<ImportGroup Label="ExtensionTargets">
155+
</ImportGroup>
156+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Quelldateien">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Headerdateien">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Ressourcendateien">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Program.cpp">
19+
<Filter>Quelldateien</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using namespace System;
2+
3+
int main()
4+
{
5+
Console::WriteLine("START");
6+
Console::WriteLine("END");
7+
return 42;
8+
}

0 commit comments

Comments
 (0)