Skip to content

Commit

Permalink
Further cleanup of format strings in log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ff14wed committed Apr 19, 2023
1 parent 223968e commit a6f3239
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/bin/find_sig_matches.rs
Expand Up @@ -18,13 +18,13 @@ fn main() {

let target_exe_path = &args[1];
let sig = &args[2];
info!("Searching for sig {} in file {}", sig, target_exe_path);
info!("Searching for sig {sig} in file {target_exe_path}");

let image_map = ImageMap::open(target_exe_path).unwrap();
let addrs = scan_sigs(image_map.as_ref(), sig).unwrap();
info!("Found addresses:");
for addr in addrs {
info!("{:x}", addr);
info!("{addr:x}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hook/mod.rs
Expand Up @@ -77,7 +77,7 @@ impl State {
HookType::Send => "SendPacket",
HookType::SendLobby => "SendLobbyPacket",
};
info!("Scanning for {} sig: `{}`", sig_name, sig_str);
info!("Scanning for {sig_name} sig: `{sig_str}`");
let scan_start = Instant::now();
let rvas = find_pattern_matches(sig_name, sig, pe_image)
.map_err(|e| format_err!("{}: {}", e, sig_str))?;
Expand Down
8 changes: 4 additions & 4 deletions src/hook/recv.rs
Expand Up @@ -113,7 +113,7 @@ impl Hook {
}
}
Err(e) => {
error!("Could not process packet: {}", e)
error!("Could not process packet: {e}")
}
}

Expand All @@ -122,13 +122,13 @@ impl Hook {

pub fn shutdown() {
if let Err(e) = unsafe { DecompressPacketChat.disable() } {
error!("Error disabling RecvChat hook: {}", e);
error!("Error disabling RecvChat hook: {e}");
};
if let Err(e) = unsafe { DecompressPacketLobby.disable() } {
error!("Error disabling RecvLobby hook: {}", e);
error!("Error disabling RecvLobby hook: {e}");
};
if let Err(e) = unsafe { DecompressPacketZone.disable() } {
error!("Error disabling RecvZone hook: {}", e);
error!("Error disabling RecvZone hook: {e}");
};
}
}
6 changes: 3 additions & 3 deletions src/hook/send.rs
Expand Up @@ -101,7 +101,7 @@ impl Hook {
}
}
Err(e) => {
error!("Could not process packet: {}", e)
error!("Could not process packet: {e}")
}
}

Expand All @@ -115,10 +115,10 @@ impl Hook {

pub fn shutdown() {
if let Err(e) = unsafe { CompressPacketChat.disable() } {
error!("Error disabling SendChat hook: {}", e);
error!("Error disabling SendChat hook: {e}");
}
if let Err(e) = unsafe { CompressPacketZone.disable() } {
error!("Error disabling SendZone hook: {}", e);
error!("Error disabling SendZone hook: {e}");
}
}
}
4 changes: 2 additions & 2 deletions src/hook/send_lobby.rs
Expand Up @@ -82,7 +82,7 @@ impl Hook {
}
}
Err(e) => {
error!("Could not process packet: {}", e)
error!("Could not process packet: {e}")
}
}

