Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add todo for non-exhaustive MftAttributType match #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/callback.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use rswinthings::winevt::callback::CallbackContext;
use rswinthings::winevt::subscription::ChannelSubscription;
use std::thread::sleep;
use std::time::Duration;
use rswinthings::winevt::subscription::ChannelSubscription;
use rswinthings::winevt::callback::CallbackContext;


fn main() {
// Create context
Expand All @@ -14,7 +13,7 @@ fn main() {
"Security".to_owned(),
Some("*".to_owned()),
None,
&context
&context,
);

// Create subscription
Expand All @@ -23,10 +22,10 @@ fn main() {
"Windows PowerShell".to_owned(),
Some("*".to_owned()),
None,
&context
&context,
);

loop {
sleep(Duration::from_millis(200));
}
}
}
5 changes: 2 additions & 3 deletions examples/traceconsumer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rswinthings::winetl::consumer::TraceConsumer;
use std::thread::sleep;
use std::time::Duration;
use rswinthings::winetl::consumer::TraceConsumer;


fn main() {
// Create context
Expand All @@ -11,4 +10,4 @@ fn main() {
println!("Sleeping...");
sleep(Duration::from_millis(200));
}
}
}
141 changes: 49 additions & 92 deletions src/bin/listen_events.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
extern crate log;
extern crate clap;
extern crate chrono;
extern crate clap;
extern crate log;
extern crate serde_json;
use clap::{App, Arg};
use std::process::exit;
use std::thread::sleep;
use std::time::Duration;
use rswinthings::utils::cli::{add_session_options_to_app, get_session_from_matches};
use rswinthings::utils::debug::set_debug_level;
use rswinthings::winevt::callback::CallbackContext;
use rswinthings::winevt::callback::OutputFormat;
use rswinthings::winevt::channels::get_channel_name_list;
use rswinthings::winevt::channels::ChannelConfig;
use rswinthings::winevt::callback::OutputFormat;
use rswinthings::winevt::callback::CallbackContext;
use rswinthings::winevt::subscription::ChannelSubscription;
use winapi::um::winevt::{
EvtSubscribeToFutureEvents,
EvtSubscribeStartAtOldestRecord
};
use rswinthings::utils::cli::{
add_session_options_to_app,
get_session_from_matches
};
use rswinthings::winevt::EvtHandle;

use std::process::exit;
use std::thread::sleep;
use std::time::Duration;
use winapi::um::winevt::{EvtSubscribeStartAtOldestRecord, EvtSubscribeToFutureEvents};

static VERSION: &'static str = "0.3.0";
static DESCRIPTION: &'static str = r"
Expand All @@ -33,7 +26,6 @@ channels. Use the print_channels tool to list available channels and
their configurations.
";


