1 unstable release

0.0.1 May 15, 2020

#12 in #ps2

MIT license

6KB
117 lines

cb2util - CodeBreaker PS2 File Utility

cb2util was made to utilize different file formats of CodeBreaker PS2.

It currently supports:

  • Code saves (v7 and v8+/Day1)
  • "cheats" files (v7+)
  • PCB files (upgrades/homebrew/etc)

The features are:

  • extract (and decrypt) all cheats from code saves and "cheats" files
  • compile your own code saves and "cheats" files
  • encrypt or decrypt PCB files
  • convert PCB files into ELF files
  • check digital signature on code saves and PCB files

Installation

The easiest and fastest way to get cb2util is to download the pre-built binaries for Windows or Linux from the Downloads site.

If you want to build cb2util from source, simply run:

$ git clone --recursive git://github.com/mlafeldt/cb2util.git
$ cd cb2util/
$ make
$ make install

CMake is supported too:

$ mkdir build
$ cd build/
$ cmake ..
$ make
$ make install

In case your system lacks elf.h, you can install it this way:

$ curl https://gist.githubusercontent.com/mlafeldt/3885346/raw/elf.h | tee /usr/local/include/elf.h

Usage

As cb2util is a command-line application, you have to pass arguments to it.

Using the --help option will display the following text:

$ cb2util --help
usage: cb2util [--version] [--help] <command> [<args>]

The available commands are:
    cbc
    cheats
    pcb

Try 'cb2util help <command>' for more information.

As written above, you must specify the command to use followed by its arguments. There's one command for each of the supported file formats, e.g. cbc for code saves. To learn how a command is supposed to work, run cb2util help <command>.

Below are some notes and examples concerning the different file formats.

Code saves (v7 and v8+/Day1)

File extension: *.cbc

Code saves (also known as Day1 or CBC files) store cheat codes that can be added to your CodeBreaker's code list. While older code saves for CB v7 are only encrypted, newer files for CB v8+ and CB Day1 are digitally signed as well. The latter is the reason why you need a hacked CB in order to use code saves compiled with cb2util (search the Web for CodeBreaker RSA fix).

usage: cb2util cbc [-d[mode] | -v] <file>...
   or: cb2util cbc -7 [-d[mode]] <file>...
   or: cb2util cbc [-b <banner>] -c <infile> <outfile>...
   or: cb2util cbc -7 -c <infile> <outfile>...

    no option
        extract cheats

    -d[mode], --decrypt[=mode]
        decrypt extracted cheats
        mode can be "auto" (default) or "force"

    -v, --verify
        verify RSA signature

    -c, --compile
        compile text to CBC file

    -b, --banner <banner>
        custom banner inserted into compiled CBC v8+ files

    -7
        files are in CBC v7 format

Examples:

Extract cheats from mgs3.cbc and print them to screen:

$ cb2util cbc mgs3.cbc

Extract cheats, decrypt encrypted cheats, and print them to screen:

$ cb2util cbc --decrypt mgs3.cbc

Same as previous example, but force decryption of all cheats:

$ cb2util cbc --decrypt=force mgs3.cbc

Check digital signature of re4.cbc:

$ cb2util cbc --verify re4.cbc

Extract and decrypt cheats from v7 code save re4.cbc, write them to re4.txt:

$ cb2util cbc --decrypt -7 re4.cbc > re4.txt

Compile cheats in mygame.txt to code save for CB v8+:

$ cb2util cbc --compile mygame.txt /path/to/cbc

Compile cheats in mygame.txt to code save for CB v7:

$ cb2util cbc --compile -7 mygame.txt /path/to/cbc

Note that the format of the text file to be compiled is described below.

"cheats" files

The "cheats" file is CodeBreaker's internal code database. It is usually saved to memory card (mc0:/PCB/cheats) and updated every time the code list is changed.

usage: cb2util cheats [-d[mode]] <file>...
   or: cb2util cheats -c <infile> <outfile>...

    no option
        extract cheats

    -d[mode], --decrypt[=mode]
        decrypt extracted cheats
        mode can be "auto" (default) or "force"

    -c, --compile
        compile text to cheats file

