Skip to content

[AUTOMATED] Go: recover function names from moduledata when the pclntab magic is wiped - #1665

Merged
mahaloz merged 6 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/go-pclntab-wiped-magic
Nov 19, 2026
Merged

mahaloz merged 6 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/go-pclntab-wiped-magic

Conversation

@coleleavitt

Copy link
Copy Markdown
Contributor

[AUTOMATED]

A Go binary whose pcHeader magic has been overwritten (packers and obfuscators do this and leave the table intact) loses every function name: 198 sub_* functions instead of 1,939, and no main.main.

mkdir goh && cd goh && go mod init goh
printf 'package main\nimport "fmt"\nfunc main() { fmt.Println("hi") }\n' > main.go
CGO_ENABLED=0 go build -ldflags=-s -o hello .      # go1.26.2
off=$(objdump -h hello | awk '$2==".gopclntab"{print strtonum("0x"$6)}')
cp hello hello.wiped && printf '\0\0\0\0' | dd of=hello.wiped bs=1 seek=$off conv=notrunc
kuna functions hello | grep -c .;        kuna functions hello | grep main.main
kuna functions hello.wiped | grep -c .;  kuna functions hello.wiped | grep main.main
1939
0x49df80	main.main
198

With this change the last two commands print 1939 and 0x49df80 main.main, and kuna decompile-all of the two files is byte-identical.

The fix

  • When no magic matches a table the image names, the pclntab pass finds runtime.firstmoduledata by its shape (new pclntab/kuna_gomoduledata.rs) and reads the table from that record alone: name table, functab, _func base, function count and text base. The header is not consulted, so a header wiped whole reads the same.
  • A record is accepted only when its slices and PC bounds agree and the functab bears them out: first entry minpc, closing entry maxpc. That test also picks the entry shape (go1.18+ offsets, go1.16/1.17 pointers); the go1.5–go1.15 record is handled too.
  • Section names and kinds are not used, so a renamed .gopclntab / .go.module and a PE (table in .rdata) work. PE Go detection counts such a table.
  • locate_header still returns the header address, so the Go type harvest works on a wiped image unchanged.
  • No option: the search runs only after every magic-based route fails, on Go images only. An intact binary takes the same path as before: kuna functions hello costs 153 ms of CPU against 163 ms before (dev build, within noise). The wiped binary costs about 10 ms more for the record search.

Tests

  • verify_go_pclntab::wiped_pclntab_magic_recovers_the_same_functions builds Go programs for linux/amd64, windows/amd64, darwin/arm64 and linux/386, zeroes the magic, and requires the inventory (address, name, size) to equal the unmodified binary's. It fails without the fix.
  • Unit tests over hand-built go1.18, go1.16 and go1.2 tables with the header zeroed, a record whose bounds the functab contradicts (rejected), and a PE that must still be detected as Go.
  • Also checked by hand on go1.12, 1.15, 1.16, 1.17, 1.20, 1.21, 1.23 and 1.26 builds, a PIE, and big-endian linux/mips: wiped and intact inventories are identical.

Fixes #1638

coleleavitt and others added 6 commits November 18, 2026 15:11
A Go binary whose pcHeader magic has been overwritten lost every function
name: no magic-based route found the table, so a go1.26 hello-world listed
198 sub_* functions instead of 1,939 and had no main.main.

When no magic matches a table the image names, the pclntab pass now finds
runtime.firstmoduledata by its shape and reads the table from that record
alone (name table, functab, _func base, function count, text base). A record
is accepted only when its slices and PC bounds agree and the functab bears
them out: its first entry is minpc and its closing entry is maxpc. That test
also selects the functab entry shape (go1.18+ offsets, go1.16/1.17 pointers);
the go1.5-go1.15 record is read too. Section names and kinds are not used, so
a renamed .gopclntab and a PE work, and PE Go detection counts such a table.
locate_header still returns the header address, which the Go type harvest
anchors on.

The search runs only after every magic-based route has failed, on Go images
only, so it ships with no option.

Fixes Noelo-Lab#1638
…r more bytes

Funcdata::find_subpiece_shadow shifted a constant's 64-bit offset right by least_byte * 8. For a 16-byte constant tested at byte offset 8 that is a shift by 64: a panic in a build with overflow checks, a wrapped shift count otherwise. _dl_relocate_object in the mcount_x86_64 fixture failed to decompile in a dev build because of it.

A constant wider than 8 bytes holds zero above bit 63, so the truncation now reads 0 there. Shifts below 64 are unchanged.

Fixes Noelo-Lab#1674
…d profile

The gh1674 stage test only fails without the fix in a build with overflow
checks: a release build wraps the shift count, and for the constant 0 the
wrapped shift reads the same 0. The unit test calls
varnode_partial_copy_shadow on 16-byte constants directly, so it fails
on the unfixed code under the test profile (the overflow panic) and also
with a wrapping shift (an 8-byte piece at offset 8 of the 16-byte
constant 0x1234 is not 0x1234).

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

# Conflicts:
#	decompiler/crates/kuna-base/src/xml.rs
#	docs/baseline-stages.json
Main (Noelo-Lab#1701) split recover_go_table into recover_go_header, which the pass
now calls directly; the moduledata fallback for a wiped magic moves into
recover_go_header so both callers keep it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
@mahaloz
mahaloz merged commit 9fe4850 into Noelo-Lab:main Nov 19, 2026
2 checks passed
@coleleavitt
coleleavitt deleted the fix/go-pclntab-wiped-magic 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] Go: function names are lost when the pclntab magic is wiped

2 participants