Analyze Huffman bit helpers and supplied tree decoding
Browse files- docs/ASSET_PIPELINE_TODO.md +2 -0
- docs/FINDINGS.md +6 -0
- docs/PROVISIONAL_TODO.md +2 -0
- docs/RESEARCH_LEDGER.md +4 -0
- docs/REVERSE_ENGINEERING_TODO.md +5 -0
- docs/research/HUFFMAN_HELPERS.md +37 -0
- docs/research/MESSAGE_BITS.md +2 -0
- docs/research/README.md +2 -0
- docs/research/huffman-helpers.json +0 -0
- scripts/analyze_huffman_helpers.py +76 -0
- scripts/test_huffman_helpers.py +76 -0
docs/ASSET_PIPELINE_TODO.md
CHANGED
|
@@ -214,3 +214,5 @@ Snapshot follow-up: [area-mask lifecycle](research/SNAPSHOT_AREAS.md) connects s
|
|
| 214 |
Client-mask follow-up: [client parsing](research/CLIENT_MASKS.md) bounds accepted area-mask length to 32 in the sampled Linux parser. Map-derived area limits, real protocol decoding and renderer mask interpretation still require validation before asset/runtime integration (RE-340).
|
| 215 |
|
| 216 |
Message-bit follow-up: [read modes and assembly](research/MESSAGE_BITS.md) establishes bounded cursor/assembly behavior with supplied Huffman symbols. Recover actual tree/codebooks and real packets before network/renderer integration with converted map assets (RE-344).
|
|
|
|
|
|
|
|
|
| 214 |
Client-mask follow-up: [client parsing](research/CLIENT_MASKS.md) bounds accepted area-mask length to 32 in the sampled Linux parser. Map-derived area limits, real protocol decoding and renderer mask interpretation still require validation before asset/runtime integration (RE-340).
|
| 215 |
|
| 216 |
Message-bit follow-up: [read modes and assembly](research/MESSAGE_BITS.md) establishes bounded cursor/assembly behavior with supplied Huffman symbols. Recover actual tree/codebooks and real packets before network/renderer integration with converted map assets (RE-344).
|
| 217 |
+
|
| 218 |
+
Huffman follow-up: [helper probes](research/HUFFMAN_HELPERS.md) establishes raw-bit round trips and supplied-tree decoding, with explicit null-path cursor differences. Real initialized codebooks and message fixtures remain prerequisites for network/map/renderer integration (RE-348).
|
docs/FINDINGS.md
CHANGED
|
@@ -372,3 +372,9 @@ Bounded qagame paths recover bomb-plant/inactivity correction requests, direct f
|
|
| 372 |
**F-116 — Observed OOB bit reads:** sampled nonzero mode reads only absolute widths 8/16/32 with little-endian loads and direct cursor increments, without consulting cursize locally; unsupported widths request an error. The -32 top-bit-set tail yields all ones through x86 shift masking. Actual legal caller/memory/runtime/platform behavior remains open. [BITS-002](research/MESSAGE_BITS.md).
|
| 373 |
|
| 374 |
**F-117 — Observed compressed reader assembly:** raw low remainder bits precede supplied Huffman symbol bytes; readcount becomes signed bit/8 +1. Signed tails use the remaining byte-multiple width after remainder subtraction. Huff_getBit instructions update cursor and bloc; real tree decoding, packets and original-runtime conformance remain open. [BITS-003](research/MESSAGE_BITS.md).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
**F-116 — Observed OOB bit reads:** sampled nonzero mode reads only absolute widths 8/16/32 with little-endian loads and direct cursor increments, without consulting cursize locally; unsupported widths request an error. The -32 top-bit-set tail yields all ones through x86 shift masking. Actual legal caller/memory/runtime/platform behavior remains open. [BITS-002](research/MESSAGE_BITS.md).
|
| 373 |
|
| 374 |
**F-117 — Observed compressed reader assembly:** raw low remainder bits precede supplied Huffman symbol bytes; readcount becomes signed bit/8 +1. Signed tails use the remaining byte-multiple width after remainder subtraction. Huff_getBit instructions update cursor and bloc; real tree decoding, packets and original-runtime conformance remain open. [BITS-003](research/MESSAGE_BITS.md).
|
| 375 |
+
|
| 376 |
+
**F-118 — Observed raw bit mutation:** byte-boundary writes clear a byte, other writes retain prior bits and OR the shifted input without local Boolean normalization. Both cursors advance modulo 2^32; supplied zero-buffer raw round trips recover input bits. Real symbol/network encoding remains open. [HUFF-001](research/HUFFMAN_HELPERS.md).
|
| 377 |
+
|
| 378 |
+
**F-119 — Observed supplied-tree receive:** internal symbol 257 consumes LSB-first bits, zero left/one right; successful leaves publish cursor and arbitrary supplied symbol words. Null children output zero and leave the caller cursor unchanged while the global advances. Real tree invariants and failure handling remain open. [HUFF-002](research/HUFFMAN_HELPERS.md).
|
| 379 |
+
|
| 380 |
+
**F-120 — Observed transmit request:** signed index selects the node pointer at object +32 +8*index; its +16 parent controls a send request with parent/node/buffer arguments. The sampled null-parent path retains cursor. send, real codebooks, valid symbol bounds and runtime/platform conformance remain open. [HUFF-003](research/HUFFMAN_HELPERS.md).
|
docs/PROVISIONAL_TODO.md
CHANGED
|
@@ -526,3 +526,5 @@ Research progress: [snapshot area-mask lifecycle](research/SNAPSHOT_AREAS.md) co
|
|
| 526 |
Research progress: [client area-mask parsing](research/CLIENT_MASKS.md) completes bounded RE-337–339. Broad protocol/renderer/runtime milestones remain open; RE-340 tracks actual codec/cursors, validation/publication and real packet/platform coverage.
|
| 527 |
|
| 528 |
Research progress: [message read modes and assembly](research/MESSAGE_BITS.md) completes bounded RE-341–343. Broad networking/runtime milestones remain open; RE-344 tracks real Huffman codecs, caller invariants and packet/platform fixtures.
|
|
|
|
|
|
|
|
|
| 526 |
Research progress: [client area-mask parsing](research/CLIENT_MASKS.md) completes bounded RE-337–339. Broad protocol/renderer/runtime milestones remain open; RE-340 tracks actual codec/cursors, validation/publication and real packet/platform coverage.
|
| 527 |
|
| 528 |
Research progress: [message read modes and assembly](research/MESSAGE_BITS.md) completes bounded RE-341–343. Broad networking/runtime milestones remain open; RE-344 tracks real Huffman codecs, caller invariants and packet/platform fixtures.
|
| 529 |
+
|
| 530 |
+
Research progress: [Huffman helper probes](research/HUFFMAN_HELPERS.md) completes bounded RE-345–347. Broad protocol/runtime milestones remain open; RE-348 tracks full send, initialized trees/codebooks, actual packet round trips and platform coverage.
|
docs/RESEARCH_LEDGER.md
CHANGED
|
@@ -205,3 +205,7 @@ Completed bounded RE-337–339 with `analyze_client_masks.py`: three verified Li
|
|
| 205 |
## 2026-10-11 — Message read modes and bit assembly
|
| 206 |
|
| 207 |
Completed bounded RE-341–343 with `analyze_message_bits.py`: eight verified graphs across both Linux ELF64 engines, eight exact reset probes, 600 OOB and 688 compressed reader compositions. BITS-001–003/F-115–117 distinguish padded backing storage from cursize, direct OOB loads from compressed cursors, composed raw-bit instructions from supplied Huffman symbols/code lengths, and requested signed width from the mutated width used by the tail. Nonbyte and 32-bit signed-tail effects are recorded without assuming legal packet reachability or cross-platform equivalence. Prologue/frame omission and explicit caller-register restoration are documented; original processes and every native callee remain unexecuted. Eight independent tests verify reset fields/canaries, dispatch/errors, little-endian/sign/cursor results, raw/symbol assembly, helper arguments/global writes, cursor formula, signed edge examples, paired outputs and restricted MOVZWL/NEGL/SHRL evaluator behavior. All 294 tests pass; new and preceding reports regenerate byte-identically, and storage/link/whitespace checks pass. RE-340 remains open; RE-344 tracks Huffman initialization/tree/codebooks/receive/transmit/put-bit, actual writer/reader packets, legal width/mode/cursor callers and full runtime/platform/snapshot/renderer conformance.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
## 2026-10-11 — Message read modes and bit assembly
|
| 206 |
|
| 207 |
Completed bounded RE-341–343 with `analyze_message_bits.py`: eight verified graphs across both Linux ELF64 engines, eight exact reset probes, 600 OOB and 688 compressed reader compositions. BITS-001–003/F-115–117 distinguish padded backing storage from cursize, direct OOB loads from compressed cursors, composed raw-bit instructions from supplied Huffman symbols/code lengths, and requested signed width from the mutated width used by the tail. Nonbyte and 32-bit signed-tail effects are recorded without assuming legal packet reachability or cross-platform equivalence. Prologue/frame omission and explicit caller-register restoration are documented; original processes and every native callee remain unexecuted. Eight independent tests verify reset fields/canaries, dispatch/errors, little-endian/sign/cursor results, raw/symbol assembly, helper arguments/global writes, cursor formula, signed edge examples, paired outputs and restricted MOVZWL/NEGL/SHRL evaluator behavior. All 294 tests pass; new and preceding reports regenerate byte-identically, and storage/link/whitespace checks pass. RE-340 remains open; RE-344 tracks Huffman initialization/tree/codebooks/receive/transmit/put-bit, actual writer/reader packets, legal width/mode/cursor callers and full runtime/platform/snapshot/renderer conformance.
|
| 208 |
+
|
| 209 |
+
## 2026-10-11 — Raw-bit helpers and supplied Huffman trees
|
| 210 |
+
|
| 211 |
+
Completed bounded RE-345–347 with `analyze_huffman_helpers.py`: ten verified graphs across the Linux ELF64 engines, 288 bit-write probes, 64 raw bit-stream round trips, 352 supplied-tree receive and 72 transmit-boundary probes. HUFF-001–003/F-118–120 distinguish byte-start clear from partial-byte OR, raw round trips from real Huffman encoding, supplied-tree traversal from initialized codebooks, null-path global advances from caller cursor publication, and transmit lookup/arguments from execution of send. Virtual backing storage, arbitrary/non-Boolean/signed inputs and leaf symbols remain explicit local probes. Transmit PUSH omission and stopped CALL boundaries are documented; no original process or native callee executes. Eight independent tests verify mutation/canaries/wrap/global writes, independent bit packing, node-table walks and null cursors, leaf words, signed lookup/request arguments, paired outputs and call boundaries. All 302 tests pass; new and preceding reports regenerate byte-identically, and storage/link/whitespace checks pass. RE-344 remains open; RE-348 tracks full recursive/unrolled send, adaptive initialization/frequencies/tree/codebooks, message/packet compositions and legal input/cursor/tree/runtime/all-platform invariants.
|
docs/REVERSE_ENGINEERING_TODO.md
CHANGED
|
@@ -412,3 +412,8 @@ Purpose: turn the supplied installation into an evidence-backed specification of
|
|
| 412 |
- [x] RE-342 Recover bounded OOB width/error dispatch, little-endian reads and cursor/signed-tail effects ([BITS-002](research/MESSAGE_BITS.md)).
|
| 413 |
- [x] RE-343 Compose raw-bit instructions and supplied compressed symbol assembly, cursor/global writes and remaining-width signed tails ([BITS-003](research/MESSAGE_BITS.md)).
|
| 414 |
- [ ] RE-344 Recover Huffman tree initialization/frequencies/codebooks/receive/transmit/put-bit, full writer-reader and real-packet compositions, overflow/truncation and legal signed width/mode/cursor callers; validate snapshot/renderer integration and original-runtime/all-platform contracts.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
- [x] RE-342 Recover bounded OOB width/error dispatch, little-endian reads and cursor/signed-tail effects ([BITS-002](research/MESSAGE_BITS.md)).
|
| 413 |
- [x] RE-343 Compose raw-bit instructions and supplied compressed symbol assembly, cursor/global writes and remaining-width signed tails ([BITS-003](research/MESSAGE_BITS.md)).
|
| 414 |
- [ ] RE-344 Recover Huffman tree initialization/frequencies/codebooks/receive/transmit/put-bit, full writer-reader and real-packet compositions, overflow/truncation and legal signed width/mode/cursor callers; validate snapshot/renderer integration and original-runtime/all-platform contracts.
|
| 415 |
+
|
| 416 |
+
- [x] RE-345 Recover bounded bit-write clear/OR/global/cursor behavior and composed raw-bit round trips ([HUFF-001](research/HUFFMAN_HELPERS.md)).
|
| 417 |
+
- [x] RE-346 Compose supplied native tree walks, leaf symbol output and null-path caller/global cursor publication ([HUFF-002](research/HUFFMAN_HELPERS.md)).
|
| 418 |
+
- [x] RE-347 Recover signed symbol-table lookup, parent routing and stopped transmit/send requests ([HUFF-003](research/HUFFMAN_HELPERS.md)).
|
| 419 |
+
- [ ] RE-348 Recover recursive/unrolled send and bit writes, adaptive tree allocation/initialization/frequency tables/codebooks, full transmit/receive and message writer/reader/real-packet compositions; validate legal inputs/tree/cursor invariants, null failures, overflow/truncation and original-runtime/all-platform contracts.
|
docs/research/HUFFMAN_HELPERS.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Raw-bit helpers and supplied Huffman trees
|
| 2 |
+
|
| 3 |
+
Reproduce with `python3 scripts/analyze_huffman_helpers.py`; validate with `python3 scripts/test_huffman_helpers.py`. [huffman-helpers.json](huffman-helpers.json) retains five hash-verified graphs per Linux ELF64 engine: Huff_putBit, Huff_getBit, Huff_offsetReceive, Huff_offsetTransmit and send. This follows [message reader assembly](MESSAGE_BITS.md).
|
| 4 |
+
|
| 5 |
+
All evaluations use synthetic sparse memory, bit cursors, trees and lookup tables. Original processes and native callees never execute. Raw helper instructions compose explicitly; receive traverses supplied nodes rather than the game's initialized codebook. Transmit omits its PUSH and stops before send, whose graph is static evidence only. Invalid values/pointers/cursors characterize local instructions, not legal game states, safe memory access or original-runtime/ABI/platform conformance.
|
| 6 |
+
|
| 7 |
+
## HUFF-001 — Bit mutation and raw round trips (RE-345)
|
| 8 |
+
|
| 9 |
+
Two hundred eighty-eight paired put-bit probes cover bit positions 0–8/15/0xffffffff/0x7fffffff, input words 0/1/2/255 and destination bytes 0/0xa5/0xff. The target is `buffer + (signed_bit >> 3)` and its bit position is `bit & 7`. At position zero within a byte, the writer first clears that byte; otherwise it retains existing bits. It then ORs the input word shifted by the bit position, truncated to a byte. The helper itself does **not** normalize the input to Boolean: input two or 255 can modify more than one bit. Caller masking must be recovered separately.
|
| 10 |
+
|
| 11 |
+
Both supplied cursor and verified global bloc become `(bit + 1) modulo 2^32`. The negative and maximum cursor fixtures supply their target backing bytes explicitly; no bounds checking or legal cursor lifecycle is established. Adjacent byte canaries are preserved.
|
| 12 |
+
|
| 13 |
+
Sixty-four paired raw round trips start at offsets zero through seven and write/read sixteen bits: all zero, all one, and both alternating patterns. Independent packing oracles verify least-significant-bit-first byte order, exact output bytes, restored input bits, final cursors/global state and canaries. Buffers start at zero. A dirty partial first byte would retain its set bits when writing zero, so these are valid bounded raw bit-stream round trips, not proof of arbitrary buffer overwrite or complete Huffman/network codecs.
|
| 14 |
+
|
| 15 |
+
## HUFF-002 — Supplied-tree decoding and null paths (RE-346)
|
| 16 |
+
|
| 17 |
+
Three hundred fifty-two paired receive probes cover complete trees of depth one/two/three, null root, null left/right child, and direct leaf symbols 0/255/256/258/0xffffffff. Bit cursors start at 0/7/8/-1 with four supplied backing byte patterns. Node fields recovered locally are left pointer +0, right pointer +8 and symbol word +52 (0x34). Symbol 257 (0x101) means internal node in this traversal; other supplied words terminate and are copied directly, without local byte-range restriction. These offsets do not establish the complete node layout or legality of arbitrary leaf symbols.
|
| 18 |
+
|
| 19 |
+
The helper initializes global bloc from the caller's bit cursor. Each internal node consumes one LSB-first bit; zero selects left and one selects right. A successful leaf stores its symbol and publishes the advanced global cursor to the caller. A root leaf consumes no bits.
|
| 20 |
+
|
| 21 |
+
A null root stores symbol zero and returns without writing the caller cursor. A null child also stores zero and returns without publishing the cursor, although global bloc has advanced by the consumed bit. For example, a null-left tree and zero backing byte at caller bit seven leaves the caller at seven and global bloc at eight. Thus failure can leave caller/global cursors different. Symbol zero alone does not distinguish this path from a successful zero-symbol leaf. Actual tree invariants, caller error handling and reachability remain open.
|
| 22 |
+
|
| 23 |
+
Independent node-table traversal verifies the results and both cursors. No Huff_getBit call is requested here: Huff_offsetReceive performs its own inline bit reads. Bounded depths and finite fixtures are not coverage of cyclic trees, arbitrary depths, truncated memory or real codebooks.
|
| 24 |
+
|
| 25 |
+
## HUFF-003 — Transmit lookup and stopped send request (RE-347)
|
| 26 |
+
|
| 27 |
+
Seventy-two paired transmit probes cover signed symbol indices -1/0/1/255/256/257, null/non-null parent pointers and cursors 0/7/0xffffffff. The symbol index is sign-extended and selects a node pointer at `huffman_object +32 +8 * symbol`. The selected node's parent pointer at +16 determines whether send is requested.
|
| 28 |
+
|
| 29 |
+
With a supplied non-null parent, the request arguments are `(parent, selected_node, output_buffer)`, and evaluation stops before CALL. With a null parent, the wrapper publishes the unchanged global cursor to the caller. The wrapper seeds global bloc from the caller cursor in both cases. Negative/out-of-range indices are backed by explicitly supplied table entries; no local index validation is observed, but valid runtime table bounds are unproven. The selected node pointer is always non-null in these probes; null-node dereference behavior is not evaluated.
|
| 30 |
+
|
| 31 |
+
The PUSH is explicitly changed to NOP for the virtual-frame slice; evaluation stops before POP on the no-send path. Caller-register restoration, recursive/unrolled send behavior and actual encoded symbol bytes remain unimplemented. The retained send graph establishes a next analysis target rather than claiming encoder conformance.
|
| 32 |
+
|
| 33 |
+
## Validation and next work
|
| 34 |
+
|
| 35 |
+
Eight tests independently check exact byte clear/OR behavior, canaries and modular cursor/global writes; raw round-trip packing; tree walk and null cursor publication; unrestricted supplied leaf words; signed lookup/send request arguments; stopped CALL boundaries and paired outputs. Full verified graphs retain instruction addresses; larger probes use trace counts/hashes. No shared evaluator changes were needed.
|
| 36 |
+
|
| 37 |
+
RE-348: recover all recursive/unrolled send paths and bit writes, tree/node allocation and adaptive initialization/frequency tables/codebooks; compose transmit/receive and actual message writers/readers, with real packets and truncation/overflow handling; audit legal symbol/input/cursor/tree invariants, null failure consumers and original-runtime/all-platform behavior before Rust protocol integration.
|
docs/research/MESSAGE_BITS.md
CHANGED
|
@@ -33,3 +33,5 @@ The remainder is subtracted from the local width register before the signed tail
|
|
| 33 |
Eight independent tests verify exact mode resets/canaries, OOB width-error dispatch, byte order/sign/cursor increments, raw-bit and symbol assembly, helper arguments/global writes and supplied cursor formula, nonbyte/32-bit signed examples, paired engine outputs, and restricted MOVZWL/NEGL/SHRL evaluator semantics. Each composition retains trace counts/hashes; full verified graphs retain instruction addresses. No native CALL instruction executes implicitly.
|
| 34 |
|
| 35 |
RE-344: recover Huffman initialization/frequency tables/tree/codebooks and bounded receive/transmit/put-bit behavior; compose writers with readers and real encoded packets, including overflow/truncation; audit legal signed widths, mode/bit/readcount invariants and actual callers; validate snapshot publication/renderer semantics and all original-runtime/platform contracts before Rust implementation.
|
|
|
|
|
|
|
|
|
| 33 |
Eight independent tests verify exact mode resets/canaries, OOB width-error dispatch, byte order/sign/cursor increments, raw-bit and symbol assembly, helper arguments/global writes and supplied cursor formula, nonbyte/32-bit signed examples, paired engine outputs, and restricted MOVZWL/NEGL/SHRL evaluator semantics. Each composition retains trace counts/hashes; full verified graphs retain instruction addresses. No native CALL instruction executes implicitly.
|
| 34 |
|
| 35 |
RE-344: recover Huffman initialization/frequency tables/tree/codebooks and bounded receive/transmit/put-bit behavior; compose writers with readers and real encoded packets, including overflow/truncation; audit legal signed widths, mode/bit/readcount invariants and actual callers; validate snapshot publication/renderer semantics and all original-runtime/platform contracts before Rust implementation.
|
| 36 |
+
|
| 37 |
+
Helper follow-up: [raw-bit and supplied-tree probes](HUFFMAN_HELPERS.md) recovers bit writing, bounded tree receive and transmit routing (RE-345–347). Actual initialized codebooks and encoded symbol/message round trips remain open.
|
docs/research/README.md
CHANGED
|
@@ -127,3 +127,5 @@ The extension collector adds five focused tests for native tail calls, command-r
|
|
| 127 |
[Client snapshot area-mask parsing](CLIENT_MASKS.md) adds RE-337–339: temporary reset/length guards, byte-reader EOF and bounded unrolled data copies. Reproduce with `python3 scripts/analyze_client_masks.py`; check with `python3 scripts/test_client_masks.py`. Actual codecs/cursors, full snapshot publication and renderer/runtime/platform contracts remain open.
|
| 128 |
|
| 129 |
[Message read modes and bit assembly](MESSAGE_BITS.md) adds RE-341–343: exact resets, OOB loads/errors/cursors and raw-bit/compressed-symbol/sign-tail compositions. Reproduce with `python3 scripts/analyze_message_bits.py`; check with `python3 scripts/test_message_bits.py`. Huffman trees, writers, legal caller invariants and real packet/runtime/platform conformance remain open.
|
|
|
|
|
|
|
|
|
| 127 |
[Client snapshot area-mask parsing](CLIENT_MASKS.md) adds RE-337–339: temporary reset/length guards, byte-reader EOF and bounded unrolled data copies. Reproduce with `python3 scripts/analyze_client_masks.py`; check with `python3 scripts/test_client_masks.py`. Actual codecs/cursors, full snapshot publication and renderer/runtime/platform contracts remain open.
|
| 128 |
|
| 129 |
[Message read modes and bit assembly](MESSAGE_BITS.md) adds RE-341–343: exact resets, OOB loads/errors/cursors and raw-bit/compressed-symbol/sign-tail compositions. Reproduce with `python3 scripts/analyze_message_bits.py`; check with `python3 scripts/test_message_bits.py`. Huffman trees, writers, legal caller invariants and real packet/runtime/platform conformance remain open.
|
| 130 |
+
|
| 131 |
+
[Raw-bit helpers and supplied Huffman trees](HUFFMAN_HELPERS.md) adds RE-345–347: byte clear/OR, raw round trips, supplied-tree decoding/null cursor paths and transmit lookup/request boundaries. Reproduce with `python3 scripts/analyze_huffman_helpers.py`; check with `python3 scripts/test_huffman_helpers.py`. Full send, real codebooks/messages and runtime/platform contracts remain open.
|
docs/research/huffman-helpers.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/analyze_huffman_helpers.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Bounded native raw-bit round trips, supplied-tree receive and transmit requests."""
|
| 3 |
+
import copy
|
| 4 |
+
import gzip
|
| 5 |
+
import itertools
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from analyze_bsp_references import global_address,trace_fields
|
| 9 |
+
from analyze_collision_composition import evaluate,get_word,put_word
|
| 10 |
+
from analyze_engine_control import control_flow
|
| 11 |
+
from analyze_qvm import write_json
|
| 12 |
+
from analyze_vm_extensions import native_functions,verified
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def run(g,m,regs,start=None,stops=None):
|
| 16 |
+
return evaluate(g,start or g['instructions'][0]['address'],stops or [x['address'] for x in g['instructions'] if x['opcode']=='retq'],m,regs,limit=10000,capture_registers=True)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def signed(v):return v-(1<<32) if v&(1<<31) else v
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def main():
|
| 23 |
+
out={'native':{},'limitations':'Paired Linux ELF64 synthetic instruction evaluation only. Original processes and native callees never execute. Trees, symbol-table pointers and memory supplied; no real adaptive tree/codebook initialization or packet codec. Huff_offsetTransmit PUSH omitted and send stopped before CALL; its body retained only as static evidence. Null/negative/malformed fixtures do not establish legal runtime reachability, memory safety or ABI/all-platform conformance.'}
|
| 24 |
+
data,cursor,output,tree,table=0x10000,0x20000,0x30000,0x40000,0x50000
|
| 25 |
+
for label in ['linux--Quake3-UrT-Ded.x86_64','linux--Quake3-UrT.x86_64']:
|
| 26 |
+
r=json.loads(Path(f'docs/research/native/{label}.json').read_text());verified((Path('.cache/UrbanTerror43')/r['source']['path']).read_bytes(),r['source']['sha256'])
|
| 27 |
+
a=r['artifacts']['disassembly.txt'];fs=native_functions(verified(gzip.open(a['path'],'rb').read(),a['uncompressed_sha256']).decode());graphs={n:control_flow(fs[n]) for n in ['Huff_putBit','Huff_getBit','Huff_offsetReceive','Huff_offsetTransmit','send']}
|
| 28 |
+
put,get,receive= [graphs[n] for n in ['Huff_putBit','Huff_getBit','Huff_offsetReceive']]
|
| 29 |
+
bloc=global_address(next(x for x in put['instructions'] if '(%rip)' in x['operands']))
|
| 30 |
+
put_probes=[]
|
| 31 |
+
for initial,value,sentinel in itertools.product(list(range(8))+[8,15,0xffffffff,0x7fffffff],[0,1,2,255],[0,0xa5,255]):
|
| 32 |
+
addr=data+(signed(initial)>>3);m={addr-1:0x7b,addr:sentinel,addr+1:0x7b};put_word(m,cursor,initial)
|
| 33 |
+
t=run(put,m,{'%rdi':value,'%rsi':data,'%rdx':cursor})
|
| 34 |
+
put_probes.append({'initial_bit':initial,'value':value,'sentinel':sentinel,'target_byte':t['memory'][addr],'final_cursor':get_word(t['memory'],cursor),'global_cursor':get_word(t['memory'],bloc),'canaries':[t['memory'][addr-1],t['memory'][addr+1]],**trace_fields(t,False)})
|
| 35 |
+
roundtrips=[]
|
| 36 |
+
for start,pattern in itertools.product(range(8),[[0]*16,[1]*16,[i%2 for i in range(16)],[(i+1)%2 for i in range(16)]]):
|
| 37 |
+
m={data+i:0 for i in range(-1,5)};m[data-1]=m[data+4]=0x7b;put_word(m,cursor,start);trace=[]
|
| 38 |
+
for bit in pattern:
|
| 39 |
+
t=run(put,m,{'%rdi':bit,'%rsi':data,'%rdx':cursor});m=t['memory'];trace+=t['trace']
|
| 40 |
+
encoded=[m[data+i] for i in range(4)];put_word(m,cursor,start);decoded=[]
|
| 41 |
+
for _ in pattern:
|
| 42 |
+
t=run(get,m,{'%rdi':data,'%rsi':cursor});m=t['memory'];decoded.append(t['registers']['rax']);trace+=t['trace']
|
| 43 |
+
roundtrips.append({'start_bit':start,'input_bits':pattern,'encoded_bytes':encoded,'decoded_bits':decoded,'final_cursor':get_word(m,cursor),'global_cursor':get_word(m,bloc),'canaries':[m[data-1],m[data+4]],**trace_fields({'trace':trace},False)})
|
| 44 |
+
receives=[]
|
| 45 |
+
for shape,initial,byte in itertools.product(['depth1','depth2','depth3','null-left','null-right','null-root','leaf0','leaf255','leaf256','leaf258','leafminus1'],[0,7,8,-1],[0,255,0x96,0x81]):
|
| 46 |
+
m={data+i:byte for i in range(-8,8)};put_word(m,cursor,initial);put_word(m,output,0xa5a5a5a5);put_word(m,bloc,0xa5a5a5a5)
|
| 47 |
+
nodes=[]
|
| 48 |
+
if shape.startswith('depth'):
|
| 49 |
+
depth=int(shape[-1]);count=(1<<(depth+1))-1
|
| 50 |
+
for i in range(count):
|
| 51 |
+
addr=tree+64*i;internal=i<(1<<depth)-1;symbol=257 if internal else 40+i
|
| 52 |
+
left=tree+64*(2*i+1) if internal else 0;right=tree+64*(2*i+2) if internal else 0
|
| 53 |
+
put_word(m,addr,left,8);put_word(m,addr+8,right,8);put_word(m,addr+52,symbol);nodes.append([addr,left,right,symbol])
|
| 54 |
+
root=tree
|
| 55 |
+
elif shape.startswith('null-'):
|
| 56 |
+
root=0 if shape=='null-root' else tree
|
| 57 |
+
put_word(m,tree,0 if shape=='null-left' else tree+64,8);put_word(m,tree+8,0 if shape=='null-right' else tree+64,8);put_word(m,tree+52,257)
|
| 58 |
+
put_word(m,tree+64+52,77);nodes=[[tree,get_word(m,tree,8),get_word(m,tree+8,8),257],[tree+64,0,0,77]]
|
| 59 |
+
else:
|
| 60 |
+
root=tree;symbol=-1 if shape=='leafminus1' else int(shape[4:]);put_word(m,tree+52,symbol);nodes=[[tree,0,0,symbol&0xffffffff]]
|
| 61 |
+
t=run(receive,m,{'%rdi':root,'%rsi':output,'%rdx':data,'%rcx':cursor})
|
| 62 |
+
receives.append({'shape':shape,'initial_bit':initial,'backing_byte':byte,'root':root,'nodes':nodes,'symbol_word':get_word(t['memory'],output),'final_cursor':get_word(t['memory'],cursor),'global_cursor':get_word(t['memory'],bloc),**trace_fields(t,False)})
|
| 63 |
+
transmit=copy.deepcopy(graphs['Huff_offsetTransmit']);omitted=[]
|
| 64 |
+
for x in transmit['instructions']:
|
| 65 |
+
if x['opcode']=='pushq':omitted.append(x['address']);x['opcode']='nop';x['operands']=''
|
| 66 |
+
send_call=next(x['address'] for x in transmit['instructions'] if x['opcode']=='callq');end=next(x['address'] for x in transmit['instructions'] if x['opcode']=='popq');probes=[]
|
| 67 |
+
for symbol,parent,initial in itertools.product([-1,0,1,255,256,257],[0,tree+64],[0,7,0xffffffff]):
|
| 68 |
+
m={};put_word(m,cursor,initial);put_word(m,table+32+8*symbol,tree,8);put_word(m,tree+16,parent,8)
|
| 69 |
+
t=run(transmit,m,{'%rdi':table,'%rsi':symbol&0xffffffff,'%rdx':data,'%rcx':cursor},stops=[send_call,end])
|
| 70 |
+
probes.append({'symbol_index':symbol,'parent_pointer':parent,'initial_bit':initial,'requests_send':t['stop']==send_call,'send_arguments':[t['registers'][k] for k in ['rdi','rsi','rdx']] if parent else None,'final_cursor':get_word(t['memory'],cursor),'global_cursor':get_word(t['memory'],bloc),**trace_fields(t,True)})
|
| 71 |
+
out['native'][label]={'source':r['source'],'disassembly_sha256':a['uncompressed_sha256'],'graphs':graphs,'bit_global_address':bloc,'put_probes':put_probes,'roundtrips':roundtrips,'receive_probes':receives,'transmit_probes':probes,'transmit_omitted_push_addresses':omitted}
|
| 72 |
+
write_json(Path('docs/research/huffman-helpers.json'),out)
|
| 73 |
+
print('Recovered 288 bit-write probes, 64 raw round trips, 352 tree receive and 72 transmit-boundary probes')
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__=='__main__':main()
|
scripts/test_huffman_helpers.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Independent byte mutation, bit-stream, tree-walk and lookup oracles."""
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import unittest
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class HuffmanHelperTests(unittest.TestCase):
|
| 9 |
+
@classmethod
|
| 10 |
+
def setUpClass(cls):cls.r=json.loads(Path('docs/research/huffman-helpers.json').read_text())
|
| 11 |
+
|
| 12 |
+
def test_byte_start_clear_and_or_value_without_boolean_normalization(self):
|
| 13 |
+
for n in self.r['native'].values():
|
| 14 |
+
self.assertEqual(len(n['put_probes']),144)
|
| 15 |
+
for p in n['put_probes']:
|
| 16 |
+
bit=p['initial_bit']&7;expected=(0 if bit==0 else p['sentinel'])|((p['value']<<bit)&255)
|
| 17 |
+
self.assertEqual(p['target_byte'],expected);self.assertEqual(p['canaries'],[0x7b]*2)
|
| 18 |
+
|
| 19 |
+
def test_cursor_increment_wrap_and_global_agreement(self):
|
| 20 |
+
for n in self.r['native'].values():
|
| 21 |
+
for p in n['put_probes']:
|
| 22 |
+
expected=(p['initial_bit']+1)&0xffffffff;self.assertEqual(p['final_cursor'],expected);self.assertEqual(p['global_cursor'],expected)
|
| 23 |
+
self.assertTrue(any(p['initial_bit']==0xffffffff and p['final_cursor']==0 for p in n['put_probes']))
|
| 24 |
+
|
| 25 |
+
def test_raw_round_trip_independent_lsb_byte_packing(self):
|
| 26 |
+
for n in self.r['native'].values():
|
| 27 |
+
self.assertEqual(len(n['roundtrips']),32)
|
| 28 |
+
for p in n['roundtrips']:
|
| 29 |
+
expected=[0]*4
|
| 30 |
+
for i,bit in enumerate(p['input_bits']):position=p['start_bit']+i;expected[position//8]|=bit<<(position%8)
|
| 31 |
+
self.assertEqual(p['encoded_bytes'],expected);self.assertEqual(p['decoded_bits'],p['input_bits'])
|
| 32 |
+
self.assertEqual(p['final_cursor'],p['start_bit']+16);self.assertEqual(p['global_cursor'],p['start_bit']+16);self.assertEqual(p['canaries'],[0x7b]*2)
|
| 33 |
+
|
| 34 |
+
def test_supplied_tree_walk_and_cursor_publication(self):
|
| 35 |
+
for n in self.r['native'].values():
|
| 36 |
+
self.assertEqual(len(n['receive_probes']),176)
|
| 37 |
+
for p in n['receive_probes']:
|
| 38 |
+
nodes={x[0]:x for x in p['nodes']};node=p['root'];position=p['initial_bit']
|
| 39 |
+
while node and nodes[node][3]==257:
|
| 40 |
+
bit=(p['backing_byte']>>(position&7))&1;position+=1;node=nodes[node][2 if bit else 1]
|
| 41 |
+
expected=nodes[node][3] if node else 0
|
| 42 |
+
self.assertEqual(p['symbol_word'],expected);self.assertEqual(p['global_cursor'],position&0xffffffff)
|
| 43 |
+
self.assertEqual(p['final_cursor'],(position if node else p['initial_bit'])&0xffffffff)
|
| 44 |
+
|
| 45 |
+
def test_null_branch_consumption_differs_from_caller_cursor(self):
|
| 46 |
+
for n in self.r['native'].values():
|
| 47 |
+
rows=[p for p in n['receive_probes'] if p['shape']=='null-left' and p['backing_byte']==0]
|
| 48 |
+
self.assertTrue(rows)
|
| 49 |
+
for p in rows:
|
| 50 |
+
self.assertEqual(p['symbol_word'],0);self.assertEqual(p['final_cursor'],p['initial_bit']&0xffffffff);self.assertEqual(p['global_cursor'],(p['initial_bit']+1)&0xffffffff)
|
| 51 |
+
|
| 52 |
+
def test_leaf_symbols_not_locally_restricted_to_byte_range(self):
|
| 53 |
+
for n in self.r['native'].values():
|
| 54 |
+
for shape,expected in [('leaf0',0),('leaf255',255),('leaf256',256),('leaf258',258),('leafminus1',0xffffffff)]:
|
| 55 |
+
rows=[p for p in n['receive_probes'] if p['shape']==shape];self.assertEqual(len(rows),16)
|
| 56 |
+
for p in rows:self.assertEqual(p['symbol_word'],expected);self.assertEqual(p['final_cursor'],p['initial_bit']&0xffffffff)
|
| 57 |
+
|
| 58 |
+
def test_transmit_signed_lookup_and_parent_request_boundary(self):
|
| 59 |
+
for n in self.r['native'].values():
|
| 60 |
+
self.assertEqual(len(n['transmit_probes']),36);self.assertEqual(len(n['transmit_omitted_push_addresses']),1)
|
| 61 |
+
calls={x['address'] for x in n['graphs']['Huff_offsetTransmit']['instructions'] if x['opcode']=='callq'}
|
| 62 |
+
for p in n['transmit_probes']:
|
| 63 |
+
self.assertEqual(p['requests_send'],bool(p['parent_pointer']))
|
| 64 |
+
self.assertEqual(p['send_arguments'],[p['parent_pointer'],0x40000,0x10000] if p['parent_pointer'] else None)
|
| 65 |
+
self.assertEqual(p['final_cursor'],p['initial_bit']);self.assertEqual(p['global_cursor'],p['initial_bit']);self.assertTrue(calls.isdisjoint(p['trace']))
|
| 66 |
+
|
| 67 |
+
def test_paired_results_and_leaf_helpers_have_no_calls(self):
|
| 68 |
+
a,b=self.r['native'].values()
|
| 69 |
+
for key in ['put_probes','roundtrips','receive_probes','transmit_probes']:
|
| 70 |
+
def clean(rows):return [{k:v for k,v in p.items() if k not in ['trace','trace_sha256']} for p in rows]
|
| 71 |
+
self.assertEqual(clean(a[key]),clean(b[key]))
|
| 72 |
+
for n in [a,b]:
|
| 73 |
+
for name in ['Huff_putBit','Huff_getBit','Huff_offsetReceive']:self.assertFalse(any(x['opcode']=='callq' for x in n['graphs'][name]['instructions']))
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__=='__main__':unittest.main()
|