| 1 |
from ctypes import (Structure, |
| 2 |
c_int, c_uint, c_ulong, c_void_p, |
| 3 |
c_uint16, c_uint32, c_size_t) |
| 4 |
from ptrace.cpu_info import CPU_X86_64 |
| 5 |
|
| 6 |
PIOD_READ_D = 1 |
| 7 |
PIOD_WRITE_D = 2 |
| 8 |
PIOD_READ_I = 3 |
| 9 |
PIOD_WRITE_I = 4 |
| 10 |
|
| 11 |
# /usr/include/machine/reg.h |
| 12 |
if CPU_X86_64: |
| 13 |
register_t = c_ulong |
| 14 |
|
| 15 |
class reg(Structure): |
| 16 |
_fields_ = ( |
| 17 |
("r15", register_t), |
| 18 |
("r14", register_t), |
| 19 |
("r13", register_t), |
| 20 |
("r12", register_t), |
| 21 |
("r11", register_t), |
| 22 |
("r10", register_t), |
| 23 |
("r9", register_t), |
| 24 |
("r8", register_t), |
| 25 |
("rdi", register_t), |
| 26 |
("rsi", register_t), |
| 27 |
("rbp", register_t), |
| 28 |
("rbx", register_t), |
| 29 |
("rdx", register_t), |
| 30 |
("rcx", register_t), |
| 31 |
("rax", register_t), |
| 32 |
("trapno", c_uint32), |
| 33 |
("fs", c_uint16), |
| 34 |
("gs", c_uint16), |
| 35 |
("err", c_uint32), |
| 36 |
("es", c_uint16), |
| 37 |
("ds", c_uint16), |
| 38 |
("rip", register_t), |
| 39 |
("cs", register_t), |
| 40 |
("rflags", register_t), |
| 41 |
("rsp", register_t), |
| 42 |
("ss", register_t), |
| 43 |
) |
| 44 |
else: |
| 45 |
class reg(Structure): |
| 46 |
_fields_ = ( |
| 47 |
("fs", c_uint), |
| 48 |
("es", c_uint), |
| 49 |
("ds", c_uint), |
| 50 |
("edi", c_uint), |
| 51 |
("esi", c_uint), |
| 52 |
("ebp", c_uint), |
| 53 |
("isp", c_uint), |
| 54 |
("ebx", c_uint), |
| 55 |
("edx", c_uint), |
| 56 |
("ecx", c_uint), |
| 57 |
("eax", c_uint), |
| 58 |
("trapno", c_uint), |
| 59 |
("err", c_uint), |
| 60 |
("eip", c_uint), |
| 61 |
("cs", c_uint), |
| 62 |
("eflags", c_uint), |
| 63 |
("esp", c_uint), |
| 64 |
("ss", c_uint), |
| 65 |
("gs", c_uint), |
| 66 |
) |
| 67 |
|
| 68 |
|
| 69 |
class ptrace_io_desc(Structure): |
| 70 |
_fields_ = ( |
| 71 |
("piod_op", c_int), |
| 72 |
("piod_offs", c_void_p), |
| 73 |
("piod_addr", c_void_p), |
| 74 |
("piod_len", c_size_t), |
| 75 |
) |