Coder Social home page Coder Social logo

windivert-rust's Introduction

Hi there, I'm Rubén

  • 🌱 I’m currently studying Software Engineerig degree in Universidad of Extremadura (Spain)
  • 🦀 In love with rust-lang

windivert-rust's People

Contributors

rubensei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

windivert-rust's Issues

Logic Errors in `ChecksumFlags`

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:

/// Sets `no_icmp` flag
pub fn set_no_icmp(mut self) -> Self {
self.0 &= 0x0002;
self
}
/// Unsets `no_icmp` flag
pub fn unset_no_icmp(mut self) -> Self {
self.0 ^= 0xFFFD;
self
}
/// Sets `no_icmpv6` flag
pub fn set_no_icmpv6(mut self) -> Self {
self.0 &= 0x0004;
self
}
/// Unsets `no_icmpv6` flag
pub fn unset_no_icmpv6(mut self) -> Self {
self.0 ^= 0xFFFB;
self
}
/// Sets `no_tcp` flag
pub fn set_no_tcp(mut self) -> Self {
self.0 &= 0x0008;
self
}
/// Unsets `no_tcp` flag
pub fn unset_no_tcp(mut self) -> Self {
self.0 ^= 0xFFF7;
self
}
/// Sets `no_udp` flag
pub fn set_no_udp(mut self) -> Self {
self.0 &= 0x0010;
self
}
/// Unsets `no_udp` flag
pub fn unset_no_udp(mut self) -> Self {
self.0 ^= 0xFFEF;
self
}

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. :)

Fix wrong rustdoc links

In the sys crate there are some links not pointing to the proper section of the official documentation

For example:

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_ipv6_address)
pub fn WinDivertHelperFormatIPv4Address(
addr: u32,
buffer: *mut ::std::os::raw::c_char,
bufLen: u32,
) -> BOOL;
/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_ipv6_address)
pub fn WinDivertHelperFormatIPv6Address(
pAddr: *const u32,
buffer: *mut ::std::os::raw::c_char,
bufLen: u32,
) -> BOOL;

public address data struct and set function

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?

Statically linking to binary?

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.

Unrelated:

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(())
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.