diff --git a/Cargo.lock b/Cargo.lock index 567475c2..147cdd62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -397,12 +397,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "bytes" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9" - [[package]] name = "bzip2" version = "0.4.4" @@ -1212,18 +1206,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "enum_dispatch" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.98", -] - [[package]] name = "env_filter" version = "0.1.3" @@ -1355,20 +1337,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "fmmap" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6099ab52d5329340a3014f60ca91bc892181ae32e752360d07be9295924dcb0b" -dependencies = [ - "byteorder", - "bytes", - "enum_dispatch", - "fs4", - "memmapix", - "parse-display", -] - [[package]] name = "fnv" version = "1.0.7" @@ -1391,16 +1359,6 @@ dependencies = [ "num", ] -[[package]] -name = "fs4" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eeb4ed9e12f43b7fa0baae3f9cdda28352770132ef2e09a23760c29cae8bd47" -dependencies = [ - "rustix", - "windows-sys 0.48.0", -] - [[package]] name = "funty" version = "2.0.0" @@ -1479,7 +1437,7 @@ dependencies = [ "bstr", "log", "regex-automata", - "regex-syntax 0.8.5", + "regex-syntax", ] [[package]] @@ -1944,7 +1902,7 @@ dependencies = [ "lazy_static", "proc-macro2", "quote", - "regex-syntax 0.8.5", + "regex-syntax", "rustc_version", "syn 2.0.98", ] @@ -2040,12 +1998,12 @@ dependencies = [ ] [[package]] -name = "memmapix" -version = "0.7.6" +name = "memmap2" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f517ab414225d5f1755bd284d9545bd08a72a3958b3c6384d72e95de9cc1a1d3" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" dependencies = [ - "rustix", + "libc", ] [[package]] @@ -2375,32 +2333,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "parse-display" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6509d08722b53e8dafe97f2027b22ccbe3a5db83cb352931e9716b0aa44bc5c" -dependencies = [ - "once_cell", - "parse-display-derive", - "regex", -] - -[[package]] -name = "parse-display-derive" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68517892c8daf78da08c0db777fcc17e07f2f63ef70041718f8a7630ad84f341" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "regex", - "regex-syntax 0.7.5", - "structmeta", - "syn 2.0.98", -] - [[package]] name = "paste" version = "1.0.15" @@ -2958,7 +2890,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax 0.8.5", + "regex-syntax", ] [[package]] @@ -2969,15 +2901,9 @@ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.5", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - [[package]] name = "regex-syntax" version = "0.8.5" @@ -3410,29 +3336,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "structmeta" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d" -dependencies = [ - "proc-macro2", - "quote", - "structmeta-derive", - "syn 2.0.98", -] - -[[package]] -name = "structmeta-derive" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.98", -] - [[package]] name = "strum" version = "0.25.0" @@ -4649,7 +4552,6 @@ dependencies = [ "digest 0.10.7", "dsa", "ecdsa", - "fmmap", "globwalk", "goldenfile", "ihex", @@ -4664,6 +4566,7 @@ dependencies = [ "md-5", "md2", "memchr", + "memmap2", "memx", "nom 7.1.3", "num-derive 0.4.2", @@ -4678,7 +4581,7 @@ dependencies = [ "rayon", "regex", "regex-automata", - "regex-syntax 0.8.5", + "regex-syntax", "roxmltree", "rsa", "rustc-hash 2.1.1", diff --git a/Cargo.toml b/Cargo.toml index 503bf553..915677b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,6 @@ ecdsa = "0.16.9" enable-ansi-support = "0.2.1" env_logger = "0.11.6" figment = "0.10.19" -fmmap = "0.3.3" globwalk = "0.9.1" goldenfile = "1.8.0" home = "0.5.11" @@ -69,6 +68,7 @@ log = "0.4.25" magic = "0.16.2" md2 = "0.10.2" md-5 = "0.10.6" +memmap2 = "0.9.5" memchr = "2.7.4" memx = "0.1.32" nom = "7.1.3" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 8845bfe8..6151f412 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -219,7 +219,7 @@ der-parser = { workspace = true, optional = true, features = ["bigint"] } digest = { workspace = true, optional = true } dsa = { workspace = true, optional = true } ecdsa = { workspace = true, optional = true } -fmmap = { workspace = true } +memmap2 = { workspace = true } indexmap = { workspace = true, features = ["serde"] } intaglio = { workspace = true } itertools = { workspace = true } diff --git a/lib/src/scanner/mod.rs b/lib/src/scanner/mod.rs index a41759f4..88003341 100644 --- a/lib/src/scanner/mod.rs +++ b/lib/src/scanner/mod.rs @@ -18,8 +18,8 @@ use std::time::Duration; use std::{cmp, fs, thread}; use bitvec::prelude::*; -use fmmap::{MmapFile, MmapFileExt}; use indexmap::IndexMap; +use memmap2::{Mmap, MmapOptions}; use protobuf::{CodedInputStream, MessageDyn}; use rustc_hash::{FxHashMap, FxHashSet}; use thiserror::Error; @@ -68,7 +68,7 @@ pub enum ScanError { /// Path of the file being scanned. path: PathBuf, /// Error that occurred. - source: fmmap::error::Error, + source: std::io::Error, }, /// Could not deserialize the protobuf message for some YARA module. #[error("can not deserialize protobuf message for YARA module `{module}`: {err}")] @@ -97,7 +97,7 @@ static INIT_HEARTBEAT: Once = Once::new(); pub enum ScannedData<'a> { Slice(&'a [u8]), Vec(Vec), - Mmap(MmapFile), + Mmap(Mmap), } impl AsRef<[u8]> for ScannedData<'_> { @@ -105,7 +105,7 @@ impl AsRef<[u8]> for ScannedData<'_> { match self { ScannedData::Slice(s) => s, ScannedData::Vec(v) => v.as_ref(), - ScannedData::Mmap(m) => m.as_slice(), + ScannedData::Mmap(m) => m.as_ref(), } } } @@ -569,9 +569,14 @@ impl<'r> Scanner<'r> { })?; ScannedData::Vec(buffered_file) } else { - mapped_file = MmapFile::open(path).map_err(|err| { - ScanError::MapError { path: path.to_path_buf(), source: err } - })?; + mapped_file = unsafe { + MmapOptions::new().map(&file).map_err(|err| { + ScanError::MapError { + path: path.to_path_buf(), + source: err, + } + }) + }?; ScannedData::Mmap(mapped_file) };