Skip to content

Commit

Permalink
Honor length argument for rule creation (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainpelissier authored Aug 31, 2024
1 parent 17ef579 commit 234edb8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ jobs:
- name: Init r2pm in a local folder
run: |
export R2PM_GITDIR=`pwd`
r2pm -ci yara
r2pm -Uci yara
r2pm -i r2yara
- name: Testing r2yara installation
run: R2_DEBUG=1 r2 -qcq -c 'yrv' --
- name: Running Testsuite
run: |
cd r2yara
make -C test
r2pm -r make -C test
build-macos:
runs-on: macos-12
steps:
Expand Down
59 changes: 31 additions & 28 deletions src/core_r2yara.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,34 +567,37 @@ static int cmd_yara_gen(R2Yara *r2yara, const char* input) {
break;
case 's':
{
char *s = r_core_cmd_str (r2yara->core, "psz");
r_list_append (r2yara->genstrings, yarastring (s));
free (s);
}
break;
case '-':
if (input && input[1] == '*') {
r_list_free (r2yara->genstrings);
r2yara->genstrings = r_list_newf (free);
} else {
char *s = r_list_pop (r2yara->genstrings);
free (s);
}
break;
case 'x':
if (input) {
int len = r_num_math (r2yara->core->num, input + 1);
char *s = r_core_cmd_strf (r2yara->core, "pcY %d", len);
r_str_trim (s);
r_list_append (r2yara->genstrings, s);
} else {
char *s = r_core_cmd_str (r2yara->core, "pcY");
r_str_trim (s);
r_list_append (r2yara->genstrings, s);
}
break;
}
return 0;
char *s;
if (input[1]) {
int len = r_num_math(r2yara->core->num, input + 1);
s = r_core_cmd_strf(r2yara->core, "psz %d", len);
} else {
s = r_core_cmd_str(r2yara->core, "psz");
}
r_list_append(r2yara->genstrings, yarastring(s));
} break;
case '-':
if (input && input[1] == '*') {
r_list_free(r2yara->genstrings);
r2yara->genstrings = r_list_newf(free);
} else {
char *s = r_list_pop(r2yara->genstrings);
free(s);
}
break;
case 'x': {
char *s;
if (input[1]) {
int len = r_num_math(r2yara->core->num, input + 1);
s = r_core_cmd_strf(r2yara->core, "pcy %d", len);
} else {
s = r_core_cmd_str(r2yara->core, "pcy");
}
r_str_trim(s);
r_list_append(r2yara->genstrings, s);
} break;
}
return 0;
}

static int cmd_yara_add(R2Yara *r2yara, const char* input) {
Expand Down
19 changes: 19 additions & 0 deletions test/db/extras/yara
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@ EXPECT=<<EOF
test
EOF
RUN

NAME=yrgs with length
FILE=malloc://1024
CMDS=<<EOF
yr-
w 4d79207061747465726e010203040506
s 100
w 4d79207061747465726ef1f2f3f4
yrgs 10
yr+
yrs
EOF
EXPECT=<<EOF
rulename
0x00000000: yara0.rulename_0 : 34643739323037303631
0x00000064: yara0.rulename_1 : 34643739323037303631
EOF
RUN

0 comments on commit 234edb8

Please sign in to comment.