-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathconfig.py
More file actions
42 lines (29 loc) · 1.27 KB
/
Copy pathconfig.py
File metadata and controls
42 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations
from dataclasses import dataclass
@dataclass(frozen=True)
class ObfuscationConfig:
"""Immutable configuration describing which techniques are enabled.
Prefer the factory classmethods over constructing directly::
# Enable everything registered
cfg = ObfuscationConfig.all_enabled()
# Enable a specific subset
cfg = ObfuscationConfig.only("variable_renamer", "string_hex_encoder")
# Start from all-enabled and exclude one
cfg = ObfuscationConfig.all_enabled().without("string_hex_encoder")
"""
enabled_techniques: frozenset[str]
@classmethod
def all_enabled(cls) -> ObfuscationConfig:
from .techniques.registry import all_technique_names
return cls(enabled_techniques=all_technique_names())
@classmethod
def only(cls, *names: str) -> ObfuscationConfig:
return cls(enabled_techniques=frozenset(names))
def without(self, *names: str) -> ObfuscationConfig:
return ObfuscationConfig(
enabled_techniques=self.enabled_techniques - frozenset(names)
)
def with_added(self, *names: str) -> ObfuscationConfig:
return ObfuscationConfig(
enabled_techniques=self.enabled_techniques | frozenset(names)
)