rust_strings/lib.rs
1//! # Rust Strings
2//!
3//! `rust-strings` is a library to extract ascii strings from binary data.
4//! It is similar to the command `strings`.
5//!
6//! ## Examples:
7//! ```
8//! use rust_strings::{FileConfig, BytesConfig, strings, dump_strings, Encoding};
9//! use std::path::{Path, PathBuf};
10//!
11//! let config = FileConfig::new(Path::new("/bin/ls")).with_min_length(5);
12//! let extracted_strings = strings(&config);
13//!
14//! // Extract utf16le strings
15//! let config = FileConfig::new(Path::new("C:\\Windows\\notepad.exe"))
16//! .with_min_length(15)
17//! .with_encoding(Encoding::UTF16LE);
18//! let extracted_strings = strings(&config);
19//!
20//! // Extract ascii and utf16le strings
21//! let config = FileConfig::new(Path::new("C:\\Windows\\notepad.exe"))
22//! .with_min_length(15)
23//! .with_encoding(Encoding::ASCII)
24//! .with_encoding(Encoding::UTF16LE);
25//! let extracted_strings = strings(&config);
26//!
27//! let config = BytesConfig::new(b"test\x00".to_vec());
28//! let extracted_strings = strings(&config);
29//! assert_eq!(vec![(String::from("test"), 0)], extracted_strings.unwrap());
30//!
31//! // Dump strings into `strings.json` file.
32//! let config = BytesConfig::new(b"test\x00".to_vec());
33//! dump_strings(&config, PathBuf::from("strings.json"));
34//! ```
35
36use std::error::Error;
37
38mod encodings;
39mod strings;
40mod strings_extractor;
41mod strings_writer;
42
43type ErrorResult = Result<(), Box<dyn Error>>;
44
45pub use encodings::{Encoding, EncodingNotFoundError};
46pub use strings::{dump_strings, strings, BytesConfig, Config, FileConfig, StdinConfig};
47
48#[cfg(feature = "python_bindings")]
49mod python_bindings;