|
|
|
@ -3774,10 +3774,6 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo, |
|
|
|
|
STAILQ_INIT(&compiler.rule_q); |
|
|
|
|
STAILQ_INIT(&compiler.current_rule_string_q); |
|
|
|
|
|
|
|
|
|
rc = yr_hash_table_create(10007, &compiler.rules_table); |
|
|
|
|
if (rc == ERROR_SUCCESS) |
|
|
|
|
rc = yr_hash_table_create(10007, &compiler.objects_table); |
|
|
|
|
if (rc == ERROR_SUCCESS) |
|
|
|
|
rc = yr_arena_create(65536, 0, &compiler.sz_arena); |
|
|
|
|
if (rc == ERROR_SUCCESS) |
|
|
|
|
rc = yr_arena_create(65536, 0, &compiler.rules_arena); |
|
|
|
@ -3792,17 +3788,18 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo, |
|
|
|
|
compiler.loop_for_of_mem_offset = -1; |
|
|
|
|
ns.name = "default"; |
|
|
|
|
compiler.current_namespace = &ns; |
|
|
|
|
compiler.the_arena = engine->the_arena; |
|
|
|
|
compiler.rules_table = engine->rules_table; |
|
|
|
|
compiler.objects_table = engine->objects_table; |
|
|
|
|
|
|
|
|
|
rc = yr_lex_parse_rules_file(fs, &compiler); |
|
|
|
|
if (rc > 0) { /* rc = number of errors */ |
|
|
|
|
/* TODO - handle the various errors? */ |
|
|
|
|
cli_errmsg("cli_loadyara: failed to parse rules file %s, error count %i\n", dbname, rc); |
|
|
|
|
yr_hash_table_destroy(compiler.rules_table, NULL); |
|
|
|
|
yr_hash_table_destroy(compiler.objects_table, NULL); |
|
|
|
|
// yr_arena_destroy(compiler.sz_arena);
|
|
|
|
|
// yr_arena_destroy(compiler.rules_arena);
|
|
|
|
|
yr_arena_destroy(compiler.sz_arena); |
|
|
|
|
yr_arena_destroy(compiler.rules_arena); |
|
|
|
|
yr_arena_destroy(compiler.code_arena); |
|
|
|
|
// yr_arena_destroy(compiler.strings_arena);
|
|
|
|
|
yr_arena_destroy(compiler.strings_arena); |
|
|
|
|
yr_arena_destroy(compiler.metas_arena); |
|
|
|
|
#ifdef YARA_FINISHED |
|
|
|
|
return CL_EMALFDB; |
|
|
|
@ -3826,12 +3823,10 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
yr_hash_table_destroy(compiler.rules_table, NULL); |
|
|
|
|
yr_hash_table_destroy(compiler.objects_table, NULL); |
|
|
|
|
// yr_arena_destroy(compiler.sz_arena);
|
|
|
|
|
// yr_arena_destroy(compiler.rules_arena);
|
|
|
|
|
yr_arena_append(engine->the_arena, compiler.sz_arena); |
|
|
|
|
yr_arena_append(engine->the_arena, compiler.rules_arena); |
|
|
|
|
yr_arena_append(engine->the_arena, compiler.strings_arena); |
|
|
|
|
yr_arena_destroy(compiler.code_arena); |
|
|
|
|
// yr_arena_destroy(compiler.strings_arena);
|
|
|
|
|
yr_arena_destroy(compiler.metas_arena); |
|
|
|
|
|
|
|
|
|
if(rc) |
|
|
|
@ -4285,6 +4280,7 @@ int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, uns |
|
|
|
|
cli_errmsg("cl_load(%s): Not supported database file type\n", path); |
|
|
|
|
return CL_EOPEN; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef YARA_PROTO |
|
|
|
|
if (yara_total) { |
|
|
|
|
cli_yaramsg("$$$$$$$$$$$$ YARA $$$$$$$$$$$$\n"); |
|
|
|
@ -4553,9 +4549,6 @@ int cl_engine_free(struct cl_engine *engine) |
|
|
|
|
for(j = 0; j < root->ac_lsigs; j++) { |
|
|
|
|
if (root->ac_lsigtable[j]->type == CLI_LSIG_NORMAL) |
|
|
|
|
mpool_free(engine->mempool, root->ac_lsigtable[j]->u.logic); |
|
|
|
|
else if (root->ac_lsigtable[j]->type == CLI_YARA_NORMAL || |
|
|
|
|
root->ac_lsigtable[j]->type == CLI_YARA_NORMAL) |
|
|
|
|
free(root->ac_lsigtable[j]->u.code_start); |
|
|
|
|
FREE_TDB(root->ac_lsigtable[j]->tdb); |
|
|
|
|
mpool_free(engine->mempool, root->ac_lsigtable[j]); |
|
|
|
|
} |
|
|
|
@ -4667,6 +4660,16 @@ int cl_engine_free(struct cl_engine *engine) |
|
|
|
|
#ifdef USE_MPOOL |
|
|
|
|
if(engine->mempool) mpool_destroy(engine->mempool); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (engine->rules_table) |
|
|
|
|
yr_hash_table_destroy(engine->rules_table, NULL); |
|
|
|
|
|
|
|
|
|
if (engine->objects_table) |
|
|
|
|
yr_hash_table_destroy(engine->objects_table, NULL); |
|
|
|
|
|
|
|
|
|
if (engine->the_arena) |
|
|
|
|
yr_arena_destroy(engine->the_arena); |
|
|
|
|
|
|
|
|
|
free(engine); |
|
|
|
|
return CL_SUCCESS; |
|
|
|
|
} |
|
|
|
@ -4680,6 +4683,13 @@ int cl_engine_compile(struct cl_engine *engine) |
|
|
|
|
if(!engine) |
|
|
|
|
return CL_ENULLARG; |
|
|
|
|
|
|
|
|
|
/* Free YARA hash tables - only needed for parse and load */ |
|
|
|
|
if (engine->rules_table) |
|
|
|
|
yr_hash_table_destroy(engine->rules_table, NULL); |
|
|
|
|
if (engine->objects_table) |
|
|
|
|
yr_hash_table_destroy(engine->objects_table, NULL); |
|
|
|
|
engine->rules_table = engine->objects_table = NULL; |
|
|
|
|
|
|
|
|
|
if(!engine->ftypes) |
|
|
|
|
if((ret = cli_loadftm(NULL, engine, 0, 1, NULL))) |
|
|
|
|
return ret; |
|
|
|
|