-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustom-Sleep.rs
59 lines (51 loc) · 1.99 KB
/
Custom-Sleep.rs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::sync::mpsc::{channel, Receiver};
use std::thread;
use std::time::Duration;
use winapi::um::winnt::{DWORD, LPVOID};
use winapi::um::processthreadsapi::{GetCurrentThread, Sleep};
use winapi::um::memoryapi::{VirtualQuery, VirtualProtect};
use winapi::um::winnt::{PAGE_READWRITE, PAGE_EXECUTE_READWRITE};
// Encrypt the stack using a strong encryption algorithm
fn encrypt_stack(src: &mut [u8], len: usize, on_encrypted: fn(&usize)) {
// Implement your strong encryption algorithm here
for i in 0..len {
src[i] ^= 0x31; // XOR each byte with 0x31 as a simple example
}
on_encrypted(&len);
}
// Function to get the current stack address
fn get_stack_address() -> LPVOID {
let mut stack_info: winapi::um::memoryapi::MEMORY_BASIC_INFORMATION = unsafe { std::mem::zeroed() };
unsafe {
VirtualQuery(
std::ptr::null(),
&mut stack_info,
std::mem::size_of::<winapi::um::memoryapi::MEMORY_BASIC_INFORMATION>(),
);
}
stack_info.AllocationBase
}
// Sleep function that encrypts the stack and uses a channel to communicate encrypted stack size
fn sleep_with_encryption(ms: DWORD, on_encrypted: fn(&usize)) {
// Get the current stack address
let stack_address = get_stack_address();
// Create a new thread for encryption
let (tx, rx) = channel::<usize>();
thread::spawn(move || {
let mut stack_buffer: Vec<u8> = vec![0; std::mem::size_of::<winapi::um::memoryapi::MEMORY_BASIC_INFORMATION>() as usize]; // Adjust the size according to your stack size
unsafe {
std::ptr::copy_nonoverlapping(stack_address as *const u8, stack_buffer.as_mut_ptr(), stack_buffer.len());
}
encrypt_stack(&mut stack_buffer, stack_buffer.len(), on_encrypted);
});
// Sleep using the Windows API
unsafe {
Sleep(ms);
}
// Wait for the encryption thread to finish and receive the encrypted stack size
let encrypted_stack_size = rx.recv().unwrap();
println!("Encrypted stack size: {}", encrypted_stack_size);
}
fn main() {
sleep_with_encryption(1000, |len| println!("Stack encrypted with length: {}", len));
}