Skip to content

[AUTOMATED] feat(analysis): libctypes on by default - #658

Merged
mahaloz merged 11 commits into
mainfrom
feat/libctypes-on
Sep 17, 2026
Merged

mahaloz merged 11 commits into
mainfrom
feat/libctypes-on

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The problem

A parameter that a libc function's own declaration names — a FILE *, a
stat *, a dirent * — comes out as void * or long unless you know to ask
for it. On a fixture in this repo:

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/stripped_dynamic_x86_64 sub_1249
void * sub_1249(void *a0) // early-return x3
{
  void *v1; // rax

  v1 = malloc(0x40);
  if (!v1) {
    perror("malloc failed");
    fclose(a0);
    return NULL;
  }
  if (fread(v1,0x40,1,a0) != 1) {

a0 goes to fread and fclose and nowhere else. The table already knows what
that is — int fclose(FILE *) is a declaration, not an inference — and says so
under --option libctypes opaque, which this makes the default:
void * sub_1249(FILE *a0).

The fix

  • libctypes defaults to opaque: the gate's unset-env case and
    reset_defaults_internal both move, mirroring the sibling dwarfstructs
    bridge (only an explicit off-token disables).
  • --option libctypes off still restores the shipped void * tables, verified
    byte-identical to a binary built from main over nine whole binaries.
  • tests/stages/kuna-libctypes.xml now restores opaque, not off, in its last
    command — the gate is a process environment variable and the stage corpus runs
    in one process, so the old restore would have disabled the table for every test
    after it.
  • The two kuna-cli env bridges pass the option's token through rather than
    matching on-tokens, so they agree with the gate reader and with the
    dwarfstructs/typedepth siblings. Inert today — the value validator rejects
    anything but off|opaque — but it is the site a later layout value would trip.
  • Two expectations pinned the old spelling and move with the default: the
    phase-catalog byte fixture (that row's default), and the ghidra-sim faillog
    line count, where one void * doing two jobs in faillog's main — the
    getpwent result and the stream ferror/fflush takes — splits into
    passwd * and FILE *.

The tests

make test 675/675 PARITY OK — but 0 of 83 datatests open a file, so that corpus
cannot see this tier either way. make test-stages 1038/1038 PARITY OK and a
re-recorded baseline byte-identical to the tree's: no assertion moved, and
replaying all 16 load file fixtures in both arms leaves 15 byte-identical.
make test-cli 178/178, with changing-namestyle-invalidates-discovered now
pinning sub_1249(FILE *param_1) — that parameter goes to fread and fclose
and nothing else, and param_1 rather than a0 is still what proves the naming
style applied.

decbench type_match, 444 slices / 10,748 functions: perfect 889 → 959, 720
improved, 0 moved off perfect, 1 worsened. Whole-binary decompile-all over
4,301 functions: none lost or gained, call targets identical in every one,
PTRSUB( 0 in both arms. Declarations go down 17,183 → 17,039 and piece
accessors (vN._off_size_) up 1,017 → 1,275: a stat * argument names the
on-stack object the call fills, so 88 scattered slots collapse into the
aggregate they were (offsets verified exact). Worst interleaved min-of-15 speed
delta +1.64% against a 5% budget. Every number, the one worsened function and
the costs included, is in docs/features/libctypes/flip.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29

mahaloz and others added 2 commits September 17, 2026 03:56
The named libc/POSIX aggregate pointers in the built-in prototype tables
(FILE *, stat *, dirent *, option *, ...) shipped behind a default-off
gate. Flip the default to `opaque`: the gate's unset-env case and
`reset_defaults_internal` both move, mirroring the sibling `dwarfstructs`
bridge (only an explicit off-token disables).

`--option libctypes off` still restores the shipped `void *` tables -
verified byte-identical to a binary built from main over eight whole
binaries.

Two expectations in the tree pinned the old spelling and move with it:
the phase-catalog byte fixture (the row's `default`), and the ghidra-sim
faillog line pin, where one `void *` doing two jobs in that fixture's
main splits into `passwd *` and `FILE *`.

The evidence for the default - typesweep over 444 slices, the
whole-binary hunk classification, the stage-corpus replay - is in
docs/features/libctypes/flip.md and record.json.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Sep 17, 2026
mahaloz and others added 9 commits September 17, 2026 04:15
…env bridge

The two kuna-cli bridges kept the on-token polarity from when the option was
default-off, so any token that is not `opaque`/`on`/`1`/`true` mapped to
`off` — the opposite of the gate reader and of the sibling dwarfstructs and
typedepth bridges. Unreachable today (the value validator rejects anything
but off|opaque) but it is the site a later layout value would trip.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
… sweep moves

The spec paragraph and the catalog's use_when overstated the flip in three
places the feature's own record already contradicted: one function does score
worse, the sweep does move numeric literals (a constant offset is absorbed into
the field name it selects) and it does change control flow in three PLT thunks
that gain a return, and the stage corpus is not blind to the row —
tests/stages/kuna-libctypes.xml pins it in both arms. The export's +58 cc errors
are split 51 shells / 7 name clash, not "all from that".

Adds the missing by-value row to flip.md: named aggregate LOCALS 0 -> 88 over
the nine sweep binaries, with gzip 0xea40's st_atim/st_mtim offsets as proof the
collapse lands exactly, and the scanner that counts them.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
… datatests

The gate note read as if every XML corpus were blind to the row. Only the 675
datatests are: 16 of the 217 stage fixtures load a file and one of them pins
this option in both arms.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
…, not by one example

58 of the 88 named by-value locals are read back through vN._off_size_, and none
of those reads lands past the shell's declared size — the check that the offsets
were preserved rather than reinterpreted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
… default

plan.md and analysis.md still describe the option as it shipped (default off);
say so at the top so neither reads as the current default.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
@mahaloz
mahaloz merged commit 12c3146 into main Sep 17, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/libctypes-on branch September 17, 2026 06:07
mahaloz added a commit that referenced this pull request Sep 17, 2026
…n the census

`libctypes` is default-on since #658 and types a `FILE *` parameter with a
named composite, so `kind == struct` alone counted 289 parameters structsynth
never touched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
mahaloz added a commit that referenced this pull request Sep 17, 2026
…e rebase

`libctypes` is on by default since #658 and names the nine `FILE *` parameters
the earlier census counted, so every number the proposal turns on moves:

- false-positive census 301 -> 292, `_IO_FILE` 9 -> 0, one ordinary false
  positive unchanged (`ls` `strmode`)
- layout precision 762/846 = 0.901 -> 704/787 = 0.894; the nine carried 59
  claimed fields of which 58 matched, so declining them costs 0.006
- `type_match` 1760.25 -> 1759.34 on the raised baseline, same four rows
- TRex Fig.6 and IsCStruct re-run rather than quoted from the first round:
  up on all eight binaries, +109 net, `ls` O2 the one regression

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
mahaloz added a commit that referenced this pull request Sep 17, 2026
…references of a pointer parameter (structsynth)

A new P5 action (`p5_types/kuna_structsynth.rs`) collects the constant-offset
loads and stores made through a pointer parameter, prunes them to a layout a C
compiler reproduces byte for byte, and type-locks the parameter to the
synthesized `struct_N *`.  Behind `--option structsynth off|param`.

Rebased onto origin/main (foldcallretphi #654, ptrfromuse #659, libctypes
default-on #658); counters re-derived on the rebased tree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
mahaloz added a commit that referenced this pull request Sep 17, 2026
…references of a pointer parameter (structsynth)

A new P5 action (`p5_types/kuna_structsynth.rs`) collects the constant-offset
loads and stores made through a pointer parameter, prunes them to a layout a C
compiler reproduces byte for byte, and type-locks the parameter to the
synthesized `struct_N *`.  Behind `--option structsynth off|param`.

Rebased onto origin/main (foldcallretphi #654, ptrfromuse #659, libctypes
default-on #658); counters re-derived on the rebased tree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
mahaloz added a commit that referenced this pull request Sep 17, 2026
…references of a pointer parameter (structsynth)

A new P5 action (`p5_types/kuna_structsynth.rs`) collects the constant-offset
loads and stores made through a pointer parameter, prunes them to a layout a C
compiler reproduces byte for byte, and type-locks the parameter to the
synthesized `struct_N *`.  Behind `--option structsynth off|param`.

Rebased onto origin/main (foldcallretphi #654, ptrfromuse #659, libctypes
default-on #658); counters re-derived on the rebased tree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
mahaloz added a commit that referenced this pull request Sep 17, 2026
…references of a pointer parameter (structsynth)

A new P5 action (`p5_types/kuna_structsynth.rs`) collects the constant-offset
loads and stores made through a pointer parameter, prunes them to a layout a C
compiler reproduces byte for byte, and type-locks the parameter to the
synthesized `struct_N *`.  Behind `--option structsynth off|param`.

Rebased onto origin/main (foldcallretphi #654, ptrfromuse #659, libctypes
default-on #658); counters re-derived on the rebased tree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant