Skip to content

[AUTOMATED] Add a callproto assertion for the prototype of one call instruction - #1673

Merged
mahaloz merged 8 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/assert-callproto
Nov 19, 2026
Merged

mahaloz merged 8 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/assert-callproto

Conversation

@coleleavitt

@coleleavitt coleleavitt commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

[AUTOMATED]

--assert can state a function's signature and type a function-pointer global, but not the arguments of one call through a pointer. Here the second call through a variadic logger gains a fifth argument, the call target itself, and nothing can remove it:

extern void (*logger)(const char *, ...);
void report(int a, const char *s) { logger("%d", a); logger("%s %d %d", s, a, a + 1); }
$ clang -O2 -c vlog.c -o vlog.o && ld.lld -shared -o vlog.so vlog.o
$ kuna decompile vlog.so report --assert 'data 0x2458 void (**logger_slot)(char *fmt, ...)'
  (*logger)("%d",(unsigned long)a0);
  (**v1)("%s %d %d",a1,(unsigned long)a0,(unsigned long)(a0 + 1),*v1); // jump-as-call

With this change the call is given its own declaration (0x13b0 is the tail jump, 0x2458 the logger slot; clang/lld 22):

$ kuna decompile vlog.so report --assert 'data 0x2458 void (**logger_slot)(char *fmt, ...)' \
      --assert 'callproto report::0x13b0 void f(char *, char *, int, int)'
  (**v1)("%s %d %d",a1,a0,a0 + 1); // jump-as-call
$ kuna decompile vlog.so report --assert 'callproto 0x1395 void f(char *)'
warning: --assert "callproto 0x1395 void f(char *)" rejected: No call is made at this address

