Skip to content

Releases

pe-doctor 1.0.4 — fully English output

Choose a tag to compare

@gem3match-dev gem3match-dev released this 29 Nov 12:21

pe-doctor

Diagnose and restore broken PE/DLL files. Two command-line tools, no GUI, one dependency.

pip install pe-doctor
pe-doctor diagnose suspect.dll          # why won't it load
pe-doctor compare broken.dll good.dll   # which section changed
pe-restore auto broken.dll good.dll     # transplant only the damaged sections
pe-restore brutexor broken.dll --section .text --apply

The point most tools miss

Entropy cannot detect XOR encryption.

XOR is a bijection — it permutes byte frequencies, so Shannon entropy is identical before and after. Measured on a real 471 KB .text section:

original     entropy 6.235   disassembly coverage 99.95%
XOR 0x5A     entropy 6.235   disassembly coverage  0.2%

Same entropy. 500× difference in decodable instructions. A tool that only measures entropy looks at a XOR-encrypted section and reports clean.

So the decisive test here is capstone disassembly coverage, not entropy. And when capstone is missing, the tool says so instead of guessing — it reports clean-partial, never clean.


What diagnose checks

Structure — DOS/PE signatures, e_lfanew, COFF header, OptionalHeader magic, section table truncation, section raw ranges past EOF, overlapping sections.

Semantics — IMAGE_FILE_DLL bit vs. presence of an export directory, import directory resolvability, export table RVA inside readable bytes, entry point inside a section.

Content — per-section entropy, head entropy, padding-byte ratio, capstone disassembly coverage (code sections only), known packer signatures (UPX, Themida, VMProtect, ASPack, PECompact, MPRESS, Enigma, Obsidium, PEtite, FSG, MEW).

Verdict — fatal blocks loading · warn is suspicious · info is a note.


Measured on real binaries

Seven production DLLs from a Windows install, zero false positives:

File Size Exit Fatal Time
advapi32.dll 0.7 MB 0 0 0.15 s
kaldifst_core.dll 1.1 MB 0 0 0.10 s
kaldifst_fstscript.dll 11.3 MB 0 0 0.70 s
mshtml.dll 22.9 MB 0 0 1.50 s
edgehtml.dll 24.8 MB 0 0 1.63 s
nvcuvid.dll 30.8 MB 0 0 2.08 s

Time scales linearly. A 30 MB NVIDIA decoder DLL takes 2 seconds.

Detection verified — six corruption types constructed against real DLLs, each classified correctly:

Corruption Detected as
.text XOR 0x5A code-not-disassemblable
Export directory zeroed no-export-dir
Entry point → 0x7FFFFFF0 ep-outside-sections
Truncated to 60% section-out-of-range ×8
Section zeroed wiped-sections
Clean file clean

Restoration verified — three recovery paths return the file to a byte-identical SHA256:

Path Result
XOR brute-force key 0x5A scored 1.000 (runner-up 0.053) → coverage 0.002 → 0.9995
Section transplant coverage 0.2% → 100%, byte-identical to reference
Export table rebuild exports 0 → 853, no blocking findings

Exit codes

Drive CI with these directly:

pe-doctor diagnose artifact.dll || echo "blocking structural defect"
  • 0 — structurally clean
  • 1 — blocking problem found
  • 2 — file unreadable or not a PE

Boundaries

Does:

  • Structural damage (section table, directories, entry point, characteristics bits)
  • Single-byte XOR
  • Transplanting any section from a same-version reference
  • Rebuilding a zeroed export table

Does not, and says so:

  • Multi-byte XOR / RC4 / AES — key space is not brute-forceable; needs a reference or a memory dump
  • Themida / VMProtect / Enigma — virtual-machine protection, no general unpack. The realistic path is a runtime memory dump plus IAT rebuild, and the output is not the original DLL
  • Truncated files without a backup — the lost bytes cannot be invented
  • Different section layout from the reference — needs section-table reconstruction; the tool refuses instead of forcing it

These boundaries are part of the tool, not a defect. A tool that claims to fix anything is not trustworthy at step one.


Requirements

