Overview
ThePassContext class provides shared state and utilities that all obfuscation passes can access. It contains the symbol table for tracking name mappings, a name generator for creating unique identifiers, configuration options, and scope resolution logic.
Source: lib/src/engine/runner/pass_context.dart:10
Constructor
Tracks original → obfuscated name mappings for debugging
Generates unique sequential obfuscated identifiers
Configuration options (exclusions, preserve_main, verbose, etc.)
The
PassContext automatically detects the project root and package name from pubspec.yaml when constructed. This is used by shouldObfuscateLibrary() to determine scope.Properties
symbolTable
Shared symbol table for recording original → obfuscated name mappings. All passes can add entries here.
nameGenerator
Shared name generator. Passes should call
nameGenerator.next() to get unique obfuscated identifiers.options
Configuration options including exclusion patterns,
preserve_main, string encryption settings, and verbose logging.Methods
shouldObfuscateLibrary()
The kernel
Library object to checktrue if the library should be obfuscated, false otherwisefalse for:
- SDK libraries (
dart:*) - External packages (package URIs not matching the current project)
- Libraries matching exclusion glob patterns in
options.excludeLibraryUriPatterns
true for:
- Libraries in the current project’s package (
package:my_app/*) - File-based libraries in the current directory
Scope Detection
PassContext automatically detects obfuscation scope:
-
Project package detection:
- Reads
pubspec.yamlfrom the current working directory - Extracts the
namefield to identify the project package - Example:
name: my_app→ onlypackage:my_app/*is obfuscated
- Reads
-
File-based libraries:
- Detects the project root path
- Includes all
file:URIs under the project directory
-
Exclusion patterns:
- Applies glob patterns from
options.excludeLibraryUriPatterns - Common patterns:
**/*.g.dart,**/*.freezed.dart
- Applies glob patterns from
This automatic scope detection ensures that only your code is obfuscated—external dependencies and SDK libraries are never touched, preventing runtime errors.
Usage Example
Integration with PassRunner
ThePassRunner creates a single PassContext instance and passes it to all configured passes:
- All passes share the same symbol table (consistent mappings)
- Name generation is sequential across all passes (no collisions)
- Configuration is consistent
See Also
Pass Interface
Base class that receives PassContext
PassRunner
Creates and manages PassContext
PassOptions
Configuration options in context
SymbolTable
Symbol table in context
NameGenerator
Name generator in context