Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
4a7738dd3d | |||
69250cf856 |
4 changed files with 50 additions and 19 deletions
|
@ -8,14 +8,12 @@ use log::{debug, error, info, trace};
|
|||
use path_clean::PathClean;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use windows::core::{PSTR, s};
|
||||
use windows::Win32::Foundation::{CloseHandle, GetLastError, HANDLE};
|
||||
use windows::Win32::Foundation::{CloseHandle, GetLastError, HANDLE, NTSTATUS};
|
||||
use windows::Win32::System::Diagnostics::Debug::WriteProcessMemory;
|
||||
use windows::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
|
||||
use windows::Win32::System::Memory::{MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_READWRITE,
|
||||
VirtualAllocEx, VirtualFreeEx};
|
||||
use windows::Win32::System::Threading::{CREATE_SUSPENDED, CreateProcessA, CreateRemoteThread,
|
||||
PROCESS_INFORMATION, ResumeThread, STARTUPINFOA,
|
||||
TerminateProcess, TerminateThread, WaitForSingleObject};
|
||||
use windows::Win32::System::Threading::{CREATE_SUSPENDED, CreateProcessA, CreateRemoteThread, GetExitCodeProcess, PROCESS_INFORMATION, ResumeThread, STARTUPINFOA, TerminateProcess, TerminateThread, WaitForSingleObject};
|
||||
|
||||
type FarProcUnwrapped = unsafe extern "system" fn() -> isize;
|
||||
type LPThreadStartRoutine = unsafe extern "system" fn(param: *mut c_void) -> u32;
|
||||
|
@ -206,6 +204,7 @@ pub fn spawn_process<'a>(launcher: Launcher, env: Environment) -> Result<Context
|
|||
if entry.is_some() & env.environment_append {
|
||||
// Usually when injecting you want your modifications to take precedence so
|
||||
// prepend is the correct operation
|
||||
// Evaluate: std::env::join_paths
|
||||
value = format!("{value}{ENV_VAR_SEPARATOR}{}", entry.unwrap()); // Has to hold value
|
||||
}
|
||||
system_variables.insert(key, value); // If key exists, it will be replaced
|
||||
|
@ -258,11 +257,30 @@ pub fn spawn_process<'a>(launcher: Launcher, env: Environment) -> Result<Context
|
|||
debug!("Injection of dll: {inject} succeeded!");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
ResumeThread(proc_info.hThread);
|
||||
CloseHandle(proc_info.hThread)?;
|
||||
CloseHandle(proc_info.hProcess)?;
|
||||
}
|
||||
unsafe { ResumeThread(proc_info.hThread); }
|
||||
info!("Successful injection finished");
|
||||
Ok(Context { proc_info, environment })
|
||||
}
|
||||
|
||||
pub fn is_process_running(proc_info: PROCESS_INFORMATION) -> bool {
|
||||
let mut exit_code = 0u32;
|
||||
let result = unsafe { GetExitCodeProcess(proc_info.hProcess, &mut exit_code) };
|
||||
match result {
|
||||
Ok(_) => {
|
||||
match NTSTATUS(exit_code as i32) {
|
||||
windows::Win32::Foundation::STILL_ACTIVE => true,
|
||||
_ => {
|
||||
unsafe {
|
||||
CloseHandle(proc_info.hThread).unwrap();
|
||||
CloseHandle(proc_info.hProcess).unwrap();
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Error while getting exit result: {err:?}");
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use clap::Parser;
|
||||
use log::{error, trace};
|
||||
use log::{error, info, trace};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -73,7 +73,7 @@ fn run(config_file: String) -> Result<injector::Context, Error> {
|
|||
trace!("{:?}", configuration);
|
||||
Ok(injector::spawn_process(
|
||||
configuration.launcher,
|
||||
configuration.environment.unwrap_or_default()
|
||||
configuration.environment.unwrap_or_default(),
|
||||
)?)
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,14 @@ fn main() {
|
|||
.init();
|
||||
|
||||
match run(args.config_file) {
|
||||
Ok(_context) => {
|
||||
Ok(context) => {
|
||||
// Since environment pointer has to outlive the process, here we can do several things,
|
||||
// either we join the thread of the process, or we just wait
|
||||
std::thread::sleep(std::time::Duration::from_secs(u64::MAX))
|
||||
},
|
||||
while injector::is_process_running(context.proc_info) {
|
||||
std::thread::sleep(std::time::Duration::from_secs(1))
|
||||
}
|
||||
info!("Application exited");
|
||||
}
|
||||
Err(err) => error!("{}", err.to_string())
|
||||
}
|
||||
}
|
10
samples/nte.toml
Normal file
10
samples/nte.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[launcher]
|
||||
executable_file = 'HTGame.exe'
|
||||
cmd_line_args = ''
|
||||
current_dir = '<REPLACE_THIS_FOR_YOUR_GAME_FOLDER>\Client\WindowsNoEditor\HT\Binaries\Win64'
|
||||
dll_list = ['<FULL_PATH_TO_NTR_DLL>']
|
||||
|
||||
[environment]
|
||||
#vars = ['TESTVAR1=AAAAAA', 'TESTVAR2=AAAAAA']
|
||||
#use_system_env = true
|
||||
#environment_append = false
|
|
@ -5,6 +5,6 @@ current_dir = '<REPLACE_THIS_FOR_YOUR_GAME_FOLDER>\Client\Binaries\Win64'
|
|||
dll_list = ['<FULL_PATH_TO_SHOREKEEPER_DLL>']
|
||||
|
||||
[environment]
|
||||
#environment = ['TESTVAR1=AAAAAA', 'TESTVAR2=AAAAAA']
|
||||
#vars = ['TESTVAR1=AAAAAA', 'TESTVAR2=AAAAAA']
|
||||
#use_system_env = true
|
||||
#environment_append = false
|
Loading…
Reference in a new issue