Skip to content

dynamic get QueryFullProcessImageNameA for XP support #263

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

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions src/symbolize/libbacktrace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -382,9 +382,27 @@ unsafe fn init_state() -> *mut bt::backtrace_state {
}

unsafe fn query_full_name(buf: &mut [i8]) -> Result<&[i8], ()> {
let dll = GetModuleHandleA(b"kernel32.dll\0".as_ptr() as *const i8);
if dll.is_null() {
return Err(())
}
let ptrQueryFullProcessImageNameA =
GetProcAddress(dll, b"QueryFullProcessImageNameA\0".as_ptr() as *const _) as usize;
if ptrQueryFullProcessImageNameA == 0
{
return Err(());
}
use core::mem;
let p1 = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
let mut len = buf.len() as u32;
let rc = QueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len);
let pfnQueryFullProcessImageNameA : extern "system" fn(
hProcess: HANDLE,
dwFlags: DWORD,
lpExeName: LPSTR,
lpdwSize: PDWORD,
) -> BOOL = mem::transmute(ptrQueryFullProcessImageNameA);

let rc = pfnQueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len);
CloseHandle(p1);

// We want to return a slice that is nul-terminated, so if
Expand Down
9 changes: 2 additions & 7 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A module to define the FFI definitions we use on Windows for `dbghelp.dll`
//! A module to define the FFI definitions we use on Windows for `dbghelp.dll`
//!
//! This module uses a custom macro, `ffi!`, to wrap all definitions to
//! automatically generate tests to assert that our definitions here are the
Expand Down Expand Up @@ -343,19 +343,14 @@ ffi! {
pub fn RtlCaptureContext(ContextRecord: PCONTEXT) -> ();
pub fn LoadLibraryA(a: *const i8) -> HMODULE;
pub fn GetProcAddress(h: HMODULE, name: *const i8) -> FARPROC;
pub fn GetModuleHandleA(name: *const i8) -> HMODULE;
pub fn OpenProcess(
dwDesiredAccess: DWORD,
bInheitHandle: BOOL,
dwProcessId: DWORD,
) -> HANDLE;
pub fn GetCurrentProcessId() -> DWORD;
pub fn CloseHandle(h: HANDLE) -> BOOL;
pub fn QueryFullProcessImageNameA(
hProcess: HANDLE,
dwFlags: DWORD,
lpExeName: LPSTR,
lpdwSize: PDWORD,
) -> BOOL;
pub fn CreateFileA(
lpFileName: LPCSTR,
dwDesiredAccess: DWORD,
Expand Down