AOT Compilation Protection
Shield provides specialized protection for .NET applications that use Ahead-of-Time (AOT) compilation, maintaining compatibility while ensuring strong security.
Understanding AOT Compilation
Ahead-of-Time (AOT) compilation differs from traditional Just-in-Time (JIT) compilation in .NET:
- Application code is compiled to native machine code before deployment
- Runtime compilation is eliminated or minimized
- Execution starts faster with lower memory consumption
- Reflection and dynamic code generation may be limited
.NET supports several AOT compilation approaches:
- ReadyToRun (R2R): Partial AOT that preserves compatibility with the CLR
- Native AOT: Full AOT compilation with minimal runtime requirements
- Mono AOT: Used for mobile and WebAssembly scenarios
Each approach presents different protection challenges that Shield addresses with specialized techniques.
Protection Strategy for AOT Applications
Shield employs a comprehensive approach to securing AOT-compiled applications:
- Pre-compilation Protection: Applies security transformations before AOT compilation
- Metadata Obfuscation: Secures metadata while maintaining AOT compatibility
- Native Code Protection: Applies protections compatible with AOT-generated native code
- Resource Security: Protects embedded resources in AOT scenarios
- AOT-Specific Optimizations: Tailors protection techniques for each AOT compilation mode
Key Protection Areas
IL Code Transformations
Shield applies transformations to your IL code before AOT compilation:
- Control flow obfuscation compatible with AOT constraints
- Name obfuscation with AOT-specific limitations in mind
- String encryption with AOT-compatible runtime decoding
Native Code Security
For fully AOT-compiled code, Shield provides:
- Metadata protection that preserves AOT compatibility
- Binary-level protections for the compiled native code
- Anti-tampering measures for the native executable
Resource and Assembly Protection
Shield secures resources in AOT scenarios:
- Resource encryption compatible with AOT constraints
- Assembly reference obfuscation that works with AOT compilation
- Protection for satellite assemblies and resources
Getting Started
Shield integrates with your AOT compilation workflow:
- Apply Shield protection before the AOT compilation step
- Configure protections using
shield.config.json
- Build your AOT-compiled application
For specific AOT scenarios, see:
- Native AOT Support - Working with .NET's Native AOT compilation
- Performance Impact - Understanding the performance considerations of protection in AOT scenarios
Recommended Configuration
Below is a recommended configuration for AOT-compiled applications:
{
"preset": "custom",
"protections": {
"rename": {
"rename_public": false,
"rename_arguments": true,
"flatten_namespaces": true
},
"control_flow_advance": {
"intensity": 6
},
"constants_encryption": {},
"resources": {
"compress": true,
"encrypt": true
}
},
"aot": {
"mode": "autodetect",
"compatibility": "high",
"preserveReflection": true
}
}
The aot
section contains settings that optimize protection for AOT-compiled applications. The mode
can be set to "autodetect", "readytorun", "nativeaot", or "mono" depending on your AOT approach.
Testing Protected Applications
After applying Shield protection to your AOT-compiled application:
- Verify successful AOT compilation with protection applied
- Test startup performance and memory consumption
- Test all functionality, especially any reflection-based features
- Test on all target platforms and architectures
Compatibility Considerations
Shield's AOT protection is compatible with:
- .NET 7+ Native AOT
- .NET ReadyToRun (R2R)
- Mono AOT (Xamarin, MAUI)
- Blazor WebAssembly AOT
The compatibility level can be adjusted based on your application's requirements:
{
"aot": {
"compatibility": "high" // Options: "high", "balanced", "aggressive"
}
}
Learn More
For more detailed information about protecting AOT-compiled applications:
Native AOT Support
Learn about protecting applications that use .NET's Native AOT compilation
Performance Impact
Understand the performance considerations when protecting AOT-compiled applications