Rizin
unix-like reverse engineering framework and cli tools
generic-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
/* definition */
5
6
// static RzList *backtrace_frames_x86_32(RzDebug *dbg, ut64 at);
7
// static RzList *backtrace_frames_x86_32_analysis(RzDebug *dbg, ut64 at);
8
9
/* implementation */
10
#include <
rz_debug.h
>
11
12
static
RzList
*
backtrace_x86_32
(
RzDebug
*
dbg
,
ut64
at) {
13
RzRegItem
*ri;
14
RzReg
*
reg
=
dbg
->
reg
;
15
ut32
i
, _esp, esp, ebp2;
16
RzList
*
list
=
rz_list_new
();
17
RzIOBind
*bio = &
dbg
->
iob
;
18
ut8
buf
[4];
19
20
list
->free =
free
;
21
ri = (at ==
UT64_MAX
) ?
rz_reg_get
(
reg
,
"ebp"
,
RZ_REG_TYPE_GPR
) :
NULL
;
22
_esp = (
ut32
)((ri) ?
rz_reg_get_value
(
reg
, ri) : at);
23
// TODO: implement [stack] map uptrace method too
24
esp = _esp;
25
for
(
i
= 0;
i
<
dbg
->
btdepth
;
i
++) {
26
bio->
read_at
(bio->
io
, esp, (
void
*)&ebp2, 4);
27
if
(ebp2 ==
UT32_MAX
)
28
break
;
29
*
buf
=
'\0'
;
30
bio->
read_at
(bio->
io
, (ebp2 - 5) - (ebp2 - 5) % 4, (
void
*)&
buf
, 4);
31
32
// TODO: arch_is_call() here and this fun will be portable
33
if
(
buf
[(ebp2 - 5) % 4] == 0xe8) {
34
RzDebugFrame
*frame =
RZ_NEW0
(
RzDebugFrame
);
35
frame->
addr
= ebp2;
36
frame->
size
= esp - _esp;
37
rz_list_append
(
list
, frame);
38
}
39
esp += 4;
40
}
41
return
list
;
42
}
43
44
/* TODO: Can I use this as in a coroutine? */
45
static
RzList
*
backtrace_x86_32_analysis
(
RzDebug
*
dbg
,
ut64
at) {
46
RzRegItem
*ri;
47
RzReg
*
reg
=
dbg
->
reg
;
48
ut32
i
, _esp, esp, eip, ebp2;
49
RzList
*
list
;
50
RzIOBind
*bio = &
dbg
->
iob
;
51
RzAnalysisFunction
*fcn;
52
RzDebugFrame
*frame;
53
ut8
buf
[4];
54
55
// TODO : frame->size by using esil to emulate first instructions
56
list
=
rz_list_new
();
57
list
->free =
free
;
58
59
ri = (at ==
UT64_MAX
) ?
rz_reg_get
(
reg
,
"ebp"
,
RZ_REG_TYPE_GPR
) :
NULL
;
60
_esp = (
ut32
)((ri) ?
rz_reg_get_value
(
reg
, ri) : at);
61
// TODO: implement [stack] map uptrace method too
62
esp = _esp;
63
64
eip =
rz_reg_get_value
(
reg
,
rz_reg_get
(
reg
,
"eip"
,
RZ_REG_TYPE_GPR
));
65
fcn =
rz_analysis_get_fcn_in
(
dbg
->
analysis
, eip,
RZ_ANALYSIS_FCN_TYPE_NULL
);
66
if
(fcn !=
NULL
) {
67
frame =
RZ_NEW0
(
RzDebugFrame
);
68
frame->
addr
= eip;
69
frame->
size
= 0;
70
rz_list_append
(
list
, frame);
71
}
72
73
for
(
i
= 1;
i
<
dbg
->
btdepth
;
i
++) {
74
bio->
read_at
(bio->
io
, esp, (
void
*)&ebp2, 4);
75
if
(ebp2 ==
UT32_MAX
)
76
break
;
77
*
buf
=
'\0'
;
78
bio->
read_at
(bio->
io
, (ebp2 - 5) - (ebp2 - 5) % 4, (
void
*)&
buf
, 4);
79
80
// TODO: arch_is_call() here and this fun will be portable
81
if
(
buf
[(ebp2 - 5) % 4] == 0xe8) {
82
frame =
RZ_NEW0
(
RzDebugFrame
);
83
frame->
addr
= ebp2;
84
frame->
size
= esp - _esp;
85
frame->
sp
= _esp;
86
frame->
bp
= _esp + frame->
size
;
87
rz_list_append
(
list
, frame);
88
}
89
esp += 4;
90
}
91
return
list
;
92
}
i
lzma_index ** i
Definition:
index.h:629
NULL
#define NULL
Definition:
cris-opc.c:27
ut32
uint32_t ut32
Definition:
demangler_util.h:31
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_32
static RzList * backtrace_x86_32(RzDebug *dbg, ut64 at)
Definition:
generic-x86.c:12
backtrace_x86_32_analysis
static RzList * backtrace_x86_32_analysis(RzDebug *dbg, ut64 at)
Definition:
generic-x86.c:45
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_reg_get
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition:
reg.c:344
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_debug.h
RZ_REG_TYPE_GPR
@ RZ_REG_TYPE_GPR
Definition:
rz_reg.h:21
RZ_NEW0
#define RZ_NEW0(x)
Definition:
rz_types.h:284
UT32_MAX
#define UT32_MAX
Definition:
rz_types_base.h:99
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_item_t
Definition:
rz_reg.h:117
rz_reg_t
Definition:
rz_reg.h:144
ut64
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
librz
debug
p
native
bt
generic-x86.c
Generated by
1.9.1