rust-strings

CI License Crates.io PyPI

rust-strings is a Rust library for extracting strings from binary data. \ It also have Python bindings.

Installation

Python

Use the package manager pip to install rust-strings.

bash pip install rust-strings

Rust

rust-strings is available on crates.io and can be included in your Cargo enabled project like this:

bash [dependencies] rust-strings = "0.1.0"

Usage

Python

```python import rust_strings

Get all ascii strings from file with minimun length of string

ruststrings.strings(filepath="/bin/ls", min_length=3)

[('ELF', 1),

('/lib64/ld-linux-x86-64.so.2', 680),

('GNU', 720),

('.

('GNU', 756),

...]

You can also set buffer size when reading from file (default is 1mb)

ruststrings.strings(filepath="/bin/ls", minlength=5, buffersize=1024)

You can set encoding if you need (default is 'ascii', options are 'utf-16le', 'utf-16be')

ruststrings.strings(filepath=r"C:\Windows\notepad.exe", min_length=5, encodings=["utf-16le"])

You can set multiple encoding

ruststrings.strings(filepath=r"C:\Windows\notepad.exe", min_length=5, encodings=["ascii", "utf-16le"])

You can also pass bytes instead of file_path

ruststrings.strings(bytes=b"test\x00\x00", minlength=4, encodings=["ascii"])

[("test", 0)]

You can also dump to json file

ruststrings.dumpstrings("strings.json", bytes=b"test\x00\x00", min_length=4, encodings=["ascii"])

strings.json content:

[["test", 0]]

```

Rust

Full documentation available in docs.rs

```rust use ruststrings::{FileConfig, BytesConfig, strings, dumpstrings, Encoding}; let config = FileConfig::new("/bin/ls").withminlength(5); let extracted_strings = strings(&config);

// Extract utf16le strings let config = FileConfig::new("C:\Windows\notepad.exe") .withminlength(15) .withencoding(Encoding::UTF16LE); let extractedstrings = strings(&config);

// Extract ascii and utf16le strings let config = FileConfig::new("C:\Windows\notepad.exe") .withminlength(15) .withencoding(Encoding::ASCII) .withencoding(Encoding::UTF16LE); let extracted_strings = strings(&config);

let config = BytesConfig::new(b"test\x00".tovec()); let extractedstrings = strings(&config); asserteq!(vec![(String::from("test"), 0)], extractedstrings.unwrap());

// Dump strings into strings.json file. let config = BytesConfig::new(b"test\x00".tovec()); dumpstrings(&config, PathBuf::from("strings.json")); ```

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT