Rizin
unix-like reverse engineering framework and cli tools
generic-x64.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 
5  int i;
6  ut8 buf[8];
7  RzDebugFrame *frame;
8  ut64 ptr, ebp2;
9  ut64 _rip, _rsp, _rbp = 0;
10  RzList *list;
11  RzReg *reg = dbg->reg;
12  RzIOBind *bio = &dbg->iob;
13 
15  if (at == UT64_MAX) {
18  } else {
19  _rsp = _rbp = at;
20  }
21 
22  list = rz_list_new();
23  list->free = free;
24  bio->read_at(bio->io, _rip, (ut8 *)&buf, 8);
25  /* %rbp=old rbp, %rbp+4 points to ret */
26  /* Plugin before function prelude: push %rbp ; mov %rsp, %rbp */
27  if (!memcmp(buf, "\x55\x89\xe5", 3) || !memcmp(buf, "\x89\xe5\x57", 3)) {
28  if (!bio->read_at(bio->io, _rsp, (ut8 *)&ptr, 8)) {
29  eprintf("read error at 0x%08" PFMT64x "\n", _rsp);
31  free(list);
32  return false;
33  }
34  frame = RZ_NEW0(RzDebugFrame);
35  frame->addr = ptr;
36  frame->size = 0; // TODO ?
37  rz_list_append(list, frame);
38  _rbp = ptr;
39  }
40 
41  for (i = 1; i < dbg->btdepth; i++) {
42  // TODO: make those two reads in a shot
43  bio->read_at(bio->io, _rbp, (ut8 *)&ebp2, 8);
44  if (ebp2 == UT64_MAX)
45  break;
46  bio->read_at(bio->io, _rbp + 8, (ut8 *)&ptr, 8);
47  if (!ptr || !_rbp)
48  break;
49  frame = RZ_NEW0(RzDebugFrame);
50  frame->addr = ptr;
51  frame->size = 0; // TODO ?
52  rz_list_append(list, frame);
53  _rbp = ebp2;
54  }
55  return list;
56 }
57 // XXX: Do this work correctly?
59  int i;
60  ut8 buf[8];
61  RzDebugFrame *frame;
62  ut64 ptr, ebp2 = UT64_MAX;
63  ut64 _rip, _rbp;
64  RzList *list;
65  RzReg *reg = dbg->reg;
66  RzIOBind *bio = &dbg->iob;
67  RzAnalysisFunction *fcn;
68 
70  if (at == UT64_MAX) {
71  //_rsp = rz_reg_get_value (reg, rz_reg_get (reg, "rsp", RZ_REG_TYPE_GPR));
73  } else {
74  _rbp = at;
75  }
76 
77  list = rz_list_new();
78  list->free = free;
79  bio->read_at(bio->io, _rip, (ut8 *)&buf, 8);
80 
81  // TODO : frame->size by using esil to emulate first instructions
83  if (fcn) {
84  frame = RZ_NEW0(RzDebugFrame);
85  frame->addr = _rip;
86  frame->size = 0;
87  frame->sp = _rbp;
88  frame->bp = _rbp + 8; // XXX
89  rz_list_append(list, frame);
90  }
91 
92  for (i = 1; i < dbg->btdepth; i++) {
93  // TODO: make those two reads in a shot
94  bio->read_at(bio->io, _rbp, (ut8 *)&ebp2, 8);
95  if (ebp2 == UT64_MAX)
96  break;
97  bio->read_at(bio->io, _rbp + 8, (ut8 *)&ptr, 8);
98  if (!ptr || !_rbp)
99  break;
100  // fcn = rz_analysis_get_fcn_in (dbg->analysis, ptr, RZ_ANALYSIS_FCN_TYPE_NULL);
101  frame = RZ_NEW0(RzDebugFrame);
102  frame->addr = ptr;
103  frame->size = 0;
104  frame->sp = _rbp;
105  frame->bp = _rbp + 8;
106  // frame->name = (fcn && fcn->name) ? strdup (fcn->name) : NULL;
107  rz_list_append(list, frame);
108  _rbp = ebp2;
109  }
110 
111  return list;
112 }
lzma_index ** i
Definition: index.h:629
RzDebug * dbg
Definition: desil.c:30
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
static RzList * backtrace_x86_64(RzDebug *dbg, ut64 at)
Definition: generic-x64.c:4
static RzList * backtrace_x86_64_analysis(RzDebug *dbg, ut64 at)
Definition: generic-x64.c:58
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
#define reg(n)
uint8_t ut8
Definition: lh5801.h:11
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
@ RZ_ANALYSIS_FCN_TYPE_NULL
Definition: rz_analysis.h:192
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define PFMT64x
Definition: rz_types.h:393
#define UT64_MAX
Definition: rz_types_base.h:86
int btdepth
Definition: rz_debug.h:259
RzAnalysis * analysis
Definition: rz_debug.h:305
RzReg * reg
Definition: rz_debug.h:286
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
ut64(WINAPI *w32_GetEnabledXStateFeatures)()