C # decompilation prevention,
C # The compiled code generates a dll or exe through the VS compiler. It is easy for some decompilation tools to view the source code or modify the source code.
To prevent code from being decompiled or tampered with, we can take some preventive measures. But it cannot be avoided, because DotNet must compile code to run in the IL intermediate language. IL is a rule and also a good decompilation.
Decompilation prevention measures:
- Set project code disassembly attributes
- Obfuscation
Method 1: Prevent Ildasm.exe (MSIL disassembly program) from disassembly assembly
The method is simple. Add the SuppressIldasm attribute to the project file AssemblyInfo. cs.
When suppressildasm.exe is used to decompile the code after suppressildasm.exe is added in the project, the system will prompt: "protected module-cannot be decompiled"
Ildasm.exe does not decompile this Assembly if the project contains the SuppressIldasm attribute. However, ILSyp, Reflector and other decompilation tools can also decompile the source code by setting SuppressIldasm attributes for the Assembly.
Disadvantages:
It can be seen that the SuppressIldasm plug-in is only effective for the ildasm.exetool. At the same time, this restriction of the ildasm.exe tool can be deleted. Reference: remove the SuppressIldasmAttribute limit of ILDasm
Method 2: Obfuscation
Obfuscation principle: Renaming a VS compiled file (exe or dll) through ildasm, string encryption, and moving disrupt the original code. This method is common.
VS2013 built-in obfuscation tool: Tools --> PreEmptive Dotfuscator and Analytics
However, VS2013 comes with Dotfuscator 5.5 and requires activation to use all functions. Currently, Baidu provides the DotfuscatorPro 4.9 cracked version for download.
Open the main interface of DotfuscatorPro 4.9
Settings-> Global Options Global configuration
Common function configuration: Disable String Encryption = NO enable String Encryption
Choose to confuse C # compile code (dll or exe)
Do not check the Library, otherwise some classes and variables will not be confused;
Rename Configuration
Common function configuration: Select = use enhanced overload induction to use the enhanced mode.
Renaming Scheme = Unprintable (non-printable characters are garbled characters). You can also choose other modes, such as lower-case letters, upper-case characters, and numbers.
String Encryption
Select the file to be encrypted (exe or dll)
You can perform other configurations as needed. (For example, control flow, Output, Setting-> Build Settings, Settings --> Project Properties)
Finally, the Build Project of the obfuscation file is generated.
Build Project generation obfuscation Project error:
Cocould not find a compatible version of ildasm to run on assembly C: \ Users \ *** bin \ Debug \ WindowsFormsApplication1.exe .?? This assembly was originally built with. NET Framework v4.0.30319.
Build Error.
Solution:
ILASM_v4.0.30319 = C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ ilasm.exe
ILDASM_v4.0.30319 = C: \ Program Files (x86) \ Microsoft SDKs \ Windows \ v8.1A \ bin \ NETFX 4.5.1 Tools \ ildasm.exe [different directories of VS versions will change]
Obfuscation code comparison
Uncompiled source code without obfuscation tools:
Use obfuscation tools to decompile the source code:
The effect is obvious, and it is difficult to see the true logic written by the decompilation code.
Disadvantages:
C # After the code is generated using a obfuscation tool, many conversion processes are added. This makes the decompilation tool unable to intuitively see the real logic of the source code. However, excessive conversion of source code may reduce the running efficiency of the software and even cause an error.