Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert byte_extract keyword parser to Rust #11380

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
451 changes: 451 additions & 0 deletions rust/src/detect/byte_extract.rs

Large diffs are not rendered by default.

420 changes: 171 additions & 249 deletions rust/src/detect/byte_math.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions rust/src/detect/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum RuleParseError<I> {
InvalidByteMath(String),
InvalidIPRep(String),
InvalidTransformBase64(String),
InvalidByteExtract(String),

Nom(I, ErrorKind),
}
Expand Down
41 changes: 40 additions & 1 deletion rust/src/detect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

//! Module for rule parsing.

pub mod byte_extract;
pub mod byte_math;
pub mod error;
pub mod iprep;
pub mod parser;
pub mod requires;
pub mod stream_size;
pub mod transform_base64;
pub mod uint;
pub mod uri;
pub mod requires;
pub mod tojson;

use crate::core::AppProto;
Expand Down Expand Up @@ -104,6 +105,44 @@ extern {
de: *mut c_void, s: *mut c_void, kwid: c_int, ctx: *const c_void, bufid: c_int,
) -> *mut c_void;
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
// endian <big|little|dce>
pub enum ByteEndian {
BigEndian = 1,
LittleEndian = 2,
EndianDCE = 3,
}

#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ByteBase {
BaseOct = 8,
BaseDec = 10,
BaseHex = 16,
}

fn get_string_value(value: &str) -> Option<ByteBase> {
let res = match value {
"hex" => Some(ByteBase::BaseHex),
"oct" => Some(ByteBase::BaseOct),
"dec" => Some(ByteBase::BaseDec),
_ => None,
};

res
}

fn get_endian_value(value: &str) -> Option<ByteEndian> {
let res = match value {
"big" => Some(ByteEndian::BigEndian),
"little" => Some(ByteEndian::LittleEndian),
"dce" => Some(ByteEndian::EndianDCE),
_ => None,
};

res
}

#[cfg(test)]
mod test {
Expand Down
Loading
Loading