/

Invalid Code

Protection ID: 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.


Rules configuration

  • shield.config.json
{
  "protections": {
    "invalid_code": {}
  }
}

Modes

  • Default: Add invalid instructions to prevent the method code from being decompiled.

Code example

  • Before:
var key =  "https://www.bytehide.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 = false, Feature = "-invalid_code")]
  • Exclude from the interface

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


Compatibility

FrameworkCompatibilityComments
.NET CoreNot recommended if reflection is used or your application is an externally loaded plugin.
.NET FrameworkNot recommended if reflection is used or your application is an externally loaded plugin.
.NET (up to 8 version)Not recommended if reflection is used or your application is an externally loaded plugin.
.NET StandardNot recommended if reflection is used or your application is an externally loaded plugin.
Xamarin IOSIt is pre-checked, but is automatically disabled in most cases.
Xamarin AndroidIt is pre-checked, but is automatically disabled in most cases.
Xamarin MacOsIt is pre-checked, but is automatically disabled in most cases.
WPF
Blazor
.NET Maui
UnityNot recommended if reflection is used or your application is an externally loaded plugin.
ASP
Silverlight
VBa (Visual Basic) or C# (CSharp)Not recommended if reflection is used or your application is an externally loaded plugin.
WinRT

Shield is compatible with all versions of .NET, it doesn't matter if you use .NET 2.0, .NET 4.7, .NET Core 2.1 or Xamarin.Forms 5.0, it will adapt automatically according to needs, you don't have to worry about this.

Previous
Events Protection