From 0e09a5594204bb413708137bc8ec62b00c74a5c3 Mon Sep 17 00:00:00 2001 From: Gianni Tedesco Date: Sat, 8 Jan 2022 01:31:59 +0900 Subject: [PATCH] Split resynth app from library --- Cargo.toml | 21 ++++++++++++--- ezpkt/Cargo.toml | 4 +-- pkt/Cargo.toml | 2 +- src/{main.rs => cli.rs} | 57 ++--------------------------------------- src/lib.rs | 53 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 62 deletions(-) rename src/{main.rs => cli.rs} (69%) create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 6028dcc..6e92039 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2018" name = "resynth" -version = "0.1.2" +version = "0.1.3" description = "A packet synthesis language" authors = ["Gianni Tedesco "] license = "GPL-3.0-only" @@ -44,9 +44,22 @@ lto = true [dependencies] pkt = { path = "pkt", version = "0.1.1" } ezpkt = { path = "ezpkt", version = "0.1.1" } + lazy-regex = "2.2.2" regex = "1.5.4" phf = { version = "0.10.1", features = ["macros"] } -clap = "3.0.0" -atty = "0.2.14" -termcolor = "1.1.2" + +clap = {version = "3.0.0", optional = true} +atty = {version = "0.2.14", optional = true} +termcolor = {version = "1.1.2", optional = true} + +[[bin]] +name = "resynth" +path = "src/cli.rs" +required-features = ["cli"] + +[features] +default = [ + "cli", +] +cli = ["clap", "atty", "termcolor"] diff --git a/ezpkt/Cargo.toml b/ezpkt/Cargo.toml index b503a26..aeca0bc 100644 --- a/ezpkt/Cargo.toml +++ b/ezpkt/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2018" name = "ezpkt" -version = "0.1.2" +version = "0.1.3" description = "A packet construction library" authors = ["Gianni Tedesco "] license = "GPL-3.0-only" @@ -25,4 +25,4 @@ include = [ ] [dependencies] -pkt = { path = "../pkt", version = "0.1.2" } +pkt = { path = "../pkt", version = "0.1.3" } diff --git a/pkt/Cargo.toml b/pkt/Cargo.toml index 7bbbc15..42c4212 100644 --- a/pkt/Cargo.toml +++ b/pkt/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2018" name = "pkt" -version = "0.1.2" +version = "0.1.3" description = "A packet construction library" authors = ["Gianni Tedesco "] license = "GPL-3.0-only" diff --git a/src/main.rs b/src/cli.rs similarity index 69% rename from src/main.rs rename to src/cli.rs index 3a22a65..381d00d 100644 --- a/src/main.rs +++ b/src/cli.rs @@ -1,60 +1,7 @@ -//! # Resynth: A Packet Synthesis Language -//! -//! Resynth is a packet synthesis language. It produces network traffic (in the form of pcap files) -//! from textual descriptions of traffic. It enables version-controlled packets-as-code workflows -//! which can be useful for various packet processing, or security research applications such as -//! DPI engines, or network intrusion detection systems. -//! -//! ## Structure of the Codebase -//! The codebase is split in to several major components -//! - [pkt] A low-level packet generation library which mostly contains structs and consts -//! to do with various network protocols. -//! - [ezpkt] A more high-level packet generation library which provides abstractions around -//! concepts such as flows -//! - [crate] The language compiler and interpreter itself is the root of the crate. In future we -//! will probably move in to its own module at some point in future. -//! - [crate::stdlib] Contains the resynth standard library which is mostly glue to allow resynth -//! programs to use the functionality in [pkt] and [ezpkt] -//! -//! ## Compiler Phases -//! 1. [crate::process_file()] is the basic wrapper function which handles all phases of the -//! compiler -//! 2. [Lexer] uses a static regex to parse each line in to a stream of tokens -//! 3. [Parser] is a hand-written LR-parser which takes a token at a time and whenever a complete -//! [statement](Stmt) is encountered, the [statement](Stmt) is pushed in to a -//! [results vector](Parser::get_results) which can later be [retreived](Parser::get_results) -//! 4. [Program] maintains the execution state of any given program. It takes one statement at a -//! time, and updates the program state based on that. If the program has a [pkt::PcapWriter] -//! attached to it, then any generated packets will be written in to the corresponding pcap file -//! as they are generated. - -#[macro_use] -mod macros; -mod err; -mod lex; -mod parse; -mod program; -mod val; -mod libapi; -mod str; -mod object; -mod args; -mod sym; -mod traits; -mod loc; - -pub mod stdlib; - -#[cfg(test)] -mod test; - use pkt::PcapWriter; -pub use err::Error; -pub use loc::Loc; -pub use lex::{Lexer, EOF, Token}; -pub use parse::{Parser, Stmt}; -pub use program::Program; +use resynth::{Error, Loc, Lexer, EOF, Parser, Program}; +use resynth::{warn, error, ok}; use std::path::{Path, PathBuf}; use std::fs; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ae2bc0c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,53 @@ +//! # Resynth: A Packet Synthesis Language +//! +//! Resynth is a packet synthesis language. It produces network traffic (in the form of pcap files) +//! from textual descriptions of traffic. It enables version-controlled packets-as-code workflows +//! which can be useful for various packet processing, or security research applications such as +//! DPI engines, or network intrusion detection systems. +//! +//! ## Structure of the Codebase +//! The codebase is split in to several major components +//! - [pkt] A low-level packet generation library which mostly contains structs and consts +//! to do with various network protocols. +//! - [ezpkt] A more high-level packet generation library which provides abstractions around +//! concepts such as flows +//! - [crate] The language compiler and interpreter itself is the root of the crate. In future we +//! will probably move in to its own module at some point in future. +//! - [crate::stdlib] Contains the resynth standard library which is mostly glue to allow resynth +//! programs to use the functionality in [pkt] and [ezpkt] +//! +//! ## Compiler Phases +//! 1. [Lexer] uses a static regex to parse each line in to a stream of tokens +//! 2. [Parser] is a hand-written LR-parser which takes a token at a time and whenever a complete +//! [statement](Stmt) is encountered, the [statement](Stmt) is pushed in to a +//! [results vector](Parser::get_results) which can later be [retreived](Parser::get_results) +//! 3. [Program] maintains the execution state of any given program. It takes one statement at a +//! time, and updates the program state based on that. If the program has a [pkt::PcapWriter] +//! attached to it, then any generated packets will be written in to the corresponding pcap file +//! as they are generated. + +#[macro_use] +mod macros; +mod err; +mod lex; +mod parse; +mod program; +mod val; +mod libapi; +mod str; +mod object; +mod args; +mod sym; +mod traits; +mod loc; + +pub mod stdlib; + +#[cfg(test)] +mod test; + +pub use err::Error; +pub use loc::Loc; +pub use lex::{Lexer, EOF, Token}; +pub use parse::{Parser, Stmt}; +pub use program::Program;