Rizin
unix-like reverse engineering framework and cli tools
fuzzy-all.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
/* implementation */
5
6
static
int
iscallret
(
RzDebug
*
dbg
,
ut64
addr
) {
7
ut8
buf
[32];
8
if
(
addr
== 0LL ||
addr
==
UT64_MAX
)
9
return
0;
10
/* check if region is executable */
11
/* check if previous instruction is a call */
12
/* if x86 expect CALL to be 5 byte length */
13
if
(
dbg
->
arch
&& !strcmp(
dbg
->
arch
,
"x86"
)) {
14
(void)
dbg
->
iob
.
read_at
(
dbg
->
iob
.
io
,
addr
- 5,
buf
, 5);
15
if
(
buf
[0] == 0xe8) {
16
return
1;
17
}
18
if
(
buf
[3] == 0xff
/* bits 4-5 (from right) of next byte must be 01 */
19
&& ((
buf
[4] & 0xf0) == 0xd0
/* Mod is 11 */
20
|| ((
buf
[4] & 0xf0) == 0x10
/* Mod is 00 */
21
&& (
buf
[4] & 0x06) != 0x04))) {
/* R/M not 10x */
22
return
1;
23
}
24
// IMMAMISSINGANYOP
25
}
else
{
26
RzAnalysisOp
op
;
27
(void)
dbg
->
iob
.
read_at
(
dbg
->
iob
.
io
,
addr
- 8,
buf
, 8);
28
(void)
rz_analysis_op
(
dbg
->
analysis
, &
op
,
addr
- 8,
buf
, 8,
RZ_ANALYSIS_OP_MASK_BASIC
);
29
if
(
op
.type ==
RZ_ANALYSIS_OP_TYPE_CALL
||
op
.type ==
RZ_ANALYSIS_OP_TYPE_UCALL
) {
30
return
1;
31
}
32
/* delay slot */
33
(void)
rz_analysis_op
(
dbg
->
analysis
, &
op
,
addr
- 4,
buf
, 4,
RZ_ANALYSIS_OP_MASK_BASIC
);
34
if
(
op
.type ==
RZ_ANALYSIS_OP_TYPE_CALL
||
op
.type ==
RZ_ANALYSIS_OP_TYPE_UCALL
) {
35
return
1;
36
}
37
}
38
return
0;
39
}
40
41
static
RzList
*
backtrace_fuzzy
(
RzDebug
*
dbg
,
ut64
at) {
42
ut8
*
stack
, *ptr;
43
int
wordsize =
dbg
->
bits
;
// XXX, dbg->bits is wordsize not bits
44
ut64
sp
;
45
RzIOBind
*bio = &
dbg
->
iob
;
46
int
i
, stacksize;
47
ut64
*p64,
addr
= 0LL;
48
ut32
*p32;
49
ut16
*p16;
50
ut64
cursp, oldsp;
51
RzList
*
list
;
52
53
stacksize = 1024 * 512;
// 512KB .. should get the size from the regions if possible
54
stack
=
malloc
(stacksize);
55
if
(at ==
UT64_MAX
) {
56
RzRegItem
*ri;
57
RzReg
*
reg
=
dbg
->
reg
;
58
const
char
*spname =
rz_reg_get_name
(
reg
,
RZ_REG_NAME_SP
);
59
if
(!spname) {
60
eprintf
(
"Cannot find stack pointer register\n"
);
61
free
(
stack
);
62
return
NULL
;
63
}
64
ri =
rz_reg_get
(
reg
, spname,
RZ_REG_TYPE_GPR
);
65
if
(!ri) {
66
eprintf
(
"Cannot find stack pointer register\n"
);
67
free
(
stack
);
68
return
NULL
;
69
}
70
sp
=
rz_reg_get_value
(
reg
, ri);
71
}
else
{
72
sp
= at;
73
}
74
75
list
=
rz_list_new
();
76
list
->free =
free
;
77
cursp = oldsp =
sp
;
78
(void)bio->
read_at
(bio->
io
,
sp
,
stack
, stacksize);
79
ptr =
stack
;
80
for
(
i
= 0;
i
<
dbg
->
btdepth
;
i
++) {
81
p64 = (
ut64
*)ptr;
82
p32 = (
ut32
*)ptr;
83
p16 = (
ut16
*)ptr;
84
switch
(wordsize) {
85
case
8:
addr
= *p64;
break
;
86
case
4:
addr
= *p32;
break
;
87
case
2:
addr
= *p16;
break
;
88
default
:
89
eprintf
(
"Invalid word size with asm.bits\n"
);
90
rz_list_free
(
list
);
91
return
NULL
;
92
}
93
if
(
iscallret
(
dbg
,
addr
)) {
94
RzDebugFrame
*frame =
RZ_NEW0
(
RzDebugFrame
);
95
frame->
addr
=
addr
;
96
frame->
size
= cursp - oldsp;
97
frame->
sp
= cursp;
98
frame->
bp
= oldsp;
// addr + (i * wordsize); // -4 || -8
99
// eprintf ("--------------> 0x%llx (%d)\n", addr, frame->size);
100
rz_list_append
(
list
, frame);
101
oldsp = cursp;
102
}
103
ptr += wordsize;
104
cursp += wordsize;
105
}
106
return
list
;
107
}
op
ut8 op
Definition:
6502dis.c:13
i
lzma_index ** i
Definition:
index.h:629
NULL
#define NULL
Definition:
cris-opc.c:27
ut16
uint16_t ut16
Definition:
demangler_util.h:30
ut32
uint32_t ut32
Definition:
demangler_util.h:31
dbg
RzDebug * dbg
Definition:
desil.c:30
backtrace_fuzzy
static RzList * backtrace_fuzzy(RzDebug *dbg, ut64 at)
Definition:
fuzzy-all.c:41
iscallret
static int iscallret(RzDebug *dbg, ut64 addr)
Definition:
fuzzy-all.c:6
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_free
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition:
list.c:137
malloc
void * malloc(size_t size)
Definition:
malloc.c:123
rz_analysis_op
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition:
op.c:96
rz_reg_get
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition:
reg.c:344
rz_reg_get_name
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition:
reg.c:147
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_OP_MASK_BASIC
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition:
rz_analysis.h:440
RZ_ANALYSIS_OP_TYPE_CALL
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition:
rz_analysis.h:378
RZ_ANALYSIS_OP_TYPE_UCALL
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition:
rz_analysis.h:379
RZ_REG_TYPE_GPR
@ RZ_REG_TYPE_GPR
Definition:
rz_reg.h:21
RZ_REG_NAME_SP
@ RZ_REG_NAME_SP
Definition:
rz_reg.h:44
RZ_NEW0
#define RZ_NEW0(x)
Definition:
rz_types.h:284
UT64_MAX
#define UT64_MAX
Definition:
rz_types_base.h:86
rz_analysis_op_t
Definition:
rz_analysis.h:811
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::arch
char * arch
Definition:
rz_debug.h:242
rz_debug_t::reg
RzReg * reg
Definition:
rz_debug.h:286
rz_debug_t::bits
int bits
Definition:
rz_debug.h:243
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
stack
Definition:
z80asm.h:140
op
Definition:
dis.c:32
ut64
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
sp
static int sp
Definition:
z80asm.c:91
addr
static int addr
Definition:
z80asm.c:58
stack
static struct stack stack[MAX_INCLUDE]
Definition:
z80asm.c:92
librz
debug
p
native
bt
fuzzy-all.c
Generated by
1.9.1