Skip to main content

thalir_core/obfuscation/
mod.rs

1/*! Strip names and metadata for confidential auditing.
2 *
3 * Proprietary code needs auditing but can't be shared openly. Hash identifiers and remove metadata
4 * while preserving security-relevant behavior, then map findings back to original names when reporting
5 * vulnerabilities.
6 */
7
8pub mod deobfuscator;
9pub mod mapping_store;
10pub mod name_obfuscator;
11pub mod pass;
12pub mod string_sanitizer;
13
14pub use deobfuscator::VulnerabilityMapper;
15pub use mapping_store::{MappingMetadata, ObfuscationMapping};
16pub use name_obfuscator::NameObfuscator;
17pub use pass::ObfuscationPass;
18pub use string_sanitizer::StringSanitizer;
19
20use serde::{Deserialize, Serialize};
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
23pub enum ObfuscationLevel {
24    None,
25    Minimal,
26    Standard,
27}
28
29impl Default for ObfuscationLevel {
30    fn default() -> Self {
31        Self::None
32    }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct ObfuscationConfig {
37    pub level: ObfuscationLevel,
38    pub retain_mapping: bool,
39    pub hash_salt: Option<String>,
40    pub strip_string_constants: bool,
41    pub strip_error_messages: bool,
42    pub strip_metadata: bool,
43}
44
45impl Default for ObfuscationConfig {
46    fn default() -> Self {
47        Self {
48            level: ObfuscationLevel::None,
49            retain_mapping: false,
50            hash_salt: None,
51            strip_string_constants: false,
52            strip_error_messages: false,
53            strip_metadata: false,
54        }
55    }
56}
57
58impl ObfuscationConfig {
59    pub fn standard() -> Self {
60        Self {
61            level: ObfuscationLevel::Standard,
62            retain_mapping: true,
63            hash_salt: None,
64            strip_string_constants: true,
65            strip_error_messages: true,
66            strip_metadata: true,
67        }
68    }
69
70    pub fn minimal() -> Self {
71        Self {
72            level: ObfuscationLevel::Minimal,
73            retain_mapping: true,
74            hash_salt: None,
75            strip_string_constants: false,
76            strip_error_messages: false,
77            strip_metadata: false,
78        }
79    }
80}