1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Shannon entropy for packed/encrypted data detection.
/// Packed PE section threshold: entropy above this is likely compressed/encrypted.
pub const PACKED_SECTION_THRESHOLD: f32 = 6.8;
/// High entropy threshold for arbitrary byte buffers.
pub const HIGH_ENTROPY_THRESHOLD: f32 = 7.0;
/// Maximum possible entropy (uniform distribution over 256 byte values).
pub const MAX_BYTE_ENTROPY: f32 = 8.0;
/// Compute Shannon entropy (bits) of a byte buffer.
///
/// Returns 0.0 for empty or single-value buffers.
/// Maximum is 8.0 (uniform distribution over all 256 byte values).
/// Uses 256-bucket frequency counting — zero deps, no allocator needed beyond the stack array.
/// Returns `true` if the buffer's entropy exceeds HIGH_ENTROPY_THRESHOLD.
/// Returns `true` if entropy matches a packed PE section (above PACKED_SECTION_THRESHOLD).
// ── Tests ─────────────────────────────────────────────────────────────────────