Skip to main content

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}
}

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.3.3.tar.gz (3.7 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.3.3-cp312-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

pyvex-9.3.3-cp312-abi3-musllinux_1_2_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

pyvex-9.3.3-cp312-abi3-musllinux_1_2_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

pyvex-9.3.3-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

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

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

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyvex-9.3.3.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyvex-9.3.3.tar.gz
Algorithm Hash digest
SHA256 ff13eec3fa358f0e15e6dd969316144bef7f40ae0d056dc66297991bee167f3c
MD5 a6d22b0e13f47b7de50b6124c2df75c6
BLAKE2b-256 a09d7455d21fd60e486b76565c80a69956e0f37998158f591a7ff5511573a495

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3.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.3.3-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyvex-9.3.3-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyvex-9.3.3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 eff55326b8318ef2552ca49e81dfdf5dd2525dd0c46915178ccb6cbf4c5008a6
MD5 7eb439cb102ae47dc91653b7aa584ae1
BLAKE2b-256 a0e6d549f9d48004ab19b712e4468acd0286e146d732561f7d879de6dd343629

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3-cp312-abi3-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.3.3-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyvex-9.3.3-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 acdb8dc28835221fc5f04e225eeede927c6bc191c71f6be5b23028e20b593a4e
MD5 c1b16620d8854d8c33ae87f36823a482
BLAKE2b-256 4fb14306d104f0da968a1ecbaa04a0bf6ee41ecc2f5c2a688999837c3a2bdae8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3-cp312-abi3-musllinux_1_2_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.3.3-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyvex-9.3.3-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 500a838f9f1621dd91c1876600060809c20bde1bc15692b2e8e866506daf0968
MD5 650d715d9002da08e1573d888f94daec
BLAKE2b-256 9d0cdc4442743afccb7ca713f9c8f8807043e62eb5c60398c6fa80ffbdcf84d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3-cp312-abi3-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.3.3-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyvex-9.3.3-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 582a4d08c389e274a6599b821689c871a0f255e8cb75142c46f01db1e5291786
MD5 c4dab51bd3757616696fa4a6f15d6c77
BLAKE2b-256 0ccf726026492bb55855dadc83a492330f7b76ec439481f76c8386bf0e8f1607

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_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.3.3-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyvex-9.3.3-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 43f34ff8b94afffee093ae5114d865f2bd1256cd7a067b8c14f804518d74524a
MD5 e5f8959d223617ead274ef8a7933c9bb
BLAKE2b-256 9a585a87edac1ac7ee0e738bed815c743928457915e5c5a11d3c8f23beeee948

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3-cp312-abi3-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.3.3-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyvex-9.3.3-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a118b03de482466409635aded350be6c9223af4a440a786c27ece7674df2a6b
MD5 bf8df65eeefdcad4a396c5de2f54a2c7
BLAKE2b-256 ecf293227f862feb2c54dc7f2496d755c88dc54aab2374a8bbc14b293c80fd81

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvex-9.3.3-cp312-abi3-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.

Release history Release notifications | RSS feed

This release

9.3.3 This release

7 files

9.3.2

7 files

9.3.1

7 files

9.3.0

7 files

9.2.223

7 files

9.2.222

7 files

9.2.221

15 files

9.2.217

15 files

9.2.215

15 files

9.2.214

13 files

9.2.213

21 files

9.2.212

21 files

9.2.211

21 files

9.2.209

21 files

9.2.208

21 files

9.2.207

21 files

9.2.205

34 files

9.2.204

34 files

9.2.203

34 files

9.2.202

34 files

9.2.201

34 files

9.2.199

34 files

9.2.198

34 files

9.2.197

34 files

9.2.196

34 files

9.2.195

34 files

9.2.194

25 files

9.2.193

33 files

9.2.192

33 files

9.2.191

33 files

9.2.190

33 files

9.2.189

33 files

9.2.188

33 files

9.2.187

33 files

9.2.186

6 files

9.2.185

6 files

9.2.184

6 files

9.2.183

6 files

9.2.182

6 files

9.2.181

6 files

9.2.180

6 files

9.2.179

6 files

9.2.178

6 files

9.2.177

6 files

9.2.176

6 files

9.2.175

6 files

9.2.174

6 files

9.2.173

6 files

9.2.172

6 files

9.2.171

6 files

9.2.170

6 files

9.2.169

6 files

9.2.168

6 files

9.2.167

6 files

9.2.166

6 files

9.2.165

6 files

9.2.162

6 files

9.2.161

6 files

9.2.160

6 files

9.2.159

6 files

9.2.158

6 files

9.2.157

6 files

9.2.156

6 files

9.2.154

6 files

9.2.153

6 files

9.2.152

6 files

9.2.150

6 files

9.2.149

6 files

9.2.148

6 files

9.2.147

6 files

9.2.146

6 files

9.2.145

6 files

9.2.144

6 files

9.2.143

6 files

9.2.142

6 files

9.2.141

6 files

9.2.140

6 files

9.2.139

6 files

9.2.138

6 files

9.2.137

6 files

9.2.136

6 files

9.2.135

6 files

9.2.134

6 files

9.2.133

6 files

9.2.132

6 files

9.2.131

6 files

9.2.130

6 files

9.2.129

6 files

9.2.128

6 files

9.2.127

6 files

9.2.126

6 files

9.2.125

6 files

9.2.124

6 files

9.2.123

6 files

9.2.122

6 files

9.2.121

6 files

9.2.120

6 files

9.2.119

6 files

9.2.118

6 files

9.2.117

6 files

9.2.116

6 files

9.2.115

6 files

9.2.114

6 files

9.2.113

6 files

9.2.112

6 files

9.2.111

6 files

9.2.110

6 files

9.2.109

6 files

9.2.108

6 files

9.2.107

6 files

9.2.106

6 files

9.2.105

6 files

9.2.104

6 files

9.2.103

6 files

9.2.102

4 files

9.2.101

4 files

9.2.100

4 files

9.2.99

4 files

9.2.98

4 files

9.2.97

4 files

9.2.96

4 files

9.2.95

4 files

9.2.94

4 files

9.2.93

4 files

9.2.92

4 files

9.2.91

4 files

9.2.90

4 files

9.2.89

4 files

9.2.88

4 files

9.2.87

4 files

9.2.86

4 files

9.2.85

4 files

9.2.84

4 files

9.2.83

4 files

9.2.82

4 files

9.2.81

4 files

9.2.80

4 files

9.2.79

4 files

9.2.78

4 files

9.2.77

4 files

9.2.76

4 files

9.2.75

4 files

9.2.74

4 files

9.2.73

4 files

9.2.72

4 files

9.2.71

4 files

9.2.70

4 files

9.2.69

4 files

9.2.68

4 files

9.2.67

4 files

9.2.66

4 files

9.2.65

4 files

9.2.64

4 files

9.2.63

4 files

9.2.62

4 files

9.2.61

4 files

9.2.60

4 files

9.2.59

4 files

9.2.58

4 files

9.2.57

4 files

9.2.56

4 files

9.2.55

4 files

9.2.54

4 files

9.2.53

4 files

9.2.52

4 files

9.2.51

4 files

9.2.50

4 files

9.2.49

4 files

9.2.48

4 files

9.2.47

4 files

9.2.46

4 files

9.2.45

4 files

9.2.44

4 files

9.2.43

4 files

9.2.42

4 files

9.2.41

4 files

9.2.40

4 files

9.2.39

4 files

9.2.38

4 files

9.2.37

4 files

9.2.36

4 files

9.2.35

4 files

9.2.34

4 files

9.2.33

4 files

9.2.32

4 files

9.2.31

4 files

9.2.30

4 files

9.2.29

4 files

9.2.28

4 files

9.2.27

4 files

9.2.26

4 files

9.2.25

4 files

9.2.24

4 files

9.2.23

4 files

9.2.22

4 files

9.2.21

4 files

9.2.20

4 files

9.2.19

4 files

9.2.18

4 files

9.2.17

4 files

9.2.16

4 files

9.2.15

4 files

9.2.14

4 files

9.2.13

4 files

9.2.12

4 files

9.2.11

4 files

9.2.10

4 files

9.2.9

4 files

9.2.8

4 files

9.2.7

4 files

9.2.6

4 files

9.2.5

4 files

9.2.4

4 files

9.2.3

4 files

9.2.2

4 files

9.2.1

4 files

9.1.12332

4 files

9.1.11752

4 files

9.1.11611

4 files

9.1.11508

4 files

9.1.10913

4 files

9.0.10730

4 files

9.0.10689

4 files

9.0.10651

4 files

9.0.10576

4 files

9.0.10534

4 files

9.0.10409

4 files

9.0.10339

4 files

9.0.10281

4 files

9.0.10159

4 files

9.0.10072

4 files

9.0.10055

4 files

9.0.10010

4 files

9.0.9947

4 files

9.0.9792

4 files

9.0.9684

4 files

9.0.9572

4 files

9.0.9506

4 files

9.0.9438

4 files

9.0.9355

4 files

9.0.9297

4 files

9.0.9166

4 files

9.0.9031

4 files

9.0.8761

4 files

9.0.8021

4 files

9.0.7912

4 files

9.0.7833

4 files

9.0.7491

4 files

9.0.7293

4 files

9.0.6885

4 files

9.0.6852

4 files

9.0.6790

4 files

9.0.6642

4 files

9.0.6588

4 files

9.0.6488

4 files

9.0.6421

4 files

9.0.6281

4 files

9.0.6136

4 files

9.0.5903

4 files

9.0.5811

4 files

9.0.5739

4 files

9.0.5610

4 files

9.0.5450

4 files

9.0.5405

4 files

9.0.5376

4 files

9.0.5327

4 files

9.0.5326

4 files

9.0.5171

4 files

9.0.5034

4 files

9.0.5002

4 files

9.0.4940

4 files

9.0.4885

4 files

9.0.4663

4 files

9.0.4495

4 files

9.0.4446

4 files

9.0.4378

4 files

8.20.7.27

5 files

8.20.7.6

5 files

8.20.6.8

5 files

8.20.6.1

5 files

8.20.5.27

5 files

8.20.1.7

5 files

8.19.10.30

5 files

8.19.10.29

3 files

8.19.7.25

5 files

8.19.4.5

5 files

8.19.2.4

2 files

8.18.10.25

5 files

8.18.10.5

5 files

7.8.9.26

5 files

7.8.8.1

5 files

7.8.7.1

1 file

7.8.6.23

1 file

7.8.6.16

1 file

7.8.2.21

3 files

7.7.12.16

1 file

7.7.9.14

3 files

7.7.9.8

3 files

6.7.7.27

1 file

6.7.6.9

1 file

6.7.4.12

1 file

6.7.3.26

1 file

6.7.1.31

3 files

6.7.1.13.post2

1 file

6.7.1.13.post1

1 file

6.7.1.13

1 file

5.6.12.3

1 file

5.6.10.5

3 files

5.6.8.25

1 file

5.6.8.22

1 file

4.6.6.28

1 file

4.6.5.27

1 file

4.6.4.28

1 file

4.6.3.28

1 file

4.6.3.15

1 file

4.6.1.27

1 file

4.6.1.5

1 file

4.6.1.4.post3

1 file

4.6.1.4.post2

1 file

4.6.1.4.post1

1 file

4.6.1.4

1 file

4.5.12.21

1 file

4.5.12.12

2 files

4.5.11.23

2 files

4.5.10.14

2 files

4.5.9.29

2 files

4.5.9.14

2 files

4.5.9.13

2 files

4.5.9.9

2 files

3.12

2 files

3.11

2 files

3.1

2 files

3.0

2 files

Supported by

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