cp2077_extractor.redarchive_reader

Partial parser for REDEngine .archive files.

Classes:

FileList(file_table_offset, file_table_size, ...)

Represents a FileList in a .archive file.

FileRecord(name_hash, timestamp, ...)

Represents a FileRecord in a .archive file.

FileSegment(offset, zsize, size)

Represents a FileSegment in a .archive file.

REDArchive(magic, version, index_pos, ...)

Represents a REDEngine .archive file.

class FileList(file_table_offset, file_table_size, crc, file_entry_count, file_segment_count, resource_dep_count, file_records, file_segments, resource_dependencies)[source]

Bases: object

Represents a FileList in a .archive file.

Methods:

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

find_filename(filename)

Find the record for the given filename, relative to the root of the archive (usually starting base).

get_segments(file)

Returns the segments for the given file.

Attributes:

crc

Checksum of ???

file_entry_count

Number of files

file_segment_count

Number of file segments

file_table_offset

Always 8

resource_dep_count

Number of resource dependencies

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

crc

Type:    int

Checksum of ???

file_entry_count

Type:    int

Number of files

file_segment_count

Type:    int

Number of file segments

file_table_offset

Type:    int

Always 8

find_filename(filename)[source]

Find the record for the given filename, relative to the root of the archive (usually starting base).

Parameters

filename (str)

Return type

FileRecord

get_segments(file)[source]

Returns the segments for the given file.

Parameters

file (FileRecord)

Return type

list[FileSegment]

resource_dep_count

Type:    int

Number of resource dependencies

class FileRecord(name_hash, timestamp, num_inline_buffer_segs, segs_start, segs_end, res_deps_start, res_deps_end, sha1_hash)[source]

Bases: object

Represents a FileRecord in a .archive file.

Methods:

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

Attributes:

name_hash

FNV1A64 hash of the filename

num_inline_buffer_segs

Number of inline buffers

res_deps_end

Index of the last resource dependency

res_deps_start

Index of the first resource dependency

segs_end

Index of the last file segment

segs_start

Index of the first file segment

sha1_hash

SHA1 hash of the file # TODO: compressed files?

timestamp

Windows filetime of file creation

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

name_hash

Type:    int

FNV1A64 hash of the filename

num_inline_buffer_segs

Type:    int

Number of inline buffers

res_deps_end

Type:    int

Index of the last resource dependency

res_deps_start

Type:    int

Index of the first resource dependency

segs_end

Type:    int

Index of the last file segment

segs_start

Type:    int

Index of the first file segment

sha1_hash

Type:    bytes

SHA1 hash of the file # TODO: compressed files?

timestamp

Type:    int

Windows filetime of file creation

class FileSegment(offset, zsize, size)[source]

Bases: object

Represents a FileSegment in a .archive file.

Methods:

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

Attributes:

offset

Offset of the data

size

Size of uncompressed data

zsize

Size of compressed data

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

offset

Type:    int

Offset of the data

size

Type:    int

Size of uncompressed data

zsize

Type:    int

Size of compressed data

class REDArchive(magic, version, index_pos, index_size, debug_pos, debug_size, filesize, custom_data_length, file_list)[source]

Bases: object

Represents a REDEngine .archive file.

Methods:

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

extract_file(fp, file)

Extract a file from the archive.

load_archive(archive_file)

Load metadata for an .archive file.

Attributes:

custom_data_length

Files created with WolvenKit only

debug_pos

Always 0

debug_size

Always 0

filesize

Size of file (excluding Filesize)

index_pos

Offset of beginning of file list

index_size

Size of file list

magic

Constant: "RDAR"

version

Currently 12

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

custom_data_length

Type:    int

Files created with WolvenKit only

debug_pos

Type:    int

Always 0

debug_size

Type:    int

Always 0

extract_file(fp, file)[source]

Extract a file from the archive.

Parameters
  • fp (IO) – File handle for the opened archive.

  • file (FileRecord) – The file to extract.

Return type

bytes

filesize

Type:    int

Size of file (excluding Filesize)

index_pos

Type:    int

Offset of beginning of file list

index_size

Type:    int

Size of file list

classmethod load_archive(archive_file)[source]

Load metadata for an .archive file.

Parameters

archive_file (Union[str, Path, PathLike])

Return type

REDArchive

magic

Type:    str

Constant: “RDAR”

version

Type:    int

Currently 12