Skip to content

Commit e2b87dd

Browse files
committed
Migrate to windows-sys
1 parent f93504e commit e2b87dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+12830
-10602
lines changed

.rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
max_width = 80
2+
tab_spaces = 4

Cargo.toml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,51 @@ repository = "https://github.com/MSxDOS/ntapi"
99
readme = "README.md"
1010
categories = ["external-ffi-bindings", "no-std", "os::windows-apis"]
1111
keywords = ["windows", "ffi", "ntapi", "native", "win32"]
12-
include = ["src/**/*", "Cargo.toml", "build.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
12+
include = [
13+
"src/**/*",
14+
"Cargo.toml",
15+
"build.rs",
16+
"README.md",
17+
"LICENSE-APACHE",
18+
"LICENSE-MIT",
19+
]
1320
edition = "2018"
1421

1522
[package.metadata.docs.rs]
1623
default-target = "x86_64-pc-windows-msvc"
17-
targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"]
24+
targets = [
25+
"aarch64-pc-windows-msvc",
26+
"i686-pc-windows-msvc",
27+
"x86_64-pc-windows-msvc",
28+
]
1829

19-
[dependencies.winapi]
20-
version = "0.3.9"
21-
features = ["cfg", "evntrace", "in6addr", "inaddr", "minwinbase", "ntsecapi", "windef", "winioctl"]
30+
[dependencies.windows-sys]
31+
version = "0.48.0"
32+
features = [
33+
'Win32_Devices_DeviceAndDriverInstallation',
34+
'Win32_Foundation',
35+
'Win32_Networking_WinSock',
36+
'Win32_Security_Authentication_Identity',
37+
'Win32_Security',
38+
'Win32_Storage_FileSystem',
39+
'Win32_System_Diagnostics_Debug',
40+
'Win32_System_Diagnostics_Etw',
41+
'Win32_System_Ioctl',
42+
'Win32_System_JobObjects',
43+
'Win32_System_Kernel',
44+
'Win32_System_Memory',
45+
'Win32_System_Performance_HardwareCounterProfiling',
46+
'Win32_System_Power',
47+
'Win32_System_SystemInformation',
48+
'Win32_System_SystemServices',
49+
'Win32_System_Threading',
50+
'Win32_System_WindowsProgramming',
51+
'Win32_UI_WindowsAndMessaging',
52+
]
2253

2354
[features]
2455
default = ["user"]
2556
func-types = []
26-
impl-default = ["winapi/impl-default"]
57+
impl-default = []
2758
user = []
2859
kernel = []

build.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use std::env::var;
22

33
fn main() {
4-
#[cfg(feature = "user")] {
5-
if var("TARGET").map(
6-
|t| t == "x86_64-pc-windows-gnu" || t == "i686-pc-windows-gnu"
7-
).unwrap_or(false) {
8-
if var("WINAPI_NO_BUNDLED_LIBRARIES").is_ok() {
9-
println!("cargo:rustc-link-lib=ntdll");
10-
} else {
11-
println!("cargo:rustc-link-lib=winapi_ntdll");
12-
}
4+
#[cfg(feature = "user")]
5+
{
6+
if var("TARGET")
7+
.map(|t| t == "x86_64-pc-windows-gnu" || t == "i686-pc-windows-gnu")
8+
.unwrap_or(false)
9+
{
10+
println!("cargo:rustc-link-lib=ntdll");
1311
}
1412
}
1513
}

src/ctypes.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pub use core::ffi::c_void;
2+
pub type c_char = i8;
3+
pub type c_schar = i8;
4+
pub type c_uchar = u8;
5+
pub type c_short = i16;
6+
pub type c_ushort = u16;
7+
pub type c_int = i32;
8+
pub type c_uint = u32;
9+
pub type c_long = i32;
10+
pub type c_ulong = u32;
11+
pub type c_longlong = i64;
12+
pub type c_ulonglong = u64;
13+
pub type c_float = f32;
14+
pub type c_double = f64;
15+
pub type __int8 = i8;
16+
pub type __uint8 = u8;
17+
pub type __int16 = i16;
18+
pub type __uint16 = u16;
19+
pub type __int32 = i32;
20+
pub type __uint32 = u32;
21+
pub type __int64 = i64;
22+
pub type __uint64 = u64;
23+
pub type wchar_t = u16;

src/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@
66
//!
77
//! [fn_ptr]: https://doc.rust-lang.org/reference/types.html#function-pointer-types
88
//! [`Default`]: https://doc.rust-lang.org/std/default/trait.Default.html#tymethod.default
9-
#![cfg(all(windows, any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
9+
#![cfg(all(
10+
windows,
11+
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
12+
))]
1013
#![no_std]
1114
#![deny(unused, unused_qualifications)]
1215
#![warn(unused_attributes)]
13-
#![allow(bad_style, deprecated, overflowing_literals, unused_macros, clippy::cast_lossless, clippy::cast_ptr_alignment, clippy::len_without_is_empty, clippy::trivially_copy_pass_by_ref, clippy::unreadable_literal)]
16+
#![allow(
17+
bad_style,
18+
deprecated,
19+
overflowing_literals,
20+
unused_macros,
21+
clippy::cast_lossless,
22+
clippy::cast_ptr_alignment,
23+
clippy::len_without_is_empty,
24+
clippy::trivially_copy_pass_by_ref,
25+
clippy::unreadable_literal
26+
)]
1427
#[doc(hidden)]
1528
pub extern crate core as _core;
1629
#[macro_use]
17-
#[doc(hidden)]
18-
pub extern crate winapi;
19-
#[macro_use]
2030
mod macros;
31+
pub mod ctypes;
2132
pub mod ntapi_base;
2233
pub mod ntdbg;
2334
pub mod ntexapi;
@@ -47,5 +58,5 @@ pub mod ntxcapi;
4758
pub mod ntzwapi;
4859
pub mod string;
4960
pub mod subprocesstag;
50-
pub mod winapi_local;
61+
pub mod windows_local;
5162
pub mod winsta;

