Rizin
unix-like reverse engineering framework and cli tools
trap_x86.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #if __i386__ || __x86_64__
5 static bool xnu_thread_get_gpr(RzDebug *dbg, xnu_thread_t *thread);
6 static xnu_thread_t *get_xnu_thread(RzDebug *dbg, int tid);
7 
8 static bool xnu_x86_hwstep_enable64(RzDebug *dbg, bool enable) {
9  RZ_REG_T *state;
10  int ret;
11  xnu_thread_t *th = get_xnu_thread(dbg, dbg->tid);
12  ret = xnu_thread_get_gpr(dbg, th);
13  if (!ret) {
14  eprintf("error to get gpr registers in trace bit intel\n");
15  return false;
16  }
17  state = (RZ_REG_T *)&th->gpr;
18  if (state->tsh.flavor == x86_THREAD_STATE32) {
19  state->uts.ts32.__eflags = (state->uts.ts32.__eflags &
20  ~0x100UL) |
21  (enable ? 0x100UL : 0);
22  } else if (state->tsh.flavor == x86_THREAD_STATE64) {
23  state->uts.ts64.__rflags = (state->uts.ts64.__rflags &
24  ~0x100UL) |
25  (enable ? 0x100UL : 0);
26  } else {
27  eprintf("Invalid bit size\n");
28  return false;
29  }
30  if (!xnu_thread_set_gpr(dbg, th)) {
31  eprintf("error xnu_thread_set_gpr in modify_trace_bit intel\n");
32  return false;
33  }
34  return true;
35 }
36 
37 static bool xnu_x86_hwstep_enable32(RzDebug *dbg, bool enable) {
38  RZ_REG_T *state;
39  xnu_thread_t *th = get_xnu_thread(dbg, dbg->tid);
40  int ret = xnu_thread_get_gpr(dbg, th);
41  if (!ret) {
42  eprintf("error to get gpr registers in trace bit intel\n");
43  return false;
44  }
45  state = (RZ_REG_T *)&th->gpr;
46  if (state->tsh.flavor == x86_THREAD_STATE32) {
47  state->uts.ts32.__eflags = (state->uts.ts32.__eflags &
48  ~0x100UL) |
49  (enable ? 0x100UL : 0);
50  } else {
51  eprintf("Invalid bit size\n");
52  return false;
53  }
54  if (!xnu_thread_set_gpr(dbg, th)) {
55  eprintf("error xnu_thread_set_gpr in modify_trace_bit intel\n");
56  return false;
57  }
58  return true;
59 }
60 
61 bool xnu_native_hwstep_enable(RzDebug *dbg, bool enable) {
62  if (dbg->bits == RZ_SYS_BITS_64)
63  return xnu_x86_hwstep_enable64(dbg, enable);
64  return xnu_x86_hwstep_enable32(dbg, enable);
65 }
66 #endif
RzDebug * dbg
Definition: desil.c:30
@ x86_THREAD_STATE64
@ x86_THREAD_STATE32
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
RZ_REG_T gpr
Definition: xnu_threads.h:55
int bits
Definition: rz_debug.h:243
Definition: dis.h:43
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4