Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue where we'd randomly fail to load the original DLL. #645

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions MelonProxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static mut ORIGINAL_FUNCS: [FARPROC; TOTAL_EXPORTS] = [std::ptr::null_mut(); TOT
#[no_mangle]
static mut ORIG_FUNCS_PTR: *const FARPROC = std::ptr::null_mut();

const INFO_BUFFER_SIZE: u32 = 32767;
const INFO_BUFFER_SIZE: usize = 32767;

/// Indicates once we are ready to accept incoming calls to proxied functions

Expand Down Expand Up @@ -111,7 +111,7 @@ fn init() {
/// Get the current DLLs path
#[cfg(target_os = "windows")]
unsafe fn get_dll_path() -> Option<String> {
let mut buffer: Vec<u16> = vec![0; 260];
let mut buffer: Vec<u16> = vec![0; INFO_BUFFER_SIZE];
if THIS_HANDLE.is_none() {
return None;
}
Expand All @@ -132,7 +132,7 @@ unsafe fn get_dll_path() -> Option<String> {

#[cfg(target_os = "windows")]
unsafe fn get_system32_path() -> Option<String> {
let mut buffer: Vec<u16> = vec![0; INFO_BUFFER_SIZE as usize];
let mut buffer: Vec<u16> = vec![0; INFO_BUFFER_SIZE];
let size = GetSystemDirectoryW(
buffer.as_mut_ptr(),
buffer.len() as u32,
Expand Down Expand Up @@ -172,9 +172,10 @@ unsafe extern "system" fn init(_: *mut c_void) -> u32 {
internal_failure!("Original DLL does not exist");
}

let path = path.to_str().unwrap_or_else(|| {
let mut path = path.to_str().unwrap_or_else(|| {
internal_failure!("Failed to convert path to string");
});
}).to_owned();
path.push('\0');

ORIG_DLL_HANDLE = Some(LoadLibraryA(path.as_ptr() as *const i8));
} else {
Expand Down