bfcodec 0.0.4
Tools and a C/C++ library to manipulate BFCodec-encrypted content
Loading...
Searching...
No Matches
bfcodec

C++ GitHub tag (with filter) License GitHub commits since latest release (by SemVer including pre-releases) CodeQL QA Tests Coverage Status Dependabot GitHub Pages Stargazers CMake Prettier

@Tatsh Buy Me A Coffee Libera.Chat Mastodon Follow Patreon

Tools and a C/C++ library to manipulate BFCodec-encrypted content.

How to use

jbt

jbt encrypts a directory of game data then zips it up. The extension depends on the target game. You must use the correct key to encrypt the data.

jbt -K 'the game key' game-data/ game-data.jbt

unjbt

Like unzip, unjbt extracts the zip file then decrypts each game file. Conversions will happen if tools are in PATH:

Input Format Output Format Tool Used
Binary Property List (plist) XML Property List libplist (if found at configure time), CoreFoundation (macOS)
CgBI PNG PNG pngcrush, pngdefry

pngdefry can be downloaded from its official site (archived). pngcrush is only available on macOS if you have Xcode installed.

unjbt -d game-data game-data.jbt

If the directory passed to -d/--extract-to does not exist it will be created.

C interface

// If using a DLL on Windows:
// #ifdef _WIN32
// #define BFCODEC_USE_DLL 1
// #endif
#include <bfcodec.h>
void func() {
const uint8_t my_key = {};
const uint8_t iv[8] = {};
bfcodec_expand_key(blf, &my_key, 16);
bfcodec_decrypt(blf, in_out_data, data_len, my_iv);
// or
bfcodec_encrypt(blf, in_out_data, data_len, my_iv);
}
BFCODEC_API void bfcodec_encrypt(C_BLOWFISH *blf, uint8_t *data, size_t len, const uint8_t iv[8])
Encrypt data in place using CBC with the given 8-byte IV.
Definition bfcodec.c:168
BFCODEC_API C_BLOWFISH * bfcodec_init(void)
Allocate and initialise a Blowfish codec with pi-derived P and S boxes.
Definition bfcodec.c:91
BFCODEC_API void bfcodec_expand_key(C_BLOWFISH *blf, const uint8_t *key, size_t key_len)
Expand key into the codec state (XOR P with key bytes, then expand via encrypt).
Definition bfcodec.c:117
BFCODEC_API void bfcodec_decrypt(C_BLOWFISH *blf, uint8_t *data, size_t len, const uint8_t iv[8])
Decrypt data in place using CBC with the given 8-byte IV.
Definition bfcodec.c:149
Definition bfcodec.c:7

Link with -lbfcodec.

C++ interface

++
// If using a DLL on Windows:
// #ifdef _WIN32
// #define BFCODEC_USE_DLL 1
// #endif
#include <bfcodecpp.h>
void func() {
auto bfc = BFCodec::create();
bfc.expandKey({ /* key here */});
bfc.decrypt(inOutData, {/* IV here */});
// or
bfc.encrypt(inOutData, {/* IV here */})
}
static std::expected< BFCodec, BFCodecError > create()
Create a codec instance (calls bfcodec_init()).
Definition bfcodec.cc:24

Link with -lbfcodec.

Building from source

Requirements:

  • CMake
  • On Linux (for tools): OpenSSL
  • Optional: libplist on non-macOS

Basic commands to build after cloning:

mkdir build
cd build
cmake ..
make

jbt and unjbt will be in the tools directory.