dos
⚠️ This project is a work in progress.
Rust-friendly bindings for Windows APIs. It is not meant to be exhaustive, only cover areas that the standard library does not.
Quick start
Add this to your Cargo.toml: cargo add dos
Features
full- Enable all featuresnet- Networkingprocess- Process and module enumerationstring- String conversion utilitiessecurity- Security and access controlsys- System information
Guiding principles
In descending order of importance:
- Safety.
unsafemust be avoided as much as possible, particularly in public APIs. - Lightweight. Everything is feature-gated, especially dependencies.
- Zero cost. Except when it can be justified, we try to avoid needlessly copying data or performing unnecessary operations.
- Escape hatch. If higher level bindings miss anything, it should be possible to use the raw bindings.
- Minimalism. APIs should if possible resemble one-to-one mappings to the underlying Windows
APIs, but with different naming conventions. This improves searchability. For example, the
underlying
GetUnicastIpAddressTableAPI is calledget_unicast_ip_address_table.
Examples
List processes
List all running processes in the system:
use ;
let snapshot = create_toolhelp32_snapshot?;
for process in snapshot.processes.take
Networking
Get all unicast IP addresses on the system:
use get_unicast_ip_address_table;
for address in get_unicast_ip_address_table?
Get the alias of a network interface using its LUID:
use convert_interface_luid_to_alias;
let my_luid = 1234;
let alias = convert_interface_luid_to_alias?;
Security
Get a security descriptor for a file:
use ;
use File;
let file = open?;
let security_info = get_security_info?;
if let Some = security_info.owner
if let Some = security_info.group
Strings
Convert from various code pages to Rust strings:
use ;
// Convert UTF-8 encoded C string to an OsString
let c_str = c"Hello, World!";
let os_string = multi_byte_to_wide_char?;
println!;
// Convert from Windows-1252 (Western European)
let c_str = c"Caf\xe9"; // "Café" in Windows-1252
let os_string = multi_byte_to_wide_char?;
println!;
Platform support
This crate is tested on Windows 10 or later. It may work on earlier Windows versions, but there is no guarantee of that.
Contributing
Contributions are welcome! Please open an issue or a pull request.
License: MIT