Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pdfalyzer

> 数据库
Open source

Analyze PDFs with colors (and YARA)

396 stars0 likes0 views
WebsiteGitHub

About

Analyze PDFs with colors (and YARA)

THE PDFALYZER

A PDF analysis tool for visualizing the inner tree-like data structure[^1] of a PDF in spectacularly large and colorful diagrams as well as scanning the binary streams embedded in the PDF for hidden potentially malicious content. The Pdfalyzer makes heavy use of YARA (via The Yaralyzer) for matching/extracting byte patterns.

Quick Start

You can use pip but pipx is a cleaner way to install for normal users. Developers should probably use poetry.

bash
# If you don't care about extracting text, encrypted PDFs, images, etc. just do this:
pipx install pdfalyzer

# Or if you want to open encrypted PDFs or use the tools that ship with Pdfalyzer (e.g. extract_pdf_text):
pipx install pdfalyzer[extract]

# Then pdfalyze to your hearts content:
pdfalyze martin_heidegger-being_illmatic.pdf

# Consult the help screen if needed:
pdfalyze -h

# (Optional) Forcibly extract all text (including from embedded images) from a file:
extract_pdf_text martin_heidegger-being_illmatic.pdf

What It Do

  1. Generate in depth visualizations of PDF tree structures[^1]. Shows every property of every PDF object at a glance. See the Example Output section below for details.
  2. Scan for mad sus content with a bunch of PDF specific YARA rules.
  3. Forcibly decode suspect bytes. The Yaralyzer does the heavy lifting.
  4. Display detailed information about embedded fonts. With character maps.
  5. Extract pages and/or text (including from embedded images) with the included command line tools.
  6. Usable as a library for your own PDF related code.

If you're looking for one of these things this may be the tool for you.

What It Don't Do

This tool is mostly for examining/working with a PDF's data and logical structure. As such it doesn't have much to offer as far as extracting text, rendering[^3], writing, etc. etc.

If you suspect you are dealing with a malcious PDF you can safely run pdfalyze on it. Embedded javascript and /OpenAction nodes etc. will not be executed. If you want to actually look at the contents of a suspect PDF you can use dangerzone to sanitize the contents with extreme prejudice before opening it.

Installation

All Platforms

Installation with pipx[^4] is preferred though pip3 / pip should also work.

bash
pipx install pdfalyzer

macOS Homebrew

If you are on macOS and use homebrew someone out there was kind enough to make Pdfalyzer available via homebrew so this should work:

bash
brew install pdfalyzer

Troubleshooting

  1. If you used pip3 instead of pipx and have an issue you should try to install with pipx.
  2. If you run into an issue about missing YARA try to install yara-python.
  3. If you encounter an error building the python cryptography package check your pip version (pip --version). If it's less than 22.0, upgrade pip with pip install --upgrade pip.
  4. If you can't get the pdfalyze command to work try python -m pdfalyzer. It's an equivalent but more portable version of the same command that does not rely on your python script paths being set up in a sane way.
  5. While Pdfalyzer has been tested on quite a few large and very complicated PDFs there are no doubt a bunch of edge cases that will trip up the code. Sifting through the various interconnected internal PDF objects and building the correct tree representation is much, much harder than it should be and requires multiple scans and a little bit of educated guessing. If a PDF fails to parse and you hit an error please open a GitHub issue with the compressed (.zip, .gz, whatever) PDF that is causing the problem attached (if possible) and I'll take a look when I can. I will not take a look at any uncompressed PDFs due to the security risks so make sure you zip it before you ship it.
  6. On Linux if you encounter an error building wheel or cffi you may need to install some packages:
    bash
    sudo apt-get install build-essential libssl-dev libffi-dev rustc

Usage

Run pdfalyze --help to see usage instructions. As of right now these are the options:

Runtime Options

If you provide none of the flags in the ANALYSIS SELECTION section of the --help then all of the analyses will be done except the --streams. In other words, these two commands are equivalent:

  1. pdfalyze lacan_buys_the_dip.pdf
  2. pdfalyze lacan_buys_the_dip.pdf -d -t -r -f -y -c

The --streams output is the one used to hunt for patterns in the embedded bytes and can be extremely verbose depending on the --quote-char options chosen (or not chosen) and contents of the PDF. The Yaralyzer handles this task; if you want to hunt for patterns in the bytes other than bytes surrounded by backticks/frontslashes/brackets/quotes/etc. you may want to use The Yaralyzer directly. Yaralyzer is a prequisite for Pdfalyzer so you may already have the yaralyze command installed and available.

Setting Command Line Options Permanently With A .pdfalyzer File

When you run pdfalyze on some PDF the tool will check for a file called .pdfalyzer in these places in this order:

  1. the current directory
  2. the user's home directory

