pklite

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: GPL-3.0 Imports: 6 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pklite decompresses MS-DOS executables that were packed with PKWARE's PKLITE.

PKLITE was released in 1990 by PKWARE as an executable packer. Unlike the legacy ZIP methods in the sibling packages (unshrink, explode, expand), PKLITE is not a ZIP compression method and has no method ID, so it cannot be registered with archive/zip. Instead it is a stand-alone decompressor that takes a packed file and returns the original executable.

PKLITE compressed .COM files (v1.00 to v2.01) and .EXE files of v1.05 to v1.12 are supported. The EXE support is limited to the large and small compression, scrambled decompressors and v1.20 files are not yet supported.

The compression is an LZ77 variant, with 16-bit little-endian bit words that are consumed from the least significant bit, and static Huffman codes for the match lengths and offsets. The format was documented by Jason Summers in the MIT licensed Deark project, which this package is based on.

Example

Example demonstrates unpacking a PKLITE compressed COM file.

package main

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/Defacto2/archive/pklite"
)

func main() {
	data, err := os.ReadFile(filepath.Join("testdata", "D2_V115.COM"))
	if err != nil {
		fmt.Println(err)
		return
	}
	out, err := pklite.Decompress(data)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%d bytes packed, %d bytes unpacked\n", len(data), len(out))
}
Output:
877 bytes packed, 4176 bytes unpacked

Index

Examples

Constants

View Source
const (
	// MaxSize is the maximum number of bytes that Decompress will return.
	MaxSize = 1 << 20
)

Variables

View Source
var (
	ErrNotPKLITE = errors.New("pklite: not a supported compressed file")
	ErrCorrupt   = errors.New("pklite: corrupt compressed data")
	ErrTruncated = errors.New("pklite: unexpected end of compressed data")
)
View Source
var ErrUnsupported = errors.New("pklite: unsupported variant")

Functions

func Decompress

func Decompress(data []byte) ([]byte, error)

Decompress returns the original executable from a PKLITE compressed COM or EXE file.

func IsCOM

func IsCOM(data []byte) bool

IsCOM reports whether data looks like a PKLITE compressed COM file.

func IsEXE

func IsEXE(data []byte) bool

IsEXE reports whether data looks like a PKLITE compressed EXE file.

func Read

func Read(r io.Reader) ([]byte, error)

Read reads all of r and returns the decompressed COM file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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