pwnlib.constants
— Easy access to header file constants¶
Module containing constants extracted from header files.
The purpose of this module is to provide quick access to constants from different architectures and operating systems.
The constants are wrapped by a convenience class that allows accessing the name of the constant, while performing all normal mathematical operations on it.
Example
>>> str(constants.freebsd.SYS_stat)
'SYS_stat'
>>> int(constants.freebsd.SYS_stat)
188
>>> hex(constants.freebsd.SYS_stat)
'0xbc'
>>> 0 | constants.linux.i386.SYS_stat
106
>>> 0 + constants.linux.amd64.SYS_stat
4
The submodule freebsd
contains all constants for FreeBSD, while the
constants for Linux have been split up by architecture.
The variables of the submodules will be “lifted up” by setting the
pwnlib.context.arch
or pwnlib.context.os
in a manner similar to
what happens in pwnlib.shellcraft
.
Example
>>> with context.local(os = 'freebsd'):
... print int(constants.SYS_stat)
188
>>> with context.local(os = 'linux', arch = 'i386'):
... print int(constants.SYS_stat)
106
>>> with context.local(os = 'linux', arch = 'amd64'):
... print int(constants.SYS_stat)
4
>>> with context.local(arch = 'i386', os = 'linux'):
... print constants.SYS_execve + constants.PROT_WRITE
13
>>> with context.local(arch = 'amd64', os = 'linux'):
... print constants.SYS_execve + constants.PROT_WRITE
61
>>> with context.local(arch = 'amd64', os = 'linux'):
... print constants.SYS_execve + constants.PROT_WRITE
61