Skip to main content

Module binary

Module binary 

Source
Expand description

Binary artifact density gate and binary-content heuristic, ported from guard_core/detection_engine/binary_prefix.py and semantic.py (looks_like_binary_content).

String-model mapping: the reference scans decoded text where undecodable bytes surface as surrogateescape code points (U+DC80..U+DCFF) and mojibake as U+FFFD; both classes count as artifacts. The engine scans &str (always valid UTF-8), so undecodable bytes never reach this module as surrogates; the port’s decode boundary represents them as U+FFFD (or drops them), which is an artifact class here. The surrogate branch is kept for parity with the reference class definition but is unreachable for char. All window arithmetic runs on code-point indices, the same index space the corpus mandates for threat positions.

Functions§

build_binary_prefix
Cumulative artifact-count prefix: counts[i] = artifacts in s[..i]. Built over code points; indexing is by code-point index (the same space the structural matchers and threat positions use).
looks_like_binary_content
looks_like_binary_content from semantic.py.
match_is_binary_density