Skip to main content

A Python interface to libVEX and VEX IR

Project description

PyVEX

Latest Release Python Version PyPI Statistics License

PyVEX is Python bindings for the VEX IR.

Project Links

Project repository: https://github.com/angr/pyvex

Documentation: https://api.angr.io/projects/pyvex/en/latest/

Installing PyVEX

PyVEX can be pip-installed:

pip install pyvex

Using PyVEX

import pyvex
import archinfo

# translate an AMD64 basic block (of nops) at 0x400400 into VEX
irsb = pyvex.lift(b"\x90\x90\x90\x90\x90", 0x400400, archinfo.ArchAMD64())

# pretty-print the basic block
irsb.pp()

# this is the IR Expression of the jump target of the unconditional exit at the end of the basic block
print(irsb.next)

# this is the type of the unconditional exit (i.e., a call, ret, syscall, etc)
print(irsb.jumpkind)

# you can also pretty-print it
irsb.next.pp()

# iterate through each statement and print all the statements
for stmt in irsb.statements:
    stmt.pp()

# pretty-print the IR expression representing the data, and the *type* of that IR expression written by every store statement
import pyvex
for stmt in irsb.statements:
    if isinstance(stmt, pyvex.IRStmt.Store):
        print("Data:", end="")
        stmt.data.pp()
        print("")

        print("Type:", end="")
        print(stmt.data.result_type)
        print("")

# pretty-print the condition and jump target of every conditional exit from the basic block
for stmt in irsb.statements:
    if isinstance(stmt, pyvex.IRStmt.Exit):
        print("Condition:", end="")
        stmt.guard.pp()
        print("")

        print("Target:", end="")
        stmt.dst.pp()
        print("")

# these are the types of every temp in the IRSB
print(irsb.tyenv.types)

# here is one way to get the type of temp 0
print(irsb.tyenv.types[0])

Keep in mind that this is a syntactic representation of a basic block. That is, it'll tell you what the block means, but you don't have any context to say, for example, what actual data is written by a store instruction.

VEX Intermediate Representation

