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 snafu::prelude::Snafu;
|
||||||
use widestring::U16CString;
|
use widestring::U16CString;
|
||||||
use winapi::{
|
use winapi::{
|
||||||
ctypes::c_void,
|
ctypes::c_void,
|
||||||
shared::{
|
shared::{
|
||||||
minwindef::{HINSTANCE, HMODULE, TRUE},
|
minwindef::{FALSE, HINSTANCE, HMODULE, TRUE}, ntdef::HANDLE, winerror::ERROR_INSUFFICIENT_BUFFER
|
||||||
winerror::ERROR_INSUFFICIENT_BUFFER,
|
|
||||||
},
|
},
|
||||||
um::{
|
um::{
|
||||||
errhandlingapi::GetLastError,
|
errhandlingapi::GetLastError, handleapi::{CloseHandle, DuplicateHandle}, libloaderapi::{FreeLibraryAndExitThread, GetModuleFileNameW}, processthreadsapi::{GetCurrentProcess, GetCurrentThread}, synchapi::WaitForSingleObject, winhttp::{WinHttpQueryOption, HINTERNET}, winnt::SYNCHRONIZE
|
||||||
libloaderapi::{FreeLibraryAndExitThread, GetModuleFileNameW},
|
|
||||||
winhttp::{WinHttpQueryOption, HINTERNET},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
pub struct LibraryHandle(HINSTANCE);
|
||||||
|
|
||||||
unsafe impl Send for LibraryHandle {}
|
unsafe impl Send for LibraryHandle {}
|
||||||
|
@ -9,6 +9,7 @@ mod updater;
|
|||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
use helpers::winapi_ext::ThreadHandle;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use winapi::{
|
use winapi::{
|
||||||
shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
|
shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE},
|
||||||
@ -30,8 +31,13 @@ extern "system" fn DllMain(dll_module: HINSTANCE, call_reason: DWORD, reserved:
|
|||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
let library_handle = unsafe { LibraryHandle::new(dll_module) };
|
let library_handle = unsafe { LibraryHandle::new(dll_module) };
|
||||||
|
let thread_handle = ThreadHandle::duplicate_thread_handle();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
if let Ok(h) = thread_handle {
|
||||||
|
h.wait_and_close(1000);
|
||||||
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"saekawa {} ({}@{}) starting up...",
|
"saekawa {} ({}@{}) starting up...",
|
||||||
env!("CARGO_PKG_VERSION"),
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
@ -354,7 +354,7 @@ fn setup_network_encryption(info: &GameInformation) -> Result<(), HookError> {
|
|||||||
.context(CryptoScanSnafu)?
|
.context(CryptoScanSnafu)?
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Search completed successfully.");
|
debug!("Search completed successfully.");
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user