Skip to main content

dolang_winterop/
lib.rs

1#![deny(warnings)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3//! Portable representations and small utilities for interoperating with
4//! Windows APIs and wire formats.
5//!
6//! The [`security`] and [`guid`] modules validate their native binary encodings
7//! and remain available
8//! on every target. This makes them suitable for RPC payloads and tools that
9//! inspect a Windows target from another operating system. Windows-only
10//! facilities, such as the APC reactor, are conditionally exported.
11//!
12//! ```
13//! use dolang_winterop::security::{AccessMask, AceBuf, AceBuildOptions, AclBuf, Sid};
14//!
15//! let sid: Sid = "S-1-5-32-544".parse()?;
16//! let ace = AceBuf::allow(
17//!     &sid,
18//!     AccessMask::from_bits_retain(0x0012_0000),
19//!     AceBuildOptions::new(),
20//! )?;
21//! let acl = AclBuf::from_aces([ace], None)?;
22//! assert_eq!(acl.ace_count(), 1);
23//! # Ok::<(), Box<dyn std::error::Error>>(())
24//! ```
25
26#[cfg(any(windows, docsrs))]
27#[cfg_attr(docsrs, doc(cfg(windows)))]
28pub mod apc;
29pub mod error;
30pub mod guid;
31pub mod process;
32pub mod security;
33
34/// Returns whether the current process is running under Wine.
35#[cfg(windows)]
36#[cfg_attr(docsrs, doc(auto_cfg = false))]
37pub fn is_wine() -> bool {
38    use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleW, GetProcAddress};
39    use windows_sys::core::w;
40
41    const WINE_GET_VERSION: &[u8] = b"wine_get_version\0";
42
43    let ntdll = unsafe { GetModuleHandleW(w!("ntdll.dll")) };
44    !ntdll.is_null() && unsafe { GetProcAddress(ntdll, WINE_GET_VERSION.as_ptr()) }.is_some()
45}
46
47/// Returns whether the current process is running under Wine.
48#[cfg(not(windows))]
49#[cfg_attr(docsrs, doc(auto_cfg = false))]
50pub const fn is_wine() -> bool {
51    false
52}