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).

Flow diagram in two rows. Top row, left to right: N native .msl dumps of the same program; an allocator-specific extractor (Scudo, Windows heap, or for Go the slots left after span and anchor pairing); per-dump block lists of signature, user address and user bytes; align_blocks counting signatures into unique, ambiguous and missing; content_align splitting ambiguous signatures by masked content. Bottom row, right to left: assemble_vector laying the paired rows end to end into an N by L slab with np.var; classify_blocks giving one verdict per block of the reference dump; translate_regions mapping kept block addresses to reference vas offsets; candidates.json; brute force on the reference dump.

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

sig

the allocator signature, a string naming what kind of block it is, not where it is

user_va

the virtual address of the block’s user bytes in its dump

data

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 <sig>#content:<16 hex> (a blake2b-8 label of the masked bytes)

in every dump, more than once in some

counted (content_invariant_repeated), not paired

in 2 to N-1 dumps

counted (partial), not paired

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).

Three panels. (a) A table of block counts per signature in dumps 0 to 2: sigA 1,1,1 and sigB 1,1,1 are unique; sigK 2,2,2 and sigL 3,3,2 are ambiguous; sigM 1,0,1 is missing. (b) The blocks of sigK and sigL per dump: a block P holding one pointer appears once in every dump and pairs as a content row; blocks r0, r1, r2 are the single dynamic block per dump and pair as the dynamic row; sigL has two dynamic blocks per dump, so no row forms and dump 0's two become dynamic candidates; block Z appears in dumps 0 and 1 only and becomes content_shared. (c) The 8-byte word 40 a1 5c 3f f6 7f 00 00, the little-endian value 0x7ff63f5ca140, is at least 0x10000 and inside a mapping, so its masked copy is eight zero bytes.

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.

A 3 by 28 byte matrix, rows dump 0 to dump 2, four paired rows laid end to end. sigA at slab offset 0, length 8, constant in its first four bytes and varying in the last four. sigB at offset 8, length 4, identical in all dumps. sigK#content at offset 12, length 8, one little-endian pointer word that differs in bytes 1 to 4. sigK#dynamic at offset 20, length 8, different random bytes in every dump. Below, a bar chart of the per-byte variance with a dashed line at 5461.25, the mean variance per row (2652.7, 0.0, 1551.7, 5145.7), and the verdict of the reference block: signature_unique kept, signature_unique_invariant dropped, content_invariant dropped although its pointer bytes vary, dynamic_residue kept.

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

empty

the block has no user bytes

dropped

signature_unique

paired in a signature-unique row whose mean variance is > 0

kept

signature_unique_invariant

paired in a signature-unique row whose mean variance is 0

dropped

content_invariant

paired in a #content row (whatever its variance)

dropped

dynamic_residue

paired in a #dynamic row

kept

dynamic_candidate

not paired, its masked content occurs in no other dump

kept

missing

its signature is absent from some dump

not judged

content_shared

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_unique keeps the whole block as soon as its mean variance is above 0: one changing byte is enough.

  • Uniqueness. A dynamic_candidate has 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 in candidates.json has no row and no mean_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:

  1. offset = va_to_vas_offset(user_va); no offset: skipped as not_captured.

  2. The block’s last byte must map to offset + length - 1; otherwise its pages are not contiguous in the view: skipped as not_contiguous.

  3. The length bytes read back at offset must equal the block’s user bytes; otherwise skipped as bytes_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: offset and length (all brute force needs), va, signature, selected_as (the verdict), and for a paired block row (the row key) and mean_variance (rounded to 2 decimals).

  • Per method: Scudo writes source search-reduce:scudo and no method key; Windows adds opaque (the reference’s undecoded heap areas); Go writes search-reduce:goheap / go_heap plus its pairing report and reduce record, and ranked regions (rank, score, pairing, slot_va, slot_state, reachable, optionally type_name).

  • Reduction method (top level, just ahead of regions): the candidates.json that search-reduce writes for a heap collect session (consensus-begin --allocator auto|scudo|windows_heap|go_heap, no --size), the search_reduce/candidates.json of a pipeline run that used a heap method, and the candidates.json of 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_heap or go_heap.

    • method_source: auto when MemDiver chose the method (a heap-auto session, or pipeline run --method auto); explicit when it was named (a forced --allocator, --method <name>, or a stand-alone heap reduction, which names its method by being called).

    • method_reason: for auto, the detector’s reason, the same text as the stderr line memdiver: heap method <method> (auto): <reason>; for explicit, requested.

    The fields are additive. A stand-alone heap reduction records explicit / requested and also returns the three fields in its summary. The generic (Welford / positional) search-reduce output 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

sigA (8 bytes)

1 / 1 / 1

unique

—

signature_unique (mean variance 2652.7), kept

sigB (4 bytes)

1 / 1 / 1

unique

—

signature_unique_invariant (0.0), dropped

sigK (8 bytes)

2 / 2 / 2

ambiguous

P: one pointer word, masked to zero, once per dump → sigK#content:<hex>; r: one dynamic block per dump → sigK#dynamic

P: content_invariant (mean variance 1551.7, from the raw pointer bytes), dropped; r: dynamic_residue (5145.7), kept

sigL (8 bytes)

3 / 3 / 2

ambiguous

two dynamic blocks in every dump → no row; Z in dumps 0 and 1 only → partial

k1, k2: dynamic_candidate, kept; Z: content_shared, dropped

sigM (8 bytes)

1 / 0 / 1

missing

—

missing, not judged

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. Check not_judged when 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 EncodePointer values) 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_candidate keeps 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_unique keeps a block on any non-zero variance, so a few large unique blocks can dominate the candidate bytes. Only go_heap reduces 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_memory overrides).

Source map

module

role

memdiver.engine.heap_block_consensus

align_blocks, pointer_ranges, mask_pointer_words, content_align, assemble_vector, align_and_assemble, coverage report, memory estimate

memdiver.engine.object_consensus

build_object_vector: lays paired slices into the slab and computes the per-byte variance

memdiver.engine.heap_block_verdicts

classify_blocks, the eight VERDICT_* strings, KEEP_VERDICTS, NOT_JUDGED_VERDICTS, verdict_funnel

memdiver.app.heap_block_reduce

validate_block_dumps, refuse_truncated, translate_regions, region_row, count_windows, CANDIDATES_FILENAME

memdiver.app.heap_block_options

the options a heap method refuses; escalate / emit defaults

memdiver.app.pipeline_method

detect_pipeline_method, resolve_pipeline_method (--method auto), detect_heap_method (the CLI heap-auto session)

memdiver.engine.scudo_chunk_consensus, memdiver.engine.scudo_candidates, memdiver.app.tools_pipeline_android

Scudo extractor, verdict wrapper, producer

memdiver.engine.winheap_block_consensus, memdiver.engine.winheap_candidates, memdiver.app.tools_pipeline_windows

Windows extractor, verdict wrapper, producer (and suggest_pipeline_method)

memdiver.engine.goheap_block_consensus, memdiver.app.goheap_reduce

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.