• Stars
    star
    490
  • Rank 86,787 (Top 2 %)
  • Language
    Python
  • Created almost 10 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

u4pak

Unpack, pack, list, test and mount Unreal Engine 4 .pak archives.

NOTE: I've wrote an alternative version of this in Rust and compiled a self-contained binary for Windows users. So there is no hassle with installing Python, plus it adds a way to supply command line arguments via a file that you can associate with the binary so you only need to double click that. It is also faster, mainly because it uses multi-threading. (Note that it's command line arguments are sligthly different.)

Basic usage:

u4pak.py info <archive>                 - print archive summary info
u4pak.py list <archive>                 - list contens of .pak archive
u4pak.py test <archive>                 - test archive integrity
u4pak.py unpack <archive>               - extract .pak archive
u4pak.py pack <archive> <files>         - create .pak archive
u4pak.py mount <archive> <mount-point>  - mount archive as read-only file system

For unpacking only unencryped archives of version 1, 2, 3, 4, and 7 are supported, for packing only version 1, 2, and 3.

NOTE: If you know (cheap) games that use other archive versions please tell me! Especially if its 5 or 6. There is a change in how certain offsets are handled at some point, but since I only have an example file of version 7 I don't know if it happened in version 5, 6, or 7.

The mount command depends on the llfuse Python package. If it's not available the rest is still working.

This script is compatible with Python 3.7.

If you get errors saying anything about 'utf8' codec can't decode byte [...] try to use another encoding by passing --encoding=iso-8859-1 or similar.

If you get an error message about an illegal file magic try to pass --ignore-magic. If you get an error message about the archive version being 0 try to pass --force-version=1 (or a higher number).

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).

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.

Some games seem to zero out parts of the file. In particular the footer, which makes it pretty much impossible to read the file without manual analysis and guessing. I suspect these games have the footer included somewhere in the game binary. If it's not obfuscated one might be able to find it using the file magic (given that the file magic is even included)?

Record

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.

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

Data Record

Offset  Size  Type            Description
     0     ?  Record          file metadata (offset field is 0, N = compressed_size)
     ?     N  uint8_t[N]      file data

Index Record

Offset  Size  Type            Description
     0     4  uint32_t        file name size (S)
     4     S  char[S]         file name (includes terminating null byte)
   4+S     ?  Record          file metadata

Index

Offset  Size  Type            Description
     0     4  uint32_t        mount point size (S)
     4     S  char[S]         mount point (includes terminating null byte)
   S+4     4  uint32_t        record count (N)
   S+8     ?  IndexRecord[N]  records

Footer

Size: 44 bytes

Offset  Size  Type         Description
     0     4  uint32_t     magic: 0x5A6F12E1
     4     4  uint32_t     version: 1, 2, 3, 4, or 7
     8     8  uint64_t     index offset
    16     8  uint64_t     index size
    24    20  uint8_t[20]  index sha1 hash

Related Projects

  • 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
  • rust-vpk: Rust rewrite of the above
  • t2fbq: unpack, list and mount Trine 2 .fbq archives
  • rust-u4pak: not yet finished Rust rewrite of this script

BSD License

Copyright (c) 2014-2019 Mathias Panzenbรถck

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

mediaextract

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

rust-u4pak

unpack, pack, list, check and mount Unreal Engine 4 .pak archives
Rust
125
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