diff options
author | Andrzej Janik <[email protected]> | 2021-01-03 18:45:48 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-03 18:45:48 +0100 |
commit | 2c0e9b912fe341bd1e513614014fa43b666d257d (patch) | |
tree | b5d3aa00a5192230657792833450848ceb557a1a /detours-sys/src | |
parent | 659b2c6ec431c3f1103e700a20da4c66467aa35d (diff) | |
download | ZLUDA-2c0e9b912fe341bd1e513614014fa43b666d257d.tar.gz ZLUDA-2c0e9b912fe341bd1e513614014fa43b666d257d.zip |
Fix Windows ZLUDA injector (#26)
Fix various bugs in injector and redirector, make them more robust and enable building them by default
Diffstat (limited to 'detours-sys/src')
-rw-r--r-- | detours-sys/src/bundled_bindings.rs | 1099 | ||||
-rw-r--r-- | detours-sys/src/lib.rs | 78 |
2 files changed, 1177 insertions, 0 deletions
diff --git a/detours-sys/src/bundled_bindings.rs b/detours-sys/src/bundled_bindings.rs new file mode 100644 index 0000000..7262bc8 --- /dev/null +++ b/detours-sys/src/bundled_bindings.rs @@ -0,0 +1,1099 @@ +/* automatically generated by rust-bindgen 0.56.0 */ + +pub type wchar_t = ::std::os::raw::c_ushort;
+pub type ULONG = ::std::os::raw::c_ulong;
+pub type DWORD = ::std::os::raw::c_ulong;
+pub type BOOL = ::std::os::raw::c_int;
+pub type BYTE = ::std::os::raw::c_uchar;
+pub type WORD = ::std::os::raw::c_ushort;
+pub type LPBYTE = *mut BYTE;
+pub type PDWORD = *mut DWORD;
+pub type LPVOID = *mut ::std::os::raw::c_void;
+pub type LPCVOID = *const ::std::os::raw::c_void;
+pub type INT = ::std::os::raw::c_int;
+pub type PVOID = *mut ::std::os::raw::c_void;
+pub type CHAR = ::std::os::raw::c_char;
+pub type LONG = ::std::os::raw::c_long;
+pub type WCHAR = wchar_t;
+pub type LPWSTR = *mut WCHAR;
+pub type LPCWSTR = *const WCHAR;
+pub type LPSTR = *mut CHAR;
+pub type LPCSTR = *const CHAR;
+pub type HANDLE = *mut ::std::os::raw::c_void;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct _GUID {
+ pub Data1: ::std::os::raw::c_ulong,
+ pub Data2: ::std::os::raw::c_ushort,
+ pub Data3: ::std::os::raw::c_ushort,
+ pub Data4: [::std::os::raw::c_uchar; 8usize],
+}
+#[test]
+fn bindgen_test_layout__GUID() {
+ assert_eq!(
+ ::std::mem::size_of::<_GUID>(),
+ 16usize,
+ concat!("Size of: ", stringify!(_GUID))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<_GUID>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(_GUID))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_GUID>())).Data1 as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_GUID),
+ "::",
+ stringify!(Data1)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_GUID>())).Data2 as *const _ as usize },
+ 4usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_GUID),
+ "::",
+ stringify!(Data2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_GUID>())).Data3 as *const _ as usize },
+ 6usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_GUID),
+ "::",
+ stringify!(Data3)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_GUID>())).Data4 as *const _ as usize },
+ 8usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_GUID),
+ "::",
+ stringify!(Data4)
+ )
+ );
+}
+pub type GUID = _GUID;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct HINSTANCE__ {
+ pub unused: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_HINSTANCE__() {
+ assert_eq!(
+ ::std::mem::size_of::<HINSTANCE__>(),
+ 4usize,
+ concat!("Size of: ", stringify!(HINSTANCE__))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<HINSTANCE__>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(HINSTANCE__))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<HINSTANCE__>())).unused as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(HINSTANCE__),
+ "::",
+ stringify!(unused)
+ )
+ );
+}
+pub type HINSTANCE = *mut HINSTANCE__;
+pub type HMODULE = HINSTANCE;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct HWND__ {
+ pub unused: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_HWND__() {
+ assert_eq!(
+ ::std::mem::size_of::<HWND__>(),
+ 4usize,
+ concat!("Size of: ", stringify!(HWND__))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<HWND__>(),
+ 4usize,
+ concat!("Alignment of ", stringify!(HWND__))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<HWND__>())).unused as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(HWND__),
+ "::",
+ stringify!(unused)
+ )
+ );
+}
+pub type HWND = *mut HWND__;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct _SECURITY_ATTRIBUTES {
+ pub nLength: DWORD,
+ pub lpSecurityDescriptor: LPVOID,
+ pub bInheritHandle: BOOL,
+}
+#[test]
+fn bindgen_test_layout__SECURITY_ATTRIBUTES() {
+ assert_eq!(
+ ::std::mem::size_of::<_SECURITY_ATTRIBUTES>(),
+ 24usize,
+ concat!("Size of: ", stringify!(_SECURITY_ATTRIBUTES))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<_SECURITY_ATTRIBUTES>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(_SECURITY_ATTRIBUTES))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_SECURITY_ATTRIBUTES>())).nLength as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_SECURITY_ATTRIBUTES),
+ "::",
+ stringify!(nLength)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<_SECURITY_ATTRIBUTES>())).lpSecurityDescriptor as *const _
+ as usize
+ },
+ 8usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_SECURITY_ATTRIBUTES),
+ "::",
+ stringify!(lpSecurityDescriptor)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<_SECURITY_ATTRIBUTES>())).bInheritHandle as *const _ as usize
+ },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_SECURITY_ATTRIBUTES),
+ "::",
+ stringify!(bInheritHandle)
+ )
+ );
+}
+pub type LPSECURITY_ATTRIBUTES = *mut _SECURITY_ATTRIBUTES;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct _PROCESS_INFORMATION {
+ pub hProcess: HANDLE,
+ pub hThread: HANDLE,
+ pub dwProcessId: DWORD,
+ pub dwThreadId: DWORD,
+}
+#[test]
+fn bindgen_test_layout__PROCESS_INFORMATION() {
+ assert_eq!(
+ ::std::mem::size_of::<_PROCESS_INFORMATION>(),
+ 24usize,
+ concat!("Size of: ", stringify!(_PROCESS_INFORMATION))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<_PROCESS_INFORMATION>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(_PROCESS_INFORMATION))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_PROCESS_INFORMATION>())).hProcess as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_PROCESS_INFORMATION),
+ "::",
+ stringify!(hProcess)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_PROCESS_INFORMATION>())).hThread as *const _ as usize },
+ 8usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_PROCESS_INFORMATION),
+ "::",
+ stringify!(hThread)
+ )
+ );
+ assert_eq!(
+ unsafe {
+ &(*(::std::ptr::null::<_PROCESS_INFORMATION>())).dwProcessId as *const _ as usize
+ },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_PROCESS_INFORMATION),
+ "::",
+ stringify!(dwProcessId)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_PROCESS_INFORMATION>())).dwThreadId as *const _ as usize },
+ 20usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_PROCESS_INFORMATION),
+ "::",
+ stringify!(dwThreadId)
+ )
+ );
+}
+pub type LPPROCESS_INFORMATION = *mut _PROCESS_INFORMATION;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct _STARTUPINFOA {
+ pub cb: DWORD,
+ pub lpReserved: LPSTR,
+ pub lpDesktop: LPSTR,
+ pub lpTitle: LPSTR,
+ pub dwX: DWORD,
+ pub dwY: DWORD,
+ pub dwXSize: DWORD,
+ pub dwYSize: DWORD,
+ pub dwXCountChars: DWORD,
+ pub dwYCountChars: DWORD,
+ pub dwFillAttribute: DWORD,
+ pub dwFlags: DWORD,
+ pub wShowWindow: WORD,
+ pub cbReserved2: WORD,
+ pub lpReserved2: LPBYTE,
+ pub hStdInput: HANDLE,
+ pub hStdOutput: HANDLE,
+ pub hStdError: HANDLE,
+}
+#[test]
+fn bindgen_test_layout__STARTUPINFOA() {
+ assert_eq!(
+ ::std::mem::size_of::<_STARTUPINFOA>(),
+ 104usize,
+ concat!("Size of: ", stringify!(_STARTUPINFOA))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<_STARTUPINFOA>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(_STARTUPINFOA))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).cb as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(cb)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).lpReserved as *const _ as usize },
+ 8usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(lpReserved)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).lpDesktop as *const _ as usize },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(lpDesktop)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).lpTitle as *const _ as usize },
+ 24usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(lpTitle)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwX as *const _ as usize },
+ 32usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwX)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwY as *const _ as usize },
+ 36usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwY)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwXSize as *const _ as usize },
+ 40usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwXSize)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwYSize as *const _ as usize },
+ 44usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwYSize)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwXCountChars as *const _ as usize },
+ 48usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwXCountChars)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwYCountChars as *const _ as usize },
+ 52usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwYCountChars)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwFillAttribute as *const _ as usize },
+ 56usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwFillAttribute)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).dwFlags as *const _ as usize },
+ 60usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(dwFlags)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).wShowWindow as *const _ as usize },
+ 64usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(wShowWindow)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).cbReserved2 as *const _ as usize },
+ 66usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(cbReserved2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).lpReserved2 as *const _ as usize },
+ 72usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(lpReserved2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).hStdInput as *const _ as usize },
+ 80usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(hStdInput)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).hStdOutput as *const _ as usize },
+ 88usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(hStdOutput)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOA>())).hStdError as *const _ as usize },
+ 96usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOA),
+ "::",
+ stringify!(hStdError)
+ )
+ );
+}
+pub type LPSTARTUPINFOA = *mut _STARTUPINFOA;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct _STARTUPINFOW {
+ pub cb: DWORD,
+ pub lpReserved: LPWSTR,
+ pub lpDesktop: LPWSTR,
+ pub lpTitle: LPWSTR,
+ pub dwX: DWORD,
+ pub dwY: DWORD,
+ pub dwXSize: DWORD,
+ pub dwYSize: DWORD,
+ pub dwXCountChars: DWORD,
+ pub dwYCountChars: DWORD,
+ pub dwFillAttribute: DWORD,
+ pub dwFlags: DWORD,
+ pub wShowWindow: WORD,
+ pub cbReserved2: WORD,
+ pub lpReserved2: LPBYTE,
+ pub hStdInput: HANDLE,
+ pub hStdOutput: HANDLE,
+ pub hStdError: HANDLE,
+}
+#[test]
+fn bindgen_test_layout__STARTUPINFOW() {
+ assert_eq!(
+ ::std::mem::size_of::<_STARTUPINFOW>(),
+ 104usize,
+ concat!("Size of: ", stringify!(_STARTUPINFOW))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<_STARTUPINFOW>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(_STARTUPINFOW))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).cb as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(cb)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).lpReserved as *const _ as usize },
+ 8usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(lpReserved)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).lpDesktop as *const _ as usize },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(lpDesktop)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).lpTitle as *const _ as usize },
+ 24usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(lpTitle)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwX as *const _ as usize },
+ 32usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwX)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwY as *const _ as usize },
+ 36usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwY)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwXSize as *const _ as usize },
+ 40usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwXSize)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwYSize as *const _ as usize },
+ 44usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwYSize)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwXCountChars as *const _ as usize },
+ 48usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwXCountChars)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwYCountChars as *const _ as usize },
+ 52usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwYCountChars)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwFillAttribute as *const _ as usize },
+ 56usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwFillAttribute)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).dwFlags as *const _ as usize },
+ 60usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(dwFlags)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).wShowWindow as *const _ as usize },
+ 64usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(wShowWindow)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).cbReserved2 as *const _ as usize },
+ 66usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(cbReserved2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).lpReserved2 as *const _ as usize },
+ 72usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(lpReserved2)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).hStdInput as *const _ as usize },
+ 80usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(hStdInput)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).hStdOutput as *const _ as usize },
+ 88usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(hStdOutput)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<_STARTUPINFOW>())).hStdError as *const _ as usize },
+ 96usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(_STARTUPINFOW),
+ "::",
+ stringify!(hStdError)
+ )
+ );
+}
+pub type LPSTARTUPINFOW = *mut _STARTUPINFOW;
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct _DETOUR_TRAMPOLINE {
+ _unused: [u8; 0],
+}
+pub type PDETOUR_TRAMPOLINE = *mut _DETOUR_TRAMPOLINE;
+#[doc = " Binary Typedefs."]
+pub type PF_DETOUR_BINARY_BYWAY_CALLBACK = ::std::option::Option<
+ unsafe extern "C" fn(pContext: PVOID, pszFile: LPCSTR, ppszOutFile: *mut LPCSTR) -> BOOL,
+>;
+pub type PF_DETOUR_BINARY_FILE_CALLBACK = ::std::option::Option<
+ unsafe extern "C" fn(
+ pContext: PVOID,
+ pszOrigFile: LPCSTR,
+ pszFile: LPCSTR,
+ ppszOutFile: *mut LPCSTR,
+ ) -> BOOL,
+>;
+pub type PF_DETOUR_BINARY_SYMBOL_CALLBACK = ::std::option::Option<
+ unsafe extern "C" fn(
+ pContext: PVOID,
+ nOrigOrdinal: ULONG,
+ nOrdinal: ULONG,
+ pnOutOrdinal: *mut ULONG,
+ pszOrigSymbol: LPCSTR,
+ pszSymbol: LPCSTR,
+ ppszOutSymbol: *mut LPCSTR,
+ ) -> BOOL,
+>;
+pub type PF_DETOUR_BINARY_COMMIT_CALLBACK =
+ ::std::option::Option<unsafe extern "C" fn(pContext: PVOID) -> BOOL>;
+pub type PF_DETOUR_ENUMERATE_EXPORT_CALLBACK = ::std::option::Option<
+ unsafe extern "C" fn(pContext: PVOID, nOrdinal: ULONG, pszName: LPCSTR, pCode: PVOID) -> BOOL,
+>;
+pub type PF_DETOUR_IMPORT_FILE_CALLBACK = ::std::option::Option<
+ unsafe extern "C" fn(pContext: PVOID, hModule: HMODULE, pszFile: LPCSTR) -> BOOL,
+>;
+pub type PF_DETOUR_IMPORT_FUNC_CALLBACK = ::std::option::Option<
+ unsafe extern "C" fn(pContext: PVOID, nOrdinal: DWORD, pszFunc: LPCSTR, pvFunc: PVOID) -> BOOL,
+>;
+pub type PF_DETOUR_IMPORT_FUNC_CALLBACK_EX = ::std::option::Option<
+ unsafe extern "C" fn(
+ pContext: PVOID,
+ nOrdinal: DWORD,
+ pszFunc: LPCSTR,
+ ppvFunc: *mut PVOID,
+ ) -> BOOL,
+>;
+pub type PDETOUR_BINARY = *mut ::std::os::raw::c_void;
+extern "C" {
+ #[doc = " Transaction APIs."]
+ pub fn DetourTransactionBegin() -> LONG;
+}
+extern "C" {
+ pub fn DetourTransactionAbort() -> LONG;
+}
+extern "C" {
+ pub fn DetourTransactionCommit() -> LONG;
+}
+extern "C" {
+ pub fn DetourTransactionCommitEx(pppFailedPointer: *mut *mut PVOID) -> LONG;
+}
+extern "C" {
+ pub fn DetourUpdateThread(hThread: HANDLE) -> LONG;
+}
+extern "C" {
+ pub fn DetourAttach(ppPointer: *mut PVOID, pDetour: PVOID) -> LONG;
+}
+extern "C" {
+ pub fn DetourAttachEx(
+ ppPointer: *mut PVOID,
+ pDetour: PVOID,
+ ppRealTrampoline: *mut PDETOUR_TRAMPOLINE,
+ ppRealTarget: *mut PVOID,
+ ppRealDetour: *mut PVOID,
+ ) -> LONG;
+}
+extern "C" {
+ pub fn DetourDetach(ppPointer: *mut PVOID, pDetour: PVOID) -> LONG;
+}
+extern "C" {
+ pub fn DetourSetIgnoreTooSmall(fIgnore: BOOL) -> BOOL;
+}
+extern "C" {
+ pub fn DetourSetRetainRegions(fRetain: BOOL) -> BOOL;
+}
+extern "C" {
+ pub fn DetourSetSystemRegionLowerBound(pSystemRegionLowerBound: PVOID) -> PVOID;
+}
+extern "C" {
+ pub fn DetourSetSystemRegionUpperBound(pSystemRegionUpperBound: PVOID) -> PVOID;
+}
+extern "C" {
+ #[doc = " Code Functions."]
+ pub fn DetourFindFunction(pszModule: LPCSTR, pszFunction: LPCSTR) -> PVOID;
+}
+extern "C" {
+ pub fn DetourCodeFromPointer(pPointer: PVOID, ppGlobals: *mut PVOID) -> PVOID;
+}
+extern "C" {
+ pub fn DetourCopyInstruction(
+ pDst: PVOID,
+ ppDstPool: *mut PVOID,
+ pSrc: PVOID,
+ ppTarget: *mut PVOID,
+ plExtra: *mut LONG,
+ ) -> PVOID;
+}
+extern "C" {
+ pub fn DetourSetCodeModule(hModule: HMODULE, fLimitReferencesToModule: BOOL) -> BOOL;
+}
+extern "C" {
+ pub fn DetourAllocateRegionWithinJumpBounds(
+ pbTarget: LPCVOID,
+ pcbAllocatedSize: PDWORD,
+ ) -> PVOID;
+}
+extern "C" {
+ #[doc = " Loaded Binary Functions."]
+ pub fn DetourGetContainingModule(pvAddr: PVOID) -> HMODULE;
+}
+extern "C" {
+ pub fn DetourEnumerateModules(hModuleLast: HMODULE) -> HMODULE;
+}
+extern "C" {
+ pub fn DetourGetEntryPoint(hModule: HMODULE) -> PVOID;
+}
+extern "C" {
+ pub fn DetourGetModuleSize(hModule: HMODULE) -> ULONG;
+}
+extern "C" {
+ pub fn DetourEnumerateExports(
+ hModule: HMODULE,
+ pContext: PVOID,
+ pfExport: PF_DETOUR_ENUMERATE_EXPORT_CALLBACK,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourEnumerateImports(
+ hModule: HMODULE,
+ pContext: PVOID,
+ pfImportFile: PF_DETOUR_IMPORT_FILE_CALLBACK,
+ pfImportFunc: PF_DETOUR_IMPORT_FUNC_CALLBACK,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourEnumerateImportsEx(
+ hModule: HMODULE,
+ pContext: PVOID,
+ pfImportFile: PF_DETOUR_IMPORT_FILE_CALLBACK,
+ pfImportFuncEx: PF_DETOUR_IMPORT_FUNC_CALLBACK_EX,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourFindPayload(hModule: HMODULE, rguid: *const GUID, pcbData: *mut DWORD) -> PVOID;
+}
+extern "C" {
+ pub fn DetourFindPayloadEx(rguid: *const GUID, pcbData: *mut DWORD) -> PVOID;
+}
+extern "C" {
+ pub fn DetourGetSizeOfPayloads(hModule: HMODULE) -> DWORD;
+}
+extern "C" {
+ #[doc = " Persistent Binary Functions."]
+ pub fn DetourBinaryOpen(hFile: HANDLE) -> PDETOUR_BINARY;
+}
+extern "C" {
+ pub fn DetourBinaryEnumeratePayloads(
+ pBinary: PDETOUR_BINARY,
+ pGuid: *mut GUID,
+ pcbData: *mut DWORD,
+ pnIterator: *mut DWORD,
+ ) -> PVOID;
+}
+extern "C" {
+ pub fn DetourBinaryFindPayload(
+ pBinary: PDETOUR_BINARY,
+ rguid: *const GUID,
+ pcbData: *mut DWORD,
+ ) -> PVOID;
+}
+extern "C" {
+ pub fn DetourBinarySetPayload(
+ pBinary: PDETOUR_BINARY,
+ rguid: *const GUID,
+ pData: PVOID,
+ cbData: DWORD,
+ ) -> PVOID;
+}
+extern "C" {
+ pub fn DetourBinaryDeletePayload(pBinary: PDETOUR_BINARY, rguid: *const GUID) -> BOOL;
+}
+extern "C" {
+ pub fn DetourBinaryPurgePayloads(pBinary: PDETOUR_BINARY) -> BOOL;
+}
+extern "C" {
+ pub fn DetourBinaryResetImports(pBinary: PDETOUR_BINARY) -> BOOL;
+}
+extern "C" {
+ pub fn DetourBinaryEditImports(
+ pBinary: PDETOUR_BINARY,
+ pContext: PVOID,
+ pfByway: PF_DETOUR_BINARY_BYWAY_CALLBACK,
+ pfFile: PF_DETOUR_BINARY_FILE_CALLBACK,
+ pfSymbol: PF_DETOUR_BINARY_SYMBOL_CALLBACK,
+ pfCommit: PF_DETOUR_BINARY_COMMIT_CALLBACK,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourBinaryWrite(pBinary: PDETOUR_BINARY, hFile: HANDLE) -> BOOL;
+}
+extern "C" {
+ pub fn DetourBinaryClose(pBinary: PDETOUR_BINARY) -> BOOL;
+}
+#[doc = " Create Process & Load Dll."]
+pub type PDETOUR_CREATE_PROCESS_ROUTINEA = ::std::option::Option<
+ unsafe extern "C" fn(
+ lpApplicationName: LPCSTR,
+ lpCommandLine: LPSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCSTR,
+ lpStartupInfo: LPSTARTUPINFOA,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ ) -> BOOL,
+>;
+pub type PDETOUR_CREATE_PROCESS_ROUTINEW = ::std::option::Option<
+ unsafe extern "C" fn(
+ lpApplicationName: LPCWSTR,
+ lpCommandLine: LPWSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCWSTR,
+ lpStartupInfo: LPSTARTUPINFOW,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ ) -> BOOL,
+>;
+extern "C" {
+ pub fn DetourCreateProcessWithDllA(
+ lpApplicationName: LPCSTR,
+ lpCommandLine: LPSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCSTR,
+ lpStartupInfo: LPSTARTUPINFOA,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ lpDllName: LPCSTR,
+ pfCreateProcessA: PDETOUR_CREATE_PROCESS_ROUTINEA,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourCreateProcessWithDllW(
+ lpApplicationName: LPCWSTR,
+ lpCommandLine: LPWSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCWSTR,
+ lpStartupInfo: LPSTARTUPINFOW,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ lpDllName: LPCSTR,
+ pfCreateProcessW: PDETOUR_CREATE_PROCESS_ROUTINEW,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourCreateProcessWithDllExA(
+ lpApplicationName: LPCSTR,
+ lpCommandLine: LPSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCSTR,
+ lpStartupInfo: LPSTARTUPINFOA,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ lpDllName: LPCSTR,
+ pfCreateProcessA: PDETOUR_CREATE_PROCESS_ROUTINEA,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourCreateProcessWithDllExW(
+ lpApplicationName: LPCWSTR,
+ lpCommandLine: LPWSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCWSTR,
+ lpStartupInfo: LPSTARTUPINFOW,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ lpDllName: LPCSTR,
+ pfCreateProcessW: PDETOUR_CREATE_PROCESS_ROUTINEW,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourCreateProcessWithDllsA(
+ lpApplicationName: LPCSTR,
+ lpCommandLine: LPSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCSTR,
+ lpStartupInfo: LPSTARTUPINFOA,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ nDlls: DWORD,
+ rlpDlls: *mut LPCSTR,
+ pfCreateProcessA: PDETOUR_CREATE_PROCESS_ROUTINEA,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourCreateProcessWithDllsW(
+ lpApplicationName: LPCWSTR,
+ lpCommandLine: LPWSTR,
+ lpProcessAttributes: LPSECURITY_ATTRIBUTES,
+ lpThreadAttributes: LPSECURITY_ATTRIBUTES,
+ bInheritHandles: BOOL,
+ dwCreationFlags: DWORD,
+ lpEnvironment: LPVOID,
+ lpCurrentDirectory: LPCWSTR,
+ lpStartupInfo: LPSTARTUPINFOW,
+ lpProcessInformation: LPPROCESS_INFORMATION,
+ nDlls: DWORD,
+ rlpDlls: *mut LPCSTR,
+ pfCreateProcessW: PDETOUR_CREATE_PROCESS_ROUTINEW,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourProcessViaHelperA(
+ dwTargetPid: DWORD,
+ lpDllName: LPCSTR,
+ pfCreateProcessA: PDETOUR_CREATE_PROCESS_ROUTINEA,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourProcessViaHelperW(
+ dwTargetPid: DWORD,
+ lpDllName: LPCSTR,
+ pfCreateProcessW: PDETOUR_CREATE_PROCESS_ROUTINEW,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourProcessViaHelperDllsA(
+ dwTargetPid: DWORD,
+ nDlls: DWORD,
+ rlpDlls: *mut LPCSTR,
+ pfCreateProcessA: PDETOUR_CREATE_PROCESS_ROUTINEA,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourProcessViaHelperDllsW(
+ dwTargetPid: DWORD,
+ nDlls: DWORD,
+ rlpDlls: *mut LPCSTR,
+ pfCreateProcessW: PDETOUR_CREATE_PROCESS_ROUTINEW,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourUpdateProcessWithDll(hProcess: HANDLE, rlpDlls: *mut LPCSTR, nDlls: DWORD)
+ -> BOOL;
+}
+extern "C" {
+ pub fn DetourUpdateProcessWithDllEx(
+ hProcess: HANDLE,
+ hImage: HMODULE,
+ bIs32Bit: BOOL,
+ rlpDlls: *mut LPCSTR,
+ nDlls: DWORD,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourCopyPayloadToProcess(
+ hProcess: HANDLE,
+ rguid: *const GUID,
+ pvData: PVOID,
+ cbData: DWORD,
+ ) -> BOOL;
+}
+extern "C" {
+ pub fn DetourRestoreAfterWith() -> BOOL;
+}
+extern "C" {
+ pub fn DetourRestoreAfterWithEx(pvData: PVOID, cbData: DWORD) -> BOOL;
+}
+extern "C" {
+ pub fn DetourIsHelperProcess() -> BOOL;
+}
+extern "C" {
+ pub fn DetourFinishHelperProcess(arg1: HWND, arg2: HINSTANCE, arg3: LPSTR, arg4: INT);
+}
diff --git a/detours-sys/src/lib.rs b/detours-sys/src/lib.rs new file mode 100644 index 0000000..9f18b97 --- /dev/null +++ b/detours-sys/src/lib.rs @@ -0,0 +1,78 @@ +#![cfg(target_os = "windows")] + +//! Bindings to the Microsoft Detours API. +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +// Rebuild with: +// bindgen ..\build\wrapper.h --whitelist-function "Detour.*" -o bundled_bindings.rs -- "-fms-compatibility" "-fms-extensions" --target=x86_64-pc-windows-msvc -I ..\..\ext\detours\src\ +include!("bundled_bindings.rs"); + +#[cfg(test)] +mod tests { + use super::*; + use std::{ffi, ptr}; + use winapi::{ + shared::minwindef::LPVOID, + um::{processthreadsapi::GetCurrentThread, synchapi::Sleep, sysinfoapi::GetTickCount}, + }; + + static mut TRUE_SLEEP: unsafe extern "system" fn(DWORD) = Sleep; + static mut SLEPT: LONG = 0; + + // Detour function that replaces the Sleep API. + unsafe extern "system" fn TimedSleep(dwMilliseconds: DWORD) { + // Save the before and after times around calling the Sleep API. + let dwBeg: DWORD = GetTickCount(); + TRUE_SLEEP(dwMilliseconds); + let dwEnd: DWORD = GetTickCount(); + + SLEPT = (dwEnd - dwBeg) as i32; + } + + extern "system" fn DllMain(_: HINSTANCE, reason: DWORD, _: LPVOID) -> BOOL { + if unsafe { DetourIsHelperProcess() } == 1 { + return 1; + } + + let tru = unsafe { &mut TRUE_SLEEP as *mut _ as *mut *mut ffi::c_void }; + let new = TimedSleep as *mut ffi::c_void; + + match reason { + // DLL_PROCESS_ATTACH + 1 => unsafe { + DetourRestoreAfterWith(); + + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread() as _); + DetourAttach(tru, new); + DetourTransactionCommit(); + }, + // DLL_PROCESS_DETACH + 0 => unsafe { + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread() as _); + DetourDetach(tru, new); + DetourTransactionCommit(); + }, + _ => (), + } + 1 + } + + #[test] + fn hook_self() { + unsafe { + DllMain(ptr::null_mut(), 1, ptr::null_mut()); + let slept; + + Sleep(500); + slept = SLEPT; + assert_ne!(SLEPT, 0); + + DllMain(ptr::null_mut(), 0, ptr::null_mut()); + Sleep(500); + assert_eq!(slept, SLEPT); + } + } +} |