Join Us and become a Member for a Verified Badge to access private areas with the latest PS4 PKGs.
PS4 CFW and Hacks       Thread starter PSXHAX       Start date May 4, 2022 at 12:44 AM       2,713       12      
May the 4th Be With You! ☄️ Following his PS2 Projects, developer @uyjulian (Twitter) updated his Github repository yesterday with a UnPackPKG script which (among other platforms) is a PS3 / PS4 PKG Unpacker for ED8 and the Trails of Cold Steel series of games outlined below.

Download: / GIT

Here's more from the included unpackpkg

Unpacks .pkg files from ED8 / Trails of Cold Steel series of games.


TODO: to be written later


The following games are known to be compatible with this program:
  • 英雄伝説: 閃の軌跡 / Eiyuu Densetsu: Sen no Kiseki / The Legend of Heroes: Trails of Cold Steel (Vita, PS3, PC, PS4)
  • 英雄伝説: 閃の軌跡 II / Eiyuu Densetsu: Sen no Kiseki II / The Legend of Heroes: Trails of Cold Steel II (Vita, PS3, PC, PS4)
  • 英雄伝説: 閃の軌跡 III / Eiyuu Densetsu: Sen no Kiseki III / The Legend of Heroes: Trails of Cold Steel III (PC, PS4, Switch)
  • 英雄伝説: 閃の軌跡 IV / Eiyuu Densetsu: Sen no Kiseki IV / The Legend of Heroes: Trails of Cold Steel IV (PC, PS4, Switch)
  • 英雄伝説: 創の軌跡 / Eiyuu Densetsu: Hajimari no Kiseki (PC, PS4)
  • 東亰ザナドゥ / Tokyo Xanadu (Vita, PC, PS4)

The program is licensed under the MIT license. Please check LICENSE for more information.

And here's the script:
# This script is intended to unpack "pkg" file from Trails of Cold Steel III/IV/Hajimari PC/Switch, but it also works on Trails of Cold Steel I/II/III/IV Vita/PS3/PS4, Hajimari no Kiseki, and Tokyo Xanadu.
# 1st argument is .pkg path, 2nd argument is output directory

# For Hajimari PC support, it requires the "zstandard" module to be installed.
# This can be installed by:
# /path/to/python3 -m pip install zstandard

import io
import sys
import struct
import os

    import zstandard

def uncompress_nislzss(src, decompressed_size, compressed_size):
    des = int.from_bytes(, byteorder="little")
    if des != decompressed_size:
        des = des if (des > decompressed_size) else decompressed_size
    cms = int.from_bytes(, byteorder="little")
    if (cms != compressed_size) and ((compressed_size - cms) != 4):
        raise Exception("compression size in header and stream don't match")
    num3 = int.from_bytes(, byteorder="little")
    fin = src.tell() + cms - 13
    cd = bytearray(des)
    num4 = 0

    while src.tell() <= fin:
        b =[0]
        if b == num3:
            b2 =[0]
            if b2 != num3:
                if b2 >= num3:
                    b2 -= 1
                b3 =[0]
                if b2 < b3:
                    for _ in range(b3):
                        cd[num4] = cd[num4 - b2]
                        num4 += 1
                    sliding_window_pos = num4 - b2
                    cd[num4:num4 + b3] = cd[sliding_window_pos:sliding_window_pos + b3]
                    num4 += b3
                cd[num4] = b2
                num4 += 1
            cd[num4] = b
            num4 += 1

    return cd

# adapted from
def uncompress_lz4(src, decompressed_size, compressed_size):
    dst = bytearray(decompressed_size)
    min_match_len = 4
    num4 = 0
    fin = src.tell() + compressed_size

    def get_length(src, length):
        """get the length of a lz4 variable length integer."""
        if length != 0x0f:
            return length

        while True:
            read_buf =
            if len(read_buf) != 1:
                raise Exception("EOF at length read")
            len_part = read_buf[0]

            length += len_part

            if len_part != 0xff:

        return length

    while src.tell() <= fin:
        # decode a block
        read_buf =
        if not read_buf:
            raise Exception("EOF at reading literal-len")
        token = read_buf[0]

        literal_len = get_length(src, (token >> 4) & 0x0f)

        # copy the literal to the output buffer
        read_buf =

        if len(read_buf) != literal_len:
            raise Exception("not literal data")
        dst[num4:num4 + literal_len] = read_buf[:literal_len]
        num4 += literal_len
        read_buf =
        if not read_buf or src.tell() > fin:
            if token & 0x0f != 0:
                raise Exception("EOF, but match-len > 0: %u" % (token % 0x0f, ))

        if len(read_buf) != 2:
            raise Exception("premature EOF")

        offset = read_buf[0] | (read_buf[1] << 8)

        if offset == 0:
            raise Exception("offset can't be 0")

        match_len = get_length(src, (token >> 0) & 0x0f)
        match_len += min_match_len

        # append the sliding window of the previous literals
        if offset < match_len:
            for _ in range(match_len):
                dst[num4] = dst[num4-offset]
                num4 += 1
            sliding_window_pos = num4 - offset
            dst[num4:num4 + match_len] = dst[sliding_window_pos:sliding_window_pos + match_len]
            num4 += match_len

    return dst

def uncompress_zstd(src, decompressed_size, compressed_size):
    dctx = zstandard.ZstdDecompressor()
    uncompressed = dctx.decompress(, max_output_size=decompressed_size)
    return uncompressed

with open(sys.argv[1], "rb") as f:
    out_dir = sys.argv[1] + "__"
    if len(sys.argv) > 2:
        out_dir = sys.argv[2]
    except FileExistsError as e:
    # Skip first four bytes, io.SEEK_CUR)
    package_file_entries = {}
    total_file_entries, = struct.unpack("<I",
    for i in range(total_file_entries):
        file_entry_name, file_entry_uncompressed_size, file_entry_compressed_size, file_entry_offset, file_entry_flags = struct.unpack("<64sIIII",
        package_file_entries[file_entry_name.rstrip(b"\x00")] = [file_entry_offset, file_entry_compressed_size, file_entry_uncompressed_size, file_entry_flags]
    for file_entry_name in sorted(package_file_entries.keys()):
        file_entry = package_file_entries[file_entry_name][0])
        output_data = None
        if file_entry[3] & 2:
            # This is the crc32 of the file, but we don't handle this yet
  , io.SEEK_CUR)
        if file_entry[3] & 4:
            output_data = uncompress_lz4(f, file_entry[2], file_entry[1])
        elif file_entry[3] & 8:
            if "zstandard" in sys.modules:
                output_data = uncompress_zstd(f, file_entry[2], file_entry[1])
                print(("File %s could not be extracted because zstandard module is not installed") % (file_entry_name.decode("ASCII")))
        elif file_entry[3] & 1:
            output_data = uncompress_nislzss(f, file_entry[2], file_entry[1])
            output_data =[2])
        if output_data is not None:
            with open(out_dir + "/" + file_entry_name.decode("ASCII"), "wb") as wf:
:arrow: Finally, for those new in the PlayStation 4 Scene below are some previous articles on various PS4 PKG tools sorted by date with the oldest first:
UnPackPKG PS4 PKG Unpacker for ED8 Trails of Cold Steel Games by UyJulian.png



You don't know, haven't made a program to extract and compress files yet .PSARC? Version for PS3 packs and unpacks, but the game does not start after that.

:fire: Latest Help Topics