If it finds a .pdfalyzer file in either such place it will load configuration options from it. Documentation on the options that can be configured with these files lives in .pdfalyzer.example which doubles as an example file you can copy into place and edit to your needs. Handy if you find yourself typing the same command line options over and over again.

Guarantees

If any PDF object ID between 1 and the /Size reported by the PDF itself could not be successfully placed in the tree warnings will be printed and the pdfalyze command will return an error code (1, specifically) to the shell. If you do not get any warnings and/or pdfalyze returns success then all[^2] of the inner PDF objects should be seen in the output.

Example Malicious PDF Investigation

BUFFERZONE Team posted an excellent example of how one might use The Pdfalyzer in tandem with Didier Stevens' PDF tools to investigate a potentially malicious PDF (archived in the doc/ dir in this repo if the link rots).

Included Command Line Tools

The Pdfalyzer comes with a few command line tools for doing stuff with PDFs:

  • combine_pdfs - Combines multiple PDFs into a single PDF. Run combine_pdfs --help for more info.
  • extract_pdf_pages - Extracts page ranges (e.g. "10-25") from a PDF and writes them to a new PDF. Run extract_pdf_pages --help for more info.
  • extract_pdf_text - Extracts text from a PDF, including applying OCR to all embedded images. Run extract_pdf_text --help for more info.

Running extract_pdf_text requires that you install The Pdfalyzer's optional dependencies:

bash
pipx install pdfalyzer[extract]

As A Python Library

For info about setting up a dev environment see Contributing below.

At its core The Pdfalyzer is taking PDF internal objects gathered by PyPDF and wrapping them in AnyTree's NodeMixin class. Given that things like searching the tree or accessing internal PDF properties will be done through those packages' code it may be helpful to review their documentation.

As far as The Pdfalyzer's unique functionality goes, Pdfalyzer is the class at the heart of the operation. It holds the PDF's logical tree as well as a few other data structures. Chief among these are the FontInfo class which pulls together various properties of a font strewn across 3 or 4 different PDF objects and the BinaryScanner class which lets you dig through the embedded streams' bytes looking for suspicious patterns.

Here's a short intro to how to access these objects:

…

Example Output

The Pdfalyzer can export visualizations to HTML, ANSI colored text, and both PNG and SVG vector images using the file export functionality that comes with Rich.

If you want to export .png images like the ones below directly from Pdfalyzer you'll need to do one of these things:

  1. Install Inkscape (homebrew users can install it with brew install --cask inkscape)
  2. Ask for the img extra when installing Pdfalyzer which will install cairosvg: pipx install pdfalyzer[img]. You'll also have to install the CairoSVG executable manually in different ways depending on your operating system, see the CairoSVG docs for the specifics.

In our experience Inkscape and CairoSVG both work though we've seen some glitchiness in the rendered output (along with straight up crashes) using CairoSVG on the SVGs rendered by Pdfalyzer so Inkscape is recommended.

Basic Tree View

As you can see the suspicious /OpenAction relationship is highlighted bright red, as would be a couple of other sus PDF instructions like /JavaScript or /AcroForm if they exist in the PDF being pdfalyzed.

The dimmer (as in "harder to see") nodes[^5] marked with Non Child Reference give you a way to visualize the relationships between PDF objects that exist outside of the tree structure's parent/child relationships.

That's a pretty basic document. Here's the basic tree for a more complicated PDF containing an NMAP cheat sheet.

Rich Tree View

This image shows a more in-depth view of of the PDF tree for the same document shown above. This tree (AKA the "rich" tree) has almost everything. Shows all PDF object properties, all relationships between objects, and sizable previews of any binary data streams embedded or encrypted in the document. Note that in addition to /OpenAction, the Adobe Type1 font binary is also red (Google's project zero regards any Adobe Type1 font as "mad sus").

And here's the rich tree for the same more complicated NMAP cheat sheet PDF linked instead of shown directly in the previous section.

Fonts

Extract character mappings from ancient Adobe font formats. It's actually PyPDF doing the lifting here but we're happy to take the credit.

View the properties of the fonts in the PDF. Comes with a preview of the beginning and end of the font's raw binary data stream (if it's that kind of font).

Binary Analysis (And Lots Of It)

YARA Scan: Check PDF for malicious content.

This repo contains all the PDF specific YARA rules I could dig up that identify byte patterns indicating a PDF may have been modified for evil. While the real dangers exist in PDF modifications no one has seen yet (and thus we have no YARA rules for), there are still a bunch of 'sus' indicators (e.g. has a Type1 font, is incorrectly terminated, etc.) that will be tripped when you scan a PDF with The Pdfalyzer.

Search Internal Binary Data for Sus Content No Malware Scanner Will Catch[^6]:

Things like, say, a hidden binary /F (PDF instruction meaning "URL") followed b

Issues· 5 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonmalicious-pdf-filesmalware-analysispdfpdf-documents

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库