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

Add support for asm, rename and alias nightly to beta #8

Merged
merged 2 commits into from
Feb 2, 2022
Merged
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = "2018"

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

[dependencies.winapi]
Expand All @@ -27,4 +27,5 @@ func-types = []
impl-default = ["winapi/impl-default"]
user = []
kernel = []
nightly = []
beta = []
nightly = ["beta"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Rust FFI bindings for Native API. Mostly based on Process Hacker [phnt](https://github.com/processhacker/processhacker/tree/master/phnt) headers as the most complete source of bindings to be found. The comments there also contain useful information on how to use specific things.

### Minimum supported Rust
Always the latest stable. Some [features][docs_link] require a nightly compiler.
Always the latest stable. Some [features][docs_link] require a beta compiler.

[travis_link]: https://travis-ci.org/MSxDOS/ntapi
[travis_badge]: https://travis-ci.org/MSxDOS/ntapi.svg?branch=master
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! **`impl-default`** -- Implement [`Default`] for structs and unions.<br/>
//! **`user`** *(default)* -- Link to `ntdll`.<br/>
//! **`kernel`** -- Link to `ntoskrnl` on MSVC targets.<br/>
//! **`nightly`** -- Unlock unstable features that require a nightly compiler:
//! **`beta`** -- Unlock unstable features that require a beta compiler:
//! - [`NtCurrentTeb`]
//! - [`__readfsdword`]
//! - [`__readgsqword`]
Expand All @@ -30,7 +30,6 @@
#![deny(unused, unused_qualifications)]
#![warn(unused_attributes)]
#![allow(bad_style, 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)]
#![cfg_attr(feature = "nightly", feature(llvm_asm))]
#[doc(hidden)]
pub extern crate core as _core;
#[macro_use]
Expand Down
8 changes: 4 additions & 4 deletions src/ntpsapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use winapi::um::winnt::{
PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY, PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY,
PROCESS_MITIGATION_SYSTEM_CALL_FILTER_POLICY, PSECURITY_QUALITY_OF_SERVICE,
};
#[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
#[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
use crate::winapi_local::um::winnt::NtCurrentTeb;
pub const GDI_HANDLE_BUFFER_SIZE32: usize = 34;
pub const GDI_HANDLE_BUFFER_SIZE64: usize = 60;
Expand Down Expand Up @@ -932,19 +932,19 @@ pub const NtCurrentThread: HANDLE = -2isize as *mut c_void;
pub const ZwCurrentThread: HANDLE = NtCurrentThread;
pub const NtCurrentSession: HANDLE = -3isize as *mut c_void;
pub const ZwCurrentSession: HANDLE = NtCurrentSession;
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
pub unsafe fn NtCurrentPeb() -> PPEB {
(*NtCurrentTeb()).ProcessEnvironmentBlock
}
pub const NtCurrentProcessToken: HANDLE = -4isize as *mut c_void;
pub const NtCurrentThreadToken: HANDLE = -5isize as *mut c_void;
pub const NtCurrentEffectiveToken: HANDLE = -6isize as *mut c_void;
pub const NtCurrentSilo: HANDLE = -1isize as *mut c_void;
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
pub unsafe fn NtCurrentProcessId() -> HANDLE {
(*NtCurrentTeb()).ClientId.UniqueProcess
}
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
pub unsafe fn NtCurrentThreadId() -> HANDLE {
(*NtCurrentTeb()).ClientId.UniqueThread
}
Expand Down
6 changes: 3 additions & 3 deletions src/ntrtl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ EXTERN!{extern "system" {
MakeReadOnly: BOOLEAN,
);
}}
#[inline] #[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
#[inline] #[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
pub unsafe fn RtlProcessHeap() -> PVOID {
use crate::ntpsapi::NtCurrentPeb;
(*NtCurrentPeb()).ProcessHeap
Expand Down Expand Up @@ -2944,13 +2944,13 @@ EXTERN!{extern "system" {
}}
#[inline]
pub unsafe fn RtlCheckBit(BitMapHeader: &RTL_BITMAP, BitPosition: ULONG) -> u8 {
#[cfg(all(target_arch = "x86_64", feature = "nightly"))] {
#[cfg(all(target_arch = "x86_64", feature = "beta"))] {
use crate::winapi_local::um::winnt::_bittest64;
_bittest64(BitMapHeader.Buffer as *const i64, BitPosition as i64)
}
#[cfg(any(
target_arch = "x86",
all(target_arch = "x86_64", not(feature = "nightly")),
all(target_arch = "x86_64", not(feature = "beta")),
target_arch = "aarch64",
))] {
(*BitMapHeader.Buffer.offset(BitPosition as isize / 32) >> (BitPosition % 32) & 1) as u8
Expand Down
36 changes: 17 additions & 19 deletions src/winapi_local/um/winnt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
use core::arch::asm;
use winapi::shared::basetsd::{DWORD64, SIZE_T, ULONG64};
use winapi::shared::minwindef::DWORD;
use winapi::um::winnt::{HANDLE, PVOID};
Expand All @@ -6,40 +8,36 @@ use winapi::um::winnt::{HANDLE, PVOID};
pub const fn UInt32x32To64(a: u32, b: u32) -> u64 {
a as u64 * b as u64
}
#[cfg(all(feature = "nightly", not(target_arch = "aarch64")))]
#[cfg(all(feature = "beta", not(target_arch = "aarch64")))]
IFDEF!{
use crate::ntpebteb::TEB;
#[inline]
pub unsafe fn _bittest64(Base: *const i64, Offset: i64) -> u8 {
let out: u8;
llvm_asm!("bt $1, $2; setb $0"
: "=r"(out)
: "*m"(Base), "r"(Offset)
: "cc"
: "intel"
);
asm!(
"bt {1}, {2}",
"setb {0}",
out(reg_byte) out,
in(reg) Base,
in(reg) Offset);
out
}
#[inline]
pub unsafe fn __readfsdword(Offset: DWORD) -> DWORD {
let out: u32;
llvm_asm!("mov $0, fs:[$1]"
: "=r"(out)
: "ri"(Offset)
:
: "intel"
);
asm!(
"mov {0:e}, fs:[{1:e}]",
out(reg) out,
in(reg) Offset);
out
}
#[inline]
pub unsafe fn __readgsqword(Offset: DWORD) -> DWORD64 {
let out: u64;
llvm_asm!("mov $0, gs:[$1]"
: "=r"(out)
: "ri"(Offset)
:
: "intel"
);
asm!(
"mov {0}, gs:[{1:e}]",
out(reg) out,
in(reg) Offset);
out
}
#[inline] #[allow(unused_unsafe)]
Expand Down