Python 3.9+ · capstone>=5.0 (installed automatically)

pefile is not used — PE parsing is hand-written so every field offset is controlled, printable, and checkable.


Links

MIT licensed.


Also on PyPI: pip install pe-doctor

1.0.4 — all console output and help text translated to English. Previously the README was English while the program printed Chinese, which was inconsistent.

pe-doctor 1.0.3 — now on PyPI, English docs

Choose a tag to compare

@gem3match-dev gem3match-dev released this 29 Nov 12:12

pe-doctor

Diagnose and restore broken PE/DLL files. Two command-line tools, no GUI, one dependency.

pip install pe-doctor
pe-doctor diagnose suspect.dll          # why won't it load
pe-doctor compare broken.dll good.dll   # which section changed
pe-restore auto broken.dll good.dll     # transplant only the damaged sections
pe-restore brutexor broken.dll --section .text --apply

The point most tools miss

Entropy cannot detect XOR encryption.

XOR is a bijection — it permutes byte frequencies, so Shannon entropy is identical before and after. Measured on a real 471 KB .text section:

original     entropy 6.235   disassembly coverage 99.95%
XOR 0x5A     entropy 6.235   disassembly coverage  0.2%

Same entropy. 500× difference in decodable instructions. A tool that only measures entropy looks at a XOR-encrypted section and reports clean.

So the decisive test here is capstone disassembly coverage, not entropy. And when capstone is missing, the tool says so instead of guessing — it reports clean-partial, never clean.


What diagnose checks

Structure — DOS/PE signatures, e_lfanew, COFF header, OptionalHeader magic, section table truncation, section raw ranges past EOF, overlapping sections.

Semantics — IMAGE_FILE_DLL bit vs. presence of an export directory, import directory resolvability, export table RVA inside readable bytes, entry point inside a section.

Content — per-section entropy, head entropy, padding-byte ratio, capstone disassembly coverage (code sections only), known packer signatures (UPX, Themida, VMProtect, ASPack, PECompact, MPRESS, Enigma, Obsidium, PEtite, FSG, MEW).

Verdict — fatal blocks loading · warn is suspicious · info is a note.


Measured on real binaries

Seven production DLLs from a Windows install, zero false positives:

File Size Exit Fatal Time
advapi32.dll 0.7 MB 0 0 0.15 s
kaldifst_core.dll 1.1 MB 0 0 0.10 s
kaldifst_fstscript.dll 11.3 MB 0 0 0.70 s
mshtml.dll 22.9 MB 0 0 1.50 s
edgehtml.dll 24.8 MB 0 0 1.63 s
nvcuvid.dll 30.8 MB 0 0 2.08 s

Time scales linearly. A 30 MB NVIDIA decoder DLL takes 2 seconds.

Detection verified — six corruption types constructed against real DLLs, each classified correctly:

Corruption Detected as
.text XOR 0x5A code-not-disassemblable
Export directory zeroed no-export-dir
Entry point → 0x7FFFFFF0 ep-outside-sections
Truncated to 60% section-out-of-range ×8
Section zeroed wiped-sections
Clean file clean

Restoration verified — three recovery paths return the file to a byte-identical SHA256:

Path Result
XOR brute-force key 0x5A scored 1.000 (runner-up 0.053) → coverage 0.002 → 0.9995
Section transplant coverage 0.2% → 100%, byte-identical to reference
Export table rebuild exports 0 → 853, no blocking findings

Exit codes

Drive CI with these directly:

pe-doctor diagnose artifact.dll || echo "blocking structural defect"
  • 0 — structurally clean
  • 1 — blocking problem found
  • 2 — file unreadable or not a PE

Boundaries

Does:

  • Structural damage (section table, directories, entry point, characteristics bits)
  • Single-byte XOR
  • Transplanting any section from a same-version reference
  • Rebuilding a zeroed export table

Does not, and says so:

  • Multi-byte XOR / RC4 / AES — key space is not brute-forceable; needs a reference or a memory dump
  • Themida / VMProtect / Enigma — virtual-machine protection, no general unpack. The realistic path is a runtime memory dump plus IAT rebuild, and the output is not the original DLL
  • Truncated files without a backup — the lost bytes cannot be invented
  • Different section layout from the reference — needs section-table reconstruction; the tool refuses instead of forcing it

