Invalid Code

This protection adds invalid code to the methods so that decompilers cannot interpret them.

This protection is available in the editions:

Developer Startup Enterprise

Invalid code added in the methods is not executed, for this reason it does not affect the operation or performance of the applications in a negative way.


Parameters

This protection has no parameters or settings.


Modes

Normal: Add invalid metadata to prevent the code from being decompiled.


Code example

  • Before:
var key =  "https://www.dotnetsafer.com";
string password = "admin";
  • After:
/* An exception occurred when decompiling this method (06000001) ICSharpCode.Decompiler.DecompilerException: 
Error decompiling System.Void Testnetcoreapp30.Program::Main(System.String[]) ---> System.Exception: 
Inconsistent stack size at IL_1A en ICSharpCode.Decompiler.ILAst.ILAstBuilder.StackAnalysis(MethodDef methodDef)
en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstBuilder.cs:line 443 
en ICSharpCode.Decompiler.ILAst.ILAstBuilder.Build(MethodDef methodDef, Boolean optimize, DecompilerContext context) 
en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstBuilder.cs:line 269 
en ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters, MethodDebugInfoBuilder& builder) 
en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 112 en 
ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider 
autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) 
en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 88 --- 
End of internal exception stack tracking --- en ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody (MethodDef methodDef, 
DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, 
MethodDebugInfoBuilder& stmtsBuilder) en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 
92 en ICSharpCode.Decompiler.Ast.AstBuilder.<>c__DisplayClass89_1.<AddMethodBody>b__0() 
en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstBuilder.cs:line 1531 */"

Exclusions

  • Exclude with attribute

Include this attribute in your source code:

[Obfuscation(Exclude = true, Feature = "InvalidCode")]
  • Exclude from the interface

You can exclude this protection from the methods or classes you want.


Compatibility

Previous
Call Hiding