Expand All @@ -91,7 +91,7 @@ impl Hook {

pub fn shutdown() {
if let Err(e) = unsafe { SendLobbyPacket.disable() } {
error!("Error disabling SendLobby hook: {}", e);
error!("Error disabling SendLobby hook: {e}");
}
}
}
14 changes: 7 additions & 7 deletions src/lib.rs
Expand Up @@ -54,8 +54,8 @@ fn handle_payload(payload: rpc::Payload, hs: Arc<hook::State>) -> Result<()> {
_ => panic!("This case shouldn't be possible"),
};
if let Err(e) = parse_sig_and_initialize_hook(hs, payload.data, hook_type) {
let err = format_err!("error initializing hook: {:?}", e);
error!("{:?}", err);
let err = format_err!("error initializing hook: {e}");
error!("{err}");
return Err(err);
}
}
Expand All @@ -73,7 +73,7 @@ fn parse_sig_and_initialize_hook(

fn initialize_hook_with_sig(hs: &Arc<hook::State>, sig: &str, hook_type: hook::HookType) -> bool {
if let Err(e) = hs.initialize_hook(sig.into(), hook_type) {
error!("Could not auto-initialize the {} hook: {}", hook_type, e);
error!("Could not auto-initialize the {hook_type} hook: {e}");
false
} else {
true
Expand Down Expand Up @@ -129,7 +129,7 @@ async fn main_with_result() -> Result<()> {
let pid = unsafe { processthreadsapi::GetCurrentProcessId() };
let pipe_name = format!(r"\\.\pipe\deucalion-{pid}");

info!("Starting server on {}", pipe_name);
info!("Starting server on {pipe_name}");
// Block on server loop
let hs_clone = hs.clone();
if let Err(e) = deucalion_server
Expand All @@ -138,7 +138,7 @@ async fn main_with_result() -> Result<()> {
})
.await
{
error!("Server encountered error running: {:?}", e)
error!("Server encountered error running: {e}")
}

// Signal the msg loop to exit and shut down the hook
Expand Down Expand Up @@ -204,12 +204,12 @@ unsafe extern "system" fn main(dll_base_addr: LPVOID) -> u32 {
consoleapi::AllocConsole();

if let Err(e) = logging_setup() {
println!("Error initializing logger: {e:?}");
println!("Error initializing logger: {e}");
}

let result = panic::catch_unwind(|| {
if let Err(e) = main_with_result() {
error!("Encountered fatal error: {e:?}");
error!("Encountered fatal error: {e}");
pause();
}
});
Expand Down
5 changes: 2 additions & 3 deletions src/procloader.rs
Expand Up @@ -94,8 +94,7 @@ pub fn fast_pattern_scan<'a, P: Pe<'a>>(

let end = image_range.end as usize;
debug!(
"Using pat len {:?} and excerpt {:x?} with excerpt_offset {:?}",
pat_len, excerpt, excerpt_offset,
"Using pat len {pat_len:?} and excerpt {excerpt:x?} with excerpt_offset {excerpt_offset:?}"
);
let finder = memmem::Finder::new(excerpt.as_slice());

Expand Down Expand Up @@ -161,7 +160,7 @@ pub fn find_pattern_matches<'a, P: Pe<'a>>(
if addrs.is_empty() {
return Err(SigScanError::MatchNotFound { name }.into());
}
info!("Found {} addr(s): {:x?}", name, addrs);
info!("Found {name} addr(s): {addrs:x?}");
Ok(addrs)
}

Expand Down
10 changes: 5 additions & 5 deletions src/server.rs
Expand Up @@ -366,7 +366,7 @@ impl Server {
}
}
_ => {
info!("Received payload from {nickname}: {:?}", payload);
info!("Received payload from {nickname}: {payload:?}");
subscriber.handle_payload(payload, &payload_handler).await?;
}
},
Expand Down Expand Up @@ -422,13 +422,13 @@ impl Server {
return Ok(());
}
}
Err(e) => error!("Disconecting {} because of error: {}", nickname, e),
Err(e) => error!("Disconecting {nickname} because of error: {e}"),
}

// If this section is reached it means that the subscriber was
// disconnected one way or another.
{
info!("Disconnected: {}", nickname);
info!("Disconnected: {nickname}");
let mut state = self.state.lock().await;
state.subscribers.remove(&subscriber.id);
// Exit once all subscribers are disconnected
Expand Down Expand Up @@ -498,11 +498,11 @@ impl Server {
let self_clone = self.clone();
subscriber_set.spawn(async move {
if let Err(e) = self_clone.handle_subscriber(stream, handler).await {
error!("Error occurred when processing stream = {:?}", e);
error!("Error occurred when processing stream = {e}");
}
});
}
Err(e) => error!("Unable to connect to subscriber: {}", e),
Err(e) => error!("Unable to connect to subscriber: {e}"),
}
}

Expand Down

0 comments on commit a6f3239

Please sign in to comment.