summaryrefslogtreecommitdiffstats
path: root/misplays.c
diff options
context:
space:
mode:
Diffstat (limited to 'misplays.c')
-rw-r--r--misplays.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/misplays.c b/misplays.c
index 70fe45b..9ae6122 100644
--- a/misplays.c
+++ b/misplays.c
@@ -62,31 +62,60 @@ static void describe_states(struct thread *dbg, PANEL *pan) {
}
static void dump_registers(struct thread *dbg, PANEL *pan) {
- struct user_regs_struct *regs = &dbg->state->regs;
- pprintw(pan, "orig_rax = 0x%016llx\n", regs->orig_rax);
- pprintw(pan, "rax = 0x%016llx\n", regs->rax);
- pprintw(pan, "rbx = 0x%016llx\n", regs->rbx);
- pprintw(pan, "rcx = 0x%016llx\n", regs->rcx);
- pprintw(pan, "rdx = 0x%016llx\n", regs->rdx);
- pprintw(pan, "rdi = 0x%016llx\n", regs->rdi);
- pprintw(pan, "rsi = 0x%016llx\n", regs->rsi);
- pprintw(pan, "rsp = 0x%016llx\n", regs->rsp);
- pprintw(pan, "rbp = 0x%016llx\n", regs->rbp);
- pprintw(pan, "rip = 0x%016llx\n", regs->rip);
+#ifdef ARCH_X86
+ if (dbg->state->regsize == sizeof(struct user_regs_32)) {
+ struct user_regs_32 *regs = &dbg->state->regs.x86_32;
+ pprintw(pan, "orig_eax = 0x%08x\n", regs->orig_eax);
+ pprintw(pan, "eax = 0x%08x\n", regs->eax);
+ pprintw(pan, "ebx = 0x%08x\n", regs->ebx);
+ pprintw(pan, "ecx = 0x%08x\n", regs->ecx);
+ pprintw(pan, "edx = 0x%08x\n", regs->edx);
+ pprintw(pan, "edi = 0x%08x\n", regs->edi);
+ pprintw(pan, "esi = 0x%08x\n", regs->esi);
+ pprintw(pan, "esp = 0x%08x\n", regs->esp);
+ pprintw(pan, "ebp = 0x%08x\n", regs->ebp);
+ pprintw(pan, "eip = 0x%08x\n", regs->eip);
+ } else {
+ struct user_regs_64 *regs = &dbg->state->regs.x86_64;
+ pprintw(pan, "orig_rax = 0x%016llx\n", regs->orig_rax);
+ pprintw(pan, "rax = 0x%016llx\n", regs->rax);
+ pprintw(pan, "rbx = 0x%016llx\n", regs->rbx);
+ pprintw(pan, "rcx = 0x%016llx\n", regs->rcx);
+ pprintw(pan, "rdx = 0x%016llx\n", regs->rdx);
+ pprintw(pan, "rdi = 0x%016llx\n", regs->rdi);
+ pprintw(pan, "rsi = 0x%016llx\n", regs->rsi);
+ pprintw(pan, "rsp = 0x%016llx\n", regs->rsp);
+ pprintw(pan, "rbp = 0x%016llx\n", regs->rbp);
+ pprintw(pan, "rip = 0x%016llx\n", regs->rip);
+ }
+#endif
}
static void dump_stack(struct thread *dbg, PANEL *pan) {
- unsigned long sp = dbg->state->regs.rsp;
- for (size_t i = 0; i < 16; i++, sp += 8) {
- unsigned long word = *(unsigned long *)deref(dbg, sp,sizeof(unsigned long));
- pprintw(pan, "0x%lx:\t0x%lx\n", sp, word);
+ struct archinfo archinfo;
+ struct iovec regs = { &dbg->state->regs, dbg->state->regsize };
+ architecture_info(&archinfo, &regs);
+
+ unsigned long sp = archinfo.stackptr;
+ for (size_t i = 0; i < 16; i++, sp += archinfo.wordsize) {
+ if (dbg->state->regsize == sizeof(struct user_regs_32)) {
+ unsigned int *word = deref(dbg, sp, sizeof(unsigned int));
+ pprintw(pan, "0x%lx:\t0x%08x\n", sp, *word);
+ } else {
+ unsigned long *word = deref(dbg, sp, sizeof(unsigned long));
+ pprintw(pan, "0x%lx:\t0x%016lx\n", sp, *word);
+ }
}
}
static int rip_visited(struct thread *th, unsigned long rip) {
struct list *states = &th->states;
for (struct state *s = states->head; s != states->end; s = s->next) {
- if (rip == s->regs.rip) {
+ struct archinfo archinfo;
+ struct iovec regs = { &s->regs, s->regsize };
+ architecture_info(&archinfo, &regs);
+
+ if (rip == archinfo.progmctr) {
return 1;
}
}
@@ -94,13 +123,17 @@ static int rip_visited(struct thread *th, unsigned long rip) {
}
static void disasm(struct thread *dbg, PANEL *pan) {
+ struct archinfo archinfo;
+ struct iovec regs = { &dbg->state->regs, dbg->state->regsize };
+ architecture_info(&archinfo, &regs);
+
csh handle;
cs_insn *insn;
- if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK) {
+ if (cs_open(archinfo.cs_arch, archinfo.cs_mode, &handle) != CS_ERR_OK) {
//perror("capstone open");
} else {
- uint64_t address = dbg->state->regs.rip;
+ uint64_t address = archinfo.progmctr;
size_t codez = 128;
const uint8_t *code = deref(dbg, address, codez);
insn = cs_malloc(handle);
@@ -110,7 +143,7 @@ static void disasm(struct thread *dbg, PANEL *pan) {
break;
}
if (dbg->stopped) {
- if (insn->address == dbg->state->regs.rip) {
+ if (insn->address == archinfo.progmctr) {
pattron(pan, COLOR_PAIR(1));
} else if (get_breakpoint(dbg->proc, insn->address)) {
pattron(pan, COLOR_PAIR(3));
@@ -120,7 +153,7 @@ static void disasm(struct thread *dbg, PANEL *pan) {
}
pprintw(pan, "0x%"PRIx64":\t%s %s\n", insn->address, insn->mnemonic, insn->op_str);
if (dbg->stopped) {
- if (insn->address == dbg->state->regs.rip) {
+ if (insn->address == archinfo.progmctr) {
pattroff(pan, COLOR_PAIR(1));
} else if (get_breakpoint(dbg->proc, insn->address)) {
pattroff(pan, COLOR_PAIR(3));