Skip to content

Commit aae9dda

Browse files
committed
Create error_handling.rs
1 parent fd5b464 commit aae9dda

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Comprehensive error handling example
2+
//! Author: BlackTechX
3+
4+
use process_ghosting::{GhostingBuilder, init, parse_hex_string};
5+
6+
fn main() {
7+
init();
8+
9+
println!("[*] Error Handling Example\n");
10+
11+
// Test 1: Invalid file
12+
println!("[Test 1] Loading non-existent file:");
13+
match GhostingBuilder::from_file("nonexistent.exe") {
14+
Ok(_) => println!(" Unexpected success"),
15+
Err(e) => println!(" Expected error: {}", e),
16+
}
17+
println!();
18+
19+
// Test 2: Invalid hex string
20+
println!("[Test 2] Parsing invalid hex:");
21+
match parse_hex_string("ZZZZ") {
22+
Ok(_) => println!(" Unexpected success"),
23+
Err(e) => println!(" Expected error: {}", e),
24+
}
25+
println!();
26+
27+
// Test 3: Invalid PE (not MZ header)
28+
println!("[Test 3] Executing invalid PE:");
29+
let invalid_pe = vec![0x00, 0x00, 0x00, 0x00]; // Not MZ
30+
match GhostingBuilder::new(&invalid_pe).x64().execute() {
31+
Ok(_) => println!(" Unexpected success"),
32+
Err(e) => println!(" Expected error: {}", e),
33+
}
34+
println!();
35+
36+
// Test 4: Empty payload
37+
println!("[Test 4] Empty payload:");
38+
match GhostingBuilder::new(&[]).x64().execute() {
39+
Ok(_) => println!(" Unexpected success"),
40+
Err(e) => println!(" Expected error: {}", e),
41+
}
42+
println!();
43+
44+
// Test 5: Truncated PE
45+
println!("[Test 5] Truncated PE (only MZ header):");
46+
let truncated_pe = vec![0x4D, 0x5A]; // Just MZ
47+
match GhostingBuilder::new(&truncated_pe).x64().execute() {
48+
Ok(_) => println!(" Unexpected success"),
49+
Err(e) => println!(" Expected error: {}", e),
50+
}
51+
println!();
52+
53+
println!("[*] Error handling tests complete.");
54+
}

0 commit comments

Comments
 (0)