-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmirror.rs
97 lines (83 loc) · 2.75 KB
/
mirror.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use ::std::{thread, time::Duration};
use ::clap::{crate_authors, crate_version, Arg, ArgAction, Command};
use ::log::Level;
use ::memflow::prelude::v1::*;
use ::mirror::prelude::v1::*;
fn main() -> Result<()> {
let matches = Command::new("memflow-mirror-example")
.version(crate_version!())
.author(crate_authors!())
.arg(Arg::new("verbose").short('v').action(ArgAction::Count))
.arg(
Arg::new("connector")
.long("connector")
.short('c')
.action(ArgAction::Append)
.required(false),
)
.arg(
Arg::new("os")
.long("os")
.short('o')
.action(ArgAction::Append)
.required(true),
)
.get_matches();
let log_level = match matches.get_count("verbose") {
0 => Level::Error,
1 => Level::Warn,
2 => Level::Info,
3 => Level::Debug,
4 => Level::Trace,
_ => Level::Trace,
};
simplelog::TermLogger::init(
log_level.to_level_filter(),
simplelog::Config::default(),
simplelog::TerminalMode::Stdout,
simplelog::ColorChoice::Auto,
)
.unwrap();
// parse args
let conn_iter = matches
.indices_of("connector")
.zip(matches.get_many::<String>("connector"))
.map(|(a, b)| a.zip(b.map(String::as_str)))
.into_iter()
.flatten();
let os_iter = matches
.indices_of("os")
.zip(matches.get_many::<String>("os"))
.map(|(a, b)| a.zip(b.map(String::as_str)))
.into_iter()
.flatten();
let chain = OsChain::new(conn_iter, os_iter)?;
// create memflow inventory + os
let inventory = Inventory::scan();
let os = inventory.builder().os_chain(chain).build()?;
// initialize capture
let mut capture = SequentialCapture::new(os);
// let mut capture = ThreadedCapture::new(os); // Alternatively a multithreaded capture can be used
capture.set_obs_capture(true);
let mut frame_counter = 0;
loop {
// update internal state, then read frame_counter and image_data
capture.update();
// only update frame_texture on demand
let current_frame_counter = capture.frame_counter();
if current_frame_counter != frame_counter {
// grab image data
let frame = capture.image_data();
// update frame_counter
frame_counter = current_frame_counter;
// output stats
println!(
"frame {} read: size={}x{}",
frame_counter,
frame.width(),
frame.height()
);
}
thread::sleep(Duration::from_millis(10));
}
}