Skip to content

Commit

Permalink
feat: include bindings for i686 (x86) and aarch64 (arm64)
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Dec 29, 2024
1 parent 0dd805b commit b979063
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deps/phnt-nightly
Submodule phnt-nightly updated 9 files
+8 −8 ntbcd.h
+9 −9 ntexapi.h
+8 −3 ntldr.h
+94 −75 ntmmapi.h
+29 −18 ntpsapi.h
+3 −0 ntrtl.h
+2 −2 ntwow64.h
+3 −0 phnt.h
+2 −0 winsta.h
7 changes: 5 additions & 2 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod regen {

let mut raw_lines = vec![
format!("// Generated at {}", chrono::offset::Local::now()),
format!("#[cfg(not(target_arch = \"{}\"))]", std::env::consts::ARCH),
format!("#[cfg(not(target_arch = \"{}\"))]", std::env::var("CARGO_CFG_TARGET_ARCH").unwrap()),
format!("compile_error!(\"These bindings can only be used on `{}` architectures. To generate bindings for your target architecture, consider using the `regenerate` feature.\");", std::env::consts::ARCH),
"".into(),
"use cty;".into(),
Expand Down Expand Up @@ -173,7 +173,10 @@ mod regen {
"\\deps\\phnt-nightly"
));

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("generated.rs");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join(format!(
"{}_bindgen.rs",
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap()
));

BindgenConfig::default()
.generate_bindings()
Expand Down
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub mod ffi {
// use vendored bindings (only available for `x86_64` arch)
#[cfg_attr(docsrs, doc(cfg(not(feature = "regenerate"))))]
#[cfg(all(not(feature = "regenerate"), target_arch = "x86_64"))]
include!("ffi/generated.rs");
include!("ffi/x86_64_bindgen.rs");
#[cfg_attr(docsrs, doc(cfg(not(feature = "regenerate"))))]
#[cfg(all(not(feature = "regenerate"), target_arch = "x86"))]
include!("ffi/i686_bindgen.rs");
#[cfg_attr(docsrs, doc(cfg(not(feature = "regenerate"))))]
#[cfg(all(not(feature = "regenerate"), target_arch = "aarch64"))]
include!("ffi/aarch64_bindgen.rs");

// use re-generated bindings
#[cfg_attr(docsrs, doc(cfg(feature = "regenerate")))]
Expand Down Expand Up @@ -73,13 +79,22 @@ pub mod ext {
out
}

#[inline]
#[cfg(target_arch = "aarch64")]
pub unsafe fn __readgsqword(offset: u32) -> usize {
0usize
}

#[inline]
pub unsafe fn NtCurrentTeb() -> *mut TEB {
const TEB_OFFSET: u32 = mem::offset_of!(NT_TIB, Self_) as u32;
if cfg!(target_arch = "x86_64") {
__readgsqword(TEB_OFFSET) as *mut TEB
} else if cfg!(target_arch = "x86") {
__readfsdword(TEB_OFFSET) as *mut TEB
} else if cfg!(target_arch = "aarch64") {
let p: *mut TEB = core::ptr::null();
p
} else {
unimplemented!("target architecture not implemented yet")
}
Expand Down

0 comments on commit b979063

Please sign in to comment.