rubensei / windivert-rust Goto Github PK
View Code? Open in Web Editor NEWRust bindings and wrapper around WinDivert user library
License: GNU Lesser General Public License v3.0
Rust bindings and wrapper around WinDivert user library
License: GNU Lesser General Public License v3.0
First off, thank you for the fantastic project! We're currently looking at building mitmproxy's Windows support with this, and it has been pretty awesome so far. 🍰
One thing I noticed in passing today is that the ChecksumFlags
implementation looks wrong:
windivert-rust/windivert-sys/src/bindings/newtypes.rs
Lines 396 to 442 in df70e96
set_no_icmp
should probably use |=
, unset_no_icmp should probably use &=
, etc? Maybe it would be even nicer to have a .set_icmp(bool)
API instead of set/unset methods. :)
Passing None to [WinDivertRecv](https://reqrypt.org/windivert-doc.html#divert_recv) gives me an immediate InsufficientBuffer error.
Originally posted by @AriFordsham in #5 (comment)
Is there a way to statically link to my binary so I don't need the WinDivert.dll with it? I don't understand the build system and linking, it's possible to statically link WinDivert here and here
EDIT: The vendored
feature should be enabled by default to make the library buildable and usable by default and reduce required intervention and setup by default, the alternative already requires many additional steps to download, extract, compile, and set an environment variable anyway, optionally disabling default features (vendored) is not a concern, you could also leave the logic the same which would allow providing WINDIVERT_PATH
even while vendored is still enabled, not requiring the user to disable or enable features at all.
Copying the built WinDivert.dll
to the binary directory relative to OUT_DIR
(up a few parent directories) by default would make binaries usable by default (in addition to the above change) without any additional intervention (setting an arbitrary WINDIVERT_PATH
environment variable).
EDIT2: Maybe a guard to uninstall the driver on drop/crash would be a good improvement.
I created a build.rs
for anyone that wants to use the officially built and signed binaries easier
use std::{fs::File, path::Path};
use anyhow::Result;
use zip::ZipArchive;
fn main() -> Result<()> {
let out_dir = std::env::var("OUT_DIR")?;
let out_dir_path = Path::new(&out_dir);
let zip_name = "WinDivert-2.2.2-A.zip";
let zip_path = out_dir_path.join(zip_name);
if !zip_path.exists() {
let base_url = "https://reqrypt.org/download";
let file_url = format!("{base_url}/{zip_name}");
let mut response = reqwest::blocking::get(file_url)?;
let mut zip_file = File::create(&zip_path)?;
std::io::copy(&mut response, &mut zip_file)?;
}
let zip_file = File::open(&zip_path)?;
let mut zip_archive = ZipArchive::new(zip_file)?;
zip_archive.extract(out_dir_path)?;
let partial_file_names = [
"x64/WinDivert.dll",
"x64/WinDivert.lib",
"x64/WinDivert32.sys",
"x64/WinDivert64.sys",
"x64/windivertctl.exe", // Good for debugging
];
let full_file_names = zip_archive
.file_names()
.filter(|full_file_name| {
partial_file_names
.iter()
.any(|partial_file_name| full_file_name.ends_with(partial_file_name))
})
.collect::<Vec<_>>();
for fill_file_name in full_file_names {
let full_file_path = out_dir_path.join(fill_file_name);
let Some(partial_file_name) = fill_file_name.split('/').last() else {
continue
};
let Ok(mut old_file) = File::open(full_file_path) else {
continue
};
let Ok(mut new_file) = File::create(format!("{out_dir}/../../../{partial_file_name}")) else {
continue
};
if std::io::copy(&mut old_file, &mut new_file).is_err() {
println!("cargo:warning={old_file:?} -> {new_file:?} failed to copy")
}
}
Ok(())
}
In the sys crate there are some links not pointing to the proper section of the official documentation
For example:
windivert-rust/windivert-sys/src/bindings/mod.rs
Lines 150 to 162 in df70e96
> This error can be ignored if the application only intends to receive part of the packet, e.g., the IP headers only.
Originally posted by @AriFordsham in #5 (comment)
I want to transmit a custom “WinDiverPacket” which is private. How can I turn it into public?
use windivert::address::WinDivertNetworkData; // Module `address` is private
use windivert::WinDivertNetworkData; // no `WinDivertNetworkData` in the root
let addr = WinDivertNetworkData::default();
// addr.set_event(...);
// ...
network_layer.send(WinDivertPacket::Network {
addr: addr,
data: buff, // my data
})
I don't know if I miss something, who can help?
Thank you for this package!
Why is it neccessary for the recv(_ex)
functions to be supplied with a buffer? Why can't the library allocate this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.