peobf
Detect XOR-style obfuscation in PE sections by disassembly coverage, because Shannon entropy is blind to bijections.
pip install peobf
peobf check C:\Windows\System32\version.dll
The problem
Most packer/obfuscation detectors threshold on Shannon entropy: above ~7.0 means "compressed or encrypted". That test misses the most common cheap obfuscation there is.
XOR is a bijection — it permutes the byte-value labels one-to-one. Shannon entropy is computed from the multiset of byte frequencies, so the entropy is exactly unchanged:
H(XOR(data, k)) == H(data) for every key k
Measured on real Windows binaries:
C:\Windows\System32\version.dll .text 12,288 bytes
case entropy disassembly coverage
original 5.4067 100.00%
xor 0x5A 5.4067 2.54%
xor 0xFF 5.4067 0.69%
xor 0x01 5.4067 0.13%
permuted 5.4067 0.41%
Entropy delta on every transformed row: +0.0000. A tool that only measures entropy reports "normal" for a section whose code is entirely undecodable.
C:\Windows\System32\advapi32.dll .text 471,040 bytes
case entropy disassembly coverage
original 6.2347 22.14%
xor 0x5A 6.2347 0.00%
xor 0xFF 6.2347 0.00%
permuted 6.2347 0.01%
What peobf measures instead
Decodable instruction coverage: start a disassembler at the section base and count what fraction of bytes valid instructions consume.
- Real x64 code is typically 20–100% (not 100% — alignment padding and inline data sit between functions).
- XOR-obfuscated code drops to 0.00%: the decoder cannot form a single valid instruction.
That gap is the signal. It needs no key, no unpacking, no execution.
Usage
# 快速看所有节区(不反汇编,毫秒级)
peobf sections suspicious.dll
# 深入分析一个节区
peobf check suspicious.dll --section .text
check prints the entropy and coverage for the original plus four bijective transforms, then gives a verdict:
| verdict | meaning |
|---|---|
looks_normal |
section decodes normally; no obfuscation evidence |
possibly_encrypted |
coverage <5% and entropy >6 |
undecodable_low_entropy |
coverage <5% but entropy low — transformed, or filled with data |
As a library
from peobf import section_report, summarize
rep = section_report(r"C:\Windows\System32\version.dll", ".text")
s = summarize(rep)
print(s["verdict"]) # looks_normal
print(s["base_coverage"]) # 1.0
print(s["entropy_blind_cases"]) # 4 ← transforms entropy missed entirely
list_sections(path) returns name / VA / raw size / entropy / permissions for every section without disassembling.
Real section layout, for calibration
advapi32.dll (778,352 bytes, PE32+, 8 sections):
name VA raw size entropy perms
.text 0x1000 471,040 6.2347 RX
fothk 0x74000 4,096 0.0159 RX
.rdata 0x75000 233,472 4.6996 R
.data 0xae000 12,288 0.8552 RW
.pdata 0xb3000 20,480 5.2377 R
.didat 0xb8000 4,096 1.2959 RW
.rsrc 0xb9000 4,096 1.6339 R
.reloc 0xba000 8,192 5.0584 R
Both directions of false positive are real. fothk has entropy 0.0159 — near zero because it is a jump table of identical stubs. Entropy flags nothing; coverage would flag it as suspicious because almost nothing decodes. Reading it shows it is benign. That is why the verdict combines both numbers instead of thresholding one.
Limits — read before trusting it
- Does not recover the key. Single-byte XOR is trivially brute-forced (try 255 keys, score coverage); longer keys and block ciphers need real work.
- Does not prove maliciousness. Protectors and packers obfuscate legitimately. The measurement says "this code is not decodable as-is", nothing more.
- Coverage near 0 can be benign if a section legitimately holds data with code-like flags. Check permissions and the section name before concluding.
- Only PE. ELF/Mach-O need different parsers; the coverage idea transfers, the code does not.
Requirements
Python 3.9+. pefile and capstone are installed as dependencies.
License
MIT
Metadata
Release files for peobf 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| peobf-1.0.0.tar.gz | 10.0 kB | Without provenance | Details for peobf-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| peobf-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for peobf-1.0.0-py3-none-any.whl |
Total release size: 20.1 kB
Release files / peobf-1.0.0.tar.gz
| Download URL | peobf-1.0.0.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b0b30dce8025ae194f228098356b78214d6c331a10d80b9032207fd5dc9f2fa
|
|
BLAKE2b-256 checksum How to use checksums |
2955e23579fc901ea9efc1cddcdcb1c93e8a9862962e340f1b5b968e46fee1da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / peobf-1.0.0-py3-none-any.whl
| Download URL | peobf-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
457367e4a6a410367d385c5acce25fb8379dd47a3fbf3c4a5818fa48c7a9eddf
|
|
BLAKE2b-256 checksum How to use checksums |
dab7dd703ad0609710d731ed789763174f338ed2cc387242a55c7f5ff313d74e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for peobf 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.