9 #define I(x) rz_cons_singleton()->x
12 char *
p = strchr(
s, ch);
16 memmove(prev,
p, strlen(
p) + 1);
24 "Usage: [command]~[modifier][word,word][endmodifier][[column]][:line]\n"
27 " &",
"",
"all words must match to grep the line",
28 " $[n]",
"",
"sort numerically / alphabetically the Nth column",
29 " $!",
"",
"sort in inverse order",
30 " ,",
"",
"token to define another keyword",
31 " +",
"",
"case insensitive grep (grep -i)",
32 " ^",
"",
"words must be placed at the beginning of line",
33 " <",
"",
"perform zoom operation on the buffer",
34 " !",
"",
"negate grep",
35 " ?",
"",
"count number of matching lines",
36 " ?.",
"",
"count number chars",
37 " ??",
"",
"show this help message",
38 " :s..e",
"",
"show lines s-e",
39 " ..",
"",
"internal 'less'",
40 " ...",
"",
"internal 'hud' (like V_)",
41 " {:",
"",
"human friendly indentation (yes, it's a smiley)",
42 " {:..",
"",
"less the output of {:",
43 " {:...",
"",
"hud the output of {:",
44 " {}",
"",
"json indentation",
45 " {}..",
"",
"less json indentation",
46 " {}...",
"",
"hud json indentation",
47 " {path}",
"",
"json path grep",
48 "endmodifier:",
"",
"",
49 " $",
"",
"words must be placed at the end of line",
51 " [n]",
"",
"show only column n",
52 " [n-m]",
"",
"show column n to m",
53 " [n-]",
"",
"show all columns starting from column n",
54 " [i,j,k]",
"",
"show the columns i, j and k",
56 " i~:0",
"",
"show first line of 'i' output",
57 " i~:-2",
"",
"show the second to last line of 'i' output",
58 " i~:0..3",
"",
"show first three lines of 'i' output",
59 " pd~mov",
"",
"disasm and grep for mov",
60 " pi~[0]",
"",
"show only opcode",
61 " i~0x400$",
"",
"show lines ending with 0x400",
74 #define RZ_CONS_GREP_BUFSIZE 4096
78 int wlen,
len, is_range, num_is_parsed,
fail = 0;
79 char *ptr, *optr, *ptr2, *ptr3, *end_ptr =
NULL, last;
80 ut64 range_begin, range_end;
106 if (!strncmp(
str,
"{:...", 5)) {
108 }
else if (!strncmp(
str,
"{:..", 4)) {
111 }
else if (
str[1] ==
'}') {
114 if (!strncmp(
str,
"{}...", 5)) {
116 }
else if (!strncmp(
str,
"{}..", 4)) {
121 char *jsonPathEnd = strchr(jsonPath,
'}');
181 }
else if (*
str ==
'?') {
196 eprintf(
"rz_cons_grep: too long!\n");
209 ptr2 = strchr(ptr,
'[');
210 ptr3 = strchr(ptr,
']');
214 range_begin = range_end = -1;
221 for (; ptr2 <= ptr3; ptr2++) {
235 for (; range_begin <= range_end; range_begin++) {
240 grep->
tokens[range_begin] = 1;
244 if (*ptr2 ==
']' && is_range && !num_is_parsed) {
253 if (!num_is_parsed) {
257 if (range_end == 0 && *ptr !=
'0') {
272 if (ptr2 && ptr2[1] !=
':' && ptr2[1] && (
IS_DIGIT(ptr2[1]) || ptr2[1] ==
'-' || ptr2[1] ==
'.')) {
273 end_ptr = end_ptr ?
RZ_MIN(end_ptr, ptr2) : ptr2;
274 char *
p, *token = ptr2 + 1;
275 p = strstr(token,
"..");
309 ptr = strchr(ptr,
',');
318 eprintf(
"grep string too long\n");
323 eprintf(
"too many grep strings\n");
345 if (
p ==
cmd || *(
p - 1) !=
'\\') {
349 memmove(
p - 1,
p, strlen(
p) + 1);
364 char *p1, *p2, *ns =
NULL;
365 const char *strsep =
"&";
428 static int cmp(
const void *
a,
const void *
b) {
434 return (
int)(
size_t)((
char *)
a - (
char *)
b);
447 int ret = (na > nb) - (na < nb);
453 int ret = strcmp(ca,
cb);
471 const char *
in =
buf;
472 int ret, total_lines = 0, l = 0, tl = 0;
534 const char *palette[] = {
559 }
else if (grep->
less) {
568 int less = grep->
less;
595 while ((
int)(
size_t)(
in -
buf) <
len) {
596 char *
p = strchr(
in,
'\n');
609 grep->
line = total_lines + grep->
line;
619 bool is_range_line_grep_only = grep->
range_line != 2 && !*grep->
str;
621 while ((
int)(
size_t)(
in -
buf) <
len) {
622 char *
p = strchr(
in,
'\n');
627 if ((!l && is_range_line_grep_only) || l > 0) {
653 if ((!ret && is_range_line_grep_only) || ret > 0) {
680 }
else if (ret < 0) {
715 if (grep->
sort != -1) {
716 #define INSERT_LINES(list) \
718 rz_list_foreach (list, iter, str) { \
719 int len = strlen(str); \
720 memcpy(ptr, str, len); \
721 memcpy(ptr + len, "\n", 2); \
749 const char *delims =
" |,;=\t";
753 bool use_tok =
false;
768 int ampfail = grep->
amp;
791 if (grep->
end && (strlen(grep->
strings[
i]) != strlen(
p))) {
817 tok = strtok(
i ?
NULL :
in, delims);
820 int toklen = strlen(tok);
823 outlen += toklen + 1;
839 outlen = outlen > 0 ? outlen - 1 : 0;
841 eprintf(
"rz_cons_grep_line: how you have reached this?\n");
854 if (grep->
sort != -1) {
static RASN1String * newstr(const char *string)
const lzma_allocator const uint8_t * in
const lzma_allocator const uint8_t size_t uint8_t * out
RZ_API RzCons * rz_cons_singleton(void)
RZ_API void rz_cons_newline(void)
RZ_API void rz_cons_cmd_help(const char *help[], bool use_color)
RZ_API void rz_cons_println(const char *str)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
static RzList * sorted_lines
#define INSERT_LINES(list)
RZ_API void rz_cons_grep_help(void)
RZ_API char * rz_cons_grep_strip(char *cmd, const char *quotestr)
static const char * help_detail_tilde[]
static char * find_next_intgrep(char *cmd, const char *quotes)
RZ_API void rz_cons_grep_parsecmd(char *cmd, const char *quotestr)
#define RZ_CONS_GREP_BUFSIZE
static char * preprocess_filter_expr(char *cmd, const char *quotes)
RZ_API int rz_cons_grep_line(char *buf, int len)
static int cmp(const void *a, const void *b)
RZ_API void rz_cons_grep_process(char *grep)
RZ_API void rz_cons_grep(const char *grep)
static char * strchr_ns(char *s, const char ch)
static void parse_grep_expression(const char *str)
static RzList * unsorted_lines
RZ_API void rz_cons_grepbuf(void)
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API char * rz_cons_hud_string(const char *s)
RZ_API char * rz_print_json_indent(const char *s, bool color, const char *tab, const char **palette)
RZ_API char * rz_print_json_human(const char *s)
RZ_API int rz_cons_less_str(const char *str, const char *exitkeys)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static int hit(RzSearchKeyword *kw, void *user, ut64 addr)
RZ_API void rz_list_reverse(RZ_NONNULL RzList *list)
Reverses the list.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define rz_return_if_fail(expr)
#define RZ_CONS_GREP_WORDS
#define RZ_CONS_GREP_TOKENS
#define RZ_CONS_GREP_WORD_SIZE
RZ_API const RzJson * rz_json_get_path(const RzJson *json, const char *path)
RZ_API RzJson * rz_json_parse(char *text)
RZ_API RZ_OWN char * rz_json_as_string(const RzJson *json, bool with_key)
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
RZ_API char * rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
RZ_API char * rz_str_scale(const char *r, int w, int h)
RZ_API char * rz_str_appendlen(char *ptr, const char *string, int slen)
RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len)
RZ_API void rz_str_case(char *str, bool up)
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
RZ_API const char * rz_str_trim_head_ro(const char *str)
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
RZ_API const char * rz_str_firstbut(const char *s, char ch, const char *but)
RZ_API int rz_str_word_set0(char *str)
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
RZ_API const char * rz_strstr_ansi(const char *a, const char *b)
RZ_API const char * rz_str_word_get0(const char *str, int idx)
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
RZ_API void rz_strbuf_free(RzStrBuf *sb)
RZ_API ut8 * rz_strbuf_getbin(RzStrBuf *sb, int *len)
RZ_API int rz_strbuf_length(RzStrBuf *sb)
#define RZ_BETWEEN(x, y, z)
RzConsPrintablePalette pal
int tokens[RZ_CONS_GREP_TOKENS]
char strings[RZ_CONS_GREP_WORDS][RZ_CONS_GREP_WORD_SIZE]
ut64(WINAPI *w32_GetEnabledXStateFeatures)()