peobf
Prefer a GUI? PE-Doctor-Pro-1.0.0-win64.zip — Windows, no Python needed. Unzip, double-click, select a file, see entropy and coverage side by side, recover an XOR'd section in one click.
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