Skip to content
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

Migrate to windows-sys from winapi #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_width = 80
tab_spaces = 4
43 changes: 37 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,51 @@ repository = "https://github.com/MSxDOS/ntapi"
readme = "README.md"
categories = ["external-ffi-bindings", "no-std", "os::windows-apis"]
keywords = ["windows", "ffi", "ntapi", "native", "win32"]
include = ["src/**/*", "Cargo.toml", "build.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
include = [
"src/**/*",
"Cargo.toml",
"build.rs",
"README.md",
"LICENSE-APACHE",
"LICENSE-MIT",
]
edition = "2018"

[package.metadata.docs.rs]
default-target = "x86_64-pc-windows-msvc"
targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"]
targets = [
"aarch64-pc-windows-msvc",
"i686-pc-windows-msvc",
"x86_64-pc-windows-msvc",
]

[dependencies.winapi]
version = "0.3.9"
features = ["cfg", "evntrace", "in6addr", "inaddr", "minwinbase", "ntsecapi", "windef", "winioctl"]
[dependencies.windows-sys]
version = "0.48.0"
features = [
'Win32_Devices_DeviceAndDriverInstallation',
'Win32_Foundation',
'Win32_Networking_WinSock',
'Win32_Security_Authentication_Identity',
'Win32_Security',
'Win32_Storage_FileSystem',
'Win32_System_Diagnostics_Debug',
'Win32_System_Diagnostics_Etw',
'Win32_System_Ioctl',
'Win32_System_JobObjects',
'Win32_System_Kernel',
'Win32_System_Memory',
'Win32_System_Performance_HardwareCounterProfiling',
'Win32_System_Power',
'Win32_System_SystemInformation',
'Win32_System_SystemServices',
'Win32_System_Threading',
'Win32_System_WindowsProgramming',
'Win32_UI_WindowsAndMessaging',
]

[features]
default = ["user"]
func-types = []
impl-default = ["winapi/impl-default"]
impl-default = []
user = []
kernel = []
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ environment:
- host: i686-pc-windows-gnu
channel: nightly
- host: x86_64-pc-windows-gnu
channel: 1.64.0
channel: 1.70.0
- host: i686-pc-windows-gnu
channel: 1.64.0
channel: 1.70.0

install:
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
Expand All @@ -24,11 +24,11 @@ install:
- rustc -vV
- cargo -vV
- if defined aarch64 (
rustup target add aarch64-pc-windows-msvc
rustup target add aarch64-pc-windows-msvc
)

build_script:
- cargo test --verbose --color always --features "func-types impl-default user"
- if defined aarch64 (
cargo test --verbose --color always --features "func-types impl-default user" --target aarch64-pc-windows-msvc --no-run
cargo test --verbose --color always --features "func-types impl-default user" --target aarch64-pc-windows-msvc --no-run
)
15 changes: 3 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
use std::env::var;

fn main() {
#[cfg(feature = "user")] {
if var("TARGET").map(
|t| t == "x86_64-pc-windows-gnu" || t == "i686-pc-windows-gnu"
).unwrap_or(false) {
if var("WINAPI_NO_BUNDLED_LIBRARIES").is_ok() {
println!("cargo:rustc-link-lib=ntdll");
} else {
println!("cargo:rustc-link-lib=winapi_ntdll");
}
}
#[cfg(feature = "user")]
{
println!("cargo:rustc-link-lib=ntdll");
}
}
23 changes: 23 additions & 0 deletions src/ctypes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub use core::ffi::c_void;
pub type c_char = i8;
pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;
pub type c_long = i32;
pub type c_ulong = u32;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type c_float = f32;
pub type c_double = f64;
pub type __int8 = i8;
pub type __uint8 = u8;
pub type __int16 = i16;
pub type __uint16 = u16;
pub type __int32 = i32;
pub type __uint32 = u32;
pub type __int64 = i64;
pub type __uint64 = u64;
pub type wchar_t = u16;
23 changes: 17 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
//!
//! [fn_ptr]: https://doc.rust-lang.org/reference/types.html#function-pointer-types
//! [`Default`]: https://doc.rust-lang.org/std/default/trait.Default.html#tymethod.default
#![cfg(all(windows, any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
#![cfg(all(
windows,
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
#![no_std]
#![deny(unused, unused_qualifications)]
#![warn(unused_attributes)]
#![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)]
#![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
)]
#[doc(hidden)]
pub extern crate core as _core;
#[macro_use]
#[doc(hidden)]
pub extern crate winapi;
#[macro_use]
mod macros;
pub mod ctypes;
pub mod ntapi_base;
pub mod ntdbg;
pub mod ntexapi;
Expand Down Expand Up @@ -47,5 +58,5 @@ pub mod ntxcapi;
pub mod ntzwapi;
pub mod string;
pub mod subprocesstag;
pub mod winapi_local;
pub mod windows_local;
pub mod winsta;
52 changes: 52 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,58 @@ macro_rules! UNION {
fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } }
}
);
($(#[$attrs:meta])* union $name:ident {
[$stype:ty; $ssize:expr],
$($variant:ident $variant_mut:ident: $ftype:ty,)+
}) => (
#[repr(C)] $(#[$attrs])*
pub struct $name([$stype; $ssize]);
impl Copy for $name {}
impl Clone for $name {
#[inline]
fn clone(&self) -> $name { *self }
}
#[cfg(feature = "impl-default")]
impl Default for $name {
#[inline]
fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } }
}
impl $name {$(
#[inline]
pub unsafe fn $variant(&self) -> &$ftype {
&*(self as *const _ as *const $ftype)
}
#[inline]
pub unsafe fn $variant_mut(&mut self) -> &mut $ftype {
&mut *(self as *mut _ as *mut $ftype)
}
)+}
);
}
macro_rules! ENUM {
{enum $name:ident { $($variant:ident = $value:expr,)+ }} => {
pub type $name = u32;
$(pub const $variant: $name = $value;)+
};
}
macro_rules! STRUCT {
($(#[$attrs:meta])* struct $name:ident {
$($field:ident: $ftype:ty,)+
}) => (
#[repr(C)] #[derive(Copy, Clone)] $(#[$attrs])*
pub struct $name {
$(pub $field: $ftype,)+
}
// impl Clone for $name {
// #[inline]
// fn clone(&self) -> $name { *self }
// }
#[cfg(feature = "impl-default")]
impl Default for $name {
#[inline]
fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } }
}
);
}
macro_rules! FN {
(stdcall $func:ident($($p:ident: $t:ty,)*) -> $ret:ty) => (
Expand Down
42 changes: 22 additions & 20 deletions src/ntapi_base.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
use winapi::shared::ntdef::{HANDLE, LONG, NTSTATUS, ULONG, ULONGLONG, USHORT};
use winapi::shared::ntstatus::FACILITY_NTWIN32;
pub type KPRIORITY = LONG;
pub type RTL_ATOM = USHORT;
use windows_sys::Win32::Foundation::{FACILITY_NTWIN32, HANDLE, NTSTATUS};

use crate::ctypes::{__uint64, c_long, c_ulong, c_ushort};

pub type KPRIORITY = c_long;
pub type RTL_ATOM = c_ushort;
pub type PRTL_ATOM = *mut RTL_ATOM;
pub const NT_FACILITY_MASK: ULONG = 0xfff;
pub const NT_FACILITY_SHIFT: ULONG = 16;
pub const NT_FACILITY_MASK: c_ulong = 0xfff;
pub const NT_FACILITY_SHIFT: c_ulong = 16;
#[inline]
pub const fn NT_FACILITY(Status: NTSTATUS) -> ULONG {
pub const fn NT_FACILITY(Status: NTSTATUS) -> c_ulong {
(Status as u32) >> NT_FACILITY_SHIFT & NT_FACILITY_MASK
}
#[inline]
pub const fn NT_NTWIN32(Status: NTSTATUS) -> bool {
NT_FACILITY(Status) == FACILITY_NTWIN32 as u32
NT_FACILITY(Status) == FACILITY_NTWIN32
}
#[inline]
pub const fn WIN32_FROM_NTSTATUS(Status: NTSTATUS) -> ULONG {
pub const fn WIN32_FROM_NTSTATUS(Status: NTSTATUS) -> c_ulong {
(Status as u32) & 0xffff
}
STRUCT!{struct CLIENT_ID {
STRUCT! {struct CLIENT_ID {
UniqueProcess: HANDLE,
UniqueThread: HANDLE,
}}
pub type PCLIENT_ID = *mut CLIENT_ID;
STRUCT!{struct CLIENT_ID32 {
UniqueProcess: ULONG,
UniqueThread: ULONG,
STRUCT! {struct CLIENT_ID32 {
UniqueProcess: c_ulong,
UniqueThread: c_ulong,
}}
pub type PCLIENT_ID32 = *mut CLIENT_ID32;
STRUCT!{struct CLIENT_ID64 {
UniqueProcess: ULONGLONG,
UniqueThread: ULONGLONG,
STRUCT! {struct CLIENT_ID64 {
UniqueProcess: __uint64,
UniqueThread: __uint64,
}}
pub type PCLIENT_ID64 = *mut CLIENT_ID64;
STRUCT!{struct KSYSTEM_TIME {
LowPart: ULONG,
High1Time: LONG,
High2Time: LONG,
STRUCT! {struct KSYSTEM_TIME {
LowPart: c_ulong,
High1Time: c_long,
High2Time: c_long,
}}
pub type PKSYSTEM_TIME = *mut KSYSTEM_TIME;
Loading