mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 02:58:20 +00:00
Infrastructure for modularizing protocol analyzers.
There's now a new directory "src/protocols/", and the plan is for each protocol analyzer to eventually have its own subdirectory in there that contains everything it defines (C++/pac/bif). The infrastructure to make that happen is in place, and two analyzers have been converted to the new model, HTTP and SSL; there's no further HTTP/SSL-specific code anywhere else in the core anymore (I believe :-) Further changes: - -N lists available plugins, -NN lists more details on what these plugins provide (analyzers, bif elements). (The latter does not work for analyzers that haven't been converted yet). - *.bif.bro files now go into scripts/base/bif/; and scripts/base/bif/plugins/ for bif files provided by plugins. - I've factored out the bifcl/binpac CMake magic from src/CMakeLists.txt to cmake/{BifCl,Binpac} - There's a new cmake/BroPlugin that contains magic to allow plugins to have a simple CMakeLists.txt. The hope is that eventually the same CMakeLists.txt can be used for compiling a plugin either statically or dynamically. - bifcl has a new option -c that changes the code it generates so that it can be used with a plugin. TODOs: - "make install" is probably broken. - Broxygen is probably broken for plugin-defined events. - event groups are broken (do we want to keep them?)
This commit is contained in:
parent
2be985433c
commit
19c1816ebb
44 changed files with 974 additions and 663 deletions
|
@ -27,7 +27,7 @@ int check_c_mode(int t)
|
|||
|
||||
WS [ \t]+
|
||||
/* Note, bifcl only accepts a single "::" in IDs while the policy
|
||||
layer acceptes multiple. (But the policy layer doesn't have
|
||||
layer acceptes multiple. (But the policy layer doesn't have
|
||||
a hierachy. */
|
||||
IDCOMPONENT [A-Za-z_][A-Za-z_0-9]*
|
||||
ID {IDCOMPONENT}(::{IDCOMPONENT})?
|
||||
|
@ -137,6 +137,8 @@ int yywrap()
|
|||
|
||||
extern int yyparse();
|
||||
char* input_filename = 0;
|
||||
char* input_filename_with_path = 0;
|
||||
char* plugin = 0;
|
||||
|
||||
FILE* fp_bro_init = 0;
|
||||
FILE* fp_func_def = 0;
|
||||
|
@ -168,15 +170,108 @@ FILE* open_output_file(const char* surfix)
|
|||
return fp;
|
||||
}
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr, "usage: bifcl [-p] *.bif\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void init_plugin_mode()
|
||||
{
|
||||
fp_bro_init = open_output_file("bro");
|
||||
fp_func_h = open_output_file("h");
|
||||
fp_func_def = open_output_file("cc");
|
||||
fp_func_init = open_output_file("init.cc");
|
||||
|
||||
fp_netvar_h = fp_func_h;
|
||||
fp_netvar_def = fp_func_def;
|
||||
fp_netvar_init = fp_func_init;
|
||||
|
||||
int n = 1024 + strlen(input_filename);
|
||||
char auto_gen_comment[n];
|
||||
|
||||
snprintf(auto_gen_comment, n,
|
||||
"This file was automatically generated by bifcl from %s (plugin mode).",
|
||||
input_filename_with_path);
|
||||
|
||||
fprintf(fp_bro_init, "# %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_func_def, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_func_h, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_func_init, "// %s\n\n", auto_gen_comment);
|
||||
|
||||
static char guard[1024];
|
||||
getcwd(guard, sizeof(guard));
|
||||
strncat(guard, "/", sizeof(guard));
|
||||
strncat(guard, input_filename, sizeof(guard));
|
||||
|
||||
for ( char* p = guard; *p; p++ )
|
||||
{
|
||||
if ( strchr("/.", *p) )
|
||||
*p = '_';
|
||||
}
|
||||
|
||||
fprintf(fp_func_h, "#ifndef %s\n", guard);
|
||||
fprintf(fp_func_h, "#define %s\n", guard);
|
||||
fprintf(fp_func_h, "\n");
|
||||
fprintf(fp_func_h, "#include \"bro-bif.h\"\n");
|
||||
|
||||
fprintf(fp_func_def, "\n");
|
||||
fprintf(fp_func_def, "#include \"%s.h\"\n", input_filename);
|
||||
fprintf(fp_func_def, "\n");
|
||||
|
||||
static char name[1024];
|
||||
strncpy(name, input_filename, sizeof(name));
|
||||
char* dot = strchr(name, '.');
|
||||
if ( dot )
|
||||
*dot = '\0';
|
||||
|
||||
fprintf(fp_func_init, "\n");
|
||||
fprintf(fp_func_init, "#include <list>\n");
|
||||
fprintf(fp_func_init, "#include <string>\n");
|
||||
fprintf(fp_func_init, "#include \"%s.h\"\n", input_filename);
|
||||
fprintf(fp_func_init, "\n");
|
||||
fprintf(fp_func_init, "namespace plugin { namespace %s {\n", plugin);
|
||||
fprintf(fp_func_init, "\n");
|
||||
fprintf(fp_func_init, "std::list<std::pair<std::string, int> > __bif_%s_init()\n", name);
|
||||
fprintf(fp_func_init, "\t{\n");
|
||||
fprintf(fp_func_init, "\tstd::list<std::pair<std::string, int> > bifs;\n");
|
||||
fprintf(fp_func_init, "\n");
|
||||
}
|
||||
|
||||
void finish_plugin_mode()
|
||||
{
|
||||
fprintf(fp_func_h, "\n");
|
||||
fprintf(fp_func_h, "#endif\n");
|
||||
|
||||
fprintf(fp_func_init, "\n");
|
||||
fprintf(fp_func_init, "\treturn bifs;\n");
|
||||
fprintf(fp_func_init, "\t}\n");
|
||||
fprintf(fp_func_init, "} }\n");
|
||||
fprintf(fp_func_init, "\n");
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
for ( int i = 1; i < argc; i++ )
|
||||
char opt;
|
||||
|
||||
while ( (opt = getopt(argc, argv, "p:")) != -1 )
|
||||
{
|
||||
switch ( opt ) {
|
||||
case 'p':
|
||||
plugin = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = optind; i < argc; i++ )
|
||||
{
|
||||
FILE* fp_input;
|
||||
char* slash;
|
||||
|
||||
input_filename = argv[i];
|
||||
input_filename = input_filename_with_path = argv[i];
|
||||
slash = strrchr(input_filename, '/');
|
||||
|
||||
if ( (fp_input = fopen(input_filename, "r")) == NULL )
|
||||
|
@ -189,17 +284,41 @@ int main(int argc, char* argv[])
|
|||
if ( slash )
|
||||
input_filename = slash + 1;
|
||||
|
||||
fp_bro_init = open_output_file("bro");
|
||||
fp_func_h = open_output_file("func_h");
|
||||
fp_func_def = open_output_file("func_def");
|
||||
fp_func_init = open_output_file("func_init");
|
||||
fp_netvar_h = open_output_file("netvar_h");
|
||||
fp_netvar_def = open_output_file("netvar_def");
|
||||
fp_netvar_init = open_output_file("netvar_init");
|
||||
if ( ! plugin )
|
||||
{
|
||||
fp_bro_init = open_output_file("bro");
|
||||
fp_func_h = open_output_file("func_h");
|
||||
fp_func_def = open_output_file("func_def");
|
||||
fp_func_init = open_output_file("func_init");
|
||||
fp_netvar_h = open_output_file("netvar_h");
|
||||
fp_netvar_def = open_output_file("netvar_def");
|
||||
fp_netvar_init = open_output_file("netvar_init");
|
||||
|
||||
int n = 1024 + strlen(input_filename);
|
||||
char auto_gen_comment[n];
|
||||
|
||||
snprintf(auto_gen_comment, n,
|
||||
"This file was automatically generated by bifcl from %s.",
|
||||
input_filename);
|
||||
|
||||
fprintf(fp_bro_init, "# %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_func_def, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_func_h, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_func_init, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_netvar_def, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_netvar_h, "// %s\n\n", auto_gen_comment);
|
||||
fprintf(fp_netvar_init, "// %s\n\n", auto_gen_comment);
|
||||
}
|
||||
|
||||
else
|
||||
init_plugin_mode();
|
||||
|
||||
yy_switch_to_buffer(yy_create_buffer(fp_input, YY_BUF_SIZE));
|
||||
yyparse();
|
||||
|
||||
if ( plugin )
|
||||
finish_plugin_mode();
|
||||
|
||||
fclose(fp_input);
|
||||
close_all_output_files();
|
||||
|
||||
|
@ -219,9 +338,13 @@ void close_all_output_files(void)
|
|||
close_if_open(&fp_func_h);
|
||||
close_if_open(&fp_func_def);
|
||||
close_if_open(&fp_func_init);
|
||||
close_if_open(&fp_netvar_h);
|
||||
close_if_open(&fp_netvar_def);
|
||||
close_if_open(&fp_netvar_init);
|
||||
|
||||
if ( ! plugin )
|
||||
{
|
||||
close_if_open(&fp_netvar_h);
|
||||
close_if_open(&fp_netvar_def);
|
||||
close_if_open(&fp_netvar_init);
|
||||
}
|
||||
}
|
||||
|
||||
void remove_file(const char *surfix)
|
||||
|
@ -232,7 +355,7 @@ void remove_file(const char *surfix)
|
|||
unlink(fn);
|
||||
}
|
||||
|
||||
void err_exit(void)
|
||||
void err_exit(void)
|
||||
{
|
||||
close_all_output_files();
|
||||
/* clean up. remove all output files we've generated so far */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue