forked from svenstaro/genact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memdump.rs
53 lines (45 loc) · 1.61 KB
/
memdump.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
/// Module that dumps some random memory locations in a slightly cool fashion.
use rand::prelude::*;
use std::io::Write;
use std::io::stdout;
use crate::utils::{csleep, dprint, is_printable_ascii, gen_hex_string};
use crate::parse_args::AppConfig;
pub fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let mut current_loc = (rng.gen_range(0, 2u64.pow(63)) / 16) * 16;
let num_lines = rng.gen_range(50, 200);
for _ in 1..num_lines {
dprint(format!("{loc:016x} ", loc = current_loc), 0);
current_loc += 0x10;
let values = (0..16)
.map(|_| gen_hex_string(&mut rng, 2))
.collect::<Vec<String>>();
// Print the values in two columns.
for (n, val) in values.iter().enumerate() {
if n == 8 {
dprint(" ", 0);
}
dprint(format!("{} ", val), 0);
let val_delay = rng.gen_range(0, 2);
stdout().flush().unwrap();
csleep(val_delay);
}
// Print the ascii values.
let mut ascii_repr = String::with_capacity(values.len());
for val in values {
let ascii_val = u8::from_str_radix(&val, 16).unwrap_or(b'.') as char;
if is_printable_ascii(ascii_val as u64) {
ascii_repr.push(ascii_val);
} else {
ascii_repr.push('.');
}
}
dprint(format!(" |{ascii_repr}|", ascii_repr = ascii_repr), 0);
let row_delay = rng.gen_range(10, 200);
csleep(row_delay);
if appconfig.should_exit() {
return;
}
println!();
}
}