# andreaskarageorgos/code-protection-for-unity architecture

> Architecture diagram of the GitHub repository andreaskarageorgos/code-protection-for-unity, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andreaskarageorgos/code-protection-for-unity
- Repository: https://github.com/andreaskarageorgos/code-protection-for-unity

## Overview

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: [`CodeProtection/Editor/MetadataBuildPostProcessor.cs`](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/MetadataBuildPostProcessor.cs) (Build postprocessor), [`CodeProtection/Editor/ProtectionSettingsEditor.cs`](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/ProtectionSettingsEditor.cs) (Settings editor), [`CodeProtection/CodeGen/CodeIntegrityVerifier.cs`](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/CodeIntegrityVerifier.cs) (Runtime verifier), [`CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs`](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs) (IL postprocessor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Configuration"]
  node_panel["Protection panel<br/>[ProtectionPanel.cs]"]
  node_settings_editor["Settings editor"]
  node_settings["Protection settings"]
end

subgraph group_compile["Compile-time protection"]
  node_il_processor["IL postprocessor"]
  node_attributes["Protection attributes"]
  node_random_injection["Random code injection"]
  node_string_obfuscation["String obfuscation"]
end

subgraph group_integrity["Integrity checking"]
  node_build_processor["Build postprocessor"]
  node_integrity_manifest["Manifest and hashing"]
  node_integrity_secret["Integrity secret"]
  node_verifier["Runtime verifier"]
  node_protected_files["Built game files"]
end

subgraph group_metadata["Metadata protection"]
  node_metadata_encryptor["Metadata encryption"]
  node_keystream["XOR keystream<br/>[XorKeystream.cs]"]
  node_metadata_file["global-metadata.dat"]
  node_native_decryptor["Native decryptor"]
end

node_developer(("Unity developer"))

node_developer -->|"configures"| node_panel
node_panel -->|"saves through"| node_settings_editor
node_settings_editor -->|"loads and updates"| node_settings
node_settings_editor -->|"generates"| node_integrity_secret
node_settings_editor -->|"writes compile config"| node_il_processor
node_il_processor -->|"runs"| node_random_injection
node_il_processor -->|"runs"| node_string_obfuscation
node_random_injection -->|"selects classes by"| node_attributes
node_string_obfuscation -->|"selects classes by"| node_attributes
node_build_processor -->|"hashes and signs"| node_integrity_manifest
node_build_processor -->|"hashes"| node_protected_files
node_build_processor -->|"uses secret"| node_integrity_secret
node_verifier -->|"reads and verifies"| node_integrity_manifest
node_verifier -->|"verifies with"| node_integrity_secret
node_verifier -->|"re-hashes"| node_protected_files
node_build_processor -->|"encrypts"| node_metadata_file
node_metadata_encryptor -->|"encrypts with"| node_keystream
node_native_decryptor -->|"decrypts at load"| node_metadata_file
node_metadata_encryptor -->|"requires matching algorithm"| node_native_decryptor

click node_panel "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/ProtectionPanel.cs"
click node_settings_editor "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/ProtectionSettingsEditor.cs"
click node_settings "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/ProtectionSettings.cs"
click node_il_processor "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs"
click node_attributes "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/ProtectionAttributes.cs"
click node_random_injection "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs"
click node_string_obfuscation "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs"
click node_build_processor "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/MetadataBuildPostProcessor.cs"
click node_integrity_manifest "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/IntegrityManifest.cs"
click node_integrity_secret "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/IntegritySecret.generated.cs"
click node_verifier "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/CodeIntegrityVerifier.cs"
click node_metadata_encryptor "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/MetadataBuildPostProcessor.cs"
click node_keystream "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/XorKeystream.cs"
click node_native_decryptor "https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Native/metadata_decrypt_patch.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_panel,node_settings_editor,node_settings toneBlue
class node_il_processor,node_attributes,node_random_injection,node_string_obfuscation toneAmber
class node_build_processor,node_integrity_manifest,node_integrity_secret,node_verifier,node_protected_files toneMint
class node_metadata_encryptor,node_keystream,node_metadata_file,node_native_decryptor toneRose
class node_developer toneIndigo
```

## Components

### Configuration

- [Protection panel](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/ProtectionPanel.cs): `CodeProtection/Editor/ProtectionPanel.cs`
- [Settings editor](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/ProtectionSettingsEditor.cs): `CodeProtection/Editor/ProtectionSettingsEditor.cs`
- [Protection settings](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/ProtectionSettings.cs): `CodeProtection/CodeGen/ProtectionSettings.cs`

### Compile-time protection

- [IL postprocessor](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs): `CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs`
- [Protection attributes](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/ProtectionAttributes.cs): `CodeProtection/CodeGen/ProtectionAttributes.cs`
- [Random code injection](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs): `CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs`
- [String obfuscation](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs): `CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs`

### Integrity checking

- [Build postprocessor](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/MetadataBuildPostProcessor.cs): `CodeProtection/Editor/MetadataBuildPostProcessor.cs`
- [Manifest and hashing](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/IntegrityManifest.cs): `CodeProtection/CodeGen/IntegrityManifest.cs`
- [Integrity secret](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/IntegritySecret.generated.cs): `CodeProtection/CodeGen/IntegritySecret.generated.cs`
- [Runtime verifier](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/CodeIntegrityVerifier.cs): `CodeProtection/CodeGen/CodeIntegrityVerifier.cs`
- **Built game files**

### Metadata protection

- [Metadata encryption](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Editor/MetadataBuildPostProcessor.cs): `CodeProtection/Editor/MetadataBuildPostProcessor.cs`
- [XOR keystream](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/CodeGen/XorKeystream.cs): `CodeProtection/CodeGen/XorKeystream.cs`
- **global-metadata.dat**
- [Native decryptor](https://github.com/andreaskarageorgos/code-protection-for-unity/blob/main/CodeProtection/Native/metadata_decrypt_patch.cpp): `CodeProtection/Native/metadata_decrypt_patch.cpp`

### Other components

- **Unity developer**

## Connections

- Unity developer → Protection panel: configures (evidence: `README.md`)
- Protection panel → Settings editor: saves through (evidence: `CodeProtection/Editor/ProtectionPanel.cs`)
- Settings editor → Protection settings: loads and updates (evidence: `CodeProtection/Editor/ProtectionSettingsEditor.cs`)
- Settings editor → Integrity secret: generates (evidence: `CodeProtection/Editor/ProtectionSettingsEditor.cs`)
- Settings editor → IL postprocessor: writes compile config (evidence: `CodeProtection/Editor/ProtectionSettingsEditor.cs`)
- IL postprocessor → Random code injection: runs (evidence: `CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs`)
- IL postprocessor → String obfuscation: runs (evidence: `README.md`)
- Random code injection → Protection attributes: selects classes by (evidence: `CodeProtection/ILPostProcessor/ProtectionILPostProcessor.cs`)
- String obfuscation → Protection attributes: selects classes by (evidence: `README.md`)
- Build postprocessor → Manifest and hashing: hashes and signs (evidence: `CodeProtection/Editor/MetadataBuildPostProcessor.cs`)
- Build postprocessor → Built game files: hashes (evidence: `CodeProtection/Editor/MetadataBuildPostProcessor.cs`)
- Build postprocessor → Integrity secret: uses secret (evidence: `README.md`)
- Runtime verifier → Manifest and hashing: reads and verifies (evidence: `CodeProtection/CodeGen/CodeIntegrityVerifier.cs`)
- Runtime verifier → Integrity secret: verifies with (evidence: `CodeProtection/CodeGen/CodeIntegrityVerifier.cs`)
- Runtime verifier → Built game files: re-hashes (evidence: `CodeProtection/CodeGen/CodeIntegrityVerifier.cs`)
- Build postprocessor → global-metadata.dat: encrypts (evidence: `CodeProtection/Editor/MetadataBuildPostProcessor.cs`)
- Metadata encryption → XOR keystream: encrypts with (evidence: `CodeProtection/Editor/MetadataBuildPostProcessor.cs`)
- Native decryptor → global-metadata.dat: decrypts at load (evidence: `CodeProtection/Native/metadata_decrypt_patch.cpp`)
- Metadata encryption → Native decryptor: requires matching algorithm (evidence: `CodeProtection/Native/metadata_decrypt_patch.cpp`)
