pub struct PowerShellProObfuscator {Show 31 fields
pub enable_compression: bool,
pub self_defending: bool,
pub protection_linker: bool,
pub rename_variables: bool,
pub rename_parameters: bool,
pub rename_functions: bool,
pub shuffle_functions: bool,
pub control_flow_flatten: bool,
pub state_machine: bool,
pub vm_strategy: bool,
pub encrypt_integers: bool,
pub split_strings: bool,
pub encrypt_strings: bool,
pub integers_to_arrays: bool,
pub floats_to_arrays: bool,
pub insert_dead_code: bool,
pub complexify_booleans: bool,
pub integers_to_floating: bool,
pub encrypt_floating: bool,
pub decoy_functions: bool,
pub detect_debugger: bool,
pub fake_dot_source_markers: bool,
pub opaque_branches: bool,
pub scriptblock_decoys: bool,
pub literal_padding: bool,
pub reflect_invoke_commands: bool,
pub string_char_array_vault: bool,
pub try_finally_noise: bool,
pub affine_integer_mask: bool,
pub event_stub: bool,
pub remove_comments: bool,
/* private fields */
}Expand description
PowerShell Pro Obfuscator WebApi client.
Fields§
§enable_compression: boolShould the source code be compressed.
self_defending: boolProtection against tampering with protected code (integrity verification).
protection_linker: boolProtection linker (decoy call graph).
rename_variables: boolRename variable names to random string values.
rename_parameters: boolRename parameter names to random string values.
rename_functions: boolRename function names to random string values.
shuffle_functions: boolShuffle function order in the output source.
control_flow_flatten: boolChange linear code execution flow via control-flow flattening.
state_machine: boolRewrite statement blocks into finite-state automata (state-machine obfuscation).
vm_strategy: boolLift selected statements into a VM engine (virtualized statements).
encrypt_integers: boolEncrypt integers.
split_strings: boolSplit strings into concatenated chunks.
encrypt_strings: boolEncrypt strings using randomly generated polymorphic encryption algorithms.
integers_to_arrays: boolMove integers to arrays.
floats_to_arrays: boolMove floats to arrays.
insert_dead_code: boolInsert dead code.
complexify_booleans: boolReplace boolean conditions with equivalent complex expressions.
integers_to_floating: boolRepresent integers via floating-point math.
encrypt_floating: boolEncrypt floating point numbers.
decoy_functions: boolInsert decoy functions.
detect_debugger: boolInsert anti-debugging detections.
fake_dot_source_markers: boolInsert fake dot-source comment markers.
opaque_branches: boolInsert opaque predicate branches.
scriptblock_decoys: boolInsert scriptblock decoys.
literal_padding: boolInsert here-string padding.
reflect_invoke_commands: boolUse indirect command invocation.
string_char_array_vault: boolStore string fragments in char-code array vaults.
try_finally_noise: boolWrap code in try/finally blocks with dead noise.
affine_integer_mask: boolApply redundant xor / affine integer masks.
event_stub: boolInsert dead event/timer stubs.
remove_comments: boolStrip comments from the output source.
Implementations§
Source§impl PowerShellProObfuscator
impl PowerShellProObfuscator
Sourcepub const API_URL: &'static str = "https://www.pelock.com/api/powershell-pro-obfuscator/v1"
pub const API_URL: &'static str = "https://www.pelock.com/api/powershell-pro-obfuscator/v1"
Default PowerShell Pro Obfuscator WebApi endpoint.
Sourcepub const ERROR_SUCCESS: i64 = 0
pub const ERROR_SUCCESS: i64 = 0
Success.
Sourcepub const ERROR_INPUT_SIZE: i64 = 1
pub const ERROR_INPUT_SIZE: i64 = 1
Invalid size for source code (it’s 1000 bytes max. for demo version).
Sourcepub const ERROR_INPUT: i64 = 2
pub const ERROR_INPUT: i64 = 2
Input source is empty.
Sourcepub const ERROR_PARSING: i64 = 3
pub const ERROR_PARSING: i64 = 3
PowerShell source code parsing error.
Sourcepub const ERROR_OBFUSCATION: i64 = 4
pub const ERROR_OBFUSCATION: i64 = 4
PowerShell parsed code obfuscation error.
Sourcepub const ERROR_OUTPUT: i64 = 5
pub const ERROR_OUTPUT: i64 = 5
An error occurred while generating output code.
Sourcepub fn new(api_key: Option<String>) -> Self
pub fn new(api_key: Option<String>) -> Self
Initialize PowerShell Pro Obfuscator client.
api_key — activation key for the service (it can be empty for demo mode).
Examples found in repository?
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17 //
18 // include PowerShell Pro Obfuscator class
19 //
20
21 //
22 // if you don't want to use crates.io use a path dependency to this crate
23 //
24 // [dependencies]
25 // powershell-pro-obfuscator = { path = ".." }
26
27 //
28 // create PowerShell Pro Obfuscator class instance (we are using our activation key)
29 //
30 let my_powershell_pro_obfuscator =
31 PowerShellProObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
32
33 //
34 // login to the service
35 //
36 let result = my_powershell_pro_obfuscator.login(true).await;
37
38 //
39 // result object holds the information about the license
40 //
41 // result.demo - is it a demo mode (invalid or empty activation key was used)
42 // result.credits_left - usage credits left after this operation
43 // result.credits_total - total number of credits for this activation code
44 // result.string_limit - max. source code size allowed (it's 1000 bytes for demo mode)
45 //
46 match result {
47 Some(PowerShellProObfuscatorResponse::Object(obj)) => {
48 println!(
49 "Demo version status - {}",
50 if obj.demo.unwrap_or(false) {
51 "true"
52 } else {
53 "false"
54 }
55 );
56 println!(
57 "Usage credits left - {}",
58 obj.credits_left.unwrap_or(0)
59 );
60 println!(
61 "Total usage credits - {}",
62 obj.credits_total.unwrap_or(0)
63 );
64 println!(
65 "Max. source code size - {}",
66 obj.string_limit.unwrap_or(0)
67 );
68 }
69 Some(PowerShellProObfuscatorResponse::Json(_)) => {}
70 None => {
71 return Err("Something unexpected happen while trying to login to the service.".into());
72 }
73 }
74
75 Ok(())
76}More examples
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17 //
18 // include PowerShell Pro Obfuscator class
19 //
20
21 //
22 // when developing from a repository clone without installing the package use:
23 //
24 // use powershell_pro_obfuscator::{PowerShellProObfuscator, PowerShellProObfuscatorResponse};
25 // (path dependency in Cargo.toml pointing to this crate)
26
27 //
28 // create PowerShell Pro Obfuscator class instance (we are using our activation key)
29 //
30 let my_powershell_pro_obfuscator =
31 PowerShellProObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
32
33 //
34 // source code in PowerShell format
35 //
36 let script_source_code = r#"function Get-Greeting {
37 param([string]$Name)
38 Write-Host "Hello World from $Name!"
39}
40Get-Greeting "PowerShell Pro Obfuscator""#;
41
42 //
43 // by default all obfuscation options are enabled, so we can just simply call:
44 //
45 let result = my_powershell_pro_obfuscator
46 .obfuscate_script_source(script_source_code, true)
47 .await;
48
49 //
50 // it's also possible to pass a PowerShell script file path instead of a string e.g.
51 //
52 // let result = my_powershell_pro_obfuscator
53 // .obfuscate_script_file(std::path::Path::new("/path/to/project/script.ps1"), true)
54 // .await;
55
56 //
57 // result object holds the obfuscation results as well as other information
58 //
59 // result.error - error code
60 // result.output - obfuscated code
61 // result.demo - was it used in demo mode (invalid or empty activation key was used)
62 // result.credits_left - usage credits left after this operation
63 // result.credits_total - total number of credits for this activation code
64 // result.expired - if this was the last usage credit for the activation key it will be set to true
65 //
66 match result {
67 Some(PowerShellProObfuscatorResponse::Object(obj)) => {
68 //
69 // display obfuscated code
70 //
71 if obj.error == PowerShellProObfuscator::ERROR_SUCCESS {
72 println!("{}", obj.output.unwrap_or_default());
73 } else {
74 return Err(
75 format!("An error occurred, error code: {}", obj.error).into(),
76 );
77 }
78 }
79 Some(PowerShellProObfuscatorResponse::Json(_)) => {}
80 None => {
81 return Err("Something unexpected happen while trying to obfuscate the code.".into());
82 }
83 }
84
85 Ok(())
86}16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17 //
18 // include PowerShell Pro Obfuscator class
19 //
20
21 //
22 // when developing from a repository clone without installing the package use:
23 //
24 // use powershell_pro_obfuscator::{PowerShellProObfuscator, PowerShellProObfuscatorResponse};
25 // (path dependency in Cargo.toml pointing to this crate)
26
27 //
28 // create PowerShell Pro Obfuscator class instance (we are using our activation key)
29 //
30 let mut my_powershell_pro_obfuscator =
31 PowerShellProObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
32
33 //
34 // should the source code be compressed (both input & compressed)
35 //
36 my_powershell_pro_obfuscator.enable_compression = false;
37
38 //
39 // global obfuscation options
40 //
41 // you can disable a particular obfuscation strategy globally if it
42 // fails or you don't want to use it without modifying the source codes
43 //
44 // by default all obfuscation strategies are enabled
45 //
46
47 //
48 // protection against tampering with protected code (integrity verification)
49 //
50 my_powershell_pro_obfuscator.self_defending = true;
51
52 //
53 // protection linker (decoy call graph)
54 //
55 my_powershell_pro_obfuscator.protection_linker = true;
56
57 //
58 // rename variable names to random string values
59 //
60 my_powershell_pro_obfuscator.rename_variables = true;
61
62 //
63 // rename parameter names to random string values
64 //
65 my_powershell_pro_obfuscator.rename_parameters = true;
66
67 //
68 // rename function names to random string values
69 //
70 my_powershell_pro_obfuscator.rename_functions = true;
71
72 //
73 // shuffle function order in the output source
74 //
75 my_powershell_pro_obfuscator.shuffle_functions = true;
76
77 //
78 // change linear code execution flow via control-flow flattening
79 //
80 my_powershell_pro_obfuscator.control_flow_flatten = true;
81
82 //
83 // rewrite statement blocks into finite-state automata (state-machine obfuscation)
84 //
85 my_powershell_pro_obfuscator.state_machine = true;
86
87 //
88 // lift selected statements into a VM engine (virtualized statements)
89 //
90 my_powershell_pro_obfuscator.vm_strategy = true;
91
92 //
93 // encrypt integers
94 //
95 my_powershell_pro_obfuscator.encrypt_integers = true;
96
97 //
98 // split strings into concatenated chunks
99 //
100 my_powershell_pro_obfuscator.split_strings = true;
101
102 //
103 // encrypt strings using randomly generated polymorphic encryption algorithms
104 //
105 my_powershell_pro_obfuscator.encrypt_strings = true;
106
107 //
108 // move integers to arrays
109 //
110 my_powershell_pro_obfuscator.integers_to_arrays = true;
111
112 //
113 // move floats to arrays
114 //
115 my_powershell_pro_obfuscator.floats_to_arrays = true;
116
117 //
118 // insert dead code
119 //
120 my_powershell_pro_obfuscator.insert_dead_code = true;
121
122 //
123 // replace boolean conditions with equivalent complex expressions
124 //
125 my_powershell_pro_obfuscator.complexify_booleans = true;
126
127 //
128 // represent integers via floating-point math
129 //
130 my_powershell_pro_obfuscator.integers_to_floating = true;
131
132 //
133 // encrypt floating point numbers
134 //
135 my_powershell_pro_obfuscator.encrypt_floating = true;
136
137 //
138 // insert decoy functions
139 //
140 my_powershell_pro_obfuscator.decoy_functions = true;
141
142 //
143 // insert anti-debugging detections
144 //
145 my_powershell_pro_obfuscator.detect_debugger = true;
146
147 //
148 // insert fake dot-source comment markers
149 //
150 my_powershell_pro_obfuscator.fake_dot_source_markers = true;
151
152 //
153 // insert opaque predicate branches
154 //
155 my_powershell_pro_obfuscator.opaque_branches = true;
156
157 //
158 // insert scriptblock decoys
159 //
160 my_powershell_pro_obfuscator.scriptblock_decoys = true;
161
162 //
163 // insert here-string padding
164 //
165 my_powershell_pro_obfuscator.literal_padding = true;
166
167 //
168 // use indirect command invocation
169 //
170 my_powershell_pro_obfuscator.reflect_invoke_commands = true;
171
172 //
173 // store string fragments in char-code array vaults
174 //
175 my_powershell_pro_obfuscator.string_char_array_vault = true;
176
177 //
178 // wrap code in try/finally blocks with dead noise
179 //
180 my_powershell_pro_obfuscator.try_finally_noise = true;
181
182 //
183 // apply redundant xor / affine integer masks
184 //
185 my_powershell_pro_obfuscator.affine_integer_mask = true;
186
187 //
188 // insert dead event/timer stubs
189 //
190 my_powershell_pro_obfuscator.event_stub = true;
191
192 //
193 // strip comments from the output source
194 //
195 my_powershell_pro_obfuscator.remove_comments = true;
196
197 //
198 // source code in PowerShell format
199 //
200 let script_source_code = r#"function Get-Greeting {
201 param([string]$Name)
202 Write-Host "Hello World from $Name!"
203}
204Get-Greeting "PowerShell Pro Obfuscator""#;
205
206 //
207 // by default all obfuscation options are enabled, so we can just simply call:
208 //
209 let result = my_powershell_pro_obfuscator
210 .obfuscate_script_source(script_source_code, true)
211 .await;
212
213 //
214 // it's also possible to pass a PowerShell script file path instead of a string e.g.
215 //
216 // let result = my_powershell_pro_obfuscator
217 // .obfuscate_script_file(std::path::Path::new("/path/to/project/script.ps1"), true)
218 // .await;
219
220 //
221 // result object holds the obfuscation results as well as other information
222 //
223 // result.error - error code
224 // result.output - obfuscated code
225 // result.demo - was it used in demo mode (invalid or empty activation key was used)
226 // result.credits_left - usage credits left after this operation
227 // result.credits_total - total number of credits for this activation code
228 // result.expired - if this was the last usage credit for the activation key it will be set to true
229 //
230 match result {
231 Some(PowerShellProObfuscatorResponse::Object(obj)) => {
232 //
233 // display obfuscated code
234 //
235 if obj.error == PowerShellProObfuscator::ERROR_SUCCESS {
236 println!("{}", obj.output.unwrap_or_default());
237 } else {
238 return Err(
239 format!("An error occurred, error code: {}", obj.error).into(),
240 );
241 }
242 }
243 Some(PowerShellProObfuscatorResponse::Json(_)) => {}
244 None => {
245 return Err("Something unexpected happen while trying to obfuscate the code.".into());
246 }
247 }
248
249 Ok(())
250}Sourcepub async fn login(
&self,
return_as_object: bool,
) -> Option<PowerShellProObfuscatorResponse>
pub async fn login( &self, return_as_object: bool, ) -> Option<PowerShellProObfuscatorResponse>
Login to the service and get the information about the current license limits.
return_as_object — return result as an object or JSON encoded string.
Examples found in repository?
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17 //
18 // include PowerShell Pro Obfuscator class
19 //
20
21 //
22 // if you don't want to use crates.io use a path dependency to this crate
23 //
24 // [dependencies]
25 // powershell-pro-obfuscator = { path = ".." }
26
27 //
28 // create PowerShell Pro Obfuscator class instance (we are using our activation key)
29 //
30 let my_powershell_pro_obfuscator =
31 PowerShellProObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
32
33 //
34 // login to the service
35 //
36 let result = my_powershell_pro_obfuscator.login(true).await;
37
38 //
39 // result object holds the information about the license
40 //
41 // result.demo - is it a demo mode (invalid or empty activation key was used)
42 // result.credits_left - usage credits left after this operation
43 // result.credits_total - total number of credits for this activation code
44 // result.string_limit - max. source code size allowed (it's 1000 bytes for demo mode)
45 //
46 match result {
47 Some(PowerShellProObfuscatorResponse::Object(obj)) => {
48 println!(
49 "Demo version status - {}",
50 if obj.demo.unwrap_or(false) {
51 "true"
52 } else {
53 "false"
54 }
55 );
56 println!(
57 "Usage credits left - {}",
58 obj.credits_left.unwrap_or(0)
59 );
60 println!(
61 "Total usage credits - {}",
62 obj.credits_total.unwrap_or(0)
63 );
64 println!(
65 "Max. source code size - {}",
66 obj.string_limit.unwrap_or(0)
67 );
68 }
69 Some(PowerShellProObfuscatorResponse::Json(_)) => {}
70 None => {
71 return Err("Something unexpected happen while trying to login to the service.".into());
72 }
73 }
74
75 Ok(())
76}Sourcepub async fn obfuscate_script_file(
&self,
script_file_path: &Path,
return_as_object: bool,
) -> Option<PowerShellProObfuscatorResponse>
pub async fn obfuscate_script_file( &self, script_file_path: &Path, return_as_object: bool, ) -> Option<PowerShellProObfuscatorResponse>
Obfuscate PowerShell script source code file using provided parameters.
return_as_object — return result as an object or JSON encoded string.
Sourcepub async fn obfuscate_script_source(
&self,
script_source: &str,
return_as_object: bool,
) -> Option<PowerShellProObfuscatorResponse>
pub async fn obfuscate_script_source( &self, script_source: &str, return_as_object: bool, ) -> Option<PowerShellProObfuscatorResponse>
Obfuscate PowerShell script source code (string) using provided parameters.
return_as_object — return result as an object or JSON encoded string.
Examples found in repository?
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17 //
18 // include PowerShell Pro Obfuscator class
19 //
20
21 //
22 // when developing from a repository clone without installing the package use:
23 //
24 // use powershell_pro_obfuscator::{PowerShellProObfuscator, PowerShellProObfuscatorResponse};
25 // (path dependency in Cargo.toml pointing to this crate)
26
27 //
28 // create PowerShell Pro Obfuscator class instance (we are using our activation key)
29 //
30 let my_powershell_pro_obfuscator =
31 PowerShellProObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
32
33 //
34 // source code in PowerShell format
35 //
36 let script_source_code = r#"function Get-Greeting {
37 param([string]$Name)
38 Write-Host "Hello World from $Name!"
39}
40Get-Greeting "PowerShell Pro Obfuscator""#;
41
42 //
43 // by default all obfuscation options are enabled, so we can just simply call:
44 //
45 let result = my_powershell_pro_obfuscator
46 .obfuscate_script_source(script_source_code, true)
47 .await;
48
49 //
50 // it's also possible to pass a PowerShell script file path instead of a string e.g.
51 //
52 // let result = my_powershell_pro_obfuscator
53 // .obfuscate_script_file(std::path::Path::new("/path/to/project/script.ps1"), true)
54 // .await;
55
56 //
57 // result object holds the obfuscation results as well as other information
58 //
59 // result.error - error code
60 // result.output - obfuscated code
61 // result.demo - was it used in demo mode (invalid or empty activation key was used)
62 // result.credits_left - usage credits left after this operation
63 // result.credits_total - total number of credits for this activation code
64 // result.expired - if this was the last usage credit for the activation key it will be set to true
65 //
66 match result {
67 Some(PowerShellProObfuscatorResponse::Object(obj)) => {
68 //
69 // display obfuscated code
70 //
71 if obj.error == PowerShellProObfuscator::ERROR_SUCCESS {
72 println!("{}", obj.output.unwrap_or_default());
73 } else {
74 return Err(
75 format!("An error occurred, error code: {}", obj.error).into(),
76 );
77 }
78 }
79 Some(PowerShellProObfuscatorResponse::Json(_)) => {}
80 None => {
81 return Err("Something unexpected happen while trying to obfuscate the code.".into());
82 }
83 }
84
85 Ok(())
86}More examples
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17 //
18 // include PowerShell Pro Obfuscator class
19 //
20
21 //
22 // when developing from a repository clone without installing the package use:
23 //
24 // use powershell_pro_obfuscator::{PowerShellProObfuscator, PowerShellProObfuscatorResponse};
25 // (path dependency in Cargo.toml pointing to this crate)
26
27 //
28 // create PowerShell Pro Obfuscator class instance (we are using our activation key)
29 //
30 let mut my_powershell_pro_obfuscator =
31 PowerShellProObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
32
33 //
34 // should the source code be compressed (both input & compressed)
35 //
36 my_powershell_pro_obfuscator.enable_compression = false;
37
38 //
39 // global obfuscation options
40 //
41 // you can disable a particular obfuscation strategy globally if it
42 // fails or you don't want to use it without modifying the source codes
43 //
44 // by default all obfuscation strategies are enabled
45 //
46
47 //
48 // protection against tampering with protected code (integrity verification)
49 //
50 my_powershell_pro_obfuscator.self_defending = true;
51
52 //
53 // protection linker (decoy call graph)
54 //
55 my_powershell_pro_obfuscator.protection_linker = true;
56
57 //
58 // rename variable names to random string values
59 //
60 my_powershell_pro_obfuscator.rename_variables = true;
61
62 //
63 // rename parameter names to random string values
64 //
65 my_powershell_pro_obfuscator.rename_parameters = true;
66
67 //
68 // rename function names to random string values
69 //
70 my_powershell_pro_obfuscator.rename_functions = true;
71
72 //
73 // shuffle function order in the output source
74 //
75 my_powershell_pro_obfuscator.shuffle_functions = true;
76
77 //
78 // change linear code execution flow via control-flow flattening
79 //
80 my_powershell_pro_obfuscator.control_flow_flatten = true;
81
82 //
83 // rewrite statement blocks into finite-state automata (state-machine obfuscation)
84 //
85 my_powershell_pro_obfuscator.state_machine = true;
86
87 //
88 // lift selected statements into a VM engine (virtualized statements)
89 //
90 my_powershell_pro_obfuscator.vm_strategy = true;
91
92 //
93 // encrypt integers
94 //
95 my_powershell_pro_obfuscator.encrypt_integers = true;
96
97 //
98 // split strings into concatenated chunks
99 //
100 my_powershell_pro_obfuscator.split_strings = true;
101
102 //
103 // encrypt strings using randomly generated polymorphic encryption algorithms
104 //
105 my_powershell_pro_obfuscator.encrypt_strings = true;
106
107 //
108 // move integers to arrays
109 //
110 my_powershell_pro_obfuscator.integers_to_arrays = true;
111
112 //
113 // move floats to arrays
114 //
115 my_powershell_pro_obfuscator.floats_to_arrays = true;
116
117 //
118 // insert dead code
119 //
120 my_powershell_pro_obfuscator.insert_dead_code = true;
121
122 //
123 // replace boolean conditions with equivalent complex expressions
124 //
125 my_powershell_pro_obfuscator.complexify_booleans = true;
126
127 //
128 // represent integers via floating-point math
129 //
130 my_powershell_pro_obfuscator.integers_to_floating = true;
131
132 //
133 // encrypt floating point numbers
134 //
135 my_powershell_pro_obfuscator.encrypt_floating = true;
136
137 //
138 // insert decoy functions
139 //
140 my_powershell_pro_obfuscator.decoy_functions = true;
141
142 //
143 // insert anti-debugging detections
144 //
145 my_powershell_pro_obfuscator.detect_debugger = true;
146
147 //
148 // insert fake dot-source comment markers
149 //
150 my_powershell_pro_obfuscator.fake_dot_source_markers = true;
151
152 //
153 // insert opaque predicate branches
154 //
155 my_powershell_pro_obfuscator.opaque_branches = true;
156
157 //
158 // insert scriptblock decoys
159 //
160 my_powershell_pro_obfuscator.scriptblock_decoys = true;
161
162 //
163 // insert here-string padding
164 //
165 my_powershell_pro_obfuscator.literal_padding = true;
166
167 //
168 // use indirect command invocation
169 //
170 my_powershell_pro_obfuscator.reflect_invoke_commands = true;
171
172 //
173 // store string fragments in char-code array vaults
174 //
175 my_powershell_pro_obfuscator.string_char_array_vault = true;
176
177 //
178 // wrap code in try/finally blocks with dead noise
179 //
180 my_powershell_pro_obfuscator.try_finally_noise = true;
181
182 //
183 // apply redundant xor / affine integer masks
184 //
185 my_powershell_pro_obfuscator.affine_integer_mask = true;
186
187 //
188 // insert dead event/timer stubs
189 //
190 my_powershell_pro_obfuscator.event_stub = true;
191
192 //
193 // strip comments from the output source
194 //
195 my_powershell_pro_obfuscator.remove_comments = true;
196
197 //
198 // source code in PowerShell format
199 //
200 let script_source_code = r#"function Get-Greeting {
201 param([string]$Name)
202 Write-Host "Hello World from $Name!"
203}
204Get-Greeting "PowerShell Pro Obfuscator""#;
205
206 //
207 // by default all obfuscation options are enabled, so we can just simply call:
208 //
209 let result = my_powershell_pro_obfuscator
210 .obfuscate_script_source(script_source_code, true)
211 .await;
212
213 //
214 // it's also possible to pass a PowerShell script file path instead of a string e.g.
215 //
216 // let result = my_powershell_pro_obfuscator
217 // .obfuscate_script_file(std::path::Path::new("/path/to/project/script.ps1"), true)
218 // .await;
219
220 //
221 // result object holds the obfuscation results as well as other information
222 //
223 // result.error - error code
224 // result.output - obfuscated code
225 // result.demo - was it used in demo mode (invalid or empty activation key was used)
226 // result.credits_left - usage credits left after this operation
227 // result.credits_total - total number of credits for this activation code
228 // result.expired - if this was the last usage credit for the activation key it will be set to true
229 //
230 match result {
231 Some(PowerShellProObfuscatorResponse::Object(obj)) => {
232 //
233 // display obfuscated code
234 //
235 if obj.error == PowerShellProObfuscator::ERROR_SUCCESS {
236 println!("{}", obj.output.unwrap_or_default());
237 } else {
238 return Err(
239 format!("An error occurred, error code: {}", obj.error).into(),
240 );
241 }
242 }
243 Some(PowerShellProObfuscatorResponse::Json(_)) => {}
244 None => {
245 return Err("Something unexpected happen while trying to obfuscate the code.".into());
246 }
247 }
248
249 Ok(())
250}