src/macros.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,58 @@ macro_rules! UNION {
8888
fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } }
8989
}
9090
);
91+
($(#[$attrs:meta])* union $name:ident {
92+
[$stype:ty; $ssize:expr],
93+
$($variant:ident $variant_mut:ident: $ftype:ty,)+
94+
}) => (
95+
#[repr(C)] $(#[$attrs])*
96+
pub struct $name([$stype; $ssize]);
97+
impl Copy for $name {}
98+
impl Clone for $name {
99+
#[inline]
100+
fn clone(&self) -> $name { *self }
101+
}
102+
#[cfg(feature = "impl-default")]
103+
impl Default for $name {
104+
#[inline]
105+
fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } }
106+
}
107+
impl $name {$(
108+
#[inline]
109+
pub unsafe fn $variant(&self) -> &$ftype {
110+
&*(self as *const _ as *const $ftype)
111+
}
112+
#[inline]
113+
pub unsafe fn $variant_mut(&mut self) -> &mut $ftype {
114+
&mut *(self as *mut _ as *mut $ftype)
115+
}
116+
)+}
117+
);
118+
}
119+
macro_rules! ENUM {
120+
{enum $name:ident { $($variant:ident = $value:expr,)+ }} => {
121+
pub type $name = u32;
122+
$(pub const $variant: $name = $value;)+
123+
};
124+
}
125+
macro_rules! STRUCT {
126+
($(#[$attrs:meta])* struct $name:ident {
127+
$($field:ident: $ftype:ty,)+
128+
}) => (
129+
#[repr(C)] #[derive(Copy, Clone)] $(#[$attrs])*
130+
pub struct $name {
131+
$(pub $field: $ftype,)+
132+
}
133+
// impl Clone for $name {
134+
// #[inline]
135+
// fn clone(&self) -> $name { *self }
136+
// }
137+
#[cfg(feature = "impl-default")]
138+
impl Default for $name {
139+
#[inline]
140+
fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } }
141+
}
142+
);
91143
}
92144
macro_rules! FN {
93145
(stdcall $func:ident($($p:ident: $t:ty,)*) -> $ret:ty) => (

src/ntapi_base.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
use winapi::shared::ntdef::{HANDLE, LONG, NTSTATUS, ULONG, ULONGLONG, USHORT};
2-
use winapi::shared::ntstatus::FACILITY_NTWIN32;
3-
pub type KPRIORITY = LONG;
4-
pub type RTL_ATOM = USHORT;
1+
use windows_sys::Win32::Foundation::{FACILITY_NTWIN32, HANDLE, NTSTATUS};
2+
3+
use crate::ctypes::{__uint64, c_long, c_ulong, c_ushort};
4+
5+
pub type KPRIORITY = c_long;
6+
pub type RTL_ATOM = c_ushort;
57
pub type PRTL_ATOM = *mut RTL_ATOM;
6-
pub const NT_FACILITY_MASK: ULONG = 0xfff;
7-
pub const NT_FACILITY_SHIFT: ULONG = 16;
8+
pub const NT_FACILITY_MASK: c_ulong = 0xfff;
9+
pub const NT_FACILITY_SHIFT: c_ulong = 16;
810
#[inline]
9-
pub const fn NT_FACILITY(Status: NTSTATUS) -> ULONG {
11+
pub const fn NT_FACILITY(Status: NTSTATUS) -> c_ulong {
1012
(Status as u32) >> NT_FACILITY_SHIFT & NT_FACILITY_MASK
1113
}
1214
#[inline]
1315
pub const fn NT_NTWIN32(Status: NTSTATUS) -> bool {
14-
NT_FACILITY(Status) == FACILITY_NTWIN32 as u32
16+
NT_FACILITY(Status) == FACILITY_NTWIN32
1517
}
1618
#[inline]
17-
pub const fn WIN32_FROM_NTSTATUS(Status: NTSTATUS) -> ULONG {
19+
pub const fn WIN32_FROM_NTSTATUS(Status: NTSTATUS) -> c_ulong {
1820
(Status as u32) & 0xffff
1921
}
20-
STRUCT!{struct CLIENT_ID {
22+
STRUCT! {struct CLIENT_ID {
2123
UniqueProcess: HANDLE,
2224
UniqueThread: HANDLE,
2325
}}
2426
pub type PCLIENT_ID = *mut CLIENT_ID;
25-
STRUCT!{struct CLIENT_ID32 {
26-
UniqueProcess: ULONG,
27-
UniqueThread: ULONG,
27+
STRUCT! {struct CLIENT_ID32 {
28+
UniqueProcess: c_ulong,
29+
UniqueThread: c_ulong,
2830
}}
2931
pub type PCLIENT_ID32 = *mut CLIENT_ID32;
30-
STRUCT!{struct CLIENT_ID64 {
31-
UniqueProcess: ULONGLONG,
32-
UniqueThread: ULONGLONG,
32+
STRUCT! {struct CLIENT_ID64 {
33+
UniqueProcess: __uint64,
34+
UniqueThread: __uint64,
3335
}}
3436
pub type PCLIENT_ID64 = *mut CLIENT_ID64;
35-
STRUCT!{struct KSYSTEM_TIME {
36-
LowPart: ULONG,
37-
High1Time: LONG,
38-
High2Time: LONG,
37+
STRUCT! {struct KSYSTEM_TIME {
38+
LowPart: c_ulong,
39+
High1Time: c_long,
40+
High2Time: c_long,
3941
}}
4042
pub type PKSYSTEM_TIME = *mut KSYSTEM_TIME;

0 commit comments

Comments
 (0)