pak

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2023 License: ISC Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// FileTypeBasic denotes an uncompressed file.
	FileTypeBasic = 0x00
	// FileTypeLz denotes a file compressed with a custom LZ77 scheme.
	FileTypeLz = 0x01
	// FileTypeDir denotes a directory entry.
	FileTypeDir = 0x02
	// FileTypeLz2 denotes an LZ77 compressed file with obfuscation.
	FileTypeLz2 = 0x03
	// FileTypeMask is a mask for grabbing the type of file for an entry.
	FileTypeMask = 0x0F

	// EntryTypeXOR is present on legacy XOR-padded entries. Filenames are
	// XOR'd with 0x71. If the EntryType is zero on-disk, it will be set to
	// XOR padded.
	EntryTypeXOR = 0x10
	// EntryTypeXTEA is present on modern XTEA-encrypted entries. Filenames
	// and some metadata are encrypted with an XTEA cipher using 16 rounds.
	EntryTypeXTEA = 0x20
	// EntryTypeBasic is an unencrypted entry type likely used for debugging.
	EntryTypeBasic = 0x80
	// EntryTypeMask is a mask for grabbing the type of entry obfuscation.
	EntryTypeMask = 0xF0
)

Enumeration of values that can be combined to form a File Entry type.

View Source
const (
	// FuseImplementation describes the fuse implementation in use in this build.
	FuseImplementation = "bazilfuse"
)
View Source
const TrailerLen = 9

TrailerLen is the number of bytes the trailer takes up on-disk.

Variables

View Source
var (
	// ErrInvalidSignature is returned when the pak file contains an invalid
	// signature.
	ErrInvalidSignature = errors.New("invalid signature")
	// ErrStopIteration is returned if iteration ends early because the
	// callback returned false.
	ErrStopIteration = errors.New("iteration stopped")
)

Errors returned by the reader.

View Source
var (
	// ErrFuseUnsupported is returned by Mount when Fuse is not supported.
	ErrFuseUnsupported = errors.New("fuse mounting not supported in build")
)

Functions

func DetectRegion

func DetectRegion(patterns []string, keys []pyxtea.Key) (pyxtea.Key, error)

DetectRegion is like DetectRegions, but only returns one key, and fails if more than one or no keys pass validation. As a special case, if *all* regions validate, the first key is selected - this helps auto-detect succeed when dealing with pak files that contain no XTEA-ciphered entries.

func DetectRegions

func DetectRegions(patterns []string, keys []pyxtea.Key) ([]pyxtea.Key, error)

DetectRegions tries to decode the file table using each of the keys from the keys slice in order. Keys which have no errenous filenames are returned.

func MustDetectRegion

func MustDetectRegion(patterns []string, keys []pyxtea.Key) pyxtea.Key

MustDetectRegion is like DetectRegion but crashes on error.

Types

type FS

type FS struct {
	// contains filtered or unexported fields
}

FS is an in-memory filesystem for pak files.

func LoadPaks

func LoadPaks(key pyxtea.Key, patterns []string) (*FS, error)

LoadPaks loads pak files from a series of patterns or paths.

func NewFS

func NewFS(key pyxtea.Key) *FS

NewFS returns a new, empty pak filesystem.

func (*FS) AddPak

func (fs *FS) AddPak(reader *Reader) error

AddPak adds a new pak on top of the filesystem.

func (*FS) AddPakFromFile

func (fs *FS) AddPakFromFile(path string) error

AddPakFromFile adds a new pak on the filesystem from a path.

func (*FS) Directory

func (fs *FS) Directory(index int) string

Directory returns the directory at a given index.

func (*FS) Extract

func (fs *FS) Extract(dest string) error

Extract extracts the filesystem onto the host disk.

func (*FS) ExtractFlat added in v0.0.2

func (fs *FS) ExtractFlat(dest string) error

ExtractFlat extracts the filesystem onto the host disk, into one flat folder.

func (*FS) FileNameByIndex added in v0.0.2

func (fs *FS) FileNameByIndex(index int) (string, error)

FileNameByIndex returns the path for a given file index.

func (*FS) LoadPaksFromFiles

func (fs *FS) LoadPaksFromFiles(paths []string) error

LoadPaksFromFiles loads pak files from a list of paths.

func (*FS) LoadPaksFromGlob

func (fs *FS) LoadPaksFromGlob(pattern string) error

LoadPaksFromGlob loads pak files using a glob pattern.

func (*FS) Mount

func (fs *FS) Mount(mountpoint string) error

Mount mounts a pak filesystem via FUSE.

func (*FS) NumDirectories

func (fs *FS) NumDirectories() int

NumDirectories returns the number of directories in the filesystem.

func (*FS) NumFiles

func (fs *FS) NumFiles() int

NumFiles returns the number of files in the filesystem.

func (*FS) ReadFile added in v0.0.2

func (fs *FS) ReadFile(filename string) ([]byte, error)

ReadFile returns a file by name.

func (*FS) ReadFileByIndex

func (fs *FS) ReadFileByIndex(index int) (string, []byte, error)

ReadFileByIndex returns the path and data for a given file index.

func (*FS) Root

func (fs *FS) Root() (fusefs.Node, error)

Root implements FUSE

type FileEntryData

type FileEntryData struct {
	PathLength     byte
	Type           byte
	Offset         uint32
	PackedFileSize uint32
	RealFileSize   uint32
}

FileEntryData is the data structure of each file entry in a Pak file.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads data from a pak file.

func NewReader

func NewReader(k pyxtea.Key, r ReaderAtLen) (*Reader, error)

NewReader returns a new reader.

func (*Reader) CalcFileSize

func (r *Reader) CalcFileSize(entry FileEntryData) (int64, error)

CalcFileSize calculates the actual filesize of a compressed file.

func (*Reader) ReadFile

func (r *Reader) ReadFile(entry FileEntryData) ([]byte, error)

ReadFile reads an entire file.

func (*Reader) ReadFileTable

func (r *Reader) ReadFileTable(callback func(path string, entry FileEntryData) bool) error

ReadFileTable reads the file table entirely. The iteration is stopped if callback returns false.

type ReaderAtLen

type ReaderAtLen interface {
	io.ReaderAt
	Len() int
}

ReaderAtLen is an io.ReaderAt that supports returning length.

type TrailerData

type TrailerData struct {
	FileListOffset uint32
	FileCount      uint32
	Signature      byte
}

TrailerData is the data structure at the end of a Pak file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL