int main(int argc, char *argv[]) { int ret_value = 0; libettercap_init(PROGRAM, EC_VERSION); ef_globals_alloc(); select_text_interface(); libettercap_ui_init(); /* etterfilter copyright */ USER_MSG("\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS); /* initialize the line number */ EF_GBL->lineno = 1; /* getopt related parsing... */ parse_options(argc, argv); /* set the input for source file */ if (EF_GBL_OPTIONS->source_file) { yyin = fopen(EF_GBL_OPTIONS->source_file, "r"); if (yyin == NULL) FATAL_ERROR("Input file not found !"); } else { FATAL_ERROR("No source file."); } /* no buffering */ setbuf(yyin, NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); /* load the tables in etterfilter.tbl */ load_tables(); /* load the constants in etterfilter.cnt */ load_constants(); /* print the message */ USER_MSG("\n Parsing source file \'%s\' ", EF_GBL_OPTIONS->source_file); ef_debug(1, "\n"); /* begin the parsing */ if (yyparse() == 0) USER_MSG(" done.\n\n"); else USER_MSG("\n\nThe script contains errors...\n\n"); /* write to file */ ret_value = write_output(); if (ret_value == -E_NOTHANDLED) FATAL_ERROR("Cannot write output file (%s): the filter is not correctly handled.", EF_GBL_OPTIONS->output_file); else if (ret_value == -E_INVALID) FATAL_ERROR("Cannot write output file (%s): the filter format is not correct. ", EF_GBL_OPTIONS->output_file); ef_exit(0); }
/* * creates the data segment into an byte array supplied as argument data * and update the file header instruction pointer 8-byte aligned * * returns length of the data segment */ static size_t create_data_segment(u_char** data, struct filter_header *fh, struct filter_op *fop, size_t n) { size_t i, len = 0; for (i = 0; i < n; i++) { switch(fop[i].opcode) { case FOP_FUNC: if (fop[i].op.func.slen) { ef_debug(1, "@"); len += add_data_segment(data, len, &fop[i].op.func.string, fop[i].op.func.slen); } if (fop[i].op.func.rlen) { ef_debug(1, "@"); len += add_data_segment(data, len, &fop[i].op.func.replace, fop[i].op.func.rlen); } break; case FOP_TEST: if (fop[i].op.test.slen) { ef_debug(1, "@"); len += add_data_segment(data, len, &fop[i].op.test.string, fop[i].op.test.slen); } break; case FOP_ASSIGN: if (fop[i].op.assign.slen) { ef_debug(1, "@"); len += add_data_segment(data, len, &fop[i].op.test.string, fop[i].op.test.slen); } break; } } /* where starts the code ? */ fh->code = fh->data + len; /* 8-byte aligned please */ if (fh->code % 8) fh->code += 8 - fh->code % 8; return len; }
/* * creates the data segment into an array * and update the file header */ static u_char * create_data_segment(struct filter_header *fh, struct filter_op *fop, size_t n) { size_t i, len = 0; u_char *data = NULL; for (i = 0; i < n; i++) { switch(fop[i].opcode) { case FOP_FUNC: if (fop[i].op.func.slen) { ef_debug(1, "@"); len += add_data_segment(&data, len, &fop[i].op.func.string, fop[i].op.func.slen); } if (fop[i].op.func.rlen) { ef_debug(1, "@"); len += add_data_segment(&data, len, &fop[i].op.func.replace, fop[i].op.func.rlen); } break; case FOP_TEST: if (fop[i].op.test.slen) { ef_debug(1, "@"); len += add_data_segment(&data, len, &fop[i].op.test.string, fop[i].op.test.slen); } break; case FOP_ASSIGN: if (fop[i].op.assign.slen) { ef_debug(1, "@"); len += add_data_segment(&data, len, &fop[i].op.test.string, fop[i].op.test.slen); } break; } } /* where starts the code ? */ fh->code = fh->data + len; return data; }
int main(int argc, char *argv[]) { /* etterfilter copyright */ fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", GBL_PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS); /* initialize the line number */ GBL.lineno = 1; /* getopt related parsing... */ parse_options(argc, argv); /* set the input for source file */ if (GBL_OPTIONS.source_file) { yyin = fopen(GBL_OPTIONS.source_file, "r"); if (yyin == NULL) FATAL_ERROR("Input file not found !"); } else { FATAL_ERROR("No source file."); } /* no buffering */ setbuf(yyin, NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); /* load the tables in etterfilter.tbl */ load_tables(); /* load the constants in etterfilter.cnt */ load_constants(); /* print the message */ fprintf(stdout, "\n Parsing source file \'%s\' ", GBL_OPTIONS.source_file); fflush(stdout); ef_debug(1, "\n"); /* begin the parsing */ if (yyparse() == 0) fprintf(stdout, " done.\n\n"); else fprintf(stdout, "\n\nThe script contains errors...\n\n"); /* write to file */ if (write_output() != ESUCCESS) FATAL_ERROR("Cannot write output file (%s)", GBL_OPTIONS.output_file); return 0; }
/* * prints a differnt sign for every different instruction */ static void print_progress_bar(struct filter_op *fop) { switch(fop->opcode) { case FOP_EXIT: ef_debug(1, "!"); break; case FOP_TEST: ef_debug(1, "?"); break; case FOP_ASSIGN: ef_debug(1, "="); break; case FOP_FUNC: ef_debug(1, "."); break; case FOP_JMP: ef_debug(1, ":"); break; case FOP_JTRUE: case FOP_JFALSE: ef_debug(1, ";"); break; } }