From 47cf13e8429e813aa2fd2b1f41f87722bc616d19 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sat, 4 May 2024 07:32:18 -0400 Subject: Parameterize architecture-specific details Abstract architecture details into architecture.h and add x86 constants. This is slightly complicated by the fact that 64-bit hosts can run 32-bit code, so we do still need to resolve some values dynamically. The architecture_info() function is intented to address this, and performs parameter lookups based on the current state of the guest process. Resolving values on a per-process-state basis is important due to the process model under Linux. If we fork to debug a 32-bit program, the forked process will be native 64-bit until the execve system call. And of course, the process is then free to exec anything it likes later on as well. Signed-off-by: Malfurious --- architecture.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 architecture.c (limited to 'architecture.c') diff --git a/architecture.c b/architecture.c new file mode 100644 index 0000000..67838a0 --- /dev/null +++ b/architecture.c @@ -0,0 +1,30 @@ +#include "architecture.h" + +void architecture_info(struct archinfo *ai, const struct iovec *regs) { + user_regs_t *data = regs->iov_base; + + /* Not every platform supports 64-bits, but those that do are generally + * backward compatible with 32-bits, so this is the one we explicitly + * compare with. */ + if (regs->iov_len == sizeof(struct user_regs_32)) { + ai->progmctr = data->PROGMCTR_32; + ai->stackptr = data->STACKPTR_32; + ai->bp_insn = BREAKPOINT_INSN_32; + ai->bp_mask = BREAKPOINT_MASK_32; + ai->bp_adjust = BREAKPOINT_ADJS_32; + ai->cs_arch = CAPSTONE_ARCH_32; + ai->cs_mode = CAPSTONE_MODE_32; + ai->cs_call = CAPSTONE_CALL_32; + ai->wordsize = WORDSIZE_32; + } else { + ai->progmctr = data->PROGMCTR_64; + ai->stackptr = data->STACKPTR_64; + ai->bp_insn = BREAKPOINT_INSN_64; + ai->bp_mask = BREAKPOINT_MASK_64; + ai->bp_adjust = BREAKPOINT_ADJS_64; + ai->cs_arch = CAPSTONE_ARCH_64; + ai->cs_mode = CAPSTONE_MODE_64; + ai->cs_call = CAPSTONE_CALL_64; + ai->wordsize = WORDSIZE_64; + } +} -- cgit v1.2.3