Block consensus engine
The three heap methods share one engine for everything that does not depend on how the heap blocks were found. Given, for each of N dumps, a list of heap blocks, it pairs the blocks across the dumps, builds the reduced heap consensus matrix from the paired blocks, gives every block of one reference dump a verdict, and translates the kept blocks back to offsets the reference dump’s brute force can read. The allocator-specific part is only the extractor that produces the block lists and the format of their signatures (see Windows heaps, Android Scudo and Go heap).
From N dumps to brute-force candidates: the yellow steps are allocator-specific, the plain steps are the shared engine, the heavily outlined ones are its output.
The engine lives in three modules: memdiver.engine.heap_block_consensus
(pairing and the matrix), memdiver.engine.heap_block_verdicts (verdicts) and
memdiver.app.heap_block_reduce (input checks and the translation into
candidates.json regions). The Scudo and Windows methods run the whole chain.
The Go method pairs most slots itself (by span, then by anchor label) and
calls the engine’s pairing only for the slots left over; it then uses the
shared verdicts and translation, see Go heap.
Inputs
Blocks. A block is anything with three attributes:
attribute |
meaning |
|---|---|
|
the allocator signature, a string naming what kind of block it is, not where it is |
|
the virtual address of the block’s user bytes in its dump |
|
the block’s user bytes |
The engine is duck-typed: it never looks at allocator structures. Every
signature format in MemDiver encodes the user length (scudo:c<class>:o<origin>:s<size>,
win:<heap kind>:<heap role>:<component>:<bucket>:s<user length>,
go:sc<spanclass>:s<size>), so blocks that share a signature have the same
length.
Pointer ranges. For each dump, pointer_ranges(reader) collects the
mapped address ranges the pointer mask tests against: every entry of the
dump’s VAS map, readable or not (a pointer may point into a PROT_NONE
reserve), or, when the dump has no VAS map, its stored memory regions. The
source is recorded as mask_source vas or regions.
Input checks (validate_block_dumps, before any heap is read): at least 2
dumps (<prefix>.too_few_dumps); every dump a file (dump_not_found) and a
native .msl (not_msl; imported minidumps and ELF cores are .msl too);
no dump named twice (duplicate_dumps: a dump compared with itself would make
its own per-run values look shared); the reference one of the dumps
(reference_not_in_dumps); positive key_sizes (invalid_key_sizes); and one
cohort unless mixed_ok is set. The prefix is scudo, winheap or goheap.
Step 1: pair by signature (align_blocks)
Count each signature in each dump. Every signature falls into exactly one class:
class |
rule |
what happens |
|---|---|---|
unique |
exactly once in every dump |
paired at once: one row of N blocks |
ambiguous |
in every dump, more than once in at least one |
passed to step 2 |
missing |
absent from at least one dump |
never compared |
A unique signature whose block in the first dump has no user bytes is not
laid out; it is reported as empty.
Step 2: pair duplicates by masked content (content_align)
A signature that occurs several times per dump cannot be paired by name: the reader cannot tell which copy in dump 0 belongs to which copy in dump 1. Step 2 splits each ambiguous signature by block content, with pointers masked out, because a pointer is the part of an otherwise identical object that changes with every run’s address layout.
The pointer mask (mask_pointer_words). Every 8-byte aligned word of the
block (offsets 0, 8, 16, …) is read as a little-endian u64. It is a
pointer, and is zeroed in the masked copy, when it is at least
MASK_MIN_POINTER = 0x10000 (smaller values are counters and lengths) and lies
inside one of the dump’s mapped ranges, end inclusive so a one-past-end
pointer counts too. Trailing bytes that do not fill a word are kept.
Grouping. For each ambiguous signature, the blocks of each dump are grouped by their masked bytes, and each distinct masked content is judged by how often it occurs in which dumps:
masked content occurs |
result |
|---|---|
once in every dump |
paired: a content-invariant row keyed |
in every dump, more than once in some |
counted ( |
in 2 to N-1 dumps |
counted ( |
in exactly one dump |
a dynamic block: its content was seen in no other dump |
If every dump has exactly one dynamic block for the signature (and N ≥ 2),
those N blocks are paired as the dynamic residue row <sig>#dynamic.
Otherwise no dynamic row is formed and the dynamic blocks are only listed, per
dump, as dynamic_candidates ({"va", "size"}) in the signature’s provenance.
The mask decides correspondence only: a paired row carries each dump’s raw bytes, so a pointer word still shows up as variance in the matrix.
The provenance (ContentAlignment) records, per ambiguous signature,
chunks_per_dump, content_invariant_paired, content_invariant_repeated,
partial, dynamic_per_dump, dynamic_candidates, dynamic_paired,
paired_chunks and unpaired_chunks, and sorts the signatures into
fully_resolved (every block paired), partially_resolved (some blocks
paired) and still_ambiguous (any block left unpaired, so a partially
resolved signature is listed there too).
The two pairing steps on the worked example below: signature counts first, then pointer-masked content for the ambiguous signatures.
Step 3: the reduced heap consensus matrix (assemble_vector)
The paired rows are laid end to end into one synthetic slab:
signature-unique rows first, sorted by signature (so their offsets do not
depend on whether step 2 ran), then the content rows in signature order, each
signature’s #content rows before its #dynamic row.
Conceptually this is an N × L byte matrix: one row per dump, one column per
byte of a paired block, L = the summed length of all paired rows. The slab is
not an address range of any dump; each paired row records where its N blocks
really are as one layout row
(slab_offset, user_length, [user_va in dump 0, ..., user_va in dump N-1]),
the same msl_layout shape a positional .msl consensus has.
For every column the engine computes the population variance across the N
dumps: the N blocks of a row are stacked as a float32 array and reduced with
np.var(axis=0) (ddof 0). Each row also gets its mean_variance, the mean of
its columns. What is kept is a ConsensusVector: the variance per column, the
bytes of the first input dump as reference_bytes, the layout rows and a
ByteClass per column (invariant / structural / pointer / key candidate, from
the usual thresholds). The full N × L matrix is never stored; each row’s
N × length block exists only while its variance is computed.
The reduced heap consensus matrix of the worked example: per-byte variance under each column, and the verdict each row gives its reference block.
The vector carries an alignment report in block bytes: bytes_compared (L)
and bytes_discarded (the user bytes of every block that was not paired, over
all dumps). When nothing was compared, or more than 10 % of the input was not,
a warning names how many bytes sat in ambiguous and in missing signatures.
Step 4: one verdict per reference block (classify_blocks)
Every block of the chosen reference dump gets exactly one verdict; the verdicts partition the reference’s blocks, so their counts add up to the blocks the reference holds. The rules are applied in this order:
verdict |
rule |
outcome |
|---|---|---|
|
the block has no user bytes |
dropped |
|
paired in a signature-unique row whose mean variance is > 0 |
kept |
|
paired in a signature-unique row whose mean variance is 0 |
dropped |
|
paired in a |
dropped |
|
paired in a |
kept |
|
not paired, its masked content occurs in no other dump |
kept |
|
its signature is absent from some dump |
not judged |
|
not paired, its signature is ambiguous and its masked content also occurs in another dump |
dropped |
KEEP_VERDICTS = signature_unique, dynamic_residue, dynamic_candidate.
missing is the one not judged verdict (NOT_JUDGED_VERDICTS): nothing
could be compared, so it is reported separately (not_judged with block
count, bytes and signatures) rather than counted as ruled out. The verdict
strings are stable; they are written into candidates.json.
verdict_funnel reports {verdict: {"chunks": n, "bytes": b}} for all eight
verdicts, kept ones first and zeros included. classify_blocks refuses a
build that skipped content alignment while signatures were ambiguous (their
blocks could not honestly be called dynamic, invariant or shared), and a
block that fits no rule is reported as an inconsistent consensus, never
silently dropped.
Dynamic candidates versus variance rows
A block can be kept for two different reasons:
Variance. A paired row (
signature_unique,dynamic_residue) has a real per-byte variance across the dumps.signature_uniquekeeps the whole block as soon as its mean variance is above 0: one changing byte is enough.Uniqueness. A
dynamic_candidatehas no row and no variance at all. It is kept because its pointer-masked content occurs in no other dump, which is what a fresh per-run secret looks like. Its region incandidates.jsonhas norowand nomean_variance.
Do not read the matrix as “keys are the high-variance columns”. On real
Windows ssh.exe dumps (Windows 10 x64 NT heap, Windows 11 ARM64 segment
heap) the session keys sat at offset 0 of a busy LFH block whose signature
occurred many times per dump; after masking, more than one block per dump had
content seen in no other dump (both traffic directions’ keys among them), so
no #dynamic row formed and every key survived as a dynamic_candidate,
never as a variance row (measured on the project’s Windows validation runs,
see Windows heaps). The matrix’s main job there is to rule
blocks out: invariant rows, content rows and shared content.
Step 5: back to the reference dump (translate_regions)
Brute force reads bytes, not blocks, so each kept block is turned into a
region of the reference dump’s flat vas view (its captured memory,
densely concatenated; see
coordinate spaces). For each kept
block:
offset = va_to_vas_offset(user_va); no offset: skipped asnot_captured.The block’s last byte must map to
offset + length - 1; otherwise its pages are not contiguous in the view: skipped asnot_contiguous.The
lengthbytes read back atoffsetmust equal the block’s user bytes; otherwise skipped asbytes_mismatch.
These guards should never fire on an intact capture; a non-zero count is
reported in skipped. Regions are sorted by offset (Go re-sorts its own by
rank). Scudo and Windows refuse a reference whose captured runs hold fewer
bytes than their pages (<prefix>.reference_truncated), because every offset
behind the short run would point at the wrong bytes; Go keeps the regions
before the short run and counts the rest as behind_truncated_run.
The total brute-force cost is reported as totals.windows: the number of
key-size windows at stride 1 over the regions, computed with the same formula
brute force uses.
What candidates.json holds
The file has the same name and the same regions contract as the positional
search-reduce output. Its shape, with illustrative values for the worked
example below (Windows method; two of its four regions shown):
{
"source": "search-reduce:winheap",
"method": "windows_heap",
"version": "0.1.0",
"consensus": {"method": "winheap_block_signature", "version": "0.1.0",
"aligned_rows": 4, "ambiguous_signatures": 1,
"missing_signatures": 1, "empty_signatures": 0},
"N": 3,
"dumps": ["run0.msl", "run1.msl", "run2.msl"],
"reference_dump": "run0.msl",
"reference_index": 0,
"cohort": null,
"region_scope": {"...": "the reference's heap-scan record"},
"opaque": {"areas": 0, "bytes": 0, "by_reason": {}},
"funnel": {"signature_unique": {"chunks": 1, "bytes": 8}, "...": "all 8 verdicts"},
"not_judged": {"chunks": 1, "bytes": 8, "signatures": ["sigM"]},
"skipped": {"not_captured": 0, "not_contiguous": 0, "bytes_mismatch": 0},
"totals": {"regions": 4, "bytes": 32, "key_sizes": [8], "stride": 1, "windows": 4},
"diagnostics": [{"code": "winheap.not_judged", "severity": "info",
"...": "1 block(s) (8 bytes) in 1 signature(s) ... never compared"}],
"method_effective": "windows_heap",
"method_source": "explicit",
"method_reason": "requested",
"regions": [
{"offset": 4096, "length": 8, "va": "0x1a2b3c0", "signature": "sigA",
"selected_as": "signature_unique", "row": "sigA", "mean_variance": 2652.67},
{"offset": 4200, "length": 8, "va": "0x1a2b428", "signature": "sigL",
"selected_as": "dynamic_candidate"}
]
}
Per region:
offsetandlength(all brute force needs),va,signature,selected_as(the verdict), and for a paired blockrow(the row key) andmean_variance(rounded to 2 decimals).Per method: Scudo writes
sourcesearch-reduce:scudoand nomethodkey; Windows addsopaque(the reference’s undecoded heap areas); Go writessearch-reduce:goheap/go_heapplus its pairing report and reduce record, and ranked regions (rank,score,pairing,slot_va,slot_state,reachable, optionallytype_name).Reduction method (top level, just ahead of
regions): thecandidates.jsonthatsearch-reducewrites for a heap collect session (consensus-begin --allocator auto|scudo|windows_heap|go_heap, no--size), thesearch_reduce/candidates.jsonof apipeline runthat used a heap method, and thecandidates.jsonof the stand-alone MCP / library heap reductions (search_reduce_scudo,search_reduce_windows_heap,search_reduce_go_heap) record which method reduced the dumps, with the same keys and values as the run summary (see Choosing a method):method_effective:scudo,windows_heaporgo_heap.method_source:autowhen MemDiver chose the method (a heap-auto session, orpipeline run --method auto);explicitwhen it was named (a forced--allocator,--method <name>, or a stand-alone heap reduction, which names its method by being called).method_reason: forauto, the detector’s reason, the same text as the stderr linememdiver: heap method <method> (auto): <reason>; forexplicit,requested.
The fields are additive. A stand-alone heap reduction records
explicit/requestedand also returns the three fields in its summary. The generic (Welford / positional)search-reduceoutput does not carry them.
Not written: the synthetic variance vector and its layout (no
variance.npy, no consensus state: brute force runs without neighbourhood
variance), the per-signature content provenance (including the dynamic
candidates of the non-reference dumps), and verdicts for any dump other than
the reference. Only the reference’s own kept blocks become regions.
Worked example
Three dumps (N = 3), reference dump 0, five signatures (the figures above draw the same data):
signature |
blocks in dump 0 / 1 / 2 |
step 1 |
step 2 |
verdicts of dump 0’s blocks |
|---|---|---|---|---|
|
1 / 1 / 1 |
unique |
— |
|
|
1 / 1 / 1 |
unique |
— |
|
|
2 / 2 / 2 |
ambiguous |
P: one pointer word, masked to zero, once per dump → |
P: |
|
3 / 3 / 2 |
ambiguous |
two dynamic blocks in every dump → no row; Z in dumps 0 and 1 only → partial |
k1, k2: |
|
1 / 0 / 1 |
missing |
— |
|
The matrix has four rows and L = 8 + 4 + 8 + 8 = 28 columns (slab offsets 0,
8, 12, 20). Dump 0 holds 8 blocks; the funnel is 1 signature_unique,
1 dynamic_residue, 2 dynamic_candidate, 1 signature_unique_invariant,
1 content_invariant, 1 content_shared, 1 missing, 0 empty. Four blocks,
32 bytes, become regions. Note the two traps the example shows: the
content_invariant row has a mean variance well above 0 (its pointer bytes
vary) and is still dropped, and the two blocks most likely to be keys (k1, k2)
are kept without any variance.
Pseudo-code
block_consensus(dumps, reference): # dumps: N >= 2 native .msl
blocks[d] = extractor(dumps[d]) # [(sig, user_va, data)], allocator-specific
ranges[d] = pointer_ranges(dumps[d]) # VAS map, else stored regions
# step 1: align_blocks
unique = sigs with count == 1 in every dump
ambiguous = sigs in every dump, count > 1 in some
missing = sigs absent from some dump
rows = [row(sig, one block per dump) for sig in sorted(unique) if block in dump 0 non-empty]
# step 2: content_align
for sig in sorted(ambiguous):
groups[d] = group dump d's blocks of sig by mask_pointer_words(data, ranges[d])
for content in sorted(all contents):
if content occurs exactly once in every dump:
rows += row(f"{sig}#content:{blake2b8(content)}", raw blocks)
dynamic[d] = dump d's blocks whose content occurs in no other dump
if every len(dynamic[d]) == 1:
rows += row(f"{sig}#dynamic", raw blocks)
# step 3: assemble_vector
slab = concat(rows) # L columns; layout row per pair
for row in rows:
var[row.cols] = np.var(stack(row.raw_blocks).astype(float32), axis=0)
row.mean_variance = mean(var[row.cols])
# step 4: classify_blocks (reference only), first rule that matches
for b in blocks[reference]:
verdict = empty if not b.data
else row verdict if b is in a row # signature_unique(_invariant),
# content_invariant, dynamic_residue
else dynamic_candidate if b in dynamic[reference]
else missing if b.sig in missing
else content_shared
# step 5: translate_regions
for b in kept(verdicts):
off = va_to_vas_offset(b.user_va) # guards: captured, contiguous, same bytes
regions += {offset: off, length: len(b.data), selected_as: verdict, ...}
write candidates.json
Limits and pitfalls
Missing means never compared. A block whose signature does not occur in every dump is never compared. If the key’s block size or requested size differs between runs, the key lands in
not_judged, not in the candidates. Checknot_judgedwhen brute force finds nothing.The pointer mask is a heuristic. Only 8-byte aligned 64-bit values are tested. 32-bit references, unaligned pointers and encoded or relative pointers (for example Windows heap-encoded headers or
EncodePointervalues) are not masked, so otherwise identical objects can look different and become dynamic (more candidates). An integer that happens to fall inside a mapped range is masked like a pointer, so different objects can look the same. ARM64 tagged pointers (top-byte-ignore) are not stripped.Uniqueness is not secrecy.
dynamic_candidatekeeps any block whose content is unique to its run: random IDs, timestamps, per-run buffers. With N = 2 every block of an ambiguous signature whose content is not shared with the other dump is dynamic; more dumps make “seen in no other dump” a stronger statement only for the blocks that do recur.Kept blocks are whole. The Scudo and Windows methods emit every kept block in full, with no variance floor inside it, and
signature_uniquekeeps a block on any non-zero variance, so a few large unique blocks can dominate the candidate bytes. Onlygo_heapreduces inside its kept slots.One reference. Only the reference dump’s blocks become candidates, and only its bytes are brute-forced. The oracle (or capture, pcap, sample) must belong to the reference run. Another reference needs another reduction.
No escalation. The verdicts are not a threshold that can be lowered; a miss means the key was not kept, not judged, or not in a parsed block.
Same run twice. Naming one dump twice is refused: its per-run values would look shared and be dropped.
Cost follows the block count. A heap of many small blocks costs several times its own bytes in Python objects. Each method extrapolates the peak memory from the first scanned dump (
block_consensus_estimate) and checks it against the memory budget (force_memoryoverrides).
Source map
module |
role |
|---|---|
|
|
|
|
|
|
|
|
|
the options a heap method refuses; escalate / emit defaults |
|
|
|
Scudo extractor, verdict wrapper, producer |
|
Windows extractor, verdict wrapper, producer (and |
|
Go span / anchor pairing, block fallback, in-slot reduce, producer |
Related: Heap-aware reduction for choosing a method and the entry points per surface; Consensus projection for how heap roles enter a positional consensus.