forked from VirusTotal/yara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
48 lines (37 loc) · 920 Bytes
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#define exit_with_code(code) { result = code; goto _exit; }
int compile_files(
YR_COMPILER* compiler,
int argc,
const char** argv)
{
for (int i = 0; i < argc - 1; i++)
{
const char* ns;
const char* file_name;
char* colon = (char*) strchr(argv[i], ':');
int errors;
// Namespace delimiter must be a colon not followed by a slash or backslash
if (colon && *(colon + 1) != '\\' && *(colon + 1) != '/')
{
file_name = colon + 1;
*colon = '\0';
ns = argv[i];
}
else
{
file_name = argv[i];
ns = NULL;
}
FILE* rule_file = fopen(file_name, "r");
if (rule_file == NULL)
{
fprintf(stderr, "error: could not open file: %s\n", file_name);
return FALSE;
}
errors = yr_compiler_add_file(compiler, rule_file, ns, file_name);
fclose(rule_file);
if (errors > 0)
return FALSE;
}
return TRUE;
}