diff --git a/Cargo.toml b/Cargo.toml index 95cd91e0..f200db71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "boreal-parser", "boreal", diff --git a/boreal-cli/tests/cli.rs b/boreal-cli/tests/cli.rs index 8289b9b3..9b36a39f 100644 --- a/boreal-cli/tests/cli.rs +++ b/boreal-cli/tests/cli.rs @@ -579,7 +579,7 @@ rule a { .assert() .stdout( predicate::str::is_match( - r#"Evaluation \{ + r"Evaluation \{ no_scan_eval_duration: .*, ac_duration: .*, ac_confirm_duration: .*, @@ -587,7 +587,7 @@ rule a { rules_eval_duration: .*, raw_regexes_eval_duration: .*, \} -"#, +", ) .unwrap(), ) diff --git a/boreal-parser/src/regex.rs b/boreal-parser/src/regex.rs index 6d1865b5..6dd82021 100644 --- a/boreal-parser/src/regex.rs +++ b/boreal-parser/src/regex.rs @@ -624,7 +624,7 @@ mod tests { ); parse( regex, - r#"/a\/b\cd/isb"#, + r"/a\/b\cd/isb", "b", Regex { ast: Node::Concat(vec![ diff --git a/boreal/src/evaluator/mod.rs b/boreal/src/evaluator/mod.rs index c0f3be26..4f2692da 100644 --- a/boreal/src/evaluator/mod.rs +++ b/boreal/src/evaluator/mod.rs @@ -329,7 +329,9 @@ impl Evaluator<'_, '_, '_, '_, '_> { } match expr { - Expression::Filesize => Ok(Value::Integer(self.mem.len() as i64)), + Expression::Filesize => Ok(Value::Integer( + self.mem.len().try_into().unwrap_or(i64::MAX), + )), #[cfg(feature = "object")] Expression::Entrypoint => { @@ -372,7 +374,8 @@ impl Evaluator<'_, '_, '_, '_, '_> { Ok(v) if v != 0 => { let var = get_var!(self, *variable_index); var.find_match_occurence(self.scan_data, v - 1) - .map(|mat| Value::Integer(mat.start as i64)) + .and_then(|mat| i64::try_from(mat.start).ok()) + .map(Value::Integer) .ok_or(PoisonKind::Undefined) } Ok(_) | Err(_) => Err(PoisonKind::Undefined), @@ -388,7 +391,8 @@ impl Evaluator<'_, '_, '_, '_, '_> { Ok(v) if v != 0 => { let var = get_var!(self, *variable_index); var.find_match_occurence(self.scan_data, v - 1) - .map(|mat| Value::Integer(mat.len() as i64)) + .and_then(|mat| i64::try_from(mat.len()).ok()) + .map(Value::Integer) .ok_or(PoisonKind::Undefined) } Ok(_) | Err(_) => Err(PoisonKind::Undefined), diff --git a/boreal/src/module/macho.rs b/boreal/src/module/macho.rs index b5bdc45e..225db1e3 100644 --- a/boreal/src/module/macho.rs +++ b/boreal/src/module/macho.rs @@ -722,7 +722,7 @@ impl MachO { continue; } } - return Some(Value::Integer(i as i64)); + return Some(i.into()); } None } diff --git a/boreal/src/module/pe.rs b/boreal/src/module/pe.rs index 9d3a1058..ac6d23c3 100644 --- a/boreal/src/module/pe.rs +++ b/boreal/src/module/pe.rs @@ -46,6 +46,7 @@ impl Module for Pe { } fn get_static_values(&self) -> HashMap<&'static str, StaticValue> { + #[allow(clippy::cast_possible_wrap)] [ ( "MACHINE_UNKNOWN", @@ -1303,10 +1304,7 @@ impl Pe { if let Some((signatures, is_signed)) = signatures::get_signatures(&data_dirs, mem, token) { - let _r = map.insert( - "number_of_signatures", - Value::Integer(signatures.len() as _), - ); + let _r = map.insert("number_of_signatures", signatures.len().into()); let _r = map.insert("is_signed", Value::Integer(is_signed.into())); let _r = map.insert("signatures", Value::Array(signatures)); } else { @@ -1864,7 +1862,7 @@ pub fn add_version_infos(mem: &[u8], offset: u32, out: &mut HashMap<&'static str }; out.extend([ - ("number_of_version_infos", (infos.len() as i64).into()), + ("number_of_version_infos", infos.len().into()), ( "version_info", Value::Dictionary( diff --git a/boreal/src/scanner/mod.rs b/boreal/src/scanner/mod.rs index f4b357d0..2f0cd97f 100644 --- a/boreal/src/scanner/mod.rs +++ b/boreal/src/scanner/mod.rs @@ -312,7 +312,7 @@ impl Inner { let mut var_evals_iterator = self .variables .iter() - .zip(ac_matches.into_iter()) + .zip(ac_matches) .map(|(var, ac_result)| VariableEvaluation::new(var, eval_params, ac_result)); for (rule, is_global) in self diff --git a/boreal/tests/it/full.rs b/boreal/tests/it/full.rs index ec3ab120..1ba246ce 100644 --- a/boreal/tests/it/full.rs +++ b/boreal/tests/it/full.rs @@ -37,7 +37,7 @@ rule b { ); compiler.add_rules_in_namespace( - r#" + r" rule c { strings: $rgx = /\s_\w+\d{,2}/ @@ -47,7 +47,7 @@ rule c { condition: any of them } - "#, + ", "2nd namespace", ); diff --git a/boreal/tests/it/regex.rs b/boreal/tests/it/regex.rs index 3f33f51f..33f18d18 100644 --- a/boreal/tests/it/regex.rs +++ b/boreal/tests/it/regex.rs @@ -43,7 +43,7 @@ rule a { ); // escaped unicode char is accepted. - let checker = Checker::new(r#"rule a { strings: $a = /\µ/ condition: $a }"#); + let checker = Checker::new(r"rule a { strings: $a = /\µ/ condition: $a }"); checker.check("µ".as_bytes(), true); } diff --git a/boreal/tests/it/variables.rs b/boreal/tests/it/variables.rs index 8e8a1e43..0154a070 100644 --- a/boreal/tests/it/variables.rs +++ b/boreal/tests/it/variables.rs @@ -53,7 +53,7 @@ fn test_variable_err() { fn test_variable_regex_modifiers() { // \x76 is 'v' let checker = Checker::new( - r#" + r" rule a { strings: $a = /f[aF]T[d-g]\x76/ nocase @@ -62,7 +62,7 @@ rule a { $d = /.{,2}quu/ nocase fullword condition: any of them -}"#, +}", ); // Nocase: work on literals, ranges, and explicit hexa char @@ -215,7 +215,7 @@ fn test_variable_regex_wide() { checker.check(b"<\x00a\x009\x00d\x00>\x00", false); checker.check(b"a\x009\x00", false); - let checker = build_checker(r#"\d[^abc]d$"#, "wide"); + let checker = build_checker(r"\d[^abc]d$", "wide"); checker.check(b"13d", false); checker.check(b"1\x003\x00d\x00", true); checker.check(b"1\x003\x00d", false); @@ -592,13 +592,13 @@ rule a {{ fn test_variable_boundary_ac_confirm() { // Make sure the boundary is taken into account when confirming an ac match. let checker = Checker::new( - r#" + r" rule a { strings: $a = /\Wabcd\W/ condition: $a -}"#, +}", ); checker.check(b"aabcde", false);