libc: the snprintf of libSceLibcInternal.sprx prints %p as bare lowercase hex without 0x (PS5 payload process); FormatPointer prints the FreeBSD 0x form #7549
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-18T13:07:28Z.
The
snprintfoflibSceLibcInternal.sprxprints%pas bare lowercase hex, without0x(measured from a PS5 payload process)Main formats it as FreeBSD does.
LibcDetail::FormatPointerfollows FreeBSD (44f00e2be8, "format %p as FreeBSD does on Windows", from #3111 and #3393). It prints0xand the hex digits, so a null pointer comes out as0x0. That commit replaced the host CRT's zero-padded 16-digit form on Windows, and #3111 expected the FreeBSD form to be what a title sees on the console. On firmware 12.70,snprintffrom the systemlibSceLibcInternal.sprx, called from a payload process, prints neither form. Thesnprintfof a title's bundledlibc.prxwas not measured.FormatPointeris used by:%m. Otherwise Linux hands the format to glibc, as the narrow printf entry indocs/dev/debt/libc.mdsays, and glibc prints0x...or(nil). Open PR #6483 addspto the Linux selector, so after that PR a narrow%pwould print whatFormatPointerprints. Its selector still matcheslonly beforesorc, so a narrow%lpwithout a wide argument would still go to glibc.The console's
libSceLibcInternal.sprxbehaves differently. Called from a payload process on a PS5 (firmware 12.70), itssnprintfprints%pas follows:0x, even with#;0for a null pointer;+and space are ignored;-pads on the right,0pads with zeros, and a precision sets the minimum number of digits;%.0pof a null pointer prints nothing (0together with a precision or with-was not measured);llength is accepted.Its
swprintfwas checked only for%p,%10p,%-10pand%.8p, with the values 0, 0x1234 and 0xabcdef. For%pand%.8pit prints the same assnprintf.snprintfwas not run with%10por%-10p, but p23 ran it with%20pand%-20p, andswprintfpads the bare digits the same way.snprintfoflibSceLibcInternal.sprxFormatPointeronmain[%p][0][0x0][%p][1234][0x1234][%5p][ 1234][0x1234][%-5p][1234 ][0x1234][%05p][01234][0x1234][%.8p][00001234][0x00001234][%10.6p][ 001234][ 0x001234][%.0p][][0x][%#p][1234][0x1234][%+p][1234][0x1234][% p][1234][0x1234][%lp][1234]Unsupported format conversionThe
FormatPointercolumn was produced by callingLibcDetail::FormatPointerfrommain(922dc8999e) with these specs; the formatter code is the same on5bf2e139ef, apart from scanf changes inFormatting.cpp. The%lprow comes from the formatters themselves: both take%ponly with no length.Fix shape: to match the
snprintfoflibSceLibcInternal.sprxas measured,FormatPointerwould drop the0xand count only the digits towards the width. The narrow formatter would also accept%lp. The console'sswprintfwas not run with%lp, so the wide formatter would keep throwing for it until that is measured. On Linux a narrow format reaches the guest formatter only when the selector routes it, so the selector would also need to route%pand%lp. The tests inFormatting.cppandGuestWideFormatting.cppwould change with it, and so would #6483's expectations. Open PR #5303 also touches this area: itsGuestWideFormatting.cpptest pinsswprintf(u"%lp")as a failure.I have not opened a PR because this reverses a deliberate choice on main and overlaps #6483 and #5303. Whether to follow
libSceLibcInternal.sprxhere is for the maintainers to decide.Measured (the
pNN:prefix names the probe; the rest of each line is copied unchanged):Method:
snprintfandswprintfwere resolved fromlibSceLibcInternal.sprxand called through pointers.AI-assisted.