Currently bindings are restricted to windows and x86_64/x86. This is reflected in the src/ffi/generated.rs:
compile_error!("These bindings can only be used on `x86_64` architectures. To generate bindings for your target architecture, consider using the `regenerate` feature.");
There are two reasons I found for this:
- The
cty crate depends on the target to create ctype definitions
extern blocks rely on linked symbols and ABIs such as stdcall may not be possible on other targets.
My use case is such that I wish to use structures such as PPEB on non-native targets such as i686-unknown-linux-gnu.
This being the case I forked this repository, which can be found here: https://github.com/Irate-Walrus/phnt-rs
In this fork I introduced a pre-generated x86_64_bindgen.rs and x86_bindgen.rs as well as two feature flags externs and fn_types.
externs allows externally linked symbols to be enabled/disabled:
#[cfg(feature="externs")]
extern "C" {
pub static GUID_NULL: GUID;
pub static mut NlsAnsiCodePage: USHORT;
...
While fn_types defines the externally linked functions as types:
#[cfg(feature="fn_types")]
mod fn_types {
pub type NtCallbackReturnFn = unsafe extern "C" fn(OutputBuffer: PVOID, OutputLength: ULONG, Status: NTSTATUS) -> NTSTATUS;
pub type NtFlushProcessWriteBuffersFn = unsafe extern "C" fn() -> NTSTATUS;
pub type NtQueryDebugFilterStateFn = unsafe extern "C" fn(ComponentId: ULONG, Level: ULONG) -> NTSTATUS;
...
This is helpful if you are trying to call these functions directly in memory:
let rtl_allocate_heap: RtlAllocateHeapFn = core::mem::transmute(rtl_allocate_heap_addr);
let ptr = rtl_allocate_heap(self.handle(), HEAP_ZERO_MEMORY, layout.size() as _)
I've also added to the GitHub workflows to auto-regenerate both x86 and x86_64 bindings and commit them to the repo.
There are a few issues that I've seen so far:
- Bad regexes in my
build.rs lead to failure with the latest bindgen version 0.71.1
- Dropping the use of
cty for internally defined ctypes may break compatibility with pre-existing users.
- Custom
rustfmt to allow for the use of regex when feature-gating externs and function types.
This issue is to gauge your interest in these changes, although it's likely I may continue in the fork to add further definitions from other header files. Thanks for you hard work, it made these changes relatively straightforward.
Currently bindings are restricted to
windowsandx86_64/x86. This is reflected in thesrc/ffi/generated.rs:There are two reasons I found for this:
ctycrate depends on thetargetto create ctype definitionsexternblocks rely on linked symbols and ABIs such asstdcallmay not be possible on other targets.My use case is such that I wish to use structures such as
PPEBon non-native targets such asi686-unknown-linux-gnu.This being the case I forked this repository, which can be found here: https://github.com/Irate-Walrus/phnt-rs
In this fork I introduced a pre-generated
x86_64_bindgen.rsandx86_bindgen.rsas well as two feature flagsexternsandfn_types.externsallows externally linked symbols to be enabled/disabled:While
fn_typesdefines the externally linked functions as types:This is helpful if you are trying to call these functions directly in memory:
I've also added to the GitHub workflows to auto-regenerate both
x86andx86_64bindings and commit them to the repo.There are a few issues that I've seen so far:
build.rslead to failure with the latest bindgen version0.71.1ctyfor internally defined ctypes may break compatibility with pre-existing users.rustfmtto allow for the use of regex when feature-gating externs and function types.This issue is to gauge your interest in these changes, although it's likely I may continue in the fork to add further definitions from other header files. Thanks for you hard work, it made these changes relatively straightforward.