Security Cipher
Home Blog About Us
Resources β–Ό
πŸ—ΊοΈ Penetration Testing Roadmap 🌐 Web Application Security Checklist πŸ€– OWASP Top 10 for LLM Applications 🧠 LLM AI Security Checklist πŸ› οΈ Security Tools 🎯 Penetration Testing Tricks πŸ“„ Secure Code Explain πŸ“– Vulnerability Explain ☁️ AWS Cloud Security Checklist
My Resume
Contact UsContact
← Security Tools View on GitHub

pefile

Python module to read and work with Portable Executable (PE) files.

pefile

PyPI version pefile test Coverage OpenSSF Scorecard Contributors Code style: black Downloads Downloads

pefile is a multi-platform Python module to parse and work with Portable Executable (PE) files. Most of the information contained in the PE file headers is accessible, as well as all the sections' details and data.

The structures defined in the Windows header files will be accessible as attributes in the PE instance. The naming of fields/attributes will try to adhere to the naming scheme in those headers. Only shortcuts added for convenience will depart from that convention.

pefile requires some basic understanding of the layout of a PE file β€” with it, it is possible to explore nearly every single feature of the PE file format.

Installation

To install pefile through pip:

pip3 install pefile

Features

Some of the tasks that pefile makes possible are:

  • Inspecting headers
  • Analyzing of sections' data
  • Retrieving embedded data
  • Reading strings from the resources
  • Warnings for suspicious and malformed values
  • Basic modifying of PEs, like writing to some fields and other parts of the PE
    • This functionality won't rearrange PE file structures to make room for new fields, so use it with care.
    • Overwriting fields should mostly be safe.
  • Packer detection with PEiD’s signatures
  • PEiD signature generation

Please, refer to Usage Examples for some code snippets that demonstrate how to use pefile.

Here are a few examples of what a dump produced with pefile looks like for different types of files:

  • a packed file
  • kernel32.dll
  • TinyPE

To work with authenticated binaries, including Authenticode signatures, please check the project verify-sigs.

pefile runs in several pipelines scanning hundreds of thousands of new PE files every day, and, while not perfect, it has grown to be pretty robust over time. That being said, small glitches are found now and then. If you bump into a PE that does not appear to be processed correctly, do report it, please! It will help make pefile a tiny bit more powerful.

Dependencies

pefile is self-contained. The module has no dependencies; it is endianness independent; and it works on Windows, macOS, and Linux.

Projects and products using pefile

  • Didier Stevens' pecheck, a tool for displaying PE file info, handles PEiD files better then pefile does.
  • MAEC, a standardized language for encoding and communicating high-fidelity information about malware based upon attributes such as behaviors, artifacts, and attack patterns. MAEC converts pefile's output into their XML format.
  • Qiew, a Hex/File format viewer.
  • VirusTotal
  • bbfreeze
  • pyemu: download, GitHub, whitepaper
  • Immunity Debugger 1.1
  • Cuckoo
  • CAPE
  • MultiScanner
  • PE Tree
  • icoextract

Additional resources

PDFs of posters depicting the PE file format:

  • Portable Executable Format Layout shows the full view of the headers and structures defined by the PE format.
  • Portable Executable Header Walkthrough shows the raw view of an executable file with the PE format fields laid out over the corresponding areas.

The following links provide detailed information about the PE format and its structures.

  • corkami's wiki page about the PE format (archive) has grown to be one of the most in-depth repositories of information about the PE format.
  • corkami's treasure trove of PE weirdness
  • An In-Depth Look into the Win32 Portable Executable File Format
  • An In-Depth Look into the Win32 Portable Executable File Format, Part 2
  • Microsoft Portable Executable and Common Object File Format Specification
  • The Portable Executable File Format (archive)
  • Get icons from Exe or DLL the PE way (archive)
  • Solar Eclipse's Tiny PE page at "http://www.phreedom.org/solar/code/tinype/" is no longer available (html-only archive), corkami's TinyPE is available here (Code only)
Press Escape to close the search panel.

Donate

Buy me a Coffee

Penetration Testing Services - Fiverr

Buy me a Coffee

Penetration Testing Services

penetration Testing Services

Web Application Security Quiz

Web Application Security Quiz

Daily Bug Bounty Writeups - Twitter

Daily Bug Bounty Writeups

Download our Latest Android Application

Guide for Penetration Testing

Daily Bug Bounty Writeups - Telegram

Daily Bug Bounty Writeups

Author

Piyush
Senior Product Security Engineer

Ethical Hacker || Penetration Tester || Gamer || Blogger || Application Security Engineer

READ ARTICLE

Donate

Buy me a Coffee

Recent Posts

  • I Ran Codex Security on a Shop API Lab: 14 Bugs, $1.64, Full Playbook
    I Ran Codex Security on a Shop API Lab: 14 Bugs, $1.64, Full Playbook
    August 3, 2026/
    0 Comments
  • How I Would Hack Your Startup in 24 Hours (Real-World Pentest Guide)
    How I Would Hack Your Startup in 24 Hours (Real-World Pentest Guide)
    July 27, 2026/
    0 Comments
  • Web Cache Poisoning in 2026: A Practical Playbook (One Request, Every Victim)
    Web Cache Poisoning in 2026: A Practical Playbook (One Request, Every Victim)
    July 19, 2026/
    0 Comments

Follow Us

SecurityCipher

Practical security guides, vulnerability deep-dives, and hands-on resources for bug bounty hunters and penetration testers.

Useful Links

  • Start Here
  • Cybersecurity Jobs
  • CVE Lookup
  • Bug Bounty Programs
  • Security Conferences
  • Payload Cheatsheets
  • Interview Prep
  • Report Templates
  • Blogs
  • About
  • Contact
  • RSS Feed

Recent Post

  • I Ran Codex Security on a Shop API Lab: 14 Bugs, $1.64, Full Playbook
  • How I Would Hack Your Startup in 24 Hours (Real-World Pentest Guide)
  • Web Cache Poisoning in 2026: A Practical Playbook (One Request, Every Victim)
Β© 2026 SecurityCipher. All rights reserved. Privacy Policies Β· Terms & Conditions