Skip to content

Convert sfo.py and pkg.py to pure C#162

Merged
bucanero merged 13 commits into
ps3dev:masterfrom
bucanero:sfo-pkg-py-to-c
Jun 8, 2026
Merged

Convert sfo.py and pkg.py to pure C#162
bucanero merged 13 commits into
ps3dev:masterfrom
bucanero:sfo-pkg-py-to-c

Conversation

@bucanero

@bucanero bucanero commented Jun 7, 2026

Copy link
Copy Markdown

Replaces the Python sfo.py and pkg.py PS3 toolchain utilities with standalone C implementations that produce identical output and accept the same CLI parameters. Eliminates the Python runtime dependency for SDK builds.

New files

  • tools/ps3py/sfo.c — SFO create/inspect/XML-roundtrip (--fromxml, --toxml, -l, --title, --appid, -d, -p)
  • tools/ps3py/pkg.c — PKG pack/list/extract (-c, -l, -x, -d); implements big-endian PKG format, SHA1 QA digest, stream-cipher encryption, and NPDRM SELF header injection
  • tools/ps3py/sha1.c / sha1.h — SHA1 implementation carried over from the fself tool

Modified files

  • tools/ps3py/Makefile — adds sfo and pkg build targets; install deploys C binaries instead of Python scripts
  • ppu_rulesSFO := sfo.pySFO := sfo, PKG := pkg.pyPKG := pkg

Bugs fixed vs. the Python originals

  • Double-slash path construction (collect_dir): snprintf("%s/%s", folder, name) with a trailing-slash folder (as ppu_rules passes) produced folder//name, giving all filenames a leading /. This broke USRDIR/EBOOT.BIN NPDRM SELF detection and caused incorrect 32-byte name alignment for that entry instead of 16.
  • Print-after-free (pack_pkg): Package Size and Data Size in stdout output always printed 0 because buf.size was read after dynbuf_free().

bucanero and others added 13 commits August 2, 2020 20:38
* Add SYSUTIL_LANG_* values to sysutil.h (ps3dev#130)

* Update sysutil.h

Add language return values for SYSUTIL_SYSTEMPARAM_ID_LANG

* Fix sysAtomicSwap and sysAtomic64Swap macros

Co-authored-by: OsirizX <osirisx99@gmail.com>
* Fix collect_dir double-slash bug, buf.size print-after-free, and remove dead code

* Fix typos in sha1.h and version strings in sfo.c/pkg.c

* Update sfo.c

* Update pkg.c

* move files

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Damián Parrino <bucanero@users.noreply.github.com>
@bucanero bucanero requested a review from TheMrIron2 June 7, 2026 22:31
@bucanero

bucanero commented Jun 7, 2026

Copy link
Copy Markdown
Author

Tested and both tools provide the same output as the original python scripts.

pkg packing example:

pkg.py --contentid=UP0001-NP0APOLLO_00-0000000000000000 testapp/ out.pkg
[X] Magic: 7f504b47
[X] Type: 00000001
[X] Offset to package info: 000000c0
[ ] unk1: 00000005
[X] Head Size: 00000080
[X] Item Count: 00000008
[X] Package Size: 00000000005973d0
[X] Data Offset: 0000000000000140
[X] Data Size: 0000000000597230
[X] ContentID: 'UP0001-NP0APOLLO_00-0000000000000000'
[X] QA_Digest: 9E8B76E5F357FFB66B2C8A5B81ECE1F8
[X] K Licensee: 00000000000000000000000000000000

output from pkg C tool:

pkg --contentid=UP0001-NP0APOLLO_00-0000000000000000 testapp/ out.pkg
[X] Magic: 7f504b47
[X] Type: 00000001
[X] Offset to package info: 000000c0
[ ] unk1: 00000005
[X] Head Size: 00000080
[X] Item Count: 00000008
[X] Package Size: 00000000005973d0
[X] Data Offset: 0000000000000140
[X] Data Size: 0000000000597230
[X] ContentID: 'UP0001-NP0APOLLO_00-0000000000000000'
[X] QA_Digest: 9E8B76E5F357FFB66B2C8A5B81ECE1F8
[X] K Licensee: 00000000000000000000000000000000

@bucanero bucanero merged commit 73e34af into ps3dev:master Jun 8, 2026
@bucanero bucanero deleted the sfo-pkg-py-to-c branch June 8, 2026 20:00
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.

3 participants