cross compiling support (with x86_64-pc-windows-gnu on linux)
This commit is contained in:
parent
d606d196be
commit
8ae8355293
4 changed files with 58 additions and 166 deletions
11
build.rs
11
build.rs
|
@ -1,11 +0,0 @@
|
|||
fn main() {
|
||||
cc::Build::new().file("version.asm").compile("version");
|
||||
|
||||
println!("cargo:rerun-if-changed=version.asm");
|
||||
println!(
|
||||
"cargo:rustc-link-search=native={}",
|
||||
std::env::var("OUT_DIR").unwrap()
|
||||
);
|
||||
println!("cargo:rustc-link-lib=static=version");
|
||||
println!("cargo:rustc-link-arg=/DEF:version.def");
|
||||
}
|
|
@ -1,29 +1,7 @@
|
|||
use libloading::{Error, Library, Symbol};
|
||||
use std::arch::asm;
|
||||
use std::env;
|
||||
use std::ffi::CStr;
|
||||
|
||||
static FUNCTION_NAMES: &[&CStr] = &[
|
||||
c"GetFileVersionInfoA",
|
||||
c"GetFileVersionInfoByHandle",
|
||||
c"GetFileVersionInfoExA",
|
||||
c"GetFileVersionInfoExW",
|
||||
c"GetFileVersionInfoSizeA",
|
||||
c"GetFileVersionInfoSizeExA",
|
||||
c"GetFileVersionInfoSizeExW",
|
||||
c"GetFileVersionInfoSizeW",
|
||||
c"GetFileVersionInfoW",
|
||||
c"VerFindFileA",
|
||||
c"VerFindFileW",
|
||||
c"VerInstallFileA",
|
||||
c"VerInstallFileW",
|
||||
c"VerLanguageNameA",
|
||||
c"VerLanguageNameW",
|
||||
c"VerQueryValueA",
|
||||
c"VerQueryValueW",
|
||||
];
|
||||
|
||||
#[no_mangle]
|
||||
static mut ORIGINAL_FUNCTIONS: [*const usize; 17] = [0 as *const usize; 17];
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
pub struct VersionDllProxy {
|
||||
library: Library,
|
||||
|
@ -52,3 +30,59 @@ impl VersionDllProxy {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! count_exprs {
|
||||
() => {0usize};
|
||||
($head:expr, $($tail:expr,)*) => {1usize + count_exprs!($($tail,)*)};
|
||||
}
|
||||
|
||||
macro_rules! version_dll_proxy {
|
||||
($($fn_name:ident),*) => {
|
||||
static FUNCTION_NAMES: &[&CStr] = &[
|
||||
$(
|
||||
unsafe { CStr::from_bytes_with_nul_unchecked(concat!(stringify!($fn_name), "\0").as_bytes()) }
|
||||
),*,
|
||||
];
|
||||
|
||||
#[no_mangle]
|
||||
static mut ORIGINAL_FUNCTIONS: [*const usize; count_exprs!($($fn_name,)*)] = [0 as *const usize; count_exprs!($($fn_name,)*)];
|
||||
|
||||
$(
|
||||
#[no_mangle]
|
||||
extern "C" fn $fn_name() {
|
||||
let function_name = FUNCTION_NAMES
|
||||
.iter()
|
||||
.position(|&name| name == CString::new(stringify!($fn_name)).unwrap().as_ref())
|
||||
.unwrap();
|
||||
let fn_addr = unsafe { ORIGINAL_FUNCTIONS[function_name] };
|
||||
unsafe {
|
||||
asm! {
|
||||
"call {tmp}",
|
||||
tmp = in(reg) fn_addr,
|
||||
clobber_abi("C")
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
version_dll_proxy! {
|
||||
GetFileVersionInfoA,
|
||||
GetFileVersionInfoByHandle,
|
||||
GetFileVersionInfoExA,
|
||||
GetFileVersionInfoExW,
|
||||
GetFileVersionInfoSizeA,
|
||||
GetFileVersionInfoSizeExA,
|
||||
GetFileVersionInfoSizeExW,
|
||||
GetFileVersionInfoSizeW,
|
||||
GetFileVersionInfoW,
|
||||
VerFindFileA,
|
||||
VerFindFileW,
|
||||
VerInstallFileA,
|
||||
VerInstallFileW,
|
||||
VerLanguageNameA,
|
||||
VerLanguageNameW,
|
||||
VerQueryValueA,
|
||||
VerQueryValueW
|
||||
}
|
||||
|
|
112
version.asm
112
version.asm
|
@ -1,112 +0,0 @@
|
|||
ifdef RAX
|
||||
.code
|
||||
extern ORIGINAL_FUNCTIONS:QWORD
|
||||
GetFileVersionInfoA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[0 * 8]
|
||||
GetFileVersionInfoA endp
|
||||
GetFileVersionInfoByHandle proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[1 * 8]
|
||||
GetFileVersionInfoByHandle endp
|
||||
GetFileVersionInfoExA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[2 * 8]
|
||||
GetFileVersionInfoExA endp
|
||||
GetFileVersionInfoExW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[3 * 8]
|
||||
GetFileVersionInfoExW endp
|
||||
GetFileVersionInfoSizeA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[4 * 8]
|
||||
GetFileVersionInfoSizeA endp
|
||||
GetFileVersionInfoSizeExA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[5 * 8]
|
||||
GetFileVersionInfoSizeExA endp
|
||||
GetFileVersionInfoSizeExW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[6 * 8]
|
||||
GetFileVersionInfoSizeExW endp
|
||||
GetFileVersionInfoSizeW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[7 * 8]
|
||||
GetFileVersionInfoSizeW endp
|
||||
GetFileVersionInfoW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[8 * 8]
|
||||
GetFileVersionInfoW endp
|
||||
VerFindFileA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[9 * 8]
|
||||
VerFindFileA endp
|
||||
VerFindFileW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[10 * 8]
|
||||
VerFindFileW endp
|
||||
VerInstallFileA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[11 * 8]
|
||||
VerInstallFileA endp
|
||||
VerInstallFileW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[12 * 8]
|
||||
VerInstallFileW endp
|
||||
VerLanguageNameA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[13 * 8]
|
||||
VerLanguageNameA endp
|
||||
VerLanguageNameW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[14 * 8]
|
||||
VerLanguageNameW endp
|
||||
VerQueryValueA proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[15 * 8]
|
||||
VerQueryValueA endp
|
||||
VerQueryValueW proc
|
||||
jmp QWORD ptr ORIGINAL_FUNCTIONS[16 * 8]
|
||||
VerQueryValueW endp
|
||||
else
|
||||
.model flat, C
|
||||
.stack 4096
|
||||
.code
|
||||
extern ORIGINAL_FUNCTIONS:DWORD
|
||||
GetFileVersionInfoA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[0 * 4]
|
||||
GetFileVersionInfoA endp
|
||||
GetFileVersionInfoByHandle proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[1 * 4]
|
||||
GetFileVersionInfoByHandle endp
|
||||
GetFileVersionInfoExA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[2 * 4]
|
||||
GetFileVersionInfoExA endp
|
||||
GetFileVersionInfoExW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[3 * 4]
|
||||
GetFileVersionInfoExW endp
|
||||
GetFileVersionInfoSizeA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[4 * 4]
|
||||
GetFileVersionInfoSizeA endp
|
||||
GetFileVersionInfoSizeExA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[5 * 4]
|
||||
GetFileVersionInfoSizeExA endp
|
||||
GetFileVersionInfoSizeExW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[6 * 4]
|
||||
GetFileVersionInfoSizeExW endp
|
||||
GetFileVersionInfoSizeW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[7 * 4]
|
||||
GetFileVersionInfoSizeW endp
|
||||
GetFileVersionInfoW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[8 * 4]
|
||||
GetFileVersionInfoW endp
|
||||
VerFindFileA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[9 * 4]
|
||||
VerFindFileA endp
|
||||
VerFindFileW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[10 * 4]
|
||||
VerFindFileW endp
|
||||
VerInstallFileA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[11 * 4]
|
||||
VerInstallFileA endp
|
||||
VerInstallFileW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[12 * 4]
|
||||
VerInstallFileW endp
|
||||
VerLanguageNameA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[13 * 4]
|
||||
VerLanguageNameA endp
|
||||
VerLanguageNameW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[14 * 4]
|
||||
VerLanguageNameW endp
|
||||
VerQueryValueA proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[15 * 4]
|
||||
VerQueryValueA endp
|
||||
VerQueryValueW proc
|
||||
jmp DWORD ptr ORIGINAL_FUNCTIONS[16 * 4]
|
||||
VerQueryValueW endp
|
||||
endif
|
||||
end
|
19
version.def
19
version.def
|
@ -1,19 +0,0 @@
|
|||
|
||||
EXPORTS
|
||||
GetFileVersionInfoA
|
||||
GetFileVersionInfoByHandle
|
||||
GetFileVersionInfoExA
|
||||
GetFileVersionInfoExW
|
||||
GetFileVersionInfoSizeA
|
||||
GetFileVersionInfoSizeExA
|
||||
GetFileVersionInfoSizeExW
|
||||
GetFileVersionInfoSizeW
|
||||
GetFileVersionInfoW
|
||||
VerFindFileA
|
||||
VerFindFileW
|
||||
VerInstallFileA
|
||||
VerInstallFileW
|
||||
VerLanguageNameA
|
||||
VerLanguageNameW
|
||||
VerQueryValueA
|
||||
VerQueryValueW
|
Loading…
Reference in a new issue