Skip to content

Commit

Permalink
chore: replace fmmap with memmap2.
Browse files Browse the repository at this point in the history
`fmmap` stopped to build with nightly Rust and seems to be unmaintained.
  • Loading branch information
plusvic committed Feb 20, 2025
1 parent 4be3451 commit b4b7247
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 116 deletions.
117 changes: 10 additions & 107 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
19 changes: 12 additions & 7 deletions lib/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}")]
Expand Down Expand Up @@ -97,15 +97,15 @@ static INIT_HEARTBEAT: Once = Once::new();
pub enum ScannedData<'a> {
Slice(&'a [u8]),
Vec(Vec<u8>),
Mmap(MmapFile),
Mmap(Mmap),
}

impl AsRef<[u8]> for ScannedData<'_> {
fn as_ref(&self) -> &[u8] {
match self {
ScannedData::Slice(s) => s,
ScannedData::Vec(v) => v.as_ref(),
ScannedData::Mmap(m) => m.as_slice(),
ScannedData::Mmap(m) => m.as_ref(),
}
}
}
Expand Down Expand Up @@ -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)
};

Expand Down

0 comments on commit b4b7247

Please sign in to comment.