mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-27 05:49:45 +08:00
💩 release模式下重启不一定成功
This commit is contained in:
@@ -78,7 +78,7 @@ pub fn is_in_admin() -> bool {
|
||||
return Err("This function is only supported on Windows.".into());
|
||||
}
|
||||
|
||||
use windows_sys::Win32::Foundation::HANDLE;
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, HANDLE};
|
||||
use windows_sys::Win32::Security::{
|
||||
AllocateAndInitializeSid, CheckTokenMembership, FreeSid, SID_IDENTIFIER_AUTHORITY, TOKEN_QUERY,
|
||||
};
|
||||
@@ -136,31 +136,29 @@ pub fn run_with_admin() -> Result<(), String> {
|
||||
use std::ffi::OsStr;
|
||||
use std::iter::once;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::process::exit;
|
||||
use windows_sys::Win32::Foundation::HWND;
|
||||
use windows_sys::Win32::UI::Shell::ShellExecuteW;
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::SW_SHOWNORMAL;
|
||||
|
||||
let exe_path = std::env::current_exe().map_err(|e| e.to_string())?;
|
||||
let exe_str: Vec<u16> = OsStr::new(exe_path.to_string_lossy().as_ref())
|
||||
.encode_wide()
|
||||
.chain(std::iter::once(0))
|
||||
.collect();
|
||||
let exe_str: Vec<u16> = exe_path.as_os_str().encode_wide().chain(once(0)).collect();
|
||||
let verb: Vec<u16> = OsStr::new("runas").encode_wide().chain(once(0)).collect();
|
||||
|
||||
let result = unsafe {
|
||||
ShellExecuteW(
|
||||
std::ptr::null_mut(),
|
||||
let workdir: Vec<u16> =
|
||||
exe_path.parent().unwrap().as_os_str().encode_wide().chain(once(0)).collect();
|
||||
unsafe {
|
||||
let result = ShellExecuteW(
|
||||
0 as HWND,
|
||||
verb.as_ptr(),
|
||||
exe_str.as_ptr(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
workdir.as_ptr(),
|
||||
SW_SHOWNORMAL,
|
||||
)
|
||||
};
|
||||
);
|
||||
|
||||
if result as usize > 32 {
|
||||
exit(0);
|
||||
} else {
|
||||
Err("Failed to restart as administrator.".into())
|
||||
if result as usize > 32 {
|
||||
std::process::exit(0);
|
||||
} else {
|
||||
Err("Failed to restart as administrator.".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! DLL 注入相关功能
|
||||
//! @since Beta v0.9.0
|
||||
|
||||
use std::ffi::{c_void, OsStr};
|
||||
use std::ffi::OsStr;
|
||||
use std::iter::once;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::ptr;
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE};
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, FreeLibrary, HANDLE, INVALID_HANDLE_VALUE};
|
||||
use windows_sys::Win32::Storage::FileSystem::PIPE_ACCESS_DUPLEX;
|
||||
use windows_sys::Win32::System::Diagnostics::Debug::WriteProcessMemory;
|
||||
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
|
||||
@@ -101,12 +101,12 @@ pub fn inject_dll(pi: &PROCESS_INFORMATION, dll_path: &str) {
|
||||
}
|
||||
|
||||
let k32 = GetModuleHandleA(b"kernel32.dll\0".as_ptr());
|
||||
if k32 == 0 {
|
||||
if k32 == std::ptr::null_mut() {
|
||||
panic!("GetModuleHandleA failed");
|
||||
}
|
||||
|
||||
let loadlib = GetProcAddress(k32, b"LoadLibraryW\0".as_ptr());
|
||||
if loadlib.is_null() {
|
||||
if loadlib.is_none() {
|
||||
panic!("GetProcAddress failed");
|
||||
}
|
||||
|
||||
@@ -162,17 +162,14 @@ pub fn call_yaemain(pi: &PROCESS_INFORMATION, base: usize, dll_path: &str) {
|
||||
unsafe {
|
||||
let local =
|
||||
LoadLibraryExW(dll_path_wide.as_ptr(), std::ptr::null_mut(), DONT_RESOLVE_DLL_REFERENCES);
|
||||
if local == 0 {
|
||||
if local == std::ptr::null_mut() {
|
||||
panic!("LoadLibraryExW failed");
|
||||
}
|
||||
|
||||
let proc = GetProcAddress(local, b"YaeMain\0".as_ptr());
|
||||
if proc.is_null() {
|
||||
FreeLibrary(local);
|
||||
panic!("无法找到 YaeMain");
|
||||
}
|
||||
let proc = GetProcAddress(local, b"YaeMain\0".as_ptr()).expect("无法找到 YaeMain");
|
||||
|
||||
let proc_addr = proc as usize;
|
||||
// Option<unsafe extern "system" fn() -> isize>
|
||||
let proc_addr = proc as *const () as usize;
|
||||
let rva = proc_addr - local as usize;
|
||||
println!("YaeMain RVA: {:#x}", rva);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use std::io::{self, Read, Write};
|
||||
use std::os::windows::io::{FromRawHandle, RawHandle};
|
||||
use std::sync::Arc;
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
use windows_sys::Win32::Foundation::CloseHandle;
|
||||
use windows_sys::Win32::System::Pipes::ConnectNamedPipe;
|
||||
|
||||
// 读取配置值
|
||||
@@ -63,7 +64,7 @@ fn read_exact_vec<R: Read>(r: &mut R, len: usize) -> io::Result<Vec<u8>> {
|
||||
|
||||
/// 调用 dll
|
||||
#[tauri::command]
|
||||
pub fn call_yae_dll(app_handle: AppHandle, game_path: String) -> () {
|
||||
pub fn call_yae_dll(app_handle: AppHandle, game_path: String) -> Result<(), String> {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
return Err("This function is only supported on Windows.".into());
|
||||
@@ -203,4 +204,5 @@ pub fn call_yae_dll(app_handle: AppHandle, game_path: String) -> () {
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Yae 插件相关枚举类型
|
||||
* UIAF 相关枚举类型
|
||||
* @since Beta v0.7.8
|
||||
*/
|
||||
|
||||
|
||||
@@ -322,7 +322,8 @@ async function toYae(): Promise<void> {
|
||||
try {
|
||||
isAdmin = await invoke<boolean>("is_in_admin");
|
||||
} catch (err) {
|
||||
showSnackbar.error("检测管理员权限失败:" + (err?.message || err));
|
||||
showSnackbar.error(`检测管理员权限失败:${err}`);
|
||||
await TGLogger.Error(`[pageAchi][toYae]检测管理员权限失败:${err}`);
|
||||
return;
|
||||
}
|
||||
if (!isAdmin) {
|
||||
@@ -332,16 +333,19 @@ async function toYae(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await invoke("run_with_admin");
|
||||
const res = await invoke("run_with_admin");
|
||||
await TGLogger.Warn(`${res}`);
|
||||
} catch (err) {
|
||||
showSnackbar.error("以管理员模式重启失败:" + (err?.message || err));
|
||||
showSnackbar.error(`以管理员模式重启失败:${err}`);
|
||||
await TGLogger.Error(`[pageAchi][toYae]以管理员模式启动失败 - ${err}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
await invoke("call_yae_dll", { gamePath: gamePath });
|
||||
} catch (err) {
|
||||
showSnackbar.error("调用Yae DLL失败:" + (err?.message || err));
|
||||
showSnackbar.error(`调用Yae DLL失败: ${err}`);
|
||||
await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user