To deal with widely diverse architectures, it is useful to carry out analyses on an intermediate representation. An IR abstracts away several architecture differences when dealing with different architectures, allowing a single analysis to be run on all of them:

  • Register names. The quantity and names of registers differ between architectures, but modern CPU designs hold to a common theme: each CPU contains several general purpose registers, a register to hold the stack pointer, a set of registers to store condition flags, and so forth. The IR provides a consistent, abstracted interface to registers on different platforms. Specifically, VEX models the registers as a separate memory space, with integer offsets (i.e., AMD64's rax is stored starting at address 16 in this memory space).
  • Memory access. Different architectures access memory in different ways. For example, ARM can access memory in both little-endian and big-endian modes. The IR must abstract away these differences.
  • Memory segmentation. Some architectures, such as x86, support memory segmentation through the use of special segment registers. The IR understands such memory access mechanisms.
  • Instruction side-effects. Most instructions have side-effects. For example, most operations in Thumb mode on ARM update the condition flags, and stack push/pop instructions update the stack pointer. Tracking these side-effects in an ad hoc manner in the analysis would be crazy, so the IR makes these effects explicit.

There are lots of choices for an IR. We use VEX, since the uplifting of binary code into VEX is quite well supported. VEX is an architecture-agnostic, side-effects-free representation of a number of target machine languages. It abstracts machine code into a representation designed to make program analysis easier. This representation has five main classes of objects:

  • Expressions. IR Expressions represent a calculated or constant value. This includes memory loads, register reads, and results of arithmetic operations.
  • Operations. IR Operations describe a modification of IR Expressions. This includes integer arithmetic, floating-point arithmetic, bit operations, and so forth. An IR Operation applied to IR Expressions yields an IR Expression as a result.
  • Temporary variables. VEX uses temporary variables as internal registers: IR Expressions are stored in temporary variables between use. The content of a temporary variable can be retrieved using an IR Expression. These temporaries are numbered, starting at t0. These temporaries are strongly typed (i.e., "64-bit integer" or "32-bit float").
  • Statements. IR Statements model changes in the state of the target machine, such as the effect of memory stores and register writes. IR Statements use IR Expressions for values they may need. For example, a memory store IR Statement uses an IR Expression for the target address of the write, and another IR Expression for the content.
  • Blocks. An IR Block is a collection of IR Statements, representing an extended basic block (termed "IR Super Block" or "IRSB") in the target architecture. A block can have several exits. For conditional exits from the middle of a basic block, a special Exit IR Statement is used. An IR Expression is used to represent the target of the unconditional exit at the end of the block.

VEX IR is actually quite well documented in the libvex_ir.h file (https://github.com/angr/vex/blob/dev/pub/libvex_ir.h) in the VEX repository. For the lazy, we'll detail some parts of VEX that you'll likely interact with fairly frequently. To begin with, here are some IR Expressions:

IR Expression Evaluated Value VEX Output Example
Constant A constant value. 0x4:I32
Read Temp The value stored in a VEX temporary variable. RdTmp(t10)
Get Register The value stored in a register. GET:I32(16)
Load Memory The value stored at a memory address, with the address specified by another IR Expression. LDle:I32 / LDbe:I64
Operation A result of a specified IR Operation, applied to specified IR Expression arguments. Add32
If-Then-Else If a given IR Expression evaluates to 0, return one IR Expression. Otherwise, return another. ITE
Helper Function VEX uses C helper functions for certain operations, such as computing the conditional flags registers of certain architectures. These functions return IR Expressions. function_name()

These expressions are then, in turn, used in IR Statements. Here are some common ones:

IR Statement Meaning VEX Output Example
Write Temp Set a VEX temporary variable to the value of the given IR Expression. WrTmp(t1) = (IR Expression)
Put Register Update a register with the value of the given IR Expression. PUT(16) = (IR Expression)
Store Memory Update a location in memory, given as an IR Expression, with a value, also given as an IR Expression. STle(0x1000) = (IR Expression)
Exit A conditional exit from a basic block, with the jump target specified by an IR Expression. The condition is specified by an IR Expression. if (condition) goto (Boring) 0x4000A00:I32

An example of an IR translation, on ARM, is produced below. In the example, the subtraction operation is translated into a single IR block comprising 5 IR Statements, each of which contains at least one IR Expression (although, in real life, an IR block would typically consist of more than one instruction). Register names are translated into numerical indices given to the GET Expression and PUT Statement. The astute reader will observe that the actual subtraction is modeled by the first 4 IR Statements of the block, and the incrementing of the program counter to point to the next instruction (which, in this case, is located at 0x59FC8) is modeled by the last statement.

The following ARM instruction:

subs R2, R2, #8

Becomes this VEX IR:

t0 = GET:I32(16)
t1 = 0x8:I32
t3 = Sub32(t0,t1)
PUT(16) = t3
PUT(68) = 0x59FC8:I32

Cool stuff!

Citing PyVEX

If you use PyVEX in an academic work, please cite the paper for which it was developed:

@article{shoshitaishvili2015firmalice,
  title={Firmalice - Automatic Detection of Authentication Bypass Vulnerabilities in Binary Firmware},
  author={Shoshitaishvili, Yan and Wang, Ruoyu and Hauser, Christophe and Kruegel, Christopher and Vigna, Giovanni},
  booktitle={NDSS},
  year={2015}
}

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvex-9.2.214.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyvex-9.2.214-cp314-cp314-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.14Windows x86-64

pyvex-9.2.214-cp314-cp314-musllinux_1_2_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ ARM64

pyvex-9.2.214-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pyvex-9.2.214-cp314-cp314-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyvex-9.2.214-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

pyvex-9.2.214-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyvex-9.2.214-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pyvex-9.2.214-cp313-cp313-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyvex-9.2.214-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

pyvex-9.2.214-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyvex-9.2.214-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pyvex-9.2.214-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file pyvex-9.2.214.tar.gz.

File metadata

  • Download URL: pyvex-9.2.214.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyvex-9.2.214.tar.gz
Algorithm Hash digest
SHA256 4e2e1220de8b8cb163d8e500c8eb6eca964184d78aefad392526488cdfb64416
MD5 b10e7e3d69337d9acc5495564b058c01
BLAKE2b-256 34f4ae57995080fd10c0359b5c120b9496a06b04ea86bb57bc78cc28fa39a1ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214.tar.gz:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pyvex-9.2.214-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyvex-9.2.214-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4f080b3245c9169b1c5dc72cfd5ae71775a30b64fd745fc0f56e2e09d6999bda
MD5 8220691bf40f4c91377a4974f96aed7b
BLAKE2b-256 0bfe7a7598b9f214fae101ca60e066381c76200fdc9fd4f0d548bad406fab937

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp314-cp314-win_amd64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp314-cp314-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp314-cp314-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7384474e066632c40b1b4d601968adf81295241de8ffb2d044a9d6f573d02ce1
MD5 fa301be83d354cb3d96cb0ce51f5c34a
BLAKE2b-256 21e1fb38c9d44b987a376f8e63c5ce770eab2cb9d17835fd42984c8c53209374

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp314-cp314-musllinux_1_2_aarch64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 01781ac6af7d6e8512b92db6df965f0da9e4d4c37caa68e4600efc5fee0cb45c
MD5 ab6541644a77c0b085b3192c40ec38e9
BLAKE2b-256 7e0dd59911cb39d1a0963e6567cf6165b65edb580b722986a1b72abf65342dd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ccdfe1c594fb49f354ac548858ff619e7df6f1bca7813fada22569ac7eb01bf7
MD5 51229cab87fa878e74574e022148040a
BLAKE2b-256 2bc677e9d2bd7ce9a427e4b17889a59c0df267be1ecc48c7cb28103cb2299a3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pyvex-9.2.214-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyvex-9.2.214-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3b1ebf8335af15e45be22641f3069d97999598277f9503d97c02952c620a5bf0
MD5 d98db46db6abd7053901fc3296ab16e6
BLAKE2b-256 4eecc93f1c1e416e00f3ea6d17a10a8b0ac4f747ddbfb84a65ccf44e685d9fb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp313-cp313-win_amd64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d013fd6e914e26e68bba71f50c707113ffcd0eae8a4de58425d787f33b9ffc24
MD5 3d538d63552b1bbbad93300d721aa8a5
BLAKE2b-256 57467fc3e812eca12352adb26a913dd3ab174f2fba1c5794c3dd28bf87484624

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bd06b2d15116b9d36cb91d55c4532c1000dda41a756497be0762d77ff42bd8fd
MD5 52e484e26c5c8429345ba0aba9306fbf
BLAKE2b-256 6e85f784f7ff3d966aa734af5257baa5b26d60c1df06502e30ef0f94229f440f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83c8b06630d28e8cbabafd22cca6bea406ffce5573c3a0a15ad13c9df35f6a9e
MD5 323e76338c3462e2fad660aefb2ed123
BLAKE2b-256 dd4292ecbf44aed6569836c8f67d3dc5bc8cf7c79668ee3cdb536d6dddeb774c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyvex-9.2.214-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyvex-9.2.214-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1d0cc02a509c485e26f233137cbfe304b0f528e7f8cc399f09c0f72a9c38615d
MD5 8957260c9bdecd2db5d71f1f071c44d1
BLAKE2b-256 95343f429d73c175e976fd9ccded94db079b7e7069788d781eee955e5bf11b31

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp312-cp312-win_amd64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b89e9a9571e05bc963b5b3fd63677b7f6ada2a3df915ef58ed35c6fbfce1a858
MD5 0a2294eb17fbc53a57e5a49960b0cc22
BLAKE2b-256 1f8c477dd69e45feeab277429d14179db1a4052d91d4047f477b0506c609d0ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b6415bb1e7a201b7b185a8c67026a5f738fb188b0051b1eff90b2f3bac51e479
MD5 e1ace908890c3a99f6db97f720fd9cc2
BLAKE2b-256 806b742e3453d2dc2aad24103c4d369d7baacbeb624688b2c9d65ad445cdd36a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvex-9.2.214-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvex-9.2.214-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2788acac68e94ddfa225403cca4e5f4159776de092e7d112d843673d8465f097
MD5 902daf35541488fe2b1671ee2fa8b379
BLAKE2b-256 46a38b186acd377edeef8c980e7480459a1999ceed943430b6cb7f240a55f932

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.2.214-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: angr-release.yml on angr/ci-settings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page