import_audit.py: --modules fails on converted .guest.prx files (PE) #6378

Closed
opened 2026-10-15 13:40:13 +00:00 by IlCapra99 · 1 comment
IlCapra99 commented 2026-10-15 13:40:13 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by IlCapra99 on 2026-10-15T13:40:13Z.


Command

python.exe .\AnyPS5\tools\import_audit.py <registries...> --libs .\AstroBot\libs\ --modules .\AstroBot\app0\sce_module\

Result

FAIL: AstroBot\app0\sce_module\libc.prx.guest.prx: sectionless ELF needs little-endian ELF64 program headers

Cause

libc.prx.guest.prx is a PE x64 DLL (starts with MZ, 2921 named exports, import table lists only KERNEL32.dll), not an ELF. read_exports (used for --libs) dispatches on ELF/PE magic, but read_modules (used for --modules) calls elf_imports / elf_exports directly. A PE has no ELF section table, so it falls into the program-header fallback and fails the ELF64 check.

Suggested fix

In read_modules, dispatch on the magic bytes: for MZ, take exports from the existing pe_exports and report no imports (the PS5 imports of converted modules are already in their .registry.json); keep the ELF path unchanged.

I tested this only on read_modules with my libc.prx.guest.prx (2921 exports read, no errors), not on a full audit run.

 def read_modules(directories):
     imports = {}
     exports = defaultdict(set)
     for directory in directories:
         for file in directory_files(directory, "*"):
             data = file.read_bytes()
-            own = elf_imports(file, data)
-            symbols, needed = own
-            imports[file.name] = (sorted(symbols), sorted(needed))
-            for name in elf_exports(file, data):
-                exports[name].add(file.name)
+            if data[:2] == b"MZ":
+                # converted guest module (PE): its PS5 imports live in its own
+                # .registry.json, the PE import table only lists host DLLs
+                imports[file.name] = ([], [])
+                names = pe_exports(file, data)
+            else:
+                symbols, needed = elf_imports(file, data)
+                imports[file.name] = (sorted(symbols), sorted(needed))
+                names = elf_exports(file, data)
+            for name in names:
+                exports[name.split(MODULE_SUFFIX, 1)[0]].add(file.name)
     return imports, {name: sorted(files) for name, files in exports.items()}

import_audit.py

Open question

Should --modules point at the original (pre-conversion) ELF modules rather than the converted output directory? The help text says "the title's own modules", which suggests that. If so, the fix may instead be a documentation or error-message change.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5867245581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6378). Originally posted by [IlCapra99](https://github.com/IlCapra99) on 2026-10-15T13:40:13Z. --- **Command** python.exe .\AnyPS5\tools\import_audit.py <registries...> --libs .\AstroBot\libs\ --modules .\AstroBot\app0\sce_module\ **Result** FAIL: AstroBot\app0\sce_module\libc.prx.guest.prx: sectionless ELF needs little-endian ELF64 program headers **Cause** `libc.prx.guest.prx` is a PE x64 DLL (starts with `MZ`, 2921 named exports, import table lists only KERNEL32.dll), not an ELF. `read_exports` (used for `--libs`) dispatches on ELF/PE magic, but `read_modules` (used for `--modules`) calls `elf_imports` / `elf_exports` directly. A PE has no ELF section table, so it falls into the program-header fallback and fails the ELF64 check. **Suggested fix** In `read_modules`, dispatch on the magic bytes: for `MZ`, take exports from the existing `pe_exports` and report no imports (the PS5 imports of converted modules are already in their `.registry.json`); keep the ELF path unchanged. I tested this only on `read_modules` with my `libc.prx.guest.prx` (2921 exports read, no errors), not on a full audit run. ```diff def read_modules(directories): imports = {} exports = defaultdict(set) for directory in directories: for file in directory_files(directory, "*"): data = file.read_bytes() - own = elf_imports(file, data) - symbols, needed = own - imports[file.name] = (sorted(symbols), sorted(needed)) - for name in elf_exports(file, data): - exports[name].add(file.name) + if data[:2] == b"MZ": + # converted guest module (PE): its PS5 imports live in its own + # .registry.json, the PE import table only lists host DLLs + imports[file.name] = ([], []) + names = pe_exports(file, data) + else: + symbols, needed = elf_imports(file, data) + imports[file.name] = (sorted(symbols), sorted(needed)) + names = elf_exports(file, data) + for name in names: + exports[name.split(MODULE_SUFFIX, 1)[0]].add(file.name) return imports, {name: sorted(files) for name, files in exports.items()} ``` [import_audit.py](https://github.com/user-attachments/files/33495470/import_audit.py) **Open question** Should `--modules` point at the original (pre-conversion) ELF modules rather than the converted output directory? The help text says "the title's own modules", which suggests that. If so, the fix may instead be a documentation or error-message change.
MarcZX10 commented 2026-10-15 13:43:51 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T13:43:51Z.


The current --modules contract is to inspect the title's original ELF modules from source/sce_module; converted .guest.prx outputs are PE files. Their PS5 imports are already represented by the per-module registry JSON passed as positional input, so the audit should keep rejecting the PE files themselves. I opened #6382 to make the help text, error and usage docs explain that directly, with a regression test for the converted filename.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6193548285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6378#issuecomment-6193548285). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-15T13:43:51Z. --- The current `--modules` contract is to inspect the title's original ELF modules from `source/sce_module`; converted `.guest.prx` outputs are PE files. Their PS5 imports are already represented by the per-module registry JSON passed as positional input, so the audit should keep rejecting the PE files themselves. I opened #6382 to make the help text, error and usage docs explain that directly, with a regression test for the converted filename.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#6378
No description provided.