The change

  • A directive callproto [<func>::]<callsite> <C declaration>. It uses the per-call-site prototype override the engine already has (the console's override prototype), on kuna decompile and on the one in-process loop decompile-all, decompile-project and the in-browser front-end share.
  • A parameter may be followed by @<storage>, in the spelling param takes, to be read from there instead of where the calling convention puts it (int a @R8D). A @<storage> after the parameter list places the return. Parameters without one are placed by the convention around those that have one.
  • override prototype takes the same declaration and no longer needs the trailing ;.
  • An address where the function makes no call is rejected, and --assert-strict makes that exit non-zero. A tail jump treated as a call counts as a call.
  • No option: the directive states a fact for one run and does nothing when absent.

Tests

  • kuna-cli/tests/call_site_prototype.rs: the repro on both decompile surfaces prints exactly four arguments, a parameter placed with @R8 reads the target register, and a non-call address is rejected (and fails under --assert-strict).
  • tests/stages/kuna-callproto.xml: nothing stated, a stated prototype, and a placed parameter, through override prototype.
  • Parser and console-lowering unit tests for the directive and the @<storage> split.
  • With no directive, output is byte-identical to before on the repro and on a 1074-function binary, and the repro decompiles in the same time (81.0 ms against 80.4 ms, best of 30).

Fixes #1643

coleleavitt and others added 2 commits November 18, 2026 15:48
…nstruction

`--assert 'callproto [<func>::]<callsite> <C declaration>'` states the
arguments and return of the call made by one instruction. A call through a
pointer or a register has no callee symbol to carry a signature, and a
variadic callback takes different arguments at each call, so `prototype`
and `data` cannot say it. The directive goes through the per-call-site
prototype override the engine already has (the console's `override
prototype`), on both the script surface and the in-process one.

A parameter may be followed by `@<storage>` to be read from that storage
rather than the place the calling convention gives it, and a `@<storage>`
after the parameter list places the return. `override prototype` takes the
same declaration, and no longer needs the trailing `;`.

An address at which the function makes no call is rejected with `No call
is made at this address`.

Fixes Noelo-Lab#1643
… one, refuse a named convention

- calltargettype skipped every call with a locked prototype, so stating the
  prototype a call already had turned `(*(int (*)(int,int))cb)(a,b)` into the
  uncompilable `(*(void *)cb)(a,b)`. A prototype stated at the call itself
  (`override prototype` / `callproto`, not a format string's) is now typed
  from its arguments like an unlocked call, with the stated parameters'
  storage standing in for the recovered storage it does not have.
- Two callproto directives for one call both reported `applied` while only
  the later took effect; the earlier is now rejected on both surfaces.
- The override is built under the default model, so a declaration naming
  another calling convention is rejected by name instead of a syntax error.
- The fixture recipe gains -fcf-protection=full (the committed binary has
  endbr64); docs example now carries the `data` assertion its output needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz

mahaloz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two commits on top of your branch (cd355a2, e2de476):

  • A stated prototype no longer makes the call uncompilable. calltargettype skipped every call with a locked prototype, so --assert 'callproto 0x118d int f(int x, int y)' on a call kuna already printed as (*(int (*)(int,int))cb)(a1,a1 + 1) turned it into (*(void *)cb)(a1,a1 + 1). Now a prototype stated at the call (override prototype / callproto, not a format string's) types the call target with that prototype. Without a data assertion the repro prints (*(void (*)(char *,char *,int,int))*v1)("%s %d %d",a1,a0,a0 + 1).
  • Two callproto directives for one call both reported applied while only the later took effect. Now the earlier one is reported rejected on both surfaces.
  • The override is built under the default model, so a declaration naming another convention (void __thiscall f(...)) is now rejected with that reason instead of Syntax error. Naming the default one is accepted.
  • The fixture recipe gains -fcf-protection=full (the committed binary has endbr64; with it, clang/lld 21 reproduce every loaded byte). The docs/cli.md example now includes the data assertion its output needs.

Tests: three CLI cases in call_site_prototype.rs plus a unit test for the transcript reader. With no directive, output is byte-identical to main on 300 binaries (30,067 functions).

mahaloz and others added 5 commits November 19, 2026 00:00
…ed prototype

Building the type from the arguments' recovered types spelled a stated
`long f(long, long)` as `unsigned long (*)(unsigned long,unsigned long)` and a
string-literal parameter as `void *`. A call whose prototype was stated at the
call now takes its return and parameter types from that declaration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
A call-site prototype is laid out under the default model, and a
declaration naming any other convention is rejected. The check compared
names only, so on x86-64 Windows `__cdecl` and `__stdcall`, which the
compiler spec declares as aliases of the default `__fastcall`
(`<modelalias>`), were rejected with a message saying they are not the
default. A named model is now accepted when it is the default or an alias
of it with the same `this` handling (`ProtoModel::is_compatible`).

The CLI test helper passed `--assert-strict` as a directive, so the
strict-exit check passed on a usage error; it is now a flag, and the
check pins exit code 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
A prototype stated at an indirect call types the call's target so the
call stays one C can make, but a variadic statement was still skipped,
so `callproto <site> void f(char *, ...)` printed the call through
`(void *)`, which no C compiler accepts, where the unstated call had been
compilable. A stated variadic prototype now types the target with its
fixed parameters and `...` when the call passes at least those, laid out
in the storage the stated parameters were given. Calls without a stated
prototype take exactly the path they took before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
Count-only conflicts: the stage corpus count in xml.rs (main 783 + this
branch's kuna-callproto = 784) and docs/baseline-stages.json, synthesized
from both sides (main 4524 + 4 = 4528).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz

mahaloz commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two small fixes on top (1742978, 4e28ecb) and a merge of main (6758619, count-only conflicts in xml.rs and docs/baseline-stages.json):

  • A stated variadic prototype now types the call target as well. Before, --assert 'callproto report::0x13b0 void f(char *, ...)' on the fixture printed (*(void *)*v1)(...), which does not compile. Now it prints (*(void (*)(char *,...))*v1)("%s %d %d",a1,...). The same happens on a parameter target (void *a0 becomes void (*a0)(char *,...)) on x86-64, MIPS, PPC, AArch64 and RISC-V.
  • A calling-convention name that the compiler spec declares as an alias of the default is accepted. On x86-64 Windows, void *__cdecl f(...) and __stdcall were rejected with "cannot name __cdecl", even though both are <modelalias> names of the default __fastcall. Real other conventions (__thiscall on x86, MSABI on SysV) are still rejected.
  • The CLI test helper passed --assert-strict as a directive, so the strict-exit check passed on exit code 2. It now passes the flag and pins exit code 1.

With no directive, output matches main byte for byte across 702 binaries (20,887 functions): DWARF objects for six architectures, 60 i386 PEs, and Go and Rust binaries. The one exception is a function that exceeds the time budget on every build, where only the reported action differs.

Main gained callee (Noelo-Lab#1676) and format/isolate (Noelo-Lab#1679) beside callproto in
the same assertion files: every directive list, Body variant and match arm
keeps both sides, assertions.rs keeps record_rejected_callee_overrides and
record_unbound_call_prototypes whole, project.rs calls both, and
assertion_outcomes runs both restatement passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz
mahaloz merged commit 6a3a067 into Noelo-Lab:main Nov 19, 2026
2 checks passed
@coleleavitt
coleleavitt deleted the fix/assert-callproto branch November 21, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOMATED] Allow --assert to state the arguments of one call instruction

2 participants