Skip to content

Analysis-tier: PowerPC64 PLT import-name recovery - #22

Merged
mahaloz merged 2 commits into
mainfrom
ppc64-plt
Jun 24, 2026
Merged

mahaloz merged 2 commits into
mainfrom
ppc64-plt

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Recover PPC64 ELFv2 (little-endian) libc import names so a call renders puts/printf, not sub_<addr>. PowerPC was listed in docs/missing-analyses.md §1 as a documented seam — but, like SPARC (PR #20), investigating the real layout shows it is fully tractable at the static load tier. This is a clean port, not a documented seam.

Why it looked like a seam (and why it isn't)

On PPC64 ELFv2 there is no .plt code section: readelf -S shows .plt as NOBITS (the runtime GOT for imports). The linker synthesizes the call stubs inline in .text. main bls to a stub of the canonical ELFv2 shape:

    std   r2,24(r1)         ; save caller TOC
    addis r12,r2,off@ha     ; r12 = TOC_base + (off@ha << 16)
    ld    r12,off@l(r12)    ; r12 = *(.plt slot) = *(TOC + (off@ha<<16) + off@l)
    mtctr r12
    bctr

The loaded .plt slot is named by an R_PPC64_JMP_SLOT reloc — the same got_slot → name map the existing decoder already builds. The one extra piece is the TOC base, which ELFv2 fixes at .got vma + 0x8000 (the .TOC. symbol); using that invariant avoids any .TOC. lookup.

What changed (elf_plt.rs)

A PowerPC arm after the .plt*-section scan: decode_ppc_text computes the TOC base (.got + 0x8000), reads .text, and decode_ppc64_stubs scans for the 5-instruction stub (std r2,24(r1); addis r12,r2; DS-form ld r12,(r12); mtctr r12; bctr), reconstructs the slot, and records the stub entry (the std r2,24(r1) — what bl targets) against the matched name. Words are read honoring file endianness so a future PPC32/BE arm can slot in; gated on PowerPc64, no-ops cleanly on every other arch. The .symtab synthetic .plt_call.* symbols are SymbolKind::Unknown (not Text), so the loader's symtab pass skips them — leaving the stub addresses free for the clean names (no collision).

BEFORE → AFTER

kuna decompile plt_ppc64le main:

// BEFORE
sub_680(v1 + 0x17c);
sub_660(v2 + -0x274c0,(int8)a0);

// AFTER
puts((char *)(v1 + 0x17c));
printf((char *)(v2 + -0x274c0),(int8)a0);

(BEFORE verified by stashing the decoder arm and rebuilding.)

Tests

  • elf_plt::tests::ppc64_plt_decode — LE real-fixture stub bytes + a BE word-layout case.
  • kuna-console/tests/verify_ppc64_plt.rs — e2e: auto-detect PowerPC:LE:64:default → bootstrap_from_elf → load function main → decompile → print C, asserting puts(/printf( named and sub_680/sub_660 gone. Ran a real decode (not skipped) — the ppc_64_le.sla is built; the specs-absent skip guard was not hit.
  • New fixture plt_ppc64le (linked dynamic PPC64le ELFv2 PIE, powerpc64le-linux-gnu-gcc -O0 + libc6-dev-ppc64el-cross in-container) + source + README provenance.

Gates

  • make test — 675/675 assertions, PARITY OK
  • make test-stages — 158/158 assertions, PARITY OK
  • make rust-test — green (incl. the new unit + e2e)

Notes

elf_plt.rs is also touched by the open SPARC PR #20 and the MIPS PLT branch — a trivial merge conflict on the distinct per-arch arms is expected and fine.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

mahaloz and others added 2 commits June 23, 2026 18:49
PPC64 ELFv2 (little-endian) was grouped in docs/missing-analyses.md §1 as a
"documented seam" — ELFv2 has no `.plt` *code* section (`.plt` is a NOBITS data
table, the runtime GOT for imports) and the linker synthesizes the call stubs
inline in `.text`. Investigating the real layout (like SPARC, PR #20) shows it
is fully tractable at the static load tier: a clean port, not a seam.

Each `.text` stub is the canonical ELFv2 veneer

    std   r2,24(r1)
    addis r12,r2,off@ha
    ld    r12,off@l(r12)
    mtctr r12
    bctr

loading a `.plt` slot `TOC_base + (off@ha << 16) + off@l`, where the ELFv2 TOC
base is `.got` vma + 0x8000. That slot is named by an `R_PPC64_JMP_SLOT` reloc
— the same `got_slot → name` map `build_got_name_map` already builds. Added a
PowerPC arm to elf_plt.rs (`decode_ppc_text` / `decode_ppc64_stubs`): after the
`.plt*`-section scan, it computes the TOC base, scans `.text` for the
5-instruction stub, reconstructs the slot, and records the stub entry (the
`std r2,24(r1)` — the `bl` target) against the matched name. Words are read
honoring file endianness so a PPC32/BE arm can slot in later; gated on
PowerPc64. No-ops cleanly on every other arch.

The `.symtab` carries synthetic `.plt_call.*` symbols at the stub addresses,
but `object` classifies them SymbolKind::Unknown (not Text), so the loader's
symtab pass skips them — leaving the stub addresses free for the clean
puts/printf names. No collision.

BEFORE → AFTER (kuna decompile plt_ppc64le main):
  before:  sub_680(v1 + 0x17c);          sub_660(v2 + -0x274c0,(int8)a0);
  after:   puts((char *)(v1 + 0x17c));   printf((char *)(v2 + -0x274c0),(int8)a0);

Fixture: plt_ppc64le (linked dynamic PPC64le ELFv2 PIE, built in-container with
powerpc64le-linux-gnu-gcc -O0 + libc6-dev-ppc64el-cross). Tests:
- elf_plt::tests::ppc64_plt_decode (LE real-fixture bytes + a BE word-layout case)
- kuna-console/tests/verify_ppc64_plt.rs (e2e, real decode, not skipped)

Docs: analysis-port-log Increment 26, plt-got work-list row, missing-analyses
§1 PPC note (now resolved), fixtures/README provenance.

Gates: make test 675/675 PARITY OK; make test-stages 158/158 PARITY OK;
make rust-test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
@mahaloz
mahaloz merged commit b6101b0 into main Jun 24, 2026
@mahaloz
mahaloz deleted the ppc64-plt branch July 29, 2026 08:01
mahaloz added a commit that referenced this pull request Sep 27, 2026
…_tab_column): stage #21/#22 and the round trip pin its integer return; stages baseline +2 keys (1438)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01V6bguCkPS65cu9ejj1fbpy
mahaloz added a commit that referenced this pull request Oct 2, 2026
…'s earlier value is used after it

Keeping the store COPY at the binary's position while the global's earlier
value is still read after it made Merge copy that earlier value out where it
is defined (the entry, a call, a loop head), above a pointer store the binary
reads the global after.  The decline now checks for such a read first, through
the copies a later propagation can fold, and leaves the store to upstream.

Witnesses w_ohoist (gcc -O2), w_oif (gcc -O0, clang -O2) and w_oloop (gcc -O0)
added to the globalstore fixtures; stage assertions #22-#24.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…'s earlier value is used after it

Keeping the store COPY at the binary's position while the global's earlier
value is still read after it made Merge copy that earlier value out where it
is defined (the entry, a call, a loop head), above a pointer store the binary
reads the global after.  The decline now checks for such a read first, through
the copies a later propagation can fold, and leaves the store to upstream.

Witnesses w_ohoist (gcc -O2), w_oif (gcc -O0, clang -O2) and w_oloop (gcc -O0)
added to the globalstore fixtures; stage assertions #22-#24.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 2, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 3, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 3, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 3, 2026
…y literal or flag

An int range or overflow check leaves the sum or difference it tested in
the second return register whatever it returns: `return 34` or `return 0`
after `addcc; addxcc; cmp; bne` on SPARC, `neg 3,3` of `cntlzw; srwi 5`
on PowerPC, ARM's `adcs r0,r0,#0; movne r0,#22`. A low-word sum or
difference (`0 - x` included) whose carry or borrow reaches a branch or
the first register is now a comparison's leftover when the first register
is worked out from comparisons and literals alone and the sum's own carry
is not one of them; a choice's input its edge's branch tested equal to a
literal counts as that literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz added a commit that referenced this pull request Oct 17, 2026
mahaloz added a commit that referenced this pull request Oct 17, 2026
mahaloz added a commit that referenced this pull request Oct 17, 2026
mahaloz added a commit to borancar/kuna that referenced this pull request Nov 14, 2026
Keep Noelo-Lab#1575's calleereginputs header, row and spec text, with the
virtual-dispatch paragraph after them; move the vcall passes to the
file's off/default form as Noelo-Lab#18-Noelo-Lab#22; options.md and phase_catalog.json
from main (regenerated after the build); synthesize baseline-stages.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
mahaloz added a commit that referenced this pull request Nov 21, 2026
…nother native node starts

The interpreter's exit to the function's own code kept the last VPC in its
node key, so every virtual exit ran its own copy of the native epilogue: a
32-bit /GS cookie check per return path (cairuh x3 extra, newstar_backdoor).
Explorer::leaves_vm mirrors angr's CFGVMDeobfuscation._vm_mode_should_end:
a computed jump or return out of the interpreter's context, with no return
address pushed, to non-protector code that is not a handler fragment, is an
exit once the VPC register holds no virtual PC, or, for a memory-cell VPC
(Themida), once the stack depth is back where native code entered the
protector (angr's _on_vm_entry_frame).  The target is keyed with no VPC, as
angr keys post-exit blocks; stack bytes below SP (past the x86-64 red zone),
the dead VM context, are dropped there.  A jump back into the protector
after an exit is keyed by its site (angr's re-entry region tag).

Merging same-address exits alone is not enough (the w1 attempt): exits land
a few instructions apart in one straight run (blaster 0x4014c8/0x4014ce,
cairuh 0x4012c8/0x4012c9, sdl 0x18003e92a/b), and huffman's exit runs into
the pre-VM early-return path's node at 0x402303.  A node of the function's
own code outside the interpreter now ends where another such node starts,
as a disassembler splits basic blocks; a start found inside an emulated run
forces one more round.  With both, every path reaches one epilogue block,
as in the reference CFG.

Eval (r23-final -> this): huffman_ultra and newstar_backdoor_ultra become
correct structure; cairuh x2 calls 0.90 -> 1.00, skeleton 0.78 -> 0.89
(still partial on strings, a reference artifact); blaster_ultra skeleton
0.97 -> 1.00; Themida blasters skeleton +0.03.  11/15 correct, 15/15
devirtualized.  Non-devirtualized output is unchanged.

Fixture pushan_vm2_x86_64 gains f_epi (two virtual exits into the stub's
native tail, one an instruction ahead); kuna-pushan-sound #21/#22 pin one
call to fin; stage baseline re-recorded 4841 -> 4843.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQdVZFuvdNY1SVmGFY
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.

1 participant