#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
use std::ffi::CStr;
use std::ffi::OsStr;
use std::iter;
use std::mem;
use std::os::windows::ffi::OsStrExt;
use winapi::shared::{minwindef, ntdef};
use winapi::um::{libloaderapi, winnt};
use crate::prelude::*;
mod time;
#[allow(missing_docs)]
pub type SYSTEM_INFORMATION_CLASS = minwindef::DWORD;
#[allow(missing_docs)]
pub const SystemPerformanceInformation: SYSTEM_INFORMATION_CLASS = 2;
#[allow(missing_docs)]
pub const SystemProcessInformation: SYSTEM_INFORMATION_CLASS = 5;
#[allow(missing_docs)]
pub const SystemProcessorPerformanceInformation: SYSTEM_INFORMATION_CLASS = 8;
#[allow(missing_docs)]
pub const SystemInterruptInformation: SYSTEM_INFORMATION_CLASS = 23;
pub unsafe fn get_ntdll() -> Result<minwindef::HMODULE> {
let dll_wide: Vec<winnt::WCHAR> = OsStr::new("ntdll.dll")
.encode_wide()
.chain(iter::once(0))
.collect();
let module = libloaderapi::GetModuleHandleW(dll_wide.as_ptr());
if module.is_null() {
Err(Error::last_os_error())
} else {
Ok(module)
}
}
pub unsafe fn NtQuerySystemInformation(
SystemInformationClass: SYSTEM_INFORMATION_CLASS,
SystemInformation: ntdef::PVOID,
SystemInformationLength: minwindef::ULONG,
ReturnLength: minwindef::PULONG,
) -> Result<ntdef::NTSTATUS> {
let ntdll = get_ntdll()?;
let funcname = CStr::from_bytes_with_nul_unchecked(b"NtQuerySystemInformation\0");
let func = libloaderapi::GetProcAddress(ntdll, funcname.as_ptr());
if func.is_null() {
return Err(Error::last_os_error());
}
let func: extern "stdcall" fn(
SYSTEM_INFORMATION_CLASS,
ntdef::PVOID,
minwindef::ULONG,
minwindef::PULONG,
) -> ntdef::NTSTATUS = mem::transmute(func as *const ());
let result = func(
SystemInformationClass,
SystemInformation,
SystemInformationLength,
ReturnLength,
);
Ok(result)
}