These boundaries are part of the tool, not a defect. A tool that claims to fix anything is not trustworthy at step one.


Requirements

Python 3.9+ · capstone>=5.0 (installed automatically)

pefile is not used — PE parsing is hand-written so every field offset is controlled, printable, and checkable.


Links

MIT licensed.


Also on PyPI: pip install pe-doctor

pe-doctor 1.0.2 — no more false clean without capstone

Choose a tag to compare

@gem3match-dev gem3match-dev released this 29 Nov 11:53

pe-doctor 1.0.2

Fix: a missing capstone no longer produces a false "clean".

What was wrong in 1.0.1

Without capstone, the disassembly-coverage check was skipped silently and a XOR-encrypted DLL was still reported as clean. Entropy cannot detect XOR — that is the whole reason this tool exists — so a downgraded run was giving a confident wrong answer.

# 1.0.1, capstone absent, XOR-encrypted .text:
findings: ['disasm-skipped', 'clean']      <- says clean

What 1.0.2 does

# 1.0.2, capstone absent, same file:
[warn] disasm-skipped   capstone 未安装,反汇编覆盖率检测已跳过
[warn] clean-partial    结构层未发现损坏,但加密检测未执行(缺 capstone)

The conclusion is no longer called clean. It says the check did not run, and tells you to install capstone and re-run.

Install

pip install pe_doctor-1.0.2-py3-none-any.whl
pip install capstone    # required for encryption detection

Measured on this machine

Seven production DLLs, zero false positives:

File Size Exit Fatal Time
advapi32.dll 0.7 MB 0 0 0.15 s
mshtml.dll 22.9 MB 0 0 1.50 s
edgehtml.dll 24.8 MB 0 0 1.63 s
nvcuvid.dll 30.8 MB 0 0 2.08 s

Exit codes: 0 clean, 1 blocking problem, 2 unreadable.

Boundaries

Single-byte XOR only. Themida / VMProtect have no general unpack and the tool says so. Truncated files need a reference copy.

MIT. Docs: https://github.com/gem3match-dev/match3-canvas-engine/blob/main/pe-doctor-tool.md

pe-doctor 1.0.1 — PE/DLL diagnosis and restoration

Choose a tag to compare

@gem3match-dev gem3match-dev released this 29 Nov 11:41

pe-doctor 1.0.1

Diagnose and restore broken PE/DLL files. Two command-line tools, no GUI, no dependencies beyond capstone.

Install

pip install pe_doctor-1.0.1-py3-none-any.whl

What it does

pe-doctor diagnose suspect.dll          # why won't it load
pe-doctor compare broken.dll good.dll   # which section changed
pe-restore auto broken.dll good.dll     # transplant only the damaged sections
pe-restore brutexor broken.dll --section .text --apply

Why this exists

Entropy cannot detect XOR encryption. XOR is a bijection — it permutes byte frequencies, so Shannon entropy is identical before and after. Measured on a real 471 KB .text section:

original     entropy 6.235   disassembly coverage 99.95%
XOR 0x5A     entropy 6.235   disassembly coverage  0.2%

Same entropy, 500x difference in decodable instructions. So the decisive test here is capstone disassembly coverage, not entropy. A tool that only measures entropy sees a XOR-encrypted section and reports "clean".

Verified

Six corruption types constructed against real Windows DLLs, each classified correctly; three restoration paths return the file to a byte-identical SHA256. Exit codes: 0 = clean, 1 = blocking problem found.

Boundaries

  • Single-byte XOR only. Multi-byte / RC4 / AES is not brute-forceable and needs a memory dump.
  • Themida / VMProtect have no general unpack. The tool says so instead of shipping something that only sometimes loads.
  • Truncated files cannot be reconstructed without a reference.

MIT licensed. Source: https://github.com/gem3match-dev/match3-canvas-engine/blob/main/pe-doctor-tool.md