wirefilter

An execution engine for Wireshark-like filters

Github星跟蹤圖

Wirefilter

Build status
Crates.io
License

This is an execution engine for Wireshark®-like filters.

It contains public APIs for parsing filter syntax, compiling them into
an executable IR and, finally, executing filters against provided values.

Example

use wirefilter::{ExecutionContext, Scheme, Type};

fn main() -> Result<(), failure::Error> {
    // Create a map of possible filter fields.
    let scheme = Scheme! {
        http.method: Bytes,
        http.ua: Bytes,
        port: Int,
    };

    // Parse a Wireshark-like expression into an AST.
    let ast = scheme.parse(r#"
        http.method != "POST" &&
        not http.ua matches "(googlebot, facebook)" &&
        port in {80 443}
    "#)?;

    println!("Parsed filter representation: {:?}", ast);

    // Compile the AST into an executable filter.
    let filter = ast.compile();

    // Set runtime field values to test the filter against.
    let mut ctx = ExecutionContext::new(&scheme);

    ctx.set_field_value("http.method", "GET")?;

    ctx.set_field_value(
        "http.ua",
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
    )?;

    ctx.set_field_value("port", 443)?;

    // Execute the filter with given runtime values.
    println!("Filter matches: {:?}", filter.execute(&ctx)?); // true

    // Amend one of the runtime values and execute the filter again.
    ctx.set_field_value("port", 8080)?;

    println!("Filter matches: {:?}", filter.execute(&ctx)?); // false

    Ok(())
}

Licensing

Licensed under the MIT license. See the LICENSE file for details.

主要指標

概覽
名稱與所有者cloudflare/wirefilter
主編程語言Rust
編程語言Shell (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2019-02-18 17:40:37
推送於2025-05-08 17:24:34
最后一次提交2025-04-16 10:42:35
發布數3
最新版本名稱v0.7.0 (發布於 )
第一版名稱v0.6.0 (發布於 )
用户参与
星數1k
關注者數23
派生數98
提交數440
已啟用問題?
問題數22
打開的問題數7
拉請求數84
打開的拉請求數3
關閉的拉請求數22
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?