stealth_enum_generator 2.2.0
stealth_enum_generator: ^2.2.0 copied to clipboard
Code generator for stealth_enum that transforms private enums into zero-cost obfuscated extension types to eliminate AOT binary metadata.
The companion build_runner code generator for stealth_enum.
This package transforms @StealthEnum() annotated private Dart enums into zero-cost, obfuscated Dart 3 extension types to neutralize AI-driven reverse engineering pipelines (REA, Blutter, Ghidra).
Getting started #
Add stealth_enum_generator to your dev_dependencies alongside build_runner, and stealth_enum to your dependencies:
dependencies:
stealth_enum: ^2.2.0
dev_dependencies:
build_runner: ^2.4.0
stealth_enum_generator: ^2.2.0
Then run:
dart pub get
# or for Flutter:
flutter pub get
How it works #
StealthEnumGenerator extends GeneratorForAnnotation<StealthEnum> from source_gen:
- Validation: Inspects
@StealthEnum()annotations, enforces private declarations (_prefix) to guarantee AOT tree-shaking, validates reserved member names, and enforces range checks on@StealthValue. - Identifier Extraction: Resolves the public type name (strips the leading
_or applies the customname:override). - Entropy & Value Generation: Derives collision-free, deterministic 32-bit hex values using keyed HMAC-SHA256 over
'$publicName::$fieldName'. Because HMAC-SHA256 satisfies the strict avalanche criterion, differential XOR attacks (valA ^ valB) cannot recover names or cancel out the secret key. Each constant is derived independently: inserting, removing, or reordering constants never shifts untouched values. Supports@StealthValue(int)for explicit, frozen integer overrides. - Extension Type Synthesis: Emits an
extension type const <Name>._(int rawValue)with static constants,valueslist, safetryFromRawValue()parsing,isValidvalidation, integer-basedtoJson()/fromJson(), and inlined pattern matching. - Fail-Closed Security: Emits explicit hex cases and fail-closed wildcards (
_ => throw StateError('')) to guarantee that corrupted or unknown values never execute a privileged branch without leaking strings. - Shared Pipeline Integration: Built with
SharedPartBuilderso it seamlessly shares.g.dartfiles withjson_serializable,freezed, and other generators.
For full documentation and examples, see the stealth_enum README.
Contributing #
PRs and issues are welcome! Please open an issue first for significant changes.
License #
Made with 💛 by aslamambiloly © 2026
