2016-05-21 16:38:29 +03:00
|
|
|
# Define structures and constants for generating elf file.
|
2018-09-23 15:31:51 +01:00
|
|
|
import ctypes
|
2025-01-23 04:07:42 +05:30
|
|
|
import platform
|
|
|
|
|
|
|
|
MACHINE = platform.machine()
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
Elf32_Half = ctypes.c_uint16 # typedef uint16_t Elf32_Half;
|
|
|
|
Elf32_Word = ctypes.c_uint32 # typedef uint32_t Elf32_Word;
|
|
|
|
Elf32_Addr = ctypes.c_uint32 # typedef uint32_t Elf32_Addr;
|
|
|
|
Elf32_Off = ctypes.c_uint32 # typedef uint32_t Elf32_Off;
|
|
|
|
Elf32_Xword = ctypes.c_uint64 # typedef uint64_t Elf32_Xword;
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
Elf64_Half = ctypes.c_uint16 # typedef uint16_t Elf64_Half;
|
|
|
|
Elf64_Word = ctypes.c_uint32 # typedef uint32_t Elf64_Word;
|
|
|
|
Elf64_Addr = ctypes.c_uint64 # typedef uint64_t Elf64_Addr;
|
|
|
|
Elf64_Off = ctypes.c_uint64 # typedef uint64_t Elf64_Off;
|
|
|
|
Elf64_Xword = ctypes.c_uint64 # typedef uint64_t Elf64_Xword;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
# Elf_Ehdr related constants.
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# e_ident size.
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_NIDENT = 16 # #define EI_NIDENT (16)
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_MAG0 = 0 # #define EI_MAG0 0 /* File identification byte 0 index */
|
|
|
|
ELFMAG0 = 0x7f # #define ELFMAG0 0x7f /* Magic number byte 0 */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_MAG1 = 1 # #define EI_MAG1 1 /* File identification byte 1 index */
|
2021-09-05 21:53:06 +01:00
|
|
|
ELFMAG1 = ord('E') # #define ELFMAG1 'E' /* Magic number byte 1 */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_MAG2 = 2 # #define EI_MAG2 2 /* File identification byte 2 index */
|
2021-09-05 21:53:06 +01:00
|
|
|
ELFMAG2 = ord('L') # #define ELFMAG2 'L' /* Magic number byte 2 */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_MAG3 = 3 # #define EI_MAG3 3 /* File identification byte 3 index */
|
2021-09-05 21:53:06 +01:00
|
|
|
ELFMAG3 = ord('F') # #define ELFMAG3 'F' /* Magic number byte 3 */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_CLASS = 4 # #define EI_CLASS 4 /* File class byte index */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_DATA = 5 # #define EI_DATA 5 /* Data encoding byte index */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
EI_OSABI = 7 # #define EI_OSABI 7 /* OS ABI identification */
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
EI_VERSION = 6 # #define EI_VERSION 6 /* File version byte index */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
ELFDATA2LSB = 1 # #define ELFDATA2LSB 1 /* 2's complement, little endian */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
ELFCLASS32 = 1 # #define ELFCLASS32 1 /* 32-bit objects */
|
2019-09-07 15:46:22 +03:00
|
|
|
ELFCLASS64 = 2 # #define ELFCLASS64 2 /* 64-bit objects */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# Legal values for e_type (object file type).
|
2019-09-07 15:46:22 +03:00
|
|
|
ET_CORE = 4 # #define ET_CORE 4 /* Core file */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# Legal values for e_machine (architecture).
|
2025-02-17 18:06:10 +05:30
|
|
|
EM_ARM = 40 # #define EM_ARM 40 /* ARM */
|
2019-09-07 15:46:22 +03:00
|
|
|
EM_X86_64 = 62 # #define EM_X86_64 62 /* AMD x86-64 architecture */
|
2025-01-23 04:07:42 +05:30
|
|
|
EM_AARCH64 = 183 # #define EM_AARCH64 183 /* ARM AARCH64 */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# Legal values for e_version (version).
|
2019-09-07 15:46:22 +03:00
|
|
|
EV_CURRENT = 1 # #define EV_CURRENT 1 /* Current version */
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
# Legal values for e_osabi
|
|
|
|
ELFOSABI_NONE = 0 # #define ELFOSABI_NONE 0 /* UNIX System V ABI */
|
|
|
|
ELFOSABI_ARM = 97 # #define ELFOSABI_ARM 97 /* ARM */
|
|
|
|
|
|
|
|
|
|
|
|
class Elf32_Ehdr(ctypes.Structure): # typedef struct
|
|
|
|
_fields_ = [
|
|
|
|
("e_ident",
|
|
|
|
ctypes.c_ubyte * EI_NIDENT), # unsigned char e_ident[EI_NIDENT];
|
|
|
|
("e_type", Elf32_Half), # Elf32_Half e_type;
|
|
|
|
("e_machine", Elf32_Half), # Elf32_Half e_machine;
|
|
|
|
("e_version", Elf32_Word), # Elf32_Word e_version;
|
|
|
|
("e_entry", Elf32_Addr), # Elf32_Addr e_entry;
|
|
|
|
("e_phoff", Elf32_Off), # Elf32_Off e_phoff;
|
|
|
|
("e_shoff", Elf32_Off), # Elf32_Off e_shoff;
|
|
|
|
("e_flags", Elf32_Word), # Elf32_Word e_flags;
|
|
|
|
("e_ehsize", Elf32_Half), # Elf32_Half e_ehsize;
|
|
|
|
("e_phentsize", Elf32_Half), # Elf32_Half e_phentsize;
|
|
|
|
("e_phnum", Elf32_Half), # Elf32_Half e_phnum;
|
|
|
|
("e_shentsize", Elf32_Half), # Elf32_Half e_shentsize;
|
|
|
|
("e_shnum", Elf32_Half), # Elf32_Half e_shnum;
|
|
|
|
("e_shstrndx", Elf32_Half) # Elf32_Half e_shstrndx;
|
|
|
|
] # } Elf32_Ehdr;
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
class Elf64_Ehdr(ctypes.Structure): # typedef struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
("e_ident",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ubyte * EI_NIDENT), # unsigned char e_ident[EI_NIDENT];
|
|
|
|
("e_type", Elf64_Half), # Elf64_Half e_type;
|
|
|
|
("e_machine", Elf64_Half), # Elf64_Half e_machine;
|
|
|
|
("e_version", Elf64_Word), # Elf64_Word e_version;
|
|
|
|
("e_entry", Elf64_Addr), # Elf64_Addr e_entry;
|
|
|
|
("e_phoff", Elf64_Off), # Elf64_Off e_phoff;
|
|
|
|
("e_shoff", Elf64_Off), # Elf64_Off e_shoff;
|
|
|
|
("e_flags", Elf64_Word), # Elf64_Word e_flags;
|
|
|
|
("e_ehsize", Elf64_Half), # Elf64_Half e_ehsize;
|
|
|
|
("e_phentsize", Elf64_Half), # Elf64_Half e_phentsize;
|
|
|
|
("e_phnum", Elf64_Half), # Elf64_Half e_phnum;
|
|
|
|
("e_shentsize", Elf64_Half), # Elf64_Half e_shentsize;
|
|
|
|
("e_shnum", Elf64_Half), # Elf64_Half e_shnum;
|
|
|
|
("e_shstrndx", Elf64_Half) # Elf64_Half e_shstrndx;
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } Elf64_Ehdr;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
# Elf_Phdr related constants.
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# Legal values for p_type (segment type).
|
2019-09-07 15:46:22 +03:00
|
|
|
PT_LOAD = 1 # #define PT_LOAD 1 /* Loadable program segment */
|
|
|
|
PT_NOTE = 4 # #define PT_NOTE 4 /* Auxiliary information */
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# Legal values for p_flags (segment flags).
|
2019-09-07 15:46:22 +03:00
|
|
|
PF_X = 1 # #define PF_X (1 << 0) /* Segment is executable */
|
|
|
|
PF_W = 1 << 1 # #define PF_W (1 << 1) /* Segment is writable */
|
|
|
|
PF_R = 1 << 2 # #define PF_R (1 << 2) /* Segment is readable */
|
|
|
|
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
class Elf32_Phdr(ctypes.Structure): # typedef struct
|
|
|
|
_fields_ = [
|
|
|
|
("p_type", Elf32_Word), # Elf32_Word p_type;
|
|
|
|
("p_offset", Elf32_Off), # Elf32_Off p_offset;
|
|
|
|
("p_vaddr", Elf32_Addr), # Elf32_Addr p_vaddr;
|
|
|
|
("p_paddr", Elf32_Addr), # Elf32_Addr p_paddr;
|
|
|
|
("p_filesz", Elf32_Word), # Elf32_Word p_filesz;
|
|
|
|
("p_memsz", Elf32_Word), # Elf32_Word p_memsz;
|
|
|
|
("p_flags", Elf32_Word), # Elf32_Word p_flags;
|
|
|
|
("p_align", Elf32_Word), # Elf32_Word p_align;
|
|
|
|
] # } Elf32_Phdr;
|
|
|
|
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
class Elf64_Phdr(ctypes.Structure): # typedef struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
("p_type", Elf64_Word), # Elf64_Word p_type;
|
|
|
|
("p_flags", Elf64_Word), # Elf64_Word p_flags;
|
|
|
|
("p_offset", Elf64_Off), # Elf64_Off p_offset;
|
|
|
|
("p_vaddr", Elf64_Addr), # Elf64_Addr p_vaddr;
|
|
|
|
("p_paddr", Elf64_Addr), # Elf64_Addr p_paddr;
|
|
|
|
("p_filesz", Elf64_Xword), # Elf64_Xword p_filesz;
|
|
|
|
("p_memsz", Elf64_Xword), # Elf64_Xword p_memsz;
|
|
|
|
("p_align", Elf64_Xword), # Elf64_Xword p_align;
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } Elf64_Phdr;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
# Elf_auxv_t related constants.
|
|
|
|
|
|
|
|
|
|
|
|
class _Elf32_auxv_t_U(ctypes.Union):
|
|
|
|
_fields_ = [("a_val", ctypes.c_uint32)]
|
|
|
|
|
|
|
|
|
|
|
|
class Elf32_auxv_t(ctypes.Structure): # typedef struct
|
|
|
|
_fields_ = [
|
|
|
|
("a_type",
|
|
|
|
ctypes.c_uint32), # uint32_t a_type; /* Entry type */
|
|
|
|
("a_un", _Elf32_auxv_t_U) # union
|
|
|
|
|
|
|
|
# uint32_t a_val; /* Integer value */
|
|
|
|
# /* We use to have pointer elements added here. We cannot do that,
|
|
|
|
# though, since it does not work when using 32-bit definitions
|
|
|
|
# on 64-bit platforms and vice versa. */
|
|
|
|
# } a_un;
|
|
|
|
] # } Elf32_auxv_t;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2018-09-23 15:31:51 +01:00
|
|
|
class _Elf64_auxv_t_U(ctypes.Union):
|
2019-09-07 15:46:22 +03:00
|
|
|
_fields_ = [("a_val", ctypes.c_uint64)]
|
|
|
|
|
|
|
|
|
|
|
|
class Elf64_auxv_t(ctypes.Structure): # typedef struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
("a_type",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_uint64), # uint64_t a_type; /* Entry type */
|
|
|
|
("a_un", _Elf64_auxv_t_U) # union
|
|
|
|
|
|
|
|
# uint64_t a_val; /* Integer value */
|
|
|
|
# /* We use to have pointer elements added here. We cannot do that,
|
|
|
|
# though, since it does not work when using 32-bit definitions
|
|
|
|
# on 64-bit platforms and vice versa. */
|
|
|
|
# } a_un;
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } Elf64_auxv_t;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
# Elf_Nhdr related constants.
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
NT_PRSTATUS = 1 # #define NT_PRSTATUS 1 /* Contains copy of prstatus struct */
|
|
|
|
NT_FPREGSET = 2 # #define NT_FPREGSET 2 /* Contains copy of fpregset struct */
|
|
|
|
NT_PRPSINFO = 3 # #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
|
|
|
|
NT_AUXV = 6 # #define NT_AUXV 6 /* Contains copy of auxv array */
|
|
|
|
NT_SIGINFO = 0x53494749 # #define NT_SIGINFO 0x53494749 /* Contains copy of siginfo_t, size might increase */
|
|
|
|
NT_FILE = 0x46494c45 # #define NT_FILE 0x46494c45 /* Contains information about mapped files */
|
|
|
|
NT_X86_XSTATE = 0x202 # #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
|
2025-02-17 18:06:10 +05:30
|
|
|
NT_ARM_VFP = 0x400 # #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
|
2025-01-23 04:07:42 +05:30
|
|
|
NT_ARM_TLS = 0x401 # #define NT_ARM_TLS 0x401 /* ARM TLS register */
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
class Elf32_Nhdr(ctypes.Structure): # typedef struct
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
"n_namesz", Elf32_Word
|
|
|
|
), # Elf32_Word n_namesz; /* Length of the note's name. */
|
|
|
|
(
|
|
|
|
"n_descsz", Elf32_Word
|
|
|
|
), # Elf32_Word n_descsz; /* Length of the note's descriptor. */
|
|
|
|
(
|
|
|
|
"n_type", Elf32_Word
|
|
|
|
), # Elf32_Word n_type; /* Type of the note. */
|
|
|
|
] # } Elf32_Nhdr;
|
|
|
|
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
class Elf64_Nhdr(ctypes.Structure): # typedef struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
|
|
|
"n_namesz", Elf64_Word
|
2021-09-05 21:53:06 +01:00
|
|
|
), # Elf64_Word n_namesz; /* Length of the note's name. */
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
|
|
|
"n_descsz", Elf64_Word
|
2021-09-05 21:53:06 +01:00
|
|
|
), # Elf64_Word n_descsz; /* Length of the note's descriptor. */
|
2019-09-07 15:46:22 +03:00
|
|
|
("n_type", Elf64_Word
|
2021-09-05 21:53:06 +01:00
|
|
|
), # Elf64_Word n_type; /* Type of the note. */
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } Elf64_Nhdr;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
# Elf_Shdr related constants.
|
|
|
|
|
|
|
|
|
|
|
|
class Elf32_Shdr(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Section name (string tbl index)
|
|
|
|
"sh_name", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section type
|
|
|
|
"sh_type", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section flags
|
|
|
|
"sh_flags", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section virtual addr at execution
|
|
|
|
"sh_addr", Elf32_Addr
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section file offset
|
|
|
|
"sh_offset", Elf32_Off
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section size in bytes
|
|
|
|
"sh_size", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Link to another section
|
|
|
|
"sh_link", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Additional section information
|
|
|
|
"sh_info", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section alignment
|
|
|
|
"sh_addralign", Elf32_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Entry size if section holds table
|
|
|
|
"sh_entsize", Elf32_Word
|
|
|
|
)
|
|
|
|
]
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
class Elf64_Shdr(ctypes.Structure):
|
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Section name (string tbl index)
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_name", Elf64_Word
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section type
|
|
|
|
"sh_type", Elf64_Word
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Section flags
|
|
|
|
"sh_flags", Elf64_Xword
|
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Section virtual addr at execution
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_addr", Elf64_Addr
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Section file offset
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_offset", Elf64_Off
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Section size in bytes
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_size", Elf64_Xword
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Link to another section
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_link", Elf64_Word
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Additional section information
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_info", Elf64_Word
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Section alignment
|
|
|
|
"sh_addralign", Elf64_Xword
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Entry size if section holds table
|
2019-09-07 15:46:22 +03:00
|
|
|
"sh_entsize", Elf64_Xword
|
2021-09-05 21:53:06 +01:00
|
|
|
)
|
|
|
|
]
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
# elf_prstatus related constants.
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2016-05-21 16:38:29 +03:00
|
|
|
# Signal info.
|
2019-09-07 15:46:22 +03:00
|
|
|
class elf_siginfo(ctypes.Structure): # struct elf_siginfo
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Signal number
|
|
|
|
"si_signo", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Extra code
|
|
|
|
"si_code", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Errno
|
|
|
|
"si_errno", ctypes.c_int
|
|
|
|
)
|
|
|
|
]
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# A time value that is accurate to the nearest
|
|
|
|
# microsecond but also has a range of years.
|
2019-09-07 15:46:22 +03:00
|
|
|
class timeval(ctypes.Structure): # struct timeval
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# __time_t tv_sec; /* Seconds. */
|
|
|
|
"tv_sec", ctypes.c_long
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# __suseconds_t tv_usec; /* Microseconds. */
|
|
|
|
"tv_usec", ctypes.c_long
|
|
|
|
)
|
|
|
|
]
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2025-01-23 04:07:42 +05:30
|
|
|
class x86_64_user_regs_struct(ctypes.Structure): # struct x86_64_user_regs_struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
("r15",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r15;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r14",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r14;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r13",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r13;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r12",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r12;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rbp",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rbp;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rbx",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rbx;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r11",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r11;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r10",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r10;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r9",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r9;
|
2019-09-07 15:46:22 +03:00
|
|
|
("r8",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int r8;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rax",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rax;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rcx",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rcx;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rdx",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rdx;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rsi",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rsi;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rdi",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rdi;
|
2019-09-07 15:46:22 +03:00
|
|
|
("orig_rax", ctypes.c_ulonglong
|
2021-09-05 21:53:06 +01:00
|
|
|
), # __extension__ unsigned long long int orig_rax;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rip",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rip;
|
2019-09-07 15:46:22 +03:00
|
|
|
("cs",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int cs;
|
2019-09-07 15:46:22 +03:00
|
|
|
("eflags",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int eflags;
|
2019-09-07 15:46:22 +03:00
|
|
|
("rsp",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int rsp;
|
2019-09-07 15:46:22 +03:00
|
|
|
("ss",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int ss;
|
2019-09-07 15:46:22 +03:00
|
|
|
("fs_base", ctypes.c_ulonglong
|
2021-09-05 21:53:06 +01:00
|
|
|
), # __extension__ unsigned long long int fs_base;
|
2019-09-07 15:46:22 +03:00
|
|
|
("gs_base", ctypes.c_ulonglong
|
2021-09-05 21:53:06 +01:00
|
|
|
), # __extension__ unsigned long long int gs_base;
|
2019-09-07 15:46:22 +03:00
|
|
|
("ds",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int ds;
|
2019-09-07 15:46:22 +03:00
|
|
|
("es",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int es;
|
2019-09-07 15:46:22 +03:00
|
|
|
("fs",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_ulonglong), # __extension__ unsigned long long int fs;
|
2019-09-07 15:46:22 +03:00
|
|
|
("gs", ctypes.c_ulonglong
|
2021-09-05 21:53:06 +01:00
|
|
|
) # __extension__ unsigned long long int gs;
|
|
|
|
]
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2025-01-23 04:07:42 +05:30
|
|
|
class aarch64_user_regs_struct(ctypes.Structure): # struct aarch64_user_regs_struct
|
|
|
|
_fields_ = [
|
|
|
|
("regs",
|
|
|
|
ctypes.c_ulonglong * 31), # unsigned long long int regs[31];
|
|
|
|
("sp",
|
|
|
|
ctypes.c_ulonglong), # unsigned long long int sp;
|
|
|
|
("pc",
|
|
|
|
ctypes.c_ulonglong), # unsigned long long int pc;
|
|
|
|
("pstate",
|
|
|
|
ctypes.c_ulonglong), # unsigned long long int pstate;
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2025-02-17 18:06:10 +05:30
|
|
|
class arm_user_regs_struct(ctypes.Structure): # struct arm_user_regs_struct
|
|
|
|
_fields_ = [
|
|
|
|
("r0",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r0;
|
|
|
|
("r1",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r1;
|
|
|
|
("r2",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r2;
|
|
|
|
("r3",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r3;
|
|
|
|
("r4",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r4;
|
|
|
|
("r5",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r5;
|
|
|
|
("r6",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r6;
|
|
|
|
("r7",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r7;
|
|
|
|
("r8",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r8;
|
|
|
|
("r9",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r9;
|
|
|
|
("r10",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int r10;
|
|
|
|
("fp",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int fp;
|
|
|
|
("ip",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int ip;
|
|
|
|
("sp",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int sp;
|
|
|
|
("lr",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int lr;
|
|
|
|
("pc",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int pc;
|
|
|
|
("cpsr",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int cpsr;
|
|
|
|
("orig_r0",
|
|
|
|
ctypes.c_ulong), # unsigned ulong int orig_r0;
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# elf_greg_t = ctypes.c_ulonglong
|
|
|
|
# ELF_NGREG = ctypes.sizeof(user_regs_struct)/ctypes.sizeof(elf_greg_t)
|
|
|
|
# elf_gregset_t = elf_greg_t*ELF_NGREG
|
2025-01-23 04:07:42 +05:30
|
|
|
user_regs_dict = {
|
|
|
|
"aarch64": aarch64_user_regs_struct,
|
2025-02-17 18:06:10 +05:30
|
|
|
"armv7l": arm_user_regs_struct,
|
2025-01-23 04:07:42 +05:30
|
|
|
"x86_64": x86_64_user_regs_struct,
|
|
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
|
|
elf_gregset_t = user_regs_dict[MACHINE]
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError("Current architecture %s is not supported." % MACHINE)
|
2016-05-21 16:38:29 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
class elf_prstatus(ctypes.Structure): # struct elf_prstatus
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Info associated with signal
|
|
|
|
# struct elf_siginfo pr_info;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_info", elf_siginfo
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Current signal
|
|
|
|
# short int pr_cursig;
|
|
|
|
"pr_cursig", ctypes.c_short
|
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Set of pending signals
|
|
|
|
# unsigned long int pr_sigpend;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_sigpend", ctypes.c_ulong
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Set of held signals
|
|
|
|
# unsigned long int pr_sighold;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_sighold", ctypes.c_ulong
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Process ID
|
|
|
|
# __pid_t pr_pid;
|
|
|
|
"pr_pid", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Parent process ID
|
|
|
|
# __pid_t pr_ppid;
|
|
|
|
"pr_ppid", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Parent group ID
|
|
|
|
# __pid_t pr_pgrp;
|
|
|
|
"pr_pgrp", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Parent session ID
|
|
|
|
# __pid_t pr_sid;
|
|
|
|
"pr_sid", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# User time
|
|
|
|
# struct timeval pr_utime;
|
|
|
|
"pr_utime", timeval
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# System time
|
|
|
|
# struct timeval pr_stime;
|
|
|
|
"pr_stime", timeval
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Cumulative user time
|
|
|
|
# struct timeval pr_cutime;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_cutime", timeval
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Cumulative system time
|
|
|
|
# struct timeval pr_cstime;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_cstime", timeval
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# GP registers
|
|
|
|
# elf_gregset_t pr_reg;
|
|
|
|
"pr_reg", elf_gregset_t
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# True if math copro being used
|
|
|
|
# int pr_fpvalid;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_fpvalid", ctypes.c_int
|
2021-09-05 21:53:06 +01:00
|
|
|
)
|
|
|
|
]
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
# elf_prpsinfo related constants.
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# Number of chars for args
|
|
|
|
# #define ELF_PRARGSZ (80)
|
|
|
|
ELF_PRARGSZ = 80
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
class elf_prpsinfo(ctypes.Structure): # struct elf_prpsinfo
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Numeric process state
|
|
|
|
# char pr_state;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_state", ctypes.c_byte
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Char for pr_state
|
|
|
|
# char pr_sname;
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_sname", ctypes.c_char
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Zombie
|
|
|
|
# char pr_zomb;
|
|
|
|
"pr_zomb", ctypes.c_byte
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Nice value
|
|
|
|
# char pr_nice;
|
|
|
|
"pr_nice", ctypes.c_byte
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Flags
|
|
|
|
# unsigned long int pr_flag;
|
|
|
|
"pr_flag", ctypes.c_ulong
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# User ID
|
|
|
|
# unsigned int pr_uid;
|
|
|
|
"pr_uid", ctypes.c_uint
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Group ID
|
|
|
|
# unsigned int pr_gid;
|
|
|
|
"pr_gid", ctypes.c_uint
|
|
|
|
),
|
|
|
|
("pr_pid", ctypes.c_int),
|
2019-09-07 15:46:22 +03:00
|
|
|
("pr_ppid", ctypes.c_int),
|
|
|
|
("pr_pgrp", ctypes.c_int),
|
|
|
|
("pr_sid", ctypes.c_int),
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* Lots missing */
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Filename of executable
|
|
|
|
# char pr_fname[16];
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_fname", ctypes.c_char * 16
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Initial part of arg list
|
|
|
|
# char pr_psargs[ELF_PRARGSZ];
|
2019-09-07 15:46:22 +03:00
|
|
|
"pr_psargs", ctypes.c_char * ELF_PRARGSZ
|
2021-09-05 21:53:06 +01:00
|
|
|
)
|
|
|
|
]
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2025-01-23 04:07:42 +05:30
|
|
|
class x86_64_user_fpregs_struct(ctypes.Structure): # struct x86_64_user_fpregs_struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
# unsigned short int cwd;
|
|
|
|
("cwd", ctypes.c_ushort),
|
|
|
|
# unsigned short int swd;
|
|
|
|
("swd", ctypes.c_ushort),
|
|
|
|
# unsigned short int ftw;
|
|
|
|
("ftw", ctypes.c_ushort),
|
|
|
|
# unsigned short int fop;
|
|
|
|
("fop", ctypes.c_ushort),
|
|
|
|
# __extension__ unsigned long long int rip;
|
|
|
|
("rip", ctypes.c_ulonglong),
|
|
|
|
# __extension__ unsigned long long int rdp;
|
|
|
|
("rdp", ctypes.c_ulonglong),
|
|
|
|
# unsigned int mxcsr;
|
|
|
|
("mxcsr", ctypes.c_uint),
|
|
|
|
# unsigned int mxcr_mask;
|
|
|
|
("mxcr_mask", ctypes.c_uint),
|
|
|
|
# unsigned int st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
|
|
|
|
("st_space", ctypes.c_uint * 32),
|
|
|
|
# unsigned int xmm_space[64]; /* 16*16 bytes for each XMM-reg = 256 bytes */
|
|
|
|
("xmm_space", ctypes.c_uint * 64),
|
|
|
|
# unsigned int padding[24];
|
|
|
|
("padding", ctypes.c_uint * 24),
|
|
|
|
]
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
2025-01-23 04:07:42 +05:30
|
|
|
class aarch64_user_fpregs_struct(ctypes.Structure): # struct aarch64_user_fpregs_struct
|
|
|
|
_fields_ = [
|
|
|
|
# unsigned long long int vregs[64];
|
|
|
|
("vregs", ctypes.c_ulonglong * 64),
|
|
|
|
# unsigned int fpsr;
|
|
|
|
("fpsr", ctypes.c_uint),
|
|
|
|
# unsigned int fpcr;
|
|
|
|
("fpcr", ctypes.c_uint),
|
|
|
|
# unsigned int padding[2];
|
|
|
|
("padding", ctypes.c_uint * 2),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
user_fpregs_dict = {
|
|
|
|
"aarch64": aarch64_user_fpregs_struct,
|
2025-02-17 18:06:10 +05:30
|
|
|
"armv7l": None,
|
2025-01-23 04:07:42 +05:30
|
|
|
"x86_64": x86_64_user_fpregs_struct,
|
|
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
|
|
elf_fpregset_t = user_fpregs_dict[MACHINE]
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError("Current architecture %s is not supported." % MACHINE)
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
# siginfo_t related constants.
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
_SI_MAX_SIZE = 128
|
2021-08-26 22:22:33 +03:00
|
|
|
_SI_PAD_SIZE = (_SI_MAX_SIZE // ctypes.sizeof(ctypes.c_int)) - 4
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* kill(). */
|
|
|
|
class _siginfo_t_U_kill(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Sending process ID
|
|
|
|
# __pid_t si_pid;
|
|
|
|
"si_pid", ctypes.c_int
|
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Real user ID of sending process
|
|
|
|
# __uid_t si_uid;
|
2019-09-07 15:46:22 +03:00
|
|
|
"si_uid", ctypes.c_uint
|
2021-09-05 21:53:06 +01:00
|
|
|
)
|
|
|
|
] # } _kill;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Type for data associated with a signal.
|
2019-09-07 15:46:22 +03:00
|
|
|
class sigval_t(ctypes.Union): # typedef union sigval
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
("sival_int", ctypes.c_int), # int sival_int;
|
|
|
|
("sical_ptr", ctypes.c_void_p), # void *sival_ptr;
|
|
|
|
] # } sigval_t;
|
|
|
|
|
|
|
|
|
|
|
|
# /* POSIX.1b timers. */
|
|
|
|
class _siginfo_t_U_timer(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Timer ID
|
|
|
|
# int si_tid;
|
|
|
|
"si_tid", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Overrun count
|
|
|
|
# int si_overrun;
|
|
|
|
"si_overrun", ctypes.c_int
|
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Signal value
|
|
|
|
# sigval_t si_sigval;
|
|
|
|
"si_sigval", sigval_t
|
|
|
|
)
|
|
|
|
] # } _timer;
|
|
|
|
|
|
|
|
|
|
|
|
# /* POSIX.1b signals. */
|
|
|
|
class _siginfo_t_U_rt(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Sending process ID
|
|
|
|
# __pid_t si_pid;
|
|
|
|
"si_pid", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Real user ID of sending process
|
|
|
|
# __uid_t si_uid;
|
2019-09-07 15:46:22 +03:00
|
|
|
"si_uid", ctypes.c_uint
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Signal value
|
|
|
|
# sigval_t si_sigval;
|
|
|
|
"si_sigval", sigval_t
|
|
|
|
)
|
|
|
|
] # } _rt;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGCHLD. */
|
|
|
|
class _siginfo_t_U_sigchld(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Which child
|
|
|
|
# __pid_t si_pid;
|
|
|
|
"si_pid", ctypes.c_int
|
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Real user ID of sending process
|
|
|
|
# __uid_t si_uid;
|
2019-09-07 15:46:22 +03:00
|
|
|
"si_uid", ctypes.c_uint
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Exit value or signal
|
|
|
|
# int si_status;
|
|
|
|
"si_status", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# __sigchld_clock_t si_utime;
|
|
|
|
"si_utime", ctypes.c_long
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# __sigchld_clock_t si_stime;
|
|
|
|
"si_stime", ctypes.c_long
|
|
|
|
)
|
|
|
|
] # } _sigchld;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
|
|
|
|
class _siginfo_t_U_sigfault(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Faulting insn/memory ref
|
|
|
|
# void *si_addr;
|
|
|
|
"si_addr", ctypes.c_void_p
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Valid LSB of the reported address
|
|
|
|
# short int si_addr_lsb;
|
2019-09-07 15:46:22 +03:00
|
|
|
"si_addr_lsb", ctypes.c_short
|
2021-09-05 21:53:06 +01:00
|
|
|
)
|
|
|
|
] # } _sigfault;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGPOLL. */
|
|
|
|
class _siginfo_t_U_sigpoll(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Band event for SIGPOLL
|
|
|
|
# long int si_band;
|
|
|
|
"si_band", ctypes.c_long
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# int si_fd;
|
|
|
|
"si_fd", ctypes.c_int
|
|
|
|
)
|
|
|
|
] # } _sigpoll;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGSYS. */
|
|
|
|
class _siginfo_t_U_sigsys(ctypes.Structure): # struct
|
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
("_call_addr", ctypes.c_void_p
|
2021-09-05 21:53:06 +01:00
|
|
|
), # void *_call_addr; /* Calling user insn. */
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
|
|
|
"_syscall", ctypes.c_int
|
2021-09-05 21:53:06 +01:00
|
|
|
), # int _syscall; /* Triggering system call number. */
|
2019-09-07 15:46:22 +03:00
|
|
|
("_arch", ctypes.c_uint
|
2021-09-05 21:53:06 +01:00
|
|
|
) # unsigned int _arch; /* AUDIT_ARCH_* of syscall. */
|
|
|
|
] # } _sigsys;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
2021-09-05 21:53:06 +01:00
|
|
|
class _siginfo_t_U(ctypes.Union): # union
|
|
|
|
_fields_ = [
|
2019-09-07 15:46:22 +03:00
|
|
|
("_pad",
|
2021-09-05 21:53:06 +01:00
|
|
|
ctypes.c_int * _SI_PAD_SIZE), # int _pad[__SI_PAD_SIZE];
|
|
|
|
|
|
|
|
# /* kill(). */
|
|
|
|
("_kill", _siginfo_t_U_kill), # struct
|
|
|
|
|
|
|
|
# __pid_t si_pid; /* Sending process ID. */
|
|
|
|
# __uid_t si_uid; /* Real user ID of sending process. */
|
|
|
|
# } _kill;
|
|
|
|
|
|
|
|
# /* POSIX.1b timers. */
|
|
|
|
("_timer", _siginfo_t_U_timer), # struct
|
|
|
|
|
|
|
|
# int si_tid; /* Timer ID. */
|
|
|
|
# int si_overrun; /* Overrun count. */
|
|
|
|
# sigval_t si_sigval; /* Signal value. */
|
|
|
|
# } _timer;
|
|
|
|
|
|
|
|
# /* POSIX.1b signals. */
|
|
|
|
("_rt", _siginfo_t_U_rt), # struct
|
|
|
|
|
|
|
|
# __pid_t si_pid; /* Sending process ID. */
|
|
|
|
# __uid_t si_uid; /* Real user ID of sending process. */
|
|
|
|
# sigval_t si_sigval; /* Signal value. */
|
|
|
|
# } _rt;
|
|
|
|
|
|
|
|
# /* SIGCHLD. */
|
|
|
|
("_sigchld", _siginfo_t_U_sigchld), # struct
|
|
|
|
|
|
|
|
# __pid_t si_pid; /* Which child. */
|
|
|
|
# __uid_t si_uid; /* Real user ID of sending process. */
|
|
|
|
# int si_status; /* Exit value or signal. */
|
|
|
|
# __sigchld_clock_t si_utime;
|
|
|
|
# __sigchld_clock_t si_stime;
|
|
|
|
# } _sigchld;
|
|
|
|
|
|
|
|
# /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
|
|
|
|
("_sigfault", _siginfo_t_U_sigfault), # struct
|
|
|
|
|
|
|
|
# void *si_addr; /* Faulting insn/memory ref. */
|
|
|
|
# short int si_addr_lsb; /* Valid LSB of the reported address. */
|
|
|
|
# } _sigfault;
|
|
|
|
|
|
|
|
# /* SIGPOLL. */
|
|
|
|
("_sigpoll", _siginfo_t_U_sigpoll), # struct
|
|
|
|
|
|
|
|
# long int si_band; /* Band event for SIGPOLL. */
|
|
|
|
# int si_fd;
|
|
|
|
# } _sigpoll;
|
|
|
|
|
|
|
|
# /* SIGSYS. */
|
|
|
|
("_sigsys", _siginfo_t_U_sigpoll) # struct
|
|
|
|
|
|
|
|
# void *_call_addr; /* Calling user insn. */
|
|
|
|
# int _syscall; /* Triggering system call number. */
|
|
|
|
# unsigned int _arch; /* AUDIT_ARCH_* of syscall. */
|
|
|
|
# } _sigsys;
|
|
|
|
] # } _sifields;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
class siginfo_t(ctypes.Structure): # typedef struct
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
(
|
|
|
|
# Signal number
|
|
|
|
# int si_signo;
|
|
|
|
"si_signo", ctypes.c_int
|
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# If non-zero, an errno value associated with
|
|
|
|
# int si_errno;
|
2019-09-07 15:46:22 +03:00
|
|
|
"si_errno", ctypes.c_int
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
# Signal code - this signal, as defined in <errno.h>
|
|
|
|
# int si_code;
|
|
|
|
"si_code", ctypes.c_int
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# Union
|
|
|
|
"_sifields", _siginfo_t_U
|
|
|
|
)
|
|
|
|
|
|
|
|
# int _pad[__SI_PAD_SIZE];
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* kill(). */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# __pid_t si_pid; /* Sending process ID. */
|
|
|
|
# __uid_t si_uid; /* Real user ID of sending process. */
|
|
|
|
# } _kill;
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* POSIX.1b timers. */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# int si_tid; /* Timer ID. */
|
|
|
|
# int si_overrun; /* Overrun count. */
|
|
|
|
# sigval_t si_sigval; /* Signal value. */
|
|
|
|
# } _timer;
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* POSIX.1b signals. */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# __pid_t si_pid; /* Sending process ID. */
|
|
|
|
# __uid_t si_uid; /* Real user ID of sending process. */
|
|
|
|
# sigval_t si_sigval; /* Signal value. */
|
|
|
|
# } _rt;
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGCHLD. */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# __pid_t si_pid; /* Which child. */
|
|
|
|
# __uid_t si_uid; /* Real user ID of sending process. */
|
|
|
|
# int si_status; /* Exit value or signal. */
|
|
|
|
# __sigchld_clock_t si_utime;
|
|
|
|
# __sigchld_clock_t si_stime;
|
|
|
|
# } _sigchld;
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# void *si_addr; /* Faulting insn/memory ref. */
|
|
|
|
# short int si_addr_lsb; /* Valid LSB of the reported address. */
|
|
|
|
# } _sigfault;
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGPOLL. */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# long int si_band; /* Band event for SIGPOLL. */
|
|
|
|
# int si_fd;
|
|
|
|
# } _sigpoll;
|
2019-09-07 15:46:22 +03:00
|
|
|
#
|
2021-09-05 21:53:06 +01:00
|
|
|
# /* SIGSYS. */
|
|
|
|
# struct
|
|
|
|
|
|
|
|
# void *_call_addr; /* Calling user insn. */
|
|
|
|
# int _syscall; /* Triggering system call number. */
|
|
|
|
# unsigned int _arch; /* AUDIT_ARCH_* of syscall. */
|
|
|
|
# } _sigsys;
|
|
|
|
# } _sifields;
|
|
|
|
] # } siginfo_t __SI_ALIGNMENT;
|
2016-05-21 16:38:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
# xsave related.
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
class ymmh_struct(ctypes.Structure): # struct ymmh_struct {
|
2021-09-05 21:53:06 +01:00
|
|
|
_fields_ = [
|
|
|
|
# u32 ymmh_space[64];
|
|
|
|
("ymmh_space", 64 * ctypes.c_uint)
|
|
|
|
] # } __packed;
|
2019-09-07 15:46:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
class xsave_hdr_struct(ctypes.Structure): # struct xsave_hdr_struct {
|
|
|
|
_fields_ = [
|
2021-09-05 21:53:06 +01:00
|
|
|
# u64 xstate_bv;
|
|
|
|
("xstate_bv", ctypes.c_ulonglong),
|
|
|
|
# u64 reserved1[2];
|
|
|
|
("reserved1", ctypes.c_ulonglong * 2),
|
|
|
|
# u64 reserved2[5];
|
|
|
|
("reserved2", ctypes.c_ulonglong * 5)
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } __packed;
|
|
|
|
|
|
|
|
|
|
|
|
class i387_fxsave_struct(ctypes.Structure): # struct i387_fxsave_struct {
|
|
|
|
_fields_ = [
|
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Control Word
|
|
|
|
# u16 cwd;
|
2019-09-07 15:46:22 +03:00
|
|
|
"cwd", ctypes.c_ushort
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Status Word
|
|
|
|
# u16 swd;
|
2019-09-07 15:46:22 +03:00
|
|
|
"swd", ctypes.c_ushort
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Tag Word
|
|
|
|
# u16 twd;
|
2019-09-07 15:46:22 +03:00
|
|
|
"twd", ctypes.c_ushort
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Last Instruction Opcode
|
|
|
|
# u16 fop;
|
2019-09-07 15:46:22 +03:00
|
|
|
"fop", ctypes.c_ushort
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
# union {
|
|
|
|
# struct {
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Instruction Pointer
|
|
|
|
# u64 rip;
|
2019-09-07 15:46:22 +03:00
|
|
|
"rip", ctypes.c_ulonglong
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# Data Pointer
|
|
|
|
# u64 rdp;
|
2019-09-07 15:46:22 +03:00
|
|
|
"rdp", ctypes.c_ulonglong
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
|
|
|
|
# struct {
|
|
|
|
# u32 fip; /* FPU IP Offset */
|
|
|
|
# u32 fcs; /* FPU IP Selector */
|
|
|
|
# u32 foo; /* FPU Operand Offset */
|
|
|
|
# u32 fos; /* FPU Operand Selector */
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# MXCSR Register State
|
|
|
|
# u32 mxcsr;
|
2019-09-07 15:46:22 +03:00
|
|
|
"mxcsr", ctypes.c_uint
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
2019-09-07 15:46:22 +03:00
|
|
|
(
|
2021-09-05 21:53:06 +01:00
|
|
|
# MXCSR Mask
|
|
|
|
# u32 mxcsr_mask;
|
2019-09-07 15:46:22 +03:00
|
|
|
"mxcsr_mask", ctypes.c_uint
|
2021-09-05 21:53:06 +01:00
|
|
|
),
|
|
|
|
# 8*16 bytes for each FP-reg = 128 bytes
|
|
|
|
(
|
|
|
|
# u32 st_space[32];
|
|
|
|
"st_space", ctypes.c_uint * 32
|
|
|
|
),
|
|
|
|
# 16*16 bytes for each XMM-reg = 256 bytes
|
|
|
|
(
|
|
|
|
# u32 xmm_space[64];
|
|
|
|
"xmm_space", ctypes.c_uint * 64
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# u32 padding[12];
|
|
|
|
"padding", ctypes.c_uint * 12
|
|
|
|
),
|
|
|
|
# union {
|
|
|
|
(
|
|
|
|
# u32 padding1[12];
|
|
|
|
"padding1", ctypes.c_uint * 12
|
|
|
|
)
|
|
|
|
# u32 sw_reserved[12];
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } __aligned(16);
|
|
|
|
|
|
|
|
|
|
|
|
class elf_xsave_struct(ctypes.Structure): # struct xsave_struct {
|
|
|
|
_fields_ = [
|
2021-09-05 21:53:06 +01:00
|
|
|
# struct i387_fxsave_struct i387;
|
|
|
|
("i387", i387_fxsave_struct),
|
|
|
|
# struct xsave_hdr_struct xsave_hdr;
|
|
|
|
("xsave_hdr", xsave_hdr_struct),
|
|
|
|
# struct ymmh_struct ymmh;
|
|
|
|
("ymmh", ymmh_struct)
|
2019-09-07 15:46:22 +03:00
|
|
|
] # } __aligned(FP_MIN_ALIGN_BYTES) __packed;
|
2025-02-17 18:06:10 +05:30
|
|
|
|
|
|
|
|
|
|
|
class vfp_hard_struct(ctypes.Structure): # struct vfp_hard_struct {
|
|
|
|
_fields_ = [
|
|
|
|
("vfp_regs", ctypes.c_ulonglong * 32), # __u64 fpregs[32];
|
|
|
|
("fpexc", ctypes.c_ulong), # __u32 fpexc;
|
|
|
|
("fpscr", ctypes.c_ulong), # __u32 fpscr;
|
|
|
|
("fpinst", ctypes.c_ulong), # __u32 fpinst;
|
|
|
|
("fpinst2", ctypes.c_ulong), # __u32 fpinst2;
|
|
|
|
] # };
|