Files

1.3 KiB
Raw Permalink Blame History

API Reference: Measuring Section Entropy to Detect Packing

Overview

scripts/analyst.py computes whole-file Shannon entropy, sliding-window peak entropy, and (for PE files, via pefile) per-section entropy with raw/virtual size comparison, flagging high-entropy executable sections. It reads the inert file and never executes it.

Dependencies

Package Version Purpose
(stdlib) — math (entropy), file IO
pefile >= 2023.2.7 per-section analysis (optional)

Core functions

shannon(data)

Shannon entropy in bits/byte (0–8).

window_stats(data, window)

Returns the peak entropy and the fraction of windows above the packing threshold; a sustained high fraction (not a single window) indicates packing when section data is unavailable.

pe_sections(path)

Per-section entropy, size, executable flag, and a suspicious flag.

Usage

python scripts/analyst.py entropy sample.exe

Sources