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
4
static
RzList
*
backtrace_x86_64
(
RzDebug
*
dbg
,
ut64
at) {
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
14
_rip =
rz_reg_get_value
(
reg
,
rz_reg_get
(
reg
,
"rip"
,
RZ_REG_TYPE_GPR
));
15
if
(at ==
UT64_MAX
) {
16
_rsp =
rz_reg_get_value
(
reg
,
rz_reg_get
(
reg
,
"rsp"
,
RZ_REG_TYPE_GPR
));
17
_rbp =
rz_reg_get_value
(
reg
,
rz_reg_get
(
reg
,
"rbp"
,
RZ_REG_TYPE_GPR
));
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);
30
rz_list_purge
(
list
);
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?
58
static
RzList
*
backtrace_x86_64_analysis
(
RzDebug
*
dbg
,
ut64
at) {
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
69
_rip =
rz_reg_get_value
(
reg
,
rz_reg_get
(
reg
,
"rip"
,
RZ_REG_TYPE_GPR
));
70
if
(at ==
UT64_MAX
) {
71
//_rsp = rz_reg_get_value (reg, rz_reg_get (reg, "rsp", RZ_REG_TYPE_GPR));
72
_rbp =
rz_reg_get_value
(
reg
,
rz_reg_get
(
reg
,
"rbp"
,
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
82
fcn =
rz_analysis_get_fcn_in
(
dbg
->
analysis
, _rip,
RZ_ANALYSIS_FCN_TYPE_NULL
);
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
}
i
lzma_index ** i
Definition:
index.h:629
dbg
RzDebug * dbg
Definition:
desil.c:30
rz_analysis_get_fcn_in
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition:
fcn.c:1687
backtrace_x86_64
static RzList * backtrace_x86_64(RzDebug *dbg, ut64 at)
Definition:
generic-x64.c:4
backtrace_x86_64_analysis
static RzList * backtrace_x86_64_analysis(RzDebug *dbg, ut64 at)
Definition:
generic-x64.c:58
free
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition:
ht_inc.c:130
buf
voidpf void * buf
Definition:
ioapi.h:138
reg
#define reg(n)
ut8
uint8_t ut8
Definition:
lh5801.h:11
list
static void list(RzEgg *egg)
Definition:
rz-gg.c:52
rz_list_new
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_list_append
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_list_purge
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition:
list.c:120
rz_reg_get
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition:
reg.c:344
eprintf
#define eprintf(x, y...)
Definition:
rlcc.c:7
rz_reg_get_value
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition:
rvalue.c:114
RZ_ANALYSIS_FCN_TYPE_NULL
@ RZ_ANALYSIS_FCN_TYPE_NULL
Definition:
rz_analysis.h:192
RZ_REG_TYPE_GPR
@ RZ_REG_TYPE_GPR
Definition:
rz_reg.h:21
RZ_NEW0
#define RZ_NEW0(x)
Definition:
rz_types.h:284
PFMT64x
#define PFMT64x
Definition:
rz_types.h:393
UT64_MAX
#define UT64_MAX
Definition:
rz_types_base.h:86
rz_analysis_function_t
Definition:
rz_analysis.h:239
rz_debug_frame_t
Definition:
rz_debug.h:119
rz_debug_frame_t::size
int size
Definition:
rz_debug.h:121
rz_debug_frame_t::bp
ut64 bp
Definition:
rz_debug.h:123
rz_debug_frame_t::addr
ut64 addr
Definition:
rz_debug.h:120
rz_debug_frame_t::sp
ut64 sp
Definition:
rz_debug.h:122
rz_debug_t
Definition:
rz_debug.h:241
rz_debug_t::btdepth
int btdepth
Definition:
rz_debug.h:259
rz_debug_t::analysis
RzAnalysis * analysis
Definition:
rz_debug.h:305
rz_debug_t::reg
RzReg * reg
Definition:
rz_debug.h:286
rz_debug_t::iob
RzIOBind iob
Definition:
rz_debug.h:293
rz_io_bind_t
Definition:
rz_io.h:230
rz_io_bind_t::read_at
RzIOReadAt read_at
Definition:
rz_io.h:240
rz_io_bind_t::io
RzIO * io
Definition:
rz_io.h:232
rz_list_t
Definition:
rz_list.h:18
rz_reg_t
Definition:
rz_reg.h:144
ut64
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
librz
debug
p
native
bt
generic-x64.c
Generated by
1.9.1