Examples:

Extract all cheats from "cheats" file and print them to screen:

$ cb2util cheats /path/to/cheats

Same as previous example, but write extracted cheats to cheats.txt:

$ cb2util cheats /path/to/cheats > cheats.txt

Extract all cheats, decrypt encrypted cheats, and print them to screen:

$ cb2util cheats --decrypt /path/to/cheats

Same as previous example, but force decryption of all cheats:

$ cb2util cheats --decrypt=force /path/to/cheats

Compile cheats in mygames.txt to "cheats" file:

$ cb2util cheats --compile mygames.txt /path/to/cheats

You can use your own "cheats" file with CodeBreaker in just a few steps:

  1. create a text file containing your cheats; the format is described below
  2. invoke cb2util to compile the text file to a "cheats" file
  3. use your favorite method to transfer the file to mc0:/PCB/cheats
  4. start CodeBreaker to see your cheats ready to be used

Text file format

To compile code saves and "cheats" files, cb2util uses libcheats for parsing cheat codes in text format. The format of the text file is quite simple:

"Game title 1"
Cheat description 1
Cheat code 1
Cheat code 2
Cheat description 2
Cheat code 1
Cheat code 2

"Game title 2"
etc.

Also, C++-style comments are allowed; all text beginning with a // sequence to the end of the line is ignored.

Example:

"TimeSplitters"
// some senseless comment
Mastercode
902D51F8 0C0B95F6
Invincible
203C8728 00000001

PCB files

File extension: *.bin

PCB files are encrypted and digitally signed binaries that can be executed by the CodeBreaker PS2. In theory, this could be any application; we've seen upgrades and homebrew so far.

usage: cb2util pcb [-s] <infile> <outfile>...
   or: cb2util pcb -e <infile> <outfile>...
   or: cb2util pcb -v <file>...

    no option
        encrypt/decrypt file

    -s, --strip
        strip RSA signature

    -e, --elf
        convert into ELF file

    -v, --verify
        verify RSA signature

Note: PCB files are encrypted with a symmetric cipher (RC4) and cb2util actually doesn't care if it's encrypting or decrypting.

Examples:

Decrypt pelican.bin to pelican.raw:

$ cb2util pcb pelican.bin pelican.raw

Decrypt pelican.bin to pelican.raw and strip RSA signature:

$ cb2util pcb --strip pelican.bin pelican.raw

Convert pelican.bin into the ELF file pelican.elf:

$ cb2util pcb --elf pelican.bin pelican.elf

Check RSA signature of pelican.bin:

$ cb2util pcb --verify pelican.bin

Game saves

File extension: *.cbs

Comming soon... ;)

Disclaimer

THIS PROGRAM IS NOT LICENSED, ENDORSED, NOR SPONSORED BY SONY COMPUTER ENTERTAINMENT, INC. NOR PELICAN ACCESSORIES, INC. ALL TRADEMARKS ARE PROPERTY OF THEIR RESPECTIVE OWNERS.

  • cb2util is licensed under the terms of the MIT License. See LICENSE file.
  • The code in arcfour.c is licensed under the terms of the FreeBSD license, which is believed to be compatible with the MIT license.
  • The SHA-1 implementation is placed in the public domain.
  • libcheats is licensed under the terms of the MIT License. See LICENSE file.
  • The license of libbig_int says that it can be redistributed/modified freely.
  • zlib has its own permissive free software license.
  • Sharness and all tests are licensed under the terms of the GNU General Public License version 2 or higher. See file COPYING for full license text.

Special Thanks

  • Alexander Valyalkin for his great libbig_int library.
  • Peter C. Gutmann and Paul Rubin for the fast implementation of SHA-1.
  • Vector for making PS2 Save Builder and saving me some time.
  • Gtlcpimp who has awakened my interest in cb2util again and provided valuable information on the "cheats" compression.
  • Greets to all the people that contribute to our code hacking community!

Contact

Dependencies

~2MB
~33K SLoC