Overview
RenamePass is an obfuscation pass that renames user-defined identifiers (classes, methods, fields, variables) to short meaningless names like _$0, _$1, etc. This makes reverse engineering significantly harder by removing semantic information from the code.
The
RenamePass uses a three-phase approach to safely rename all declarations and their references throughout the AST.Class Definition
lib/src/engine/passes/rename/rename_pass.dart:16
How It Works
TheRenamePass operates in three distinct phases:
Phase 1: Collection
Collects all renameable nodes and assigns obfuscated names using
RenameVisitorPhase 2: Transformation
Applies the renames so all declarations and references are updated using
RenameTransformerPhase 3: Unbinding
Unbinds canonical names for renamed user libraries so they can be recomputed correctly by
BinaryPrinter.writeComponentFileConfiguration Options
TheRenamePass behavior is controlled through PassOptions:
If
true, the top-level main procedure is not renamed. This is useful for maintaining a recognizable entry point.URI/path glob patterns for libraries to skip entirely. Libraries matching these patterns won’t be obfuscated.
Library Filtering
The pass automatically skips:- Dart SDK libraries (
dart:*) - External packages (packages not matching the project package name)
- Libraries matching exclude patterns (configured via
excludeLibraryUriPatterns) - Nodes with
@pragmaannotations (preserved to maintain framework compatibility)
Usage Example
Basic Usage
With PassRunner
Symbol Table Integration
TheRenamePass populates the SymbolTable with mappings from original names to obfuscated names. This is useful for:
- Debugging: Understanding what original names map to
- Stack trace deobfuscation: Converting obfuscated stack traces back to readable form
- Symbol maps: Generating external symbol mapping files
Testing
test/engine/passes/rename_pass_test.dart:25
Related
PassRunner
Orchestrates multiple passes
SymbolTable
Tracks original to obfuscated name mappings
StringEncryptPass
Encrypts string literals with XOR encoding
DeadCodePass
Injects unreachable dead code branches