• Stars
    star
    125
  • Rank 277,412 (Top 6 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created about 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

unpack, pack, list, check and mount Unreal Engine 4 .pak archives

Rust U4Pak

Build status Release License

More or less re-implementation of Python U4Pak for fun, ease of use (standalone binary), and speed (multi-threading).

This is a tool to pack, unpack, check, and list the contents of Unreal Engine 4 packages. Under Linux it can also be used to read-only FUSE-mount archives. Note that only a limited number of pak versions are supported.

Table 1. Supported Versions

Pak Version

Unreal Engine Version

Reading

Writing

1

< 4.0

✔️

✔️

2

4.0 - 4.2

✔️

✔️

3

4.3 - 4.15

✔️

✔️

4

4.16 - 4.19

✔️

5

4.20

✔️

6

-

✔️

7

4.21

✔️

8

4.22 - 4.24

✔️

9

4.25

✔️

10

-

✔️

11

4.26 - 4.27

✔️

Table 2. Supported Compression

Name

Supported

None

✔️

Zlib

✔️

Gzip

LZ4

Instead of passing arguments you can also put the arguments in a file with the extension .u4pak and pass the path to that instead. This is useful for Windows users that aren’t used to a terminal. You can even associate the extension with u4pak.exe so that it will be automatically opened with it when you double click it. File paths in a .u4pak file are relative to the directory containing the file. The syntax of these files is not shell syntax. If you don’t have any white space, double quotes ("), or hash marks () in your file names you don’t have to worry about anything. is used to start a comment line (only if it doesn’t touch any non-white space on it’s left) and " is used to quote arguments containing white space, #, or ". In order to write a " in a quoted argument you simply need to double it, meaning an argument that contains nothing but a single " is written as """". Newlines are ignored like any other white space. An example .u4pak file whould be:

# This is packing my project:
pack
--version=4
--mount-point=../../..

"C:\Users\Alice\My Documents\U4Project\NewArchive.pak"

":rename=/:C:\Users\Alice\My Documents\U4Project\Some Files"
":zlib,rename=/:Some Other Files"

If u4pak.exe is run by double clicking or by dropping a .u4pak file on it it won’t immediately close the terminal window, but will instead ask you to press ENTER. It does this so you have a chance to read the output. Since I don’t use Windows (I cross compile on Linux and test with Wine) I could not test this particular feature. If it doesn’t work please report a bug. In order to force the "Press ENTER to continue…​" message you can pass the argument --pause-on-exit=always (Windows-only).

1. Usage

u4pak [--pause-on-exit=<always|never|auto>] [SUBCOMMAND]

Or:

u4pak "C:\Path\to\arguments.u4pak"

2. Sub-Commands

Sub-Command

Description

check

Check consistency of a package

help

Prints general help message or the help of the given subcommand(s)

info

Show summarized information of a package

list

List content of a package

mount

Mount package as read-only filesystem (Linux-only)

pack

Create a new package

unpack

Unpack content of a package

For help to the various sub-commands run u4pak help SUBCOMMAND.

3. File Format

Byte order is little endian and the character encoding of file names seems to be ASCII (or ISO-8859-1/UTF-8 that coincidentally only uses ASCII compatiple characters).

Offsets and sizes seem to be 64bit or at least unsigned 32bit integers. If interpreted as 32bit integers all sizes (except the size of file names) and offsets are followed by another 32bit integer of the value 0, which makes me guess these are 64bit values. Also some values exceed the range of signed 32bit integers, so they have to be at least unsigned 32bit integers.

This information was reverse engineered from the Elemental Demo for Linux (which contains a 2.5 GB .pak file), the Unreal Engine 4 - Five Tech Demos, version 7 was reverse engineered from the Supraland Demo, and the Conan Exiles variant was reverse egineered from the SandstormFix_EXP workshop item. Reverse engineering was done by poking around the pak files with a hex editor, no kind of decompilation was done by me.

Versions >= 8 where reversed from an empty unreal engine project.

Basic layout
  • Data Records

  • Index

    • Index Header

    • Index Records

  • Footer

In order to parse a file you need to read the footer first. The footer contains an offset pointer to the start of the index records. The index records then contain offset pointers to the data records.

3.1. Encoded Record

Offset  Size  Type         Description
     0     4  uint32_t     bitfield containing record information
                              0-5  : Compression block size
                              6-21 : Compression blocks count
                              22   : Encrypted
                              23-28: Compression method
                              29   : Size 32-bit safe?
                              30   : Uncompressed size 32-bit safe?
                              31   : Offset 32-bit safe?
if offset 32 bit
     4     4  uint32_t     offset
else
     4     8  uint64_t     offset
end
if uncompressed size 32 bit
     ?     4  uint32_t     uncompressed size
else
     ?     8  uint64_t     uncompressed size
end
if compression method != 0x00
  if size 32 bit
     ?     4  uint32_t     size
  else
     ?     4  uint32_t     size
  end
end
if compression block count > 0 && (encrypted || compression block count != 1)
  for _ in 0..compression block count
     ?     4  uint32_t     block size
  end
end

3.2. Record

Note
This structure, while still present in version >= 10 is not used anymore by default. See Encoded Record for the current record information.
Offset  Size  Type         Description
     0     8  uint64_t     offset
     8     8  uint64_t     size (N)
    16     8  uint64_t     uncompressed size
    24     4  uint32_t     compression method:
                              0x00 ... none
                              0x01 ... zlib
                              0x10 ... bias memory
                              0x20 ... bias speed
if version <= 1
    28     8  uint64_t     timestamp
end
     ?    20  uint8_t[20]  data sha1 hash
if version >= 3
 if compression_method != 0x00
  ?+20     4  uint32_t     block count (M)
  ?+24  M*16  CB[M]        compression blocks
 end
     ?     1  uint8_t      is encrypted
   ?+1     4  uint32_t     The uncompressed size of each compression block.
end                        The last block can be smaller, of course.
if variant == "Conan Exiles"
     ?     4  uint32_t     Unknown field. For Conan Exiles index record only
                           seen it to have the value 0.
end

3.3. Compression Block (CB)

Size

16 bytes

Offset  Size  Type         Description
     0     8  uint64_t     compressed data block start offset.
                           version <= 4: offset is absolute to the file
                           version 7: offset is relative to the offset
                                      field in the corresponding Record
     8     8  uint64_t     compressed data block end offset.
                           There may or may not be a gap between blocks.
                           version <= 4: offset is absolute to the file
                           version 7: offset is relative to the offset
                                      field in the corresponding Record

3.4. Data Record

Offset  Size  Type            Description
     0     ?  Record          file metadata (offset field is 0, N = compressed_size)
if variant == "Conan Exiles"
     ?    20  ?               Unknown. Maybe another SHA-1 sum of something?
                              The first 4 bytes have values other than the extra
                              4 bytes in the index record, which is why I didn't
                              put those into the general record structure.
else if version >= 4 and compression_method != 0x00
     ?     4  uint32_t        Unknown.
end
     ?     N  uint8_t[N]      file data
Note

Starting with version 4 there is an additional 4 bytes in the repeated data record copy (the record that precedes the actual file date, not the record in the index). I don’t know what that is. It is not always the same value. E.g. it is the same for some files, but different for others. The first 2 bytes seem to be always the same (0x78 0x9c in a v4 and a v7 pak that I saw), so maybe its 2 16 bit fields?

This is why I’ve deactivated packing for versions > 3.

3.5. Full Directory Index

The data structure is a map<DirectoryName, map<FileName, offset>>.

Offset  Size  Type            Description
     0     4  uint32_t        directory count (D)
for i in 0..D
     ?     4  int32_t         directory name size (DS)
                              For some games a negative value means it’s a UTF-16
                              string in 2 * -S bytes.
   ?+4    DS  char[DS]        directory name (includes terminating null byte)
?+4+DS     4  uint32_t        file count (F)
  for j in 0..F
     ?     4  int32_t         file name size (FS)
                              For some games a negative value means it’s a UTF-16
                              string in 2 * -S bytes.
   ?+4    FS  char[FS]        file name (includes terminating null byte)
?+4+FS     4  uint32_t        offset in encoded entry info
  end
end

3.6. Index Record

Note
This structure, while still present in version >= 10 is not used anymore by default. See Full Directory Index for record information.
Offset  Size  Type            Description
     0     4  int32_t         file name size (S)
                              For some games a negative value means it's a UTF-16
                              string in 2 * -S bytes.
     4     S  char[S]         file name (includes terminating null byte)
   4+S     ?  Record          file metadata
if variant == "Conan Exiles"
     ?     4  ?               Unknown. Only saw all 0 so far.
end

3.7. Index

Version >= 10
Offset  Size  Type            Description
     0     4  int32_t         mount point size (S)
                              For some games a negative value means it’s a UTF-16
                              string in 2 * -S bytes.
     4     S  char[S]         mount point (includes terminating null byte)
   S+4     4  int32_t         entry count
   S+8     8  uint64_t        path hash seed (1)
  S+16     4  uint32_t        has path hash index
if has path index != 0
  S+20     8  int64_t         path hash index offset
  S+28     8  int64_t         path hash index size
  S+36    20  uint8_t[20]     path hash index hash
end
     ?     4  uint32_t        has full directory index
if has full directory index != 0
   ?+4     8  int64_t         full directory index offset
  ?+12     8                  full directory index size
  ?+20    20  uint8_t[20]     full directory index hash
end
     ?     4  int32_t         encoded entry info size (P)
   ?+4     P  uint8_t[P]      encoded entry info 
   ?+P     4  uint32_t        file count, probably unused / 0 (N)
 ?+P+4     ?  IndexRecord[N]  records
  1. Needs clarification

Legacy (Version < 10)
Offset  Size  Type            Description
     0     4  int32_t         mount point size (S)
                              For some games a negative value means it's a UTF-16
                              string in 2 * -S bytes.
     4     S  char[S]         mount point (includes terminating null byte)
   S+4     4  uint32_t        record count (N)
   S+8     ?  IndexRecord[N]  records
Table 3. Size and index features

Versions

Size

Index Encryption

Encryption Key Guid

Compression method name

Frozen Index

v1 - v3

44 bytes

v4 - v6

45 bytes

✔️

v7

65 bytes

✔️

✔️

v8

193 bytes

✔️

✔️

✔️(Max. 4)

v9

226 bytes

✔️

✔️

✔️(Max. 5)

✔️

v10 - v11

225 bytes

✔️

✔️

✔️(Max. 5)

Offset  Size  Type         Description
if version >= 7
     0    20  uint8_t[20]  encryption key Guid
end
if version >= 4
     ?     1  uint8_t      encrypted index
end
     ?     4  uint32_t     magic: 0x5A6F12E1
   ?+4     4  uint32_t     version: 1 - 11
   ?+8     8  uint64_t     index offset
  ?+16     8  uint64_t     index size
  ?+24    20  uint8_t[20]  index sha1 hash
if version == 9
  ?+44     1  uint8_t      frozen index
end
if version == 8
  ?+44   128  uint8_t[128] compression methods (4 * 32 chars)
else if version > 8
     ?   160  uint8_t[160] compression methods (5 * 32 chars)
end
  • fezpak: pack, unpack, list and mount FEZ .pak archives

  • psypkg: pack, unpack, list and mount Psychonauts .pkg archives

  • bgebf: unpack, list and mount Beyond Good and Evil .bf archives

  • unvpk: extract, list, check and mount Valve .vpk archives (C++)

  • rust-vpk: Rust rewrite of the above (Rust)

  • t2fbq: unpack, list and mount Trine 2 .fbq archives

  • u4pak: old Python version of this program

5. MPLv2 License

Rust U4Pak - pack, unpack, check, list and mount Unreal Engine 4 packages

Copyright © 2023 Mathias Panzenböck, L. Sprengel

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

More Repositories

1

SocialSharePrivacy

Fork of "jquery.socialshareprivacy.js | 2 Klicks fuer mehr Datenschutz" http://www.heise.de/extras/socialshareprivacy/ that is extensible.
JavaScript
681
star
2

u4pak

unpack, pack, list, check and mount Unreal Engine 4 .pak archives
Python
490
star
3

mediaextract

Extracts media files (AVI, Ogg, Wave, PNG, ...) that are embedded within other files.
C
149
star
4

Browser-Ponies

Reimplementation of Desktop Ponies in JavaScript
JavaScript
109
star
5

qjoypad

fork of qjoypad http://qjoypad.sourceforge.net/
C++
105
star
6

verify-ehc

Simple Python script to decode and verify an European Health Certificate QR-code
Python
60
star
7

blender_ipython

Run IPython in the context of Blender's embedded Python interpreter.
Python
53
star
8

VTFLib

Linux port of Nem's VTFLib http://nemesis.thewavelength.net/index.php?p=40
C++
44
star
9

formatstring

A C++14 type safe format string library heavily inspired by Python's str.format() function.
C++
43
star
10

blender-addon-import-pixelart

Blender add-on that imports pixle art images as colored cubes.
Python
27
star
11

oembedendpoints

This is a simple file (JSON) based registry of know oembed endpoints.
JavaScript
22
star
12

rust-vpk

Extract Valve VPK (V1 & V2) archives (and create V1 archives).
Rust
21
star
13

embedplayer

Unified jQuery interface to various audio/video players without dependency on their official JavaScript libraries.
JavaScript
21
star
14

jsqoi

QOI (Quite OK Image format) TypeScript port.
TypeScript
18
star
15

panzi-json-logic

Pure Python 3 JsonLogic and CertLogic implementation.
Python
18
star
16

unvpk

Extract Valve VPK archives.
C++
17
star
17

fezpak

pack, unpack, list and mount FEZ .pak archives
Python
16
star
18

Yakuake

This is a git mirror of Yakuake, the Quake like shell for KDE. It also contains some little improvements over the original (hopefully they will be merged).
C++
14
star
19

cook-serve-hoomans

A mod for Cook, Serve, Delicious!
C
13
star
20

HLLib

git mirror and patches to HLLib: http://nemesis.thewavelength.net/index.php?p=35
C++
11
star
21

git-kdiff3

Use kdiff3 as git diff viewer.
Shell
10
star
22

qvtf

Load Valve Texture Format files in Qt4 applications.
C++
10
star
23

numbers-js

Countdown numbers game solver written in JavaScript
JavaScript
10
star
24

CRC-and-checksum-functions

CRC and checksum functions from the former c.snippets.org
C
10
star
25

get_video_from_m3u

Downloads MPEG-TS chunks from a m3u playlist.
Python
9
star
26

ocarina_tabs

Font and HTML editor for 12 hole ocarina tabs
JavaScript
8
star
27

get_image_size.py

extract image dimensions given a file path using just core modules
Python
7
star
28

react-dnd-touch-pointer-events-backend

Touch (iOS, Android, ...) and Pointer Events (Windows Phone) backend for React Drag and Drop
JavaScript
6
star
29

bgebf

unpack, list and mount Beyond Good and Evil .bf archives
Python
5
star
30

psypkg

unpack, list and mount Psychonauts .pkg archives
Python
5
star
31

cook-serve-hoomans2

A mod for Cook, Serve, Delicious! 2!!
C
5
star
32

pixbufloader-vtf

Load Valve Texture Files in Gtk+ applications
C++
5
star
33

intercept-youtube-links

Inserts a hop to all watch links on YouTube in order to disable auto-play. The link won't be inserted by a normal click, only middle-click/context menu/D'n'D.
JavaScript
5
star
34

KIO-VTF-Thumb-Creator

KIO Thumbnail Creator plugin for Valve Texture Files
C++
4
star
35

rust-hox

Rust
4
star
36

numbers

Countdown numbers game solver.
C
4
star
37

localchannels

Communication channels between browser windows from same origin.
JavaScript
4
star
38

pipes

Very simple C library that lets you build pipe chains.
C
3
star
39

numbers-c

Countdown numbers game solver written in C.
C
3
star
40

jQuery-Parse-HTML

Adds $.parseHTML(markup). Supports Firefox, WebKit, Opera and IE >= 9.
JavaScript
3
star
41

t2fbq

Unpack, list and mount Trine 2 .fbq archives.
Python
3
star
42

jQuery-Cookies

A small but powerful cookie plugin for jQuery.
JavaScript
2
star
43

roxpak

unpack, list and mount RoX .pak archives
Python
2
star
44

WordCountBot

Very simple IRC bot that counts mentioned words in the last X seconds.
Python
2
star
45

dltest

Tiny tool to test loading of symbols from shared objects.
C
2
star
46

MDN-JavaScript-Shims

Here I try to collect all JavaScript shims from developer.mozilla.org. Please inform my if something is missing or not up to date.
JavaScript
2
star
47

mandelbrot

Simple C program to create Mandelbrot tiles and HTML viewer for these tiles. Based on http://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python/
JavaScript
2
star
48

parsecdat

pack, unpack, list and mount parsec .dat archives
Python
2
star
49

sudoku

simple sudoku solver
C
2
star
50

Magnatune-Player

This is an old version. See bitbucket for the current version.
JavaScript
2
star
51

ripcheck

fork of ripcheck https://sourceforge.net/projects/ripcheck/
C
2
star
52

scrollIntoViewIfNeeded

A very simple jQuery plugin that adds the methods "scrollIntoView" and "scrollIntoViewIfNeeded".
JavaScript
1
star
53

strbuf

A very simple string buffer for C.
C
1
star
54

hotkeys

Hotkey library for jQuery (Work in progress!)
JavaScript
1
star
55

SocialSharePrivacy-Mirror

Git mirror of "jquery.socialshareprivacy.js | 2 Klicks fuer mehr Datenschutz" by Heise Zeitschriften Verlag GmbH & Co. KG http://www.heise.de/extras/socialshareprivacy/
JavaScript
1
star
56

sysv-helper

Some simple bash scripts to help you write System V init scripts.
Shell
1
star
57

wavhdr

Prepend WAV header to file. Saves result into a new file appending .wav
C
1
star
58

wrap

Tiny C tool that wraps lines of plaintext files keeping indentation.
C
1
star
59

minmath

Example of how to write a recursive descent parser that adheres to operator precedence.
C
1
star
60

jsonpp

JSON pretty printer with colored output on the shell.
Python
1
star
61

sendfile

A tiny program that calls the Linux function sendfile
C
1
star
62

phonon-vlc

phonon-vlc 0.4.0 (which is still compatible with KDE 4.6) with additional supported mime types.
C++
1
star
63

jQuery-Format

Python/Ruby/C/ERB like string formatting for JavaScript
JavaScript
1
star
64

KDE-Folderview-Translucent-D-n-D-Hack

Adds a hack to KDE's Folderview Plasma App to make dragged icons translucent (if translucency is supported by the window manager)
C++
1
star
65

json-logic-compiler

Compiles JsonLogic expressions to JavaScript.
TypeScript
1
star
66

xor

A very simple tool to xor a file with a key.
C
1
star
67

pix2svg

Convert pixle art to SVG.
Python
1
star
68

python-subproclines

Read lines of stdout and stderr of a subprocess in parallel without the need for threads.
Python
1
star
69

cook-serve-hoomans3

A mod for Cook, Serve, Delicious! 3?!
C
1
star
70

numbers-python

Contdown numbers game solver written in Python
Python
1
star
71

jQuery-NoGif

GIF like animated image sequences
JavaScript
1
star
72

js-print-table

Print a table to console in TypeScript.
TypeScript
1
star
73

bfdl

Binary Format Description Language (just for fun)
Python
1
star