Skip to main content

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

Metadata

Release files for peobf 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for peobf 1.1.0
File Size Uploaded Provenance Actions
peobf-1.1.0.tar.gz 9.6 kB Without provenance Details for peobf-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for peobf 1.1.0
File Interpreter ABI Platform Actions
peobf-1.1.0-py3-none-any.whl Python 3 none any Details for peobf-1.1.0-py3-none-any.whl

Total release size: 19.8 kB

Release files / peobf-1.1.0.tar.gz

Download URL peobf-1.1.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b7bf5376e1e63c823fe6e700b0e4e8267d9e27266076f32079a6810ecacb0a3
BLAKE2b-256 checksum
How to use checksums
9d49d2b1425cb52fd7e24de0055519c1d49f77218c8ba7f0209c3ff46ac7908e
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.1.0-py3-none-any.whl

Download URL peobf-1.1.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9850ef7aeb153701b10525c30b6f865cec76bd62ad444f9b373d48ae03fef415
BLAKE2b-256 checksum
How to use checksums
d49261ffc72b536e9b4012a841604543c2ec37cc7bc000b93a5b981517295ee8
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.1.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page