Rizin
unix-like reverse engineering framework and cli tools
strings.c File Reference
#include "rz_search.h"

Go to the source code of this file.

Enumerations

enum  { ENCODING_ASCII = 0 , ENCODING_CP850 = 1 }
 

Functions

RZ_API int rz_search_get_encoding (const char *name)
 
static bool is_encoded (int encoding, unsigned char c)
 
RZ_API int rz_search_strings_update (RzSearch *s, ut64 from, const ut8 *buf, int len)
 

Variables

static char * encodings [3] = { "ascii", "cp850", NULL }
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ENCODING_ASCII 
ENCODING_CP850 

Definition at line 7 of file strings.c.

7  {
8  ENCODING_ASCII = 0,
10 };
@ ENCODING_CP850
Definition: strings.c:9
@ ENCODING_ASCII
Definition: strings.c:8

Function Documentation

◆ is_encoded()

static bool is_encoded ( int  encoding,
unsigned char  c 
)
static

Definition at line 31 of file strings.c.

31  {
32  switch (encoding) {
33  case ENCODING_ASCII:
34  break;
35  case ENCODING_CP850:
36  switch (c) {
37  // CP850
38  case 128: // cedilla
39  case 133: // a grave
40  case 135: // minicedilla
41  case 160: // a acute
42  case 161: // i acute
43  case 129: // u dieresi
44  case 130: // e acute
45  case 139: // i dieresi
46  case 162: // o acute
47  case 163: // u acute
48  case 164: // enye
49  case 165: // enyemay
50  case 181: // A acute
51  case 144: // E acute
52  case 214: // I acute
53  case 224: // O acute
54  case 233: // U acute
55  return true;
56  }
57  break;
58  }
59  return false;
60 }
#define c(i)
Definition: sha256.c:43

References c, cmd_descs_generate::encoding, ENCODING_ASCII, and ENCODING_CP850.

Referenced by rz_search_strings_update().

◆ rz_search_get_encoding()

RZ_API int rz_search_get_encoding ( const char *  name)

Definition at line 16 of file strings.c.

16  {
17  int i;
18  if (!name || !*name) {
19  return ENCODING_ASCII;
20  }
21  ut32 lename = strlen(name);
22  for (i = 0; encodings[i]; i++) {
23  ut32 sz = RZ_MIN(strlen(encodings[i]), lename);
24  if (!rz_str_ncasecmp(name, encodings[i], sz)) {
25  return i;
26  }
27  }
28  return ENCODING_ASCII;
29 }
lzma_index ** i
Definition: index.h:629
uint32_t ut32
RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n)
Definition: str.c:129
#define RZ_MIN(x, y)
static char * encodings[3]
Definition: strings.c:12
Definition: z80asm.h:102

References ENCODING_ASCII, encodings, i, RZ_MIN, and rz_str_ncasecmp().

◆ rz_search_strings_update()

RZ_API int rz_search_strings_update ( RzSearch s,
ut64  from,
const ut8 buf,
int  len 
)

Definition at line 62 of file strings.c.

62  {
63  int i = 0;
64  int matches = 0;
65  char str[4096];
67  RzSearchKeyword *kw;
68 
69  rz_list_foreach (s->kws, iter, kw) {
70  for (i = 0; i < len; i++) {
71  char ch = buf[i];
72  // non-cp850 encoded
73  if (IS_PRINTABLE(ch) || IS_WHITESPACE(ch) || is_encoded(0, ch)) {
74  str[matches] = ch;
75  if (matches < sizeof(str)) {
76  matches++;
77  }
78  } else {
79  /* wide char check \x??\x00\x??\x00 */
80  if (matches && i + 2 < len && buf[i + 2] == '\0' && buf[i] == '\0' && buf[i + 1] != '\0') {
81  return 1; // widechar
82  }
83  /* check if the length fits on our request */
84  if (matches >= s->string_min && (s->string_max == 0 || matches <= s->string_max)) {
85  str[matches] = '\0';
86  int len = strlen(str);
87  if (len > 2) {
88  ut64 off = (ut64)from + i - matches;
89  rz_search_hit_new(s, kw, off);
90  }
91  fflush(stdout);
92  }
93  matches = 0;
94  }
95  }
96  }
97  return 0;
98 }
size_t len
Definition: 6502dis.c:15
voidpf void * buf
Definition: ioapi.h:138
int off
Definition: pal.c:13
static RzSocket * s
Definition: rtr.c:28
#define IS_WHITESPACE(x)
Definition: rz_str_util.h:13
#define IS_PRINTABLE(x)
Definition: rz_str_util.h:10
RZ_API int rz_search_hit_new(RzSearch *s, RzSearchKeyword *kw, ut64 addr)
Definition: search.c:107
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static bool is_encoded(int encoding, unsigned char c)
Definition: strings.c:31
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References from, i, is_encoded(), IS_PRINTABLE, IS_WHITESPACE, len, off, rz_search_hit_new(), s, cmd_descs_generate::str, and ut64().

Referenced by rz_search_set_mode().

Variable Documentation

◆ encodings

char* encodings[3] = { "ascii", "cp850", NULL }
static

Definition at line 12 of file strings.c.

Referenced by rz_search_get_encoding().