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

use std::error::Error;

mod encodings;
mod strings;
mod strings_extractor;
mod strings_writer;

type ErrorResult = Result<(), Box<dyn Error>>;

pub use encodings::{Encoding, EncodingNotFoundError};
pub use strings::{dump_strings, strings, BytesConfig, Config, FileConfig, StdinConfig};

#[cfg(feature = "python_bindings")]
mod python_bindings;