|
|
|
@ -793,47 +793,47 @@ static inline void SCACCreateDeltaTable(MpmCtx *mpm_ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* create space for the state table. We could have used the existing goto
|
|
|
|
|
* table, but since we have it set to hold 32 bit state values, we will create
|
|
|
|
|
* a new state table here of type SC_AC_STATE_TYPE(current set to uint16_t) */
|
|
|
|
|
ctx->state_table_u32 = SCMalloc(ctx->state_count *
|
|
|
|
|
sizeof(SC_AC_STATE_TYPE_U32) * 256);
|
|
|
|
|
if (ctx->state_table_u32 == NULL) {
|
|
|
|
|
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
memset(ctx->state_table_u32, 0,
|
|
|
|
|
ctx->state_count * sizeof(SC_AC_STATE_TYPE_U32) * 256);
|
|
|
|
|
|
|
|
|
|
mpm_ctx->memory_cnt++;
|
|
|
|
|
mpm_ctx->memory_size += (ctx->state_count *
|
|
|
|
|
sizeof(SC_AC_STATE_TYPE_U32) * 256);
|
|
|
|
|
|
|
|
|
|
StateQueue q;
|
|
|
|
|
memset(&q, 0, sizeof(StateQueue));
|
|
|
|
|
/* create space for the state table. We could have used the existing goto
|
|
|
|
|
* table, but since we have it set to hold 32 bit state values, we will create
|
|
|
|
|
* a new state table here of type SC_AC_STATE_TYPE(current set to uint16_t) */
|
|
|
|
|
ctx->state_table_u32 = SCMalloc(ctx->state_count *
|
|
|
|
|
sizeof(SC_AC_STATE_TYPE_U32) * 256);
|
|
|
|
|
if (ctx->state_table_u32 == NULL) {
|
|
|
|
|
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
memset(ctx->state_table_u32, 0,
|
|
|
|
|
ctx->state_count * sizeof(SC_AC_STATE_TYPE_U32) * 256);
|
|
|
|
|
|
|
|
|
|
for (ascii_code = 0; ascii_code < 256; ascii_code++) {
|
|
|
|
|
SC_AC_STATE_TYPE_U32 temp_state = ctx->goto_table[0][ascii_code];
|
|
|
|
|
ctx->state_table_u32[0][ascii_code] = temp_state;
|
|
|
|
|
if (temp_state != 0)
|
|
|
|
|
SCACEnqueue(&q, temp_state);
|
|
|
|
|
}
|
|
|
|
|
mpm_ctx->memory_cnt++;
|
|
|
|
|
mpm_ctx->memory_size += (ctx->state_count *
|
|
|
|
|
sizeof(SC_AC_STATE_TYPE_U32) * 256);
|
|
|
|
|
|
|
|
|
|
while (!SCACStateQueueIsEmpty(&q)) {
|
|
|
|
|
r_state = SCACDequeue(&q);
|
|
|
|
|
StateQueue q;
|
|
|
|
|
memset(&q, 0, sizeof(StateQueue));
|
|
|
|
|
|
|
|
|
|
for (ascii_code = 0; ascii_code < 256; ascii_code++) {
|
|
|
|
|
int32_t temp_state = ctx->goto_table[r_state][ascii_code];
|
|
|
|
|
if (temp_state != SC_AC_FAIL) {
|
|
|
|
|
SC_AC_STATE_TYPE_U32 temp_state = ctx->goto_table[0][ascii_code];
|
|
|
|
|
ctx->state_table_u32[0][ascii_code] = temp_state;
|
|
|
|
|
if (temp_state != 0)
|
|
|
|
|
SCACEnqueue(&q, temp_state);
|
|
|
|
|
ctx->state_table_u32[r_state][ascii_code] = temp_state;
|
|
|
|
|
} else {
|
|
|
|
|
ctx->state_table_u32[r_state][ascii_code] =
|
|
|
|
|
ctx->state_table_u32[ctx->failure_table[r_state]][ascii_code];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!SCACStateQueueIsEmpty(&q)) {
|
|
|
|
|
r_state = SCACDequeue(&q);
|
|
|
|
|
|
|
|
|
|
for (ascii_code = 0; ascii_code < 256; ascii_code++) {
|
|
|
|
|
int32_t temp_state = ctx->goto_table[r_state][ascii_code];
|
|
|
|
|
if (temp_state != SC_AC_FAIL) {
|
|
|
|
|
SCACEnqueue(&q, temp_state);
|
|
|
|
|
ctx->state_table_u32[r_state][ascii_code] = temp_state;
|
|
|
|
|
} else {
|
|
|
|
|
ctx->state_table_u32[r_state][ascii_code] =
|
|
|
|
|
ctx->state_table_u32[ctx->failure_table[r_state]][ascii_code];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -854,14 +854,14 @@ static inline void SCACClubOutputStatePresenceWithDeltaTable(MpmCtx *mpm_ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (state = 0; state < ctx->state_count; state++) {
|
|
|
|
|
for (ascii_code = 0; ascii_code < 256; ascii_code++) {
|
|
|
|
|
temp_state = ctx->state_table_u32[state & 0x00FFFFFF][ascii_code];
|
|
|
|
|
if (ctx->output_table[temp_state & 0x00FFFFFF].no_of_entries != 0)
|
|
|
|
|
ctx->state_table_u32[state & 0x00FFFFFF][ascii_code] |= (1 << 24);
|
|
|
|
|
for (state = 0; state < ctx->state_count; state++) {
|
|
|
|
|
for (ascii_code = 0; ascii_code < 256; ascii_code++) {
|
|
|
|
|
temp_state = ctx->state_table_u32[state & 0x00FFFFFF][ascii_code];
|
|
|
|
|
if (ctx->output_table[temp_state & 0x00FFFFFF].no_of_entries != 0)
|
|
|
|
|
ctx->state_table_u32[state & 0x00FFFFFF][ascii_code] |= (1 << 24);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -1245,45 +1245,45 @@ uint32_t SCACSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
|
|
|
|
|
} /* for (i = 0; i < buflen; i++) */
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
register SC_AC_STATE_TYPE_U32 state = 0;
|
|
|
|
|
SC_AC_STATE_TYPE_U32 (*state_table_u32)[256] = ctx->state_table_u32;
|
|
|
|
|
for (i = 0; i < buflen; i++) {
|
|
|
|
|
state = state_table_u32[state & 0x00FFFFFF][u8_tolower(buf[i])];
|
|
|
|
|
if (state & 0xFF000000) {
|
|
|
|
|
uint32_t no_of_entries = ctx->output_table[state & 0x00FFFFFF].no_of_entries;
|
|
|
|
|
uint32_t *pids = ctx->output_table[state & 0x00FFFFFF].pids;
|
|
|
|
|
uint32_t k;
|
|
|
|
|
for (k = 0; k < no_of_entries; k++) {
|
|
|
|
|
if (pids[k] & 0xFFFF0000) {
|
|
|
|
|
if (SCMemcmp(pid_pat_list[pids[k] & 0x0000FFFF].cs,
|
|
|
|
|
buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1,
|
|
|
|
|
pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) {
|
|
|
|
|
/* inside loop */
|
|
|
|
|
if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) {
|
|
|
|
|
continue;
|
|
|
|
|
register SC_AC_STATE_TYPE_U32 state = 0;
|
|
|
|
|
SC_AC_STATE_TYPE_U32 (*state_table_u32)[256] = ctx->state_table_u32;
|
|
|
|
|
for (i = 0; i < buflen; i++) {
|
|
|
|
|
state = state_table_u32[state & 0x00FFFFFF][u8_tolower(buf[i])];
|
|
|
|
|
if (state & 0xFF000000) {
|
|
|
|
|
uint32_t no_of_entries = ctx->output_table[state & 0x00FFFFFF].no_of_entries;
|
|
|
|
|
uint32_t *pids = ctx->output_table[state & 0x00FFFFFF].pids;
|
|
|
|
|
uint32_t k;
|
|
|
|
|
for (k = 0; k < no_of_entries; k++) {
|
|
|
|
|
if (pids[k] & 0xFFFF0000) {
|
|
|
|
|
if (SCMemcmp(pid_pat_list[pids[k] & 0x0000FFFF].cs,
|
|
|
|
|
buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1,
|
|
|
|
|
pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) {
|
|
|
|
|
/* inside loop */
|
|
|
|
|
if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) {
|
|
|
|
|
;
|
|
|
|
|
} else {
|
|
|
|
|
pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] |= (1 << ((pids[k] & 0x0000FFFF) % 8));
|
|
|
|
|
pmq->pattern_id_array[pmq->pattern_id_array_cnt++] = pids[k] & 0x0000FFFF;
|
|
|
|
|
}
|
|
|
|
|
matches++;
|
|
|
|
|
} else {
|
|
|
|
|
if (pmq->pattern_id_bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
|
|
|
|
|
;
|
|
|
|
|
if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) {
|
|
|
|
|
;
|
|
|
|
|
} else {
|
|
|
|
|
pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] |= (1 << ((pids[k] & 0x0000FFFF) % 8));
|
|
|
|
|
pmq->pattern_id_array[pmq->pattern_id_array_cnt++] = pids[k] & 0x0000FFFF;
|
|
|
|
|
}
|
|
|
|
|
matches++;
|
|
|
|
|
} else {
|
|
|
|
|
pmq->pattern_id_bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
|
|
|
|
|
pmq->pattern_id_array[pmq->pattern_id_array_cnt++] = pids[k];
|
|
|
|
|
if (pmq->pattern_id_bitarray[pids[k] / 8] & (1 << (pids[k] % 8))) {
|
|
|
|
|
;
|
|
|
|
|
} else {
|
|
|
|
|
pmq->pattern_id_bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
|
|
|
|
|
pmq->pattern_id_array[pmq->pattern_id_array_cnt++] = pids[k];
|
|
|
|
|
}
|
|
|
|
|
matches++;
|
|
|
|
|
}
|
|
|
|
|
matches++;
|
|
|
|
|
//loop1:
|
|
|
|
|
//;
|
|
|
|
|
}
|
|
|
|
|
//loop1:
|
|
|
|
|
//;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* for (i = 0; i < buflen; i++) */
|
|
|
|
|
} /* for (i = 0; i < buflen; i++) */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
|