Files
PS2Recomp/ps2xAnalyzer
Ranieri 93e221feaa Feature/runtime ecosystem refactor (#107)
* feat: remove memory and pad from stub section

* feat: add support for resume entry targets in CodeGenerator (this allow jumps in address outside function)
feat: refactor entry point discovery one more try to reduce big generated file

* feat: optmizations for release build

* feat: remove unused  file

* feat: added some test cases for code gen

* feat: added log macro and remove win specific code

* feat: refactor runtime folder structure
feat: added reset sound driver RPC state and compatibility layout
feat: rename and added new test
feat: update RPC calls to use defined constants
feat: added more PSMC(16, 32)
feat: change cd read to try find the asset ignoring case sensitive
fix: fix some render problems
feat: add logs on pad
feat: added more RPC handles

* feat: added game override for code veronica

* feat: apply vita patch

* feat: flags to disable build

* feat: fix merges
feat: break a lot of tests

* feat: better throw error on empty cd path
feat: remove recompiler unusde function
feat: apply missing patch

* feat: gamedp is now part of lib
feat: missing file

* feat: small cleanup

* feat: missing vita changes

* feat: fix more merge

* feat: fix tests

* feat: last missing feature

* feat: added missing import

* feat: rename test local functions

* feat: init syscall on ps2 list

* feat: added DMA helpers

* feat: faster builds
feat: more implement for darkcloud

* feat: back missing file

* feat: added missing includes

* feat: remove test

* feat: missing include

* feat: read register funtion

* feat: build  fix

* feat: force  exit on detach thread
2026-04-04 23:09:56 -03:00
..

PS2 ELF Analyzer Tool

The PS2 ELF Analyzer Tool automates the creation of TOML configuration files for the PS2Recomp static recompiler. It identifies function boundaries, library stubs, and problematic instructions.

Analysis Paths

The analyzer supports three distinct paths for discovering code within a PS2 binary:

1. DWARF Debug Information

If the ELF was compiled with debug symbols (-g), the analyzer uses libdwarf to extract perfect function names and exact start/end addresses. This is common in homebrew or early development builds.

2. Native Heuristic Scanner (Test only)

For commercial games where symbols are stripped, the analyzer uses a "JAL Scanner":

  • It scans executable sections for JAL (Jump and Link) instructions.
  • It infers function start points based on jump targets.
  • It generates names like sub_XXXXXXXX.

Use this path only as a quick fallback when you do not yet have a Ghidra project. It is not the preferred workflow for retail games.

3. Ghidra Integration (For Retail and Stripped Games, Preferred)

This is the recommended workflow for almost every commercial game:

  1. Use the provided script: ps2xRecomp/tools/ghidra/ExportPS2Functions.java.
  2. Run it in Ghidra to export a CSV map of all functions.
  3. Let the script generate the TOML, and keep the CSV path in ghidra_output = "path/to/map.csv".
  4. Run the recompiler with that exported TOML.
  5. The recompiler will prioritize Ghidra's boundaries over its own heuristics.

Key Features

  • Analyzes PS2 ELF binaries to extract symbols, functions, and structure
  • Identifies common library functions that should be stubbed
  • Flags system functions that should be skipped during recompilation
  • Detects potential instruction patterns that may need patching
  • Generates a ready-to-use TOML configuration file for PS2Recomp

Using the Analyzer

ps2_analyzer <input_elf> <output_toml>

Parameters:

  • input_elf: Path to the PS2 ELF file.
  • output_toml: Path where the generated TOML configuration will be saved.

Example Workflow

  1. Open game.elf in Ghidra.
  2. Run ps2xRecomp/tools/ghidra/ExportPS2Functions.java.
  3. Use the exported TOML and CSV.
  4. Run the recompiler: ps2recomp config.toml

Fallback:

  1. Run ps2_analyzer game.elf config.toml.
  2. Use that TOML only for quick bring-up or symbol-rich builds.

Generated Configuration

The tool creates a TOML file with the following sections:

  • [general]: Paths to ELF and Ghidra maps.
  • stubs: List of library functions to be replaced by C++ stubs.
  • skip: List of functions to be ignored (entry points, initialization).
  • [patches]: Individual instructions that need to be replaced (SYSCALLs, COP0, etc.).

Limitations

  • Heuristics may not catch all special cases in highly optimized code.
  • Self-modifying code is flagged but requires manual review.
  • Indirect jumps (jump tables) are detected but complex ones might need manual TOML entries.

For more details on the recompilation process, see the Main README.