pyvex

9.2.211 · active · verified Thu Apr 16

PyVEX is a Python interface to libVEX, Valgrind's VEX Intermediate Representation (IR) engine. It provides bindings to translate machine code from various architectures into a common, architecture-agnostic, side-effects-free IR, facilitating static and dynamic program analysis. PyVEX is a foundational component of the angr binary analysis framework and is actively maintained with frequent releases, typically alongside the broader angr project.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to lift a small block of AMD64 NOP instructions into PyVEX's IRSB (Intermediate Representation Super-Block). It then pretty-prints the entire IRSB, iterates through its statements, and shows how to access the default exit (jump target) expression and kind. This requires `archinfo` to be installed.

import pyvex
import archinfo

# Binary code: 5 NOPs (0x90) for AMD64
binary_code = b"\x90\x90\x90\x90\x90"
# Base address for the code
base_address = 0x400400
# Architecture definition
architecture = archinfo.ArchAMD64()

# Lift the binary code into a VEX Intermediate Representation Super-Block (IRSB)
irsb = pyvex.lift(binary_code, base_address, architecture)

print("--- Lifted IRSB ---")
irsb.pp() # Pretty-print the IRSB

print("\n--- IRSB Statements ---")
for stmt in irsb.statements:
    stmt.pp()

print("\n--- Next IR Expression (Jump Target) ---")
irsb.next.pp()
print(f"Jump Kind: {irsb.jumpkind}")

view raw JSON →