A file archiver for Fallout 2 "DAT2" files
# show help
fo2dat --help
# list contents of master.dat
fo2dat -tf master.dat
# extract master.dat into current dir
fo2dat -xf master.dat
# extract master.dat into fo2/
mkdir fo2
fo2dat -xf master.dat -C fo2
Source: http://falloutmods.wikia.com/wiki/DAT_file_format
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . |
| . |
| data |
| len = sum(entry.packed_size for entry in tree_entries) |
| . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| num_files |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . |
| . |
| tree_entries |
| len = tree_size - 4 |
| . |
| . |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| tree_size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| file_size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Top-level container for all archive data
- All multi-byte numbers are little-endian
dataandtree_entriesare variable length.tree_sizeholds the size (in bytes) of bothtree_entriesandtree_size.- The size of
datacan be calculated by adding thepacked_sizeof eachtree_entryintree_entries
- Contains the data for all files described in
tree_entries - The data of all files is concatenated together with no separators
- The offset and size of each file in
datais described in the file's respectivetree_entryintree_entries - A file's data MAY be compressed with zlib compression. Although a file's
tree_entrycontains anis_compressedflag, a file's compression should be checked by testing that the first two bytes of data are the zlib magic number (0x78da). If the file is smaller than two bytes, it is not compressed.
- Contains metadata for each file in
dat_file - A continuous block of
tree_entrys with no separators - The starting offset for
tree_entriescan be calculated fromtree_size - With some Fallout2 DAT2 files,
tree_entriescan contain duplicate entries, these are ignored
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| filename_len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| . |
| . |
| filename |
| (ASCII, len = filename_len) |
| . ----------------|
| . | is_compressed |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| decompressed_size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| packed_size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Contains metadata of a file in
dat_file - The data of the file is held in
dat_filesdatablock, starting atoffsetand ending atoffset + packed_size is_compressedcan have a value of either0x0(uncompressed) or0x1(compressed). For robustness, this flag should be ignored and, instead, the first two bytes of the file data should be read for the zlib magic number (0x78da)- Filenames are stored in DOS 8.3 format: 8 characters for the file name,
followed by a period (
.), followed by a 3 character long extension.