Expand description
ratdmp – a standalone crate (open source, dual-licensed
MIT/Apache-2.0). Depends on serde (so ExtractedString can be
serialized – the caller decides how to wrap it in JSON/its own protocol
if needed, this crate only returns a plain Vec<ExtractedString>) and
rayon, used only by the opt-in parallel scanning path
(extract_strings_from_file_parallel) – the default sequential/
streaming path does not touch it.
Pulls printable ASCII / UTF-16LE strings out of a raw .dmp memory-dump
file (or any other binary file). Pure post-processing over an
already-existing file on disk (no WinAPI / process-permission
involved) – scans the buffer sequentially, grouping contiguous runs of
printable bytes (ASCII) and UTF-16LE runs (printable low byte, high byte
== 0x00), the same principle as the Unix strings command. It does NOT
parse the MDMP file format’s internal structure – scanning the whole
payload is the only approach that doesn’t depend on the Windows/DbgHelp
version that produced the dump.
Two things keep this fast and memory-safe on multi-gigabyte files:
- Chunked streaming (
CHUNK_SIZE= 32MB per read) viaRead, carrying exactly 1 trailing byte over to the next chunk so a UTF-16LE pair straddling an I/O boundary is always tested correctly – the whole file (which can be several GB) is NEVER loaded into RAM at once. - ASCII and UTF-16LE are detected SIMULTANEOUSLY in a single pass
(
StringRunScanner::feed) instead of two independent loops – fewer passes over the buffer.
SPEED OPTIMIZATIONS (results unchanged, speed only): (1) a precomputed
256-entry PRINTABLE_TABLE lookup table built at compile time instead
of a range-match per byte; (2) each byte is looked up in the printable
table EXACTLY ONCE (the ascii branch and the utf16 branch, when that
byte acts as the “lo” byte, share the same lookup); (3) fast-skip jumps
straight over an entire run of consecutive non-printable bytes when no
run is currently open (skipping the lookahead/aligned computation and
the no-op flush() calls for each junk byte entirely) – non-printable
binary regions typically make up the bulk of a real RAM dump, so this
is the hottest path.
Noise filtering (higher filter accuracy than a naive strings-style
scan, same ASCII/UTF-16LE run-grouping logic): a naive scan accepts ANY
run meeting min_len as a valid “string”, including a run of a single
repeated character (AAAAAAAA...) or two characters alternating
(ABABABAB...) – an extremely common kind of noise in real RAM dumps
(byte-fill/heap-fill patterns on alloc/free, alignment padding, repeated
memset), which almost never carries useful information and needlessly
bloats the result. is_low_information_repeat() filters exactly those
two simple repeat shapes (period 1 and period 2, only triggered from a
long-enough threshold so it doesn’t accidentally drop short real
strings like “0000”/“====” which can still be real data) – it does NOT
filter more broadly (no entropy/complex statistics) to avoid false
negatives (missing real strings), staying true to the “only filter
what’s certainly noise” spirit.
Structs§
- Entropy
Region - A fixed file region whose byte distribution has high Shannon entropy.
- Extracted
String - Noise
Config - Runtime-configurable noise-filter thresholds (see
is_low_information_repeat). Previously these were the hardcoded constantsNOISE_REPEAT1_MIN_LEN/NOISE_REPEAT2_MIN_LEN– now callers (including the CLI’s--noise-threshold <N>) can tune or fully disable the filter. - Yara
Match - A YARA rule that matched while a dump was being streamed.
Constants§
- ENTROPY_
BLOCK_ SIZE - Fixed window used by the entropy pass. Keeping this separate from the string-scan chunk makes entropy results comparable across files.
- MAX_
STRINGS - Default
max_strings(see MIN_STRING_LEN above). - MIN_
STRING_ LEN - Default
min_lenwhen the caller doesn’t pass one – a reasonable baseline for theextract_strings*functions below when the caller wants a sensible default instead of picking their own.
Functions§
- extract_
strings - Returns a list of
ExtractedString, sorted by ascending offset, from a byte slice ALREADY in RAM.max_stringsis an upper bound to avoid unbounded growth of memory / the JSON returned to the UI. - extract_
strings_ from_ file - Extracts strings from a
.dmpfile, in chunks – does NOT read the whole file into RAM. - extract_
strings_ from_ file_ parallel - Same as
extract_strings_from_file, but scans the file in parallel across multiple OS threads viarayon’s work-stealing thread pool instead of a single sequential pass. Best on multi-core machines with fast storage / a warm page cache, where the CPU-bound scan (not disk I/O) is the bottleneck. Peak memory is bounded bynum_active_threads * (PARALLEL_CHUNK_SIZE + MAX_RUN_CHARS), not by the file size. Userayon::ThreadPoolBuilder::num_threads(or theRAYON_NUM_THREADSenv var) to control the degree of parallelism; by default rayon uses one thread per logical CPU. - extract_
strings_ from_ file_ streaming - File-based streaming variant of
extract_strings_from_reader_streaming. - extract_
strings_ from_ file_ with_ noise_ config - Same as
extract_strings_from_file, but with a configurable noise filter (seeNoiseConfig) instead of the hardcoded defaults. - extract_
strings_ from_ reader - Extracts strings directly from a
Read, in chunks – NEVER loads more thanCHUNK_SIZEbytes into RAM at once, suitable for multi-GB dump files. Carries exactly 1 trailing byte from each chunk into the next so a UTF-16LE pair straddling an I/O boundary is always tested correctly. - extract_
strings_ from_ reader_ streaming - Streams extracted strings to
on_foundwhile scanning a reader. - extract_
strings_ from_ reader_ with_ noise_ config - Same as
extract_strings_from_reader, but with a configurable noise filter (seeNoiseConfig) instead of the hardcoded defaults. - extract_
strings_ with_ noise_ config - Same as
extract_strings, but with a configurable noise filter (seeNoiseConfig) instead of the hardcoded defaults. - scan_
entropy_ from_ file_ streaming - Streams high-entropy fixed-size regions from a file.
- scan_
entropy_ from_ file_ streaming_ with_ data - Like
scan_entropy_from_file_streaming, but also provides each matching block’s bytes to the callback before the scan buffer is reused. - scan_
yara_ from_ file_ streaming - File-based convenience wrapper for
scan_yara_from_reader_streaming. - scan_
yara_ from_ reader_ streaming - Compiles YARA source and scans a reader in bounded chunks.
- shannon_
entropy - Computes Shannon entropy in bits per byte for a byte slice.