Files
ppsspp/headless/ReverseEngineer.h
Henrik RydgårdandClaude Opus 5.5 edef36d97e Load game patches installed on a PSP, given its Fuse ID
- Fixes #12343

Killzone: Liberation's Chapter 5 DLC is an installer that the PSP turns
into ms0:/PSP/GAME/<id>/KZL.PRX, which the game loads with
sceKernelLoadModuleDNAS. That file is a PGD around a type 3 PRX (decrypt
mode 18), both keyed to the console that installed it. Its Fuse ID
gives everything needed:

- libkirk: the per-console key derivation, and KIRK commands 3, 5 and 8
  built on it (KIRK ROM per uofw, key mesh per psdevwiki).
- PrxDecrypter: type 3, which is type 5 with the first step through
  KIRK command 3 (JPCSP's PRX.java), and the DNAS PGD unwrap.
- sceKernelLoadModuleDNAS uses the new FuseID setting (or --fuse-id).
  Without one, or with the wrong one, the game falls back to its stock
  module and an OSD message says why.
- Headless --re-decrypt takes --re-decrypt-key and --fuse-id, to decrypt
  such a file offline.

Verified with a patch installed on a real PSP: the v1.20 module loads,
starts and reads CHAPTER5.BIN. Type 5 output is unchanged (an NPJH50521
PBOOT.PBP decrypts byte-identically). How to install one over PSPLink is
in docs/dnas-patches.md.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-14 18:10:08 +02:00

59 lines
2.7 KiB
C++

// Copyright (c) 2026- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include <string>
#include "Common/CommonTypes.h"
struct ReverseEngineerOptions {
// PRX/ELF to load. Can be either a host path or a PSP path like "flash0:/kd/libmp3.prx",
// resolved against the configured NAND directory, or even something like
// "disc0:/PSP_GAME/USRDIR/MODULES/LIBDEFLT.PRX", read out of the
// disc image named as the positional argument.
std::string modulePath;
// The disc image that a "disc0:" modulePath is read from.
std::string discPath;
// Where to write the report. Created if missing.
std::string outDir;
// If set, only this function is disassembled (by name, or "0x08801234").
std::string funcFilter;
// Optional .syms file applied before dumping, so names show up in every caller.
std::string symsFile;
// If non-zero, modulePath is a flat code image rather than a PRX: it's copied to this
// address and scanned directly, with no loader, no relocation and no imports/exports.
u32 rawBase = 0;
bool verbose = false;
};
// Loads a module standalone (no game), analyzes it, and writes a report. Returns a process
// exit code.
int RunReverseEngineer(const ReverseEngineerOptions &opts);
// Decrypts one encrypted PSP file and writes the plaintext, without loading anything.
// Handles any container pspDecryptPRX() knows a tag for - including the ME images in
// flash0:/kd/resource, which are ordinary tagged containers with the signature blanked, so the
// normal module loader won't touch them. A game patch installed on a PSP (a PGD around a type 3
// PRX) also needs the secure install ID the game loads it with and that PSP's Fuse ID, as hex.
// Returns a process exit code.
int RunDecryptFile(const std::string &inPath, const std::string &outPath, const std::string &secureIdHex = "", const std::string &fuseIdHex = "");
// Copies one file out of a disc image (ISO/CSO/...) as-is, e.g. "disc0:/PSP_GAME/USRDIR/MOVIE.PMF".
// Returns a process exit code.
int RunDumpDiscFile(const std::string &discPath, const std::string &inPath, const std::string &outPath);