int main(int argc, char const *argv[]) { fa_fa_initialize(); run_fs(); fa_fa_terminate(); }
void test_reshape_algorithm() { int num1 = tidfa_num; reshape(); int num2 = tidfa_num; printf("%d new states are needed!\n", num2 - num1); int p = 0; int i = 0; bool http_accept = false; for (; i < strlen(indata); i++) { p = tidfa_newtr[p][indata[i]]; if (new_tidfa_accept[p] != -1) { http_accept = true; break; } } if (http_accept) i++; printf("Tidfa accept state = %d\n", p); printf("Character consump = %d\n", i); tsNode *t = tidfaState[getfa(p)]; while(t != NULL) { if (t->tidfa_q == p) break; t = t->next; } matches = t->matches; run_string(indata + i, t->x); printState(t->x); printf("matches=%d\n", matches); printf("----------------run all character all once---------------\n"); state st; matches = 0; st.flow_data_length = strlen(indata); st.flow_data = (const u_char*)indata; while (st.fdpos < st.flow_data_length && st.q != NULL) CALL_MEMBER_FN(st, st.q)(); printState(st); printf("matches=%d\n", matches); printf("---------------run_fs function---------\n"); matches = 0; state st1; for (int j = 0; j < strlen(indata); j++) run_fs(indata[j], st1); printState(st1); printf("matches=%d\n", matches); return ; }
void get_subroutine_dfa() { int lo = 0, hi = 0; f[lo].tidfa_q = 0; f[lo].matches = 0; while(lo <= hi) { stateNode u = f[lo]; //printStateNode(u); for (int i = 0; i < 256; i++) { stateNode v = u; int tiq = v.tidfa_q; matches = u.matches; int new_tidfa_q = tidfa_newtr[tiq][i]; if (new_tidfa_q == 1){ continue; //prune the self-recursive state of DFA. } if (new_tidfa_q == 2 && tiq != 0) { continue; //prune the matching fail edge. } v.tidfa_q = new_tidfa_q; run_fs(i, v.st); v.matches = matches; if (v.st.q == NULL) continue; if (variablesExceed(v.st)) continue; if (tidfaState[getfa(v.tidfa_q)] == NULL) { if (getStateQId(u.st) != 100 && getStateQId(v.st) < 200 && u.st.q != v.st.q) { //catch difference between LPDFA except CA0 or Act states. insert_tran_edge(u.tidfa_q, i, v.st, matches); matches = 0; } insert_tsNode(tidfaState[getfa(v.tidfa_q)], v.st, matches, v.tidfa_q); } else { tsNode *item = findtiState(getfa(v.tidfa_q), v); if (item == NULL) { if (getStateQId(u.st) != 100 && getStateQId(v.st) < 200 && u.st.q != v.st.q) { //catch difference between LPDFA except CA0 or Act states. tsNode *t = findtiState_no_result(getfa(v.tidfa_q), v); tidfa_newtr[tiq][i] = t->tidfa_q; insert_tran_edge(u.tidfa_q, i, v.st, matches); continue; } insert_tsNode(tidfaState[getfa(v.tidfa_q)], v.st, matches, tidfa_num); //this should be tidfa_num not v.tidfa_q father[tidfa_num] = v.tidfa_q; for (int k = 0; k < 256; k++) tidfa_newtr[tidfa_num][k] = tidfa_newtr[v.tidfa_q][k]; tidfa_newtr[tiq][i] = tidfa_num; if (new_tidfa_accept[v.tidfa_q] != -1) new_tidfa_accept[tidfa_num] = new_tidfa_accept[v.tidfa_q]; v.tidfa_q = tidfa_num; tidfa_num++; }else { //v.tidfa_q = item->tidfa_q; //FIX ME tidfa_newtr[tiq][i] = item->tidfa_q; continue; } } //printf("-----i=%d-----v--getfa(tidfa)=%d-\n", i, getfa(v.tidfa_q)); //printStateNode(v); if (new_tidfa_accept[v.tidfa_q] != -1) { //printf("ACCEPT state.\n"); continue; } f[++hi] = v; } if (kdebug) printf("\n%d %d\n", lo, tidfa_num); lo++; } printf("-------------------------@*@---------------------------------------\n"); return ; }
void reshape() { int lo = 0, hi = 0; f[lo].tidfa_q = 0; f[lo].matches = 0; while(lo <= hi) { stateNode u = f[lo]; if (kdebug) printStateNode(u); for (int i = 0; i < 256; i++) { stateNode v = u; int tiq = v.tidfa_q; matches = u.matches; int new_tidfa_q = tidfa_newtr[tiq][i]; if (new_tidfa_q == 1){ continue; //prune the self-recursive state of DFA. } if (new_tidfa_q == 2 && tiq != 0) { continue; //prune the matching fail edge. } v.tidfa_q = new_tidfa_q; run_fs(i, v.st); v.matches = matches; if (v.st.q == NULL) continue; if (variablesExceed(v.st)) { printf("Variable Exceed!!!\n"); printState(v.st); continue; } if (tidfaState[getfa(v.tidfa_q)] == NULL) { insert_tsNode(tidfaState[getfa(v.tidfa_q)], v.st, matches, v.tidfa_q); } else { tsNode *item = findtiState(getfa(v.tidfa_q), v); if (item == NULL) { insert_tsNode(tidfaState[getfa(v.tidfa_q)], v.st, matches, tidfa_num); //this should be tidfa_num not v.tidfa_q father[tidfa_num] = v.tidfa_q; for (int k = 0; k < 256; k++) tidfa_newtr[tidfa_num][k] = tidfa_newtr[v.tidfa_q][k]; tidfa_newtr[tiq][i] = tidfa_num; if (new_tidfa_accept[v.tidfa_q] != -1) new_tidfa_accept[tidfa_num] = new_tidfa_accept[v.tidfa_q]; v.tidfa_q = tidfa_num; tidfa_num++; }else { //v.tidfa_q = item->tidfa_q; //FIX ME tidfa_newtr[tiq][i] = item->tidfa_q; continue; } } if (kdebug) { printf("-----i=%d-----v--getfa(tidfa)=%d-\n", i, getfa(v.tidfa_q)); printStateNode(v); printf("hhahah = %d", tidfa_newtr[v.tidfa_q][48]); } if (new_tidfa_accept[v.tidfa_q] != -1) { if (kdebug) printf("ACCEPT state.\n"); continue; } f[++hi] = v; } if (kdebug) printf("\n%d %d\n", lo, tidfa_num); lo++; } printf("-------------------------^-^---------------------------------------\n"); return ; }