Rizin
unix-like reverse engineering framework and cli tools
rz_search.h
Go to the documentation of this file.
1 #ifndef RZ_SEARCH_H
2 #define RZ_SEARCH_H
3 
4 #include <rz_types.h>
5 #include <rz_util.h>
6 #include <rz_list.h>
7 #include <rz_io.h>
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
14 
15 enum {
27 };
28 
29 #define RZ_SEARCH_DISTANCE_MAX 10
30 
31 #define RZ_SEARCH_KEYWORD_TYPE_BINARY 'i'
32 #define RZ_SEARCH_KEYWORD_TYPE_STRING 's'
33 
34 typedef struct rz_search_keyword_t {
39  void *data;
40  int count;
41  int kwidx;
42  int icase; // ignore case
43  int type;
44  ut64 last; // last hit hint
46 
47 typedef struct rz_search_hit_t {
51 
52 typedef int (*RzSearchCallback)(RzSearchKeyword *kw, void *user, ut64 where);
53 
54 typedef struct rz_search_t {
55  int n_kws; // hit${n_kws}_${count}
56  int mode;
58  ut32 string_min; // max length of strings for RZ_SEARCH_STRING
59  ut32 string_max; // min length of strings for RZ_SEARCH_STRING
60  void *data; // data used by search algorithm
61  void *user; // user data passed to callback
64  ut64 maxhits; // search.maxhits
66  int distance;
67  int inverse;
68  bool overlap; // whether two matches can overlap
70  int align;
71  int (*update)(struct rz_search_t *s, ut64 from, const ut8 *buf, int len);
72  RzList *kws; // TODO: Use rz_search_kw_new ()
74  char bckwrds;
76 
77 #ifdef RZ_API
78 
79 #define RZ_SEARCH_AES_BOX_SIZE 31
80 
84 
85 /* keyword management */
87 RZ_API int rz_search_update(RzSearch *s, ut64 from, const ut8 *buf, long len);
88 RZ_API int rz_search_update_i(RzSearch *s, ut64 from, const ut8 *buf, long len);
89 
91 RZ_API RzSearchKeyword *rz_search_keyword_new(const ut8 *kw, int kwlen, const ut8 *bm, int bmlen, const char *data);
92 RZ_API RzSearchKeyword *rz_search_keyword_new_str(const char *kw, const char *bm, const char *data, int icase);
93 RZ_API RzSearchKeyword *rz_search_keyword_new_wide(const char *kw, const char *bm, const char *data, int icase);
94 RZ_API RzSearchKeyword *rz_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data);
95 RZ_API RzSearchKeyword *rz_search_keyword_new_hexmask(const char *kwstr, const char *data);
97 
102 
103 // TODO: is this an internal API?
105 RZ_API int rz_search_aes_update(RzSearch *s, ut64 from, const ut8 *buf, int len);
107 RZ_API int rz_search_magic_update(RzSearch *_s, ut64 from, const ut8 *buf, int len);
111 // Returns 2 if search.maxhits is reached, 0 on error, otherwise 1
113 RZ_API void rz_search_set_distance(RzSearch *s, int dist);
115 // RZ_API int rz_search_set_callback(RzSearch *s, int (*callback)(struct rz_search_kw_t *, void *, ut64), void *user);
118 
119 /* pattern search */
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif
128 #endif
size_t len
Definition: 6502dis.c:15
RZ_API int rz_search_aes_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: aes-find.c:43
RZ_API int rz_search_pattern(RzSearch *s, ut64 from, ut64 to)
Definition: bytepat.c:61
#define RZ_API
uint32_t ut32
int max
Definition: enough.c:225
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
RZ_API RzSearchKeyword * rz_search_keyword_new_str(const char *kwbuf, const char *bmstr, const char *data, int ignore_case)
Definition: keyword.c:58
RZ_API RzSearchKeyword * rz_search_keyword_new_wide(const char *kwbuf, const char *bmstr, const char *data, int ignore_case)
Definition: keyword.c:82
RZ_API RzSearchKeyword * rz_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data)
Definition: keyword.c:132
RZ_API void rz_search_keyword_free(RzSearchKeyword *kw)
Definition: keyword.c:49
RZ_API RzSearchKeyword * rz_search_keyword_new_regexp(const char *str, const char *data)
Definition: keyword.c:196
RZ_API RzSearchKeyword * rz_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut8 *bmbuf, int bmlen, const char *data)
Definition: keyword.c:16
RZ_API RzSearchKeyword * rz_search_keyword_new_hexmask(const char *kwstr, const char *data)
Definition: keyword.c:173
uint8_t ut8
Definition: lh5801.h:11
RZ_API int rz_search_privkey_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: privkey-find.c:71
#define min(a, b)
Definition: qsort.h:83
RZ_API int rz_search_regexp_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: regexp.c:8
static RzSocket * s
Definition: rtr.c:28
struct rz_search_hit_t RzSearchHit
RZ_LIB_VERSION_HEADER(rz_search)
struct rz_search_t RzSearch
@ RZ_SEARCH_LAST
Definition: rz_search.h:26
@ RZ_SEARCH_REGEXP
Definition: rz_search.h:18
@ RZ_SEARCH_STRING
Definition: rz_search.h:20
@ RZ_SEARCH_ESIL
Definition: rz_search.h:16
@ RZ_SEARCH_AES
Definition: rz_search.h:22
@ RZ_SEARCH_PATTERN
Definition: rz_search.h:19
@ RZ_SEARCH_MAGIC
Definition: rz_search.h:25
@ RZ_SEARCH_DELTAKEY
Definition: rz_search.h:24
@ RZ_SEARCH_KEYWORD
Definition: rz_search.h:17
@ RZ_SEARCH_PRIV_KEY
Definition: rz_search.h:23
@ RZ_SEARCH_XREFS
Definition: rz_search.h:21
int(* RzSearchCallback)(RzSearchKeyword *kw, void *user, ut64 where)
Definition: rz_search.h:52
struct rz_search_keyword_t RzSearchKeyword
RZ_API void rz_search_string_prepare_backward(RzSearch *s)
Definition: search.c:516
RZ_API RzList * rz_search_find(RzSearch *s, ut64 addr, const ut8 *buf, int len)
Definition: search.c:498
RZ_API int rz_search_update(RzSearch *s, ut64 from, const ut8 *buf, long len)
Definition: search.c:470
RZ_API void rz_search_set_callback(RzSearch *s, RzSearchCallback(callback), void *user)
Definition: search.c:463
RZ_API int rz_search_begin(RzSearch *s)
Definition: search.c:96
RZ_API int rz_search_set_mode(RzSearch *s, int mode)
Definition: search.c:78
RZ_API void rz_search_kw_reset(RzSearch *s)
Definition: search.c:544
RZ_API int rz_search_update_i(RzSearch *s, ut64 from, const ut8 *buf, long len)
Definition: search.c:483
RZ_API RzSearch * rz_search_new(int mode)
Definition: search.c:19
RZ_API int rz_search_hit_new(RzSearch *s, RzSearchKeyword *kw, ut64 addr)
Definition: search.c:107
RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: search.c:144
RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: search.c:359
RZ_API int rz_search_set_string_limits(RzSearch *s, ut32 min, ut32 max)
Definition: search.c:64
RZ_API RzSearch * rz_search_free(RzSearch *s)
Definition: search.c:52
RZ_API void rz_search_reset(RzSearch *s, int mode)
Definition: search.c:537
RZ_API void rz_search_pattern_size(RzSearch *s, int size)
Definition: search.c:459
RZ_API int rz_search_kw_add(RzSearch *s, RzSearchKeyword *kw)
Definition: search.c:506
RZ_API void rz_search_set_distance(RzSearch *s, int dist)
Definition: search.c:449
RZ_API int rz_search_magic_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: search.c:73
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
static int
Definition: sfsocketcall.h:114
RZ_API int rz_search_strings_update(RzSearch *s, ut64 from, const ut8 *buf, int len)
Definition: strings.c:62
RzSearchKeyword * kw
Definition: rz_search.h:48
int distance
Definition: rz_search.h:66
bool overlap
Definition: rz_search.h:68
ut32 string_min
Definition: rz_search.h:58
char bckwrds
Definition: rz_search.h:74
int(* update)(struct rz_search_t *s, ut64 from, const ut8 *buf, int len)
Definition: rz_search.h:71
RzIOBind iob
Definition: rz_search.h:73
void * data
Definition: rz_search.h:60
void * user
Definition: rz_search.h:61
RzList * hits
Definition: rz_search.h:65
int contiguous
Definition: rz_search.h:69
ut64 maxhits
Definition: rz_search.h:64
RzList * kws
Definition: rz_search.h:72
int inverse
Definition: rz_search.h:67
ut32 pattern_size
Definition: rz_search.h:57
ut64 nhits
Definition: rz_search.h:63
ut32 string_max
Definition: rz_search.h:59
RzSearchCallback callback
Definition: rz_search.h:62
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58