scanmem alternative with concurrent memory scanning
1use rand::Rng;
2use std::{
3 io::{self, Read, Write},
4 sync::mpsc,
5 thread,
6 time::Duration,
7};
8
9// This is a practice program to test if the main programs behaviour works fine
10// This program has been validated and confirmed to work as expected with scanmem
11
12fn main() {
13 let mut rng = rand::rng();
14
15 // Create an array of 10 random numbers
16 // const LEN: usize = 10_000_000;
17 const LEN: usize = 1000;
18
19 let mut numbers: Vec<i32> = vec![0; LEN];
20
21 for i in 0..LEN {
22 numbers[i] = rng.random_range(1..10);
23 }
24
25 let (tx, rx) = mpsc::channel();
26
27 thread::spawn(move || {
28 let mut buffer = [0; 1];
29 loop {
30 if let Ok(_) = io::stdin().read_exact(&mut buffer) {
31 let _ = tx.send(());
32 }
33 }
34 });
35
36 loop {
37 print!("\x1B[2J\x1B[1;1H");
38
39 println!("Memory Scanner Target - Press ENTER for new values, Ctrl+C to quit");
40 println!("Current values:");
41
42 for (i, &num) in numbers.iter().take(10).enumerate() {
43 println!("Index {}: {}", i, num);
44 }
45
46 println!("\nPress ENTER to generate new values...");
47 io::stdout().flush().unwrap();
48
49 if rx.recv_timeout(Duration::from_secs(1)).is_ok() {
50 for i in 0..LEN {
51 numbers[i] = rng.random_range(1..10);
52 }
53 }
54 }
55}