fn make_app<'a, 'b>() -> App<'a, 'b> {
let channel = Arg::with_name("channel")
.short("-c")
Expand Down Expand Up @@ -77,16 +69,14 @@ fn make_app<'a, 'b>() -> App<'a, 'b> {
add_session_options_to_app(app)
}


fn get_query_list_from_system(
session: &Option<EvtHandle>,
context: &CallbackContext,
flags: Option<u32>
context: &CallbackContext,
flags: Option<u32>,
) -> Vec<ChannelSubscription> {
let mut subscriptions: Vec<ChannelSubscription> = Vec::new();
// Get a list off all the channels
let channel_list = get_channel_name_list(&session)
.expect("Error getting channel list");
let channel_list = get_channel_name_list(&session).expect("Error getting channel list");
// Iterate each channel in our available channels
for channel in channel_list {
// Get the config for this channel
Expand All @@ -112,119 +102,86 @@ fn get_query_list_from_system(
eprintln!("listening to channel: {}", channel);

// Create subscription
let subscription = match ChannelSubscription::new(
session,
channel.to_string(),
None,
flags,
&context
){
Ok(s) => s,
Err(e) => {
eprintln!("Error creating subscription for {}: {:?}", channel, e);
continue;
}
};
let subscription =
match ChannelSubscription::new(session, channel.to_string(), None, flags, &context) {
Ok(s) => s,
Err(e) => {
eprintln!("Error creating subscription for {}: {:?}", channel, e);
continue;
}
};

subscriptions.push(subscription);
}

subscriptions
}


fn get_query_list_from_str_list<'a>(
session: &Option<EvtHandle>,
context: &CallbackContext,
context: &CallbackContext,
flags: Option<u32>,
channel_list: Vec<&'a str>
channel_list: Vec<&'a str>,
) -> Vec<ChannelSubscription> {
let mut subscriptions: Vec<ChannelSubscription> = Vec::new();

for channel in channel_list {
// Create subscription
let subscription = match ChannelSubscription::new(
session,
channel.to_string(),
None,
flags,
&context
){
Ok(s) => s,
Err(e) => {
eprintln!("Error creating subscription for {}: {:?}", channel, e);
continue;
}
};
let subscription =
match ChannelSubscription::new(session, channel.to_string(), None, flags, &context) {
Ok(s) => s,
Err(e) => {
eprintln!("Error creating subscription for {}: {:?}", channel, e);
continue;
}
};

subscriptions.push(
subscription
);
subscriptions.push(subscription);
}

subscriptions
}


fn main() {
let app = make_app();
let options = app.get_matches();

match options.value_of("debug") {
Some(d) => set_debug_level(d).expect(
"Error setting debug level"
),
None => set_debug_level("Error").expect(
"Error setting debug level"
)
Some(d) => set_debug_level(d).expect("Error setting debug level"),
None => set_debug_level("Error").expect("Error setting debug level"),
}

// Get Session
let session: Option<EvtHandle> = match get_session_from_matches(
&options
).expect("Error getting session from options") {
Some(s) => Some(s.0),
None => None
};
let session: Option<EvtHandle> =
match get_session_from_matches(&options).expect("Error getting session from options") {
Some(s) => Some(s.0),
None => None,
};

let format_enum = match options.value_of("format") {
Some(f) => {
match f {
"xml" => OutputFormat::XmlFormat,
"jsonl" => OutputFormat::JsonlFormat,
other => {
eprintln!("Unkown format: {}", other);
exit(-1);
}
Some(f) => match f {
"xml" => OutputFormat::XmlFormat,
"jsonl" => OutputFormat::JsonlFormat,
other => {
eprintln!("Unkown format: {}", other);
exit(-1);
}
},
None => OutputFormat::JsonlFormat
None => OutputFormat::JsonlFormat,
};

// Historical flag
let flags = match options.is_present("historical") {
true => Some(EvtSubscribeStartAtOldestRecord),
false => Some(EvtSubscribeToFutureEvents)
false => Some(EvtSubscribeToFutureEvents),
};

// Create context
let context = CallbackContext::new()
.with_format(format_enum);
let context = CallbackContext::new().with_format(format_enum);

let _subscritions = match options.values_of("channel") {
Some(v_list) => {
get_query_list_from_str_list(
&session,
&context,
flags,
v_list.collect()
)
},
None => get_query_list_from_system(
&session,
&context,
flags
)
Some(v_list) => get_query_list_from_str_list(&session, &context, flags, v_list.collect()),
None => get_query_list_from_system(&session, &context, flags),
};

eprintln!("Listening to events...");
Expand Down
65 changes: 27 additions & 38 deletions src/bin/listen_mft.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
extern crate serde_json;
use clap::{App, Arg};
use rswinthings::mft::EntryListener;
use rswinthings::usn::listener::UsnVolumeListener;
use rswinthings::utils::debug::set_debug_level;
use rswinthings::utils::json::get_difference_value;
use rusty_usn::record::UsnEntry;
use std::io::stdin;
use std::io::BufRead;
use clap::{App, Arg};
use std::process::exit;
use std::thread;
use std::sync::mpsc;
use std::sync::mpsc::{Sender, Receiver};
use rusty_usn::record::UsnEntry;
use rswinthings::utils::json::get_difference_value;
use rswinthings::utils::debug::set_debug_level;
use rswinthings::mft::EntryListener;
use rswinthings::usn::listener::UsnVolumeListener;
use std::sync::mpsc::{Receiver, Sender};
use std::thread;

static VERSION: &'static str = "0.2.0";


fn make_app<'a, 'b>() -> App<'a, 'b> {
let format = Arg::with_name("file")
.short("-f")
Expand All @@ -39,23 +38,20 @@ fn make_app<'a, 'b>() -> App<'a, 'b> {
.arg(debug)
}


fn run(mut listener: EntryListener) {
let (tx, rx): (Sender<UsnEntry>, Receiver<UsnEntry>) = mpsc::channel();

let mut previous_value = listener.get_current_value().expect("Unable to get current mft entry value");
let mut previous_value = listener
.get_current_value()
.expect("Unable to get current mft entry value");
println!("{}", previous_value.to_string());

let volume_str = listener.get_volume_string().expect("Error getting volume path.");
let usn_volume_listener = UsnVolumeListener::new(
volume_str,
false,
tx.clone()
);
let volume_str = listener
.get_volume_string()
.expect("Error getting volume path.");
let usn_volume_listener = UsnVolumeListener::new(volume_str, false, tx.clone());

let _thread = thread::spawn(move || {
usn_volume_listener.listen_to_volume(None)
});
let _thread = thread::spawn(move || usn_volume_listener.listen_to_volume(None));

loop {
let usn_entry = match rx.recv() {
Expand All @@ -69,12 +65,11 @@ fn run(mut listener: EntryListener) {
continue;
}

let current_value = listener.get_current_value().expect("Unable to get current mft entry value");
let current_value = listener
.get_current_value()
.expect("Unable to get current mft entry value");

let difference_value = get_difference_value(
&previous_value,
&current_value
);
let difference_value = get_difference_value(&previous_value, &current_value);

match difference_value.as_object() {
None => continue,
Expand All @@ -83,28 +78,24 @@ fn run(mut listener: EntryListener) {
continue;
}

let value_str = serde_json::to_string_pretty(
&difference_value
).expect("Unable to format Value");

let value_str = serde_json::to_string_pretty(&difference_value)
.expect("Unable to format Value");

println!("{}", value_str);

previous_value = current_value.to_owned();
}
}
}
}


fn main() {
let app = make_app();
let options = app.get_matches();

// Set debug
match options.value_of("debug") {
Some(d) => set_debug_level(d).expect(
"Error setting debug level"
),
Some(d) => set_debug_level(d).expect("Error setting debug level"),
None => {}
}

Expand All @@ -116,9 +107,7 @@ fn main() {
}
};

let listener = EntryListener::new(
file_path
).expect("Error creating EntryListener");
let listener = EntryListener::new(file_path).expect("Error creating EntryListener");

run(listener);
}
}
Loading