How andreaskarageorgos/code-protection-for-unity works
Code Protection is a Unity toolkit that applies compile-time obfuscation, build-time integrity and metadata protection, and runtime integrity verification. The user configures features in the editor panel; settings are saved into generated configuration, then the IL postprocessor rewrites eligible assemblies during compilation. Build postprocessing encrypts IL2CPP metadata when enabled and creates a signed integrity manifest; the runtime verifier checks that manifest at startup. The native metadata decryptor is a manual libil2cpp integration. Some subsystem connections are documented in the README rather than shown in sampled implementation excerpts.
Main entry points: MetadataBuildPostProcessor.cs Build postprocessor · ProtectionSettingsEditor.cs Settings editor · CodeIntegrityVerifier.cs Runtime verifier · ProtectionILPostProcessor.cs IL postprocessor
Components 17
Configuration
- Protection panel
CodeProtection/Editor/ProtectionPanel.cs - Settings editor
CodeProtection/Editor/ProtectionSettingsEditor.cs - Protection settings
CodeProtection/CodeGen/ProtectionSettings.cs
Compile-time protection
- IL postprocessor
CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs - Protection attributes
CodeProtection/CodeGen/ProtectionAttributes.cs - Random code injection
CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs - String obfuscation
CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs
Integrity checking
- Build postprocessor
CodeProtection/Editor/MetadataBuildPostProcessor.cs - Manifest and hashing
CodeProtection/CodeGen/IntegrityManifest.cs - Integrity secret
CodeProtection/CodeGen/IntegritySecret.generated.cs - Runtime verifier
CodeProtection/CodeGen/CodeIntegrityVerifier.cs - Built game files
Metadata protection
- Metadata encryption
CodeProtection/Editor/MetadataBuildPostProcessor.cs - XOR keystream
CodeProtection/CodeGen/XorKeystream.cs - global-metadata.dat
- Native decryptor
CodeProtection/Native/metadata_decrypt_patch.cpp
Other components
- Unity developer
Connections 19
- Unity developer → Protection panel: configures
README.md - Protection panel → Settings editor: saves through
CodeProtection/Editor/ProtectionPanel.cs - Settings editor → Protection settings: loads and updates
CodeProtection/Editor/ProtectionSettingsEditor.cs - Settings editor → Integrity secret: generates
CodeProtection/Editor/ProtectionSettingsEditor.cs - Settings editor → IL postprocessor: writes compile config
CodeProtection/Editor/ProtectionSettingsEditor.cs - IL postprocessor → Random code injection: runs
CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs - IL postprocessor → String obfuscation: runs
README.md - Random code injection → Protection attributes: selects classes by
CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs - String obfuscation → Protection attributes: selects classes by
README.md - Build postprocessor → Manifest and hashing: hashes and signs
CodeProtection/Editor/MetadataBuildPostProcessor.cs - Build postprocessor → Built game files: hashes
CodeProtection/Editor/MetadataBuildPostProcessor.cs - Build postprocessor → Integrity secret: uses secret
README.md - Runtime verifier → Manifest and hashing: reads and verifies
CodeProtection/CodeGen/CodeIntegrityVerifier.cs - Runtime verifier → Integrity secret: verifies with
CodeProtection/CodeGen/CodeIntegrityVerifier.cs - Runtime verifier → Built game files: re-hashes
CodeProtection/CodeGen/CodeIntegrityVerifier.cs - Build postprocessor → global-metadata.dat: encrypts
CodeProtection/Editor/MetadataBuildPostProcessor.cs - Metadata encryption → XOR keystream: encrypts with
CodeProtection/Editor/MetadataBuildPostProcessor.cs - Native decryptor → global-metadata.dat: decrypts at load
CodeProtection/Native/metadata_decrypt_patch.cpp - Metadata encryption → Native decryptor: requires matching algorithm
CodeProtection/Native/metadata_decrypt_patch.cpp