Add the import-layer repair and the Themida absorption

references/iat-virtualization-and-call-site-rewriting.md records the two edits one
protector family makes to a native image: the import slot stops holding an address and
the indirect call that read it becomes a relative call to a stub. It carries the pairing
rule -- a site's target equals a slot's value -- the three placements of the filler byte
in a six-byte rewrite and the refusal when there is none, the divergence between builds
that modify the code section and builds that only redirect the table, the small set of
imports redirected twice, the choice between repairing, extracting a payload, observing
and reporting, and the limits an automatic unpacker inherits from its own dump.

scripts/iat_callsite_restore.py implements the mechanical half offline: inventory the
slots from three sources, pair by value, decide the six-byte window per site, refuse an
ambiguous slot and a site whose sixth byte is the next instruction, rewrite, then
re-decode every written site from the file it wrote. It is report-only unless --out is
given, and it does not unpack: a virtualised entry has no site list to restore.

Registered in both symptom tables, the routing, reference and script indexes, the
capability registry as call_site_restore, and the coverage, route-inventory and evidence
tables. dynamic-debugging.md gains the instrument rule the second write-up demonstrates
(a target that runs at full speed and dies when stopped has a perturbation detector),
memory-and-dumps.md gains the call-site step of a rebuild, environment.md gains the
compatibility-shim trap, and protectors-and-packers.md gains one recognition row plus a
pointer rather than the detail, because that file makes no product-level claims.

The target-behaviour claims stay unverified: no protected sample was analysed here. What
is observed is the tool's behaviour on a generated image -- both filler positions, both
refusals, both displacement forms -- and what the source material states about itself.
FINDINGS F16 records the defect this pass produced, a slot's magnitude read as its
meaning, with the test that fails without the fix. .gitignore gains ref/, which was not
covered by the existing rule because that rule carries a leading dot.
This commit is contained in:
root
2026-10-27 16:29:59 +08:00
parent af9603c985
commit e5b45d9072
19 changed files with 1281 additions and 2 deletions
+24
View File
@@ -154,6 +154,30 @@ on this host rather than an error.
*Fix and check:* long values wrap onto continuation lines instead of being cut. A test asserts a long
value survives into the output intact.
## Repair-script defects
**F16. A slot's magnitude was read as its meaning, so an ordinary import table looked protected.**
*Symptom:* the import-layer repair's first version classified every slot whose value was below the
image base as a handle, and its verdict rule turned that class into `needs-trace` — a
protected-image verdict for a file that was never protected. Nothing about the output looked wrong:
the classes were counted, the verdict followed from them, and the report was internally consistent.
*Root cause:* an unbound import table holds RVAs, and an RVA is also a number below the image base.
The classifier inferred intent from magnitude instead of testing whether the value resolves to
something in the image, or whether a call targets it. The same mistake in the other direction would
have called a real handle an address.
*How it surfaced:* while reading `peutil.py`'s import walk to build the slot inventory. The reader
returns the table's entries as they are in the file, which is what made "below the base" visibly
ambiguous rather than obviously a handle.
*Fix and check:* the classes are positions (`zero`, `below_image`, `in_image`, `above_image`) and the
verdict follows from the pairing rather than from a class. The regression is
`tests/unit/test_iat_callsite_restore.py::test_a_clean_image_reports_no_pairs`, which asserts
`no-pairs` on a generated unbound image — the case the old rule reported as `needs-trace`. The
reference states the correction in prose, because the same inference is easy to repeat by hand.
## Gate, harness and lint defects
**F11. The hard index-row limit was computed and then unable to fail anything.**