Skip to main content

Extract strings from binary data

Project description

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.

pip install rust-strings

Rust

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

[dependencies]
rust-strings = "0.6.0"

Usage

Python

import rust_strings

# Get all ascii strings from file with minimun length of string
rust_strings.strings(file_path="/bin/ls", min_length=3)
# [('ELF', 1),
#  ('/lib64/ld-linux-x86-64.so.2', 680),
#  ('GNU', 720),
#  ('.<O', 725),
#  ('GNU', 756),
# ...]

# You can also set buffer size when reading from file (default is 1mb)
rust_strings.strings(file_path="/bin/ls", min_length=5, buffer_size=1024)

# You can set encoding if you need (default is 'ascii', options are 'utf-16le', 'utf-16be')
rust_strings.strings(file_path=r"C:\Windows\notepad.exe", min_length=5, encodings=["utf-16le"])

# You can set multiple encoding
rust_strings.strings(file_path=r"C:\Windows\notepad.exe", min_length=5, encodings=["ascii", "utf-16le"])

# You can also pass bytes instead of file_path
rust_strings.strings(bytes=b"test\x00\x00", min_length=4, encodings=["ascii"])
# [("test", 0)]

# You can also dump to json file
rust_strings.dump_strings("strings.json", bytes=b"test\x00\x00", min_length=4, encodings=["ascii"])
# `strings.json` content:
# [["test", 0]]

Rust

Full documentation available in docs.rs

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"));

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

rust_strings-0.6.0-cp312-none-win_amd64.whl (137.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

rust_strings-0.6.0-cp312-none-win32.whl (132.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

rust_strings-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

rust_strings-0.6.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

rust_strings-0.6.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

rust_strings-0.6.0-cp312-cp312-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64

rust_strings-0.6.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

rust_strings-0.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

rust_strings-0.6.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

rust_strings-0.6.0-cp312-cp312-macosx_10_12_x86_64.whl (252.7 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

rust_strings-0.6.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (497.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

rust_strings-0.6.0-cp311-none-win_amd64.whl (137.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rust_strings-0.6.0-cp311-none-win32.whl (132.5 kB view hashes)

Uploaded CPython 3.11 Windows x86

rust_strings-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rust_strings-0.6.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

rust_strings-0.6.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

rust_strings-0.6.0-cp311-cp311-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64

rust_strings-0.6.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

rust_strings-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

rust_strings-0.6.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

rust_strings-0.6.0-cp311-cp311-macosx_10_12_x86_64.whl (253.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

rust_strings-0.6.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (499.2 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

rust_strings-0.6.0-cp310-none-win_amd64.whl (137.2 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rust_strings-0.6.0-cp310-none-win32.whl (132.5 kB view hashes)

Uploaded CPython 3.10 Windows x86

rust_strings-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rust_strings-0.6.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

rust_strings-0.6.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

rust_strings-0.6.0-cp310-cp310-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64

rust_strings-0.6.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

rust_strings-0.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

rust_strings-0.6.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

rust_strings-0.6.0-cp310-cp310-macosx_10_12_x86_64.whl (253.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

rust_strings-0.6.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (499.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

rust_strings-0.6.0-cp39-none-win_amd64.whl (137.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rust_strings-0.6.0-cp39-none-win32.whl (132.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

rust_strings-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rust_strings-0.6.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

rust_strings-0.6.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

rust_strings-0.6.0-cp39-cp39-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64

rust_strings-0.6.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

rust_strings-0.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

rust_strings-0.6.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

rust_strings-0.6.0-cp39-cp39-macosx_10_12_x86_64.whl (253.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

rust_strings-0.6.0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (499.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

rust_strings-0.6.0-cp38-none-win_amd64.whl (137.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rust_strings-0.6.0-cp38-none-win32.whl (132.6 kB view hashes)

Uploaded CPython 3.8 Windows x86

rust_strings-0.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

rust_strings-0.6.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

rust_strings-0.6.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

rust_strings-0.6.0-cp38-cp38-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64

rust_strings-0.6.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

rust_strings-0.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

rust_strings-0.6.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

rust_strings-0.6.0-cp38-cp38-macosx_10_12_x86_64.whl (252.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.12+ x86-64

rust_strings-0.6.0-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (498.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

rust_strings-0.6.0-cp37-none-win_amd64.whl (137.0 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

rust_strings-0.6.0-cp37-none-win32.whl (132.6 kB view hashes)

Uploaded CPython 3.7 Windows x86

rust_strings-0.6.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

rust_strings-0.6.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ s390x

rust_strings-0.6.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

rust_strings-0.6.0-cp37-cp37m-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64

rust_strings-0.6.0-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARMv7l

rust_strings-0.6.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

rust_strings-0.6.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

rust_strings-0.6.0-cp37-cp37m-macosx_10_12_x86_64.whl (252.9 kB view hashes)

Uploaded CPython 3.7m macOS 10.12+ x86-64

rust_strings-0.6.0-cp37-cp37m-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (498.3 kB view hashes)

Uploaded CPython 3.7m macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page