mirror of
https://github.com/beerpiss/saekawa.git
synced 2024-11-27 17:00:50 +01:00
feat: wait for the thread loading us to unload
nicer log messages
This commit is contained in:
parent
6b624dc264
commit
275b18ae4f
@ -1,18 +1,51 @@
|
||||
use std::ptr;
|
||||
|
||||
use snafu::prelude::Snafu;
|
||||
use widestring::U16CString;
|
||||
use winapi::{
|
||||
ctypes::c_void,
|
||||
shared::{
|
||||
minwindef::{HINSTANCE, HMODULE, TRUE},
|
||||
winerror::ERROR_INSUFFICIENT_BUFFER,
|
||||
minwindef::{FALSE, HINSTANCE, HMODULE, TRUE}, ntdef::HANDLE, winerror::ERROR_INSUFFICIENT_BUFFER
|
||||
},
|
||||
um::{
|
||||
errhandlingapi::GetLastError,
|
||||
libloaderapi::{FreeLibraryAndExitThread, GetModuleFileNameW},
|
||||
winhttp::{WinHttpQueryOption, HINTERNET},
|
||||
errhandlingapi::GetLastError, handleapi::{CloseHandle, DuplicateHandle}, libloaderapi::{FreeLibraryAndExitThread, GetModuleFileNameW}, processthreadsapi::{GetCurrentProcess, GetCurrentThread}, synchapi::WaitForSingleObject, winhttp::{WinHttpQueryOption, HINTERNET}, winnt::SYNCHRONIZE
|
||||
},
|
||||
};
|
||||
|
||||
pub struct ThreadHandle(HANDLE);
|
||||
|
||||
unsafe impl Send for ThreadHandle {}
|
||||
unsafe impl Sync for ThreadHandle {}
|
||||
impl ThreadHandle {
|
||||
pub fn duplicate_thread_handle() -> Result<Self, u32> {
|
||||
unsafe {
|
||||
let mut cur_thread = ptr::null_mut();
|
||||
let result = DuplicateHandle(
|
||||
GetCurrentProcess(),
|
||||
GetCurrentThread(),
|
||||
GetCurrentProcess(),
|
||||
&mut cur_thread,
|
||||
SYNCHRONIZE,
|
||||
FALSE,
|
||||
0,
|
||||
);
|
||||
|
||||
if result == 0 {
|
||||
return Err(GetLastError());
|
||||
}
|
||||
|
||||
Ok(ThreadHandle(cur_thread as HANDLE))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wait_and_close(self, ms: u32) {
|
||||
unsafe {
|
||||
WaitForSingleObject(self.0, ms);
|
||||
CloseHandle(self.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LibraryHandle(HINSTANCE);
|
||||
|
||||
unsafe impl Send for LibraryHandle {}
|
||||
|
@ -9,6 +9,7 @@ mod updater;
|
||||
|
||||
use std::thread;
|
||||
|
||||
use helpers::winapi_ext::ThreadHandle;
|
||||
use log::{error, info, warn};
|
||||
use winapi::{
|
||||
shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
|
||||
@ -30,8 +31,13 @@ extern "system" fn DllMain(dll_module: HINSTANCE, call_reason: DWORD, reserved:
|
||||
init_logger();
|
||||
|
||||
let library_handle = unsafe { LibraryHandle::new(dll_module) };
|
||||
let thread_handle = ThreadHandle::duplicate_thread_handle();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Ok(h) = thread_handle {
|
||||
h.wait_and_close(1000);
|
||||
}
|
||||
|
||||
info!(
|
||||
"saekawa {} ({}@{}) starting up...",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
|
@ -354,7 +354,7 @@ fn setup_network_encryption(info: &GameInformation) -> Result<(), HookError> {
|
||||
.context(CryptoScanSnafu)?
|
||||
};
|
||||
|
||||
info!("Search completed successfully.");
|
||||
debug!("Search completed successfully.");
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user