mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-06 05:15:00 -06:00
Send executables initial message, use filename not path
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -89,7 +89,13 @@ async fn handle_socket(session_id: usize, websocket: WebSocket) {
|
|||||||
});
|
});
|
||||||
tokio::task::spawn(fut_handle_tx_buffer);
|
tokio::task::spawn(fut_handle_tx_buffer);
|
||||||
|
|
||||||
let mut store = STORE.lock().await;
|
let store = &mut *STORE.lock().await;
|
||||||
|
|
||||||
|
// Create the executable message first, borrow issues
|
||||||
|
let executable_message = OutgoingMessage::Executables {
|
||||||
|
executables: store.executable_json(),
|
||||||
|
};
|
||||||
|
|
||||||
let session = store
|
let session = store
|
||||||
.sessions
|
.sessions
|
||||||
.get_mut(&session_id)
|
.get_mut(&session_id)
|
||||||
@@ -100,7 +106,7 @@ async fn handle_socket(session_id: usize, websocket: WebSocket) {
|
|||||||
id: session_id,
|
id: session_id,
|
||||||
session: session.clone(),
|
session: session.clone(),
|
||||||
});
|
});
|
||||||
drop(store);
|
session.send_message(executable_message);
|
||||||
|
|
||||||
// Handle incoming messages
|
// Handle incoming messages
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
|
|||||||
@@ -94,15 +94,16 @@ impl<'a> State<'a> {
|
|||||||
let key_start = search(&data, pattern.as_bytes(), 0).unwrap();
|
let key_start = search(&data, pattern.as_bytes(), 0).unwrap();
|
||||||
let key_end = key_start + pattern.len();
|
let key_end = key_start + pattern.len();
|
||||||
|
|
||||||
let filename = path::Path::new(&exe_path);
|
let path = path::Path::new(&exe_path);
|
||||||
let name = filename.file_stem().unwrap().to_str().unwrap();
|
let name = path.file_stem().unwrap().to_str().unwrap();
|
||||||
let extension = match filename.extension() {
|
let extension = match path.extension() {
|
||||||
Some(s) => s.to_str().unwrap(),
|
Some(s) => s.to_str().unwrap(),
|
||||||
None => "",
|
None => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
let exe = Executable {
|
let exe = Executable {
|
||||||
data,
|
data,
|
||||||
|
filename: path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
extension: extension.to_string(),
|
extension: extension.to_string(),
|
||||||
key_start: key_start,
|
key_start: key_start,
|
||||||
@@ -141,11 +142,26 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn executable_json(&self) -> Vec<ExecutableJson> {
|
||||||
|
let mut executables = Vec::new();
|
||||||
|
|
||||||
|
for (key, exe) in &self.executables {
|
||||||
|
executables.push(ExecutableJson {
|
||||||
|
id: key.to_string(),
|
||||||
|
size: exe.data.len(),
|
||||||
|
filename: exe.filename.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return executables;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct Executable {
|
pub struct Executable {
|
||||||
pub data: Vec<u8>, // the raw data of the executable
|
pub data: Vec<u8>, // the raw data of the executable
|
||||||
|
pub filename: String,
|
||||||
pub name: String, // the name before the extension
|
pub name: String, // the name before the extension
|
||||||
pub extension: String, // may be empty string
|
pub extension: String, // may be empty string
|
||||||
pub key_start: usize, // the index of the byte where the key starts
|
pub key_start: usize, // the index of the byte where the key starts
|
||||||
|
|||||||
Reference in New Issue
Block a user