﻿Usage: PlayStationELFConverter [--info|--elf2exe|--exe2elf] [--quiet] [--overwrite] [--japan|--na|--europe] [--text-offset TEXT_SEGMENT_FILE_OFFSET --text-address TEXT_SEGMENT_ADDRESS --text-size TEXT_SEGMENT_SIZE] [--data-offset DATA_SEGMENT_FILE_OFFSET --data-address DATA_SEGMENT_ADDRESS --data-size DATA_SEGMENT_SIZE] [--bss-offset BSS_SEGMENT_FILE_OFFSET --bss-address BSS_SEGMENT_ADDRESS --bss-size BSS_SEGMENT_SIZE] [--stack-address STACK_SEGMENT_ADDRESS --stack-size STACK_SEGMENT_SIZE] INPUT_FILE (OUTPUT_FILE)

Examples:

PlayStationELFConverter --info SLPS_123.45

PlayStationELFConverter --elf2exe --europe slps_123 PSX.EXE

PlayStationELFConverter --exe2elf PSX.EXE slps_123

Options:
  --info
    Display ELF or PSX-EXE header information for the input file

  --elf2exe
	Convert a 32-bit, little-endian MIPS ELF binary to a PSX-EXE format binary

  --exe2elf
	Convert a PSX-EXE binary to 32-bit, little-endian MIPS ELF format binary

  --quiet
    (Optional)
	When performing conversions, do not display any console output

  --overwrite
    (Optional)
    When performing conversions, overwrite the output file if it already 
	exists

  --overlay "[ID],[OFFSET],[LENGTH],[SOURCE_FILE](,[START_OFFSET],[LENGTH])"
    In EXE-to-ELF mode, include the specified PsyQ overlay during processing.
	May be specified multiple times, as long as none of the overlays 
	have overlapping address space in memory.
	If the optional START_OFFSET and LENGTH values are omitted, the entire 
	content of the source file will be used to populate the overlay segment.

  --japan
    in ELF-to-EXE mode, writes the Japanese region license string to the file

  --na
    in ELF-to-EXE mode, writes the North American region license string to the
	file

  --europe
    in ELF-to-EXE mode, writes the European region license string to the file

  --text-offset, --data-offset, --bss-offset
	(Optional)
	When converting to ELF format, manually specify the offset in the PSX-EXE
	file of the text, data, and/or bss segments. See below.

  --text-address, --data-address, --bss-address
	(Optional)
	When converting to ELF format, manually specify the memory address
	of the text, data, and/or bss segments. See below.

  --stack-address
	(Optional)
	When converting to PSX-EXE format, manually specify the memory address 
	value for the stack segment instead of using the default (0x801FFFF0). Not 
	recommended. See below.

  --text-size, --data-size, --bss-size
	(Optional)
	When converting to ELF format, manually specify the size
	of the text, data, and/or bss segments. See below.

  --stack-size
	(Optional)
	When converting to PSX-EXE format, manually specify the size of the stack 
	segment instead of using the default (0x801FFFF0). Not recommended.  See 
	below.



Notes:

One of --info, --elf2exe, or --exe2elf must be specified.

In --info mode, one filename must also be specified.

In --elf2exe or --exe2elf modes, two filenames (the input and output files) must be specified. The output file cannot be the same as the input file.

In --elf2exe mode, one of the region options must be specified.

The PSX-EXE header includes fields which can contain memory addresses and sizes for four segments:

	* text
	* data
	* bss
	* stack

However, in the most commonly-encountered variant of the format, the data and bss fields are left set to all zeroes, the text segment fields are used to represent the entire program content stored in the binary, and the stack segment fields are always set to an offset of 0x801FFFF0 with a size of zero. In other words, a typical PSX-EXE file has all of the logical segments from the original ELF aggregated into a single segment of type "text", and the distinction between text, data, and bss is lost.

When converting a PSX-EXE file back to ELF format, if the actual offsets (in the PSX-EXE file), addresses, and sizes are known for the text, data, and bss segments (e.g. from debug symbol files), they may be specified using the corresponding options in order to produce a more accurate ELF for reverse-engineering. If these values are not specified, then the text segment address and size will be parsed from the PSX-EXE, and all binary data from the PSX-EXE will be placed in that single segment in the resulting ELF file. The Data and BSS segments will be defined in the ELF, but will have lengths of zero. This should be fine in most cases. 

Unlike an ELF file, 

Setting the stack segment address and size manually are not recommended, as these values are essentially fixed for the PlayStation, and the values in the PSX-EXE itself do not actually represent the values used by the console. The parameters are included for unusual circumstances.



Thank You / References:

LameGuy64's elf2x utility: http://www.psxdev.net/forum/viewtopic.php?f=75&t=1613

si17911@ci.uminho.pt : http://www.emulatronia.com/doctec/consolas/psx/exeheader.txt

