Skip to main content

PowerShellProObfuscator

Struct PowerShellProObfuscator 

Source
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: bool

Should the source code be compressed.

§self_defending: bool

Protection against tampering with protected code (integrity verification).

§protection_linker: bool

Protection linker (decoy call graph).

§rename_variables: bool

Rename variable names to random string values.

§rename_parameters: bool

Rename parameter names to random string values.

§rename_functions: bool

Rename function names to random string values.

§shuffle_functions: bool

Shuffle function order in the output source.

§control_flow_flatten: bool

Change linear code execution flow via control-flow flattening.

§state_machine: bool

Rewrite statement blocks into finite-state automata (state-machine obfuscation).

§vm_strategy: bool

Lift selected statements into a VM engine (virtualized statements).

§encrypt_integers: bool

Encrypt integers.

§split_strings: bool

Split strings into concatenated chunks.

§encrypt_strings: bool

Encrypt strings using randomly generated polymorphic encryption algorithms.

§integers_to_arrays: bool

Move integers to arrays.

§floats_to_arrays: bool

Move floats to arrays.

§insert_dead_code: bool

Insert dead code.

§complexify_booleans: bool

Replace boolean conditions with equivalent complex expressions.

§integers_to_floating: bool

Represent integers via floating-point math.

§encrypt_floating: bool

Encrypt floating point numbers.

§decoy_functions: bool

Insert decoy functions.

§detect_debugger: bool

Insert anti-debugging detections.

§fake_dot_source_markers: bool

Insert fake dot-source comment markers.

§opaque_branches: bool

Insert opaque predicate branches.

§scriptblock_decoys: bool

Insert scriptblock decoys.

§literal_padding: bool

Insert here-string padding.

§reflect_invoke_commands: bool

Use indirect command invocation.

§string_char_array_vault: bool

Store string fragments in char-code array vaults.

§try_finally_noise: bool

Wrap code in try/finally blocks with dead noise.

§affine_integer_mask: bool

Apply redundant xor / affine integer masks.

§event_stub: bool

Insert dead event/timer stubs.

§remove_comments: bool

Strip comments from the output source.

Implementations§

Source§

impl PowerShellProObfuscator

Source

pub const API_URL: &'static str = "https://www.pelock.com/api/powershell-pro-obfuscator/v1"

Default PowerShell Pro Obfuscator WebApi endpoint.

Source

pub const ERROR_SUCCESS: i64 = 0

Success.

Source

pub const ERROR_INPUT_SIZE: i64 = 1

Invalid size for source code (it’s 1000 bytes max. for demo version).

Source

pub const ERROR_INPUT: i64 = 2

Input source is empty.

Source

pub const ERROR_PARSING: i64 = 3

PowerShell source code parsing error.

Source

pub const ERROR_OBFUSCATION: i64 = 4

PowerShell parsed code obfuscation error.

Source

pub const ERROR_OUTPUT: i64 = 5

An error occurred while generating output code.

Source

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?
examples/powershell-pro-obfuscator-example-is-demo.rs (line 31)
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
Hide additional examples
examples/powershell-pro-obfuscator-example-simple.rs (line 31)
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}
examples/powershell-pro-obfuscator-example.rs (line 31)
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}
Source

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?
examples/powershell-pro-obfuscator-example-is-demo.rs (line 36)
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}
Source

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.

Source

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?
examples/powershell-pro-obfuscator-example-simple.rs (line 46)
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
Hide additional examples
examples/powershell-pro-obfuscator-example.rs (line 210)
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}

Trait Implementations§

Source§

impl Clone for PowerShellProObfuscator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PowerShellProObfuscator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more