Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
regeciovad committed Oct 19, 2020
1 parent f0e1da8 commit daa7d07
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 116 deletions.
86 changes: 45 additions & 41 deletions libyara/ahocorasick.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,38 +151,37 @@ static YR_AC_STATE* _yr_ac_next_state(YR_AC_STATE* state, uint8_t input)
{
switch (next_state->type)
{
// Literal - the input byte has to be the same
case YR_ATOM_TYPE_LITERAL:
if (state2->type == YR_ATOM_TYPE_LITERAL)
{
if (next_state->input == state2->input)
return next_state;
}
break;
// Atom - accepts everything
case YR_ATOM_TYPE_ANY:
return next_state;
// Class - the input has to be set in the class
case YR_ATOM_TYPE_CLASS:
if (state2->type == YR_ATOM_TYPE_LITERAL)
{
if (yr_bitmask_is_set(next_state->bitmap, state2->input))
return next_state;
}
else if (state2->type == YR_ATOM_TYPE_CLASS)
{
if (_yr_ac_bitmap_subset(next_state->bitmap, state2->bitmap))
return next_state;
}
break;
// Literal - the input byte has to be the same
case YR_ATOM_TYPE_LITERAL:
if (state2->type == YR_ATOM_TYPE_LITERAL)
{
if (next_state->input == state2->input)
return next_state;
}
break;
// Atom - accepts everything
case YR_ATOM_TYPE_ANY:
return next_state;
// Class - the input has to be set in the class
case YR_ATOM_TYPE_CLASS:
if (state2->type == YR_ATOM_TYPE_LITERAL)
{
if (yr_bitmask_is_set(next_state->bitmap, state2->input))
return next_state;
}
else if (state2->type == YR_ATOM_TYPE_CLASS)
{
if (_yr_ac_bitmap_subset(next_state->bitmap, state2->bitmap))
return next_state;
}
break;
}
next_state = next_state->siblings;
}

return NULL;
return NULL;
}


//
// _yr_ac_next_state_typed
//
Expand Down Expand Up @@ -212,16 +211,16 @@ static YR_AC_STATE* _yr_ac_next_state_typed(
{
switch (type)
{
case YR_ATOM_TYPE_LITERAL:
if (next_state->input == input)
return next_state;
break;
case YR_ATOM_TYPE_ANY:
case YR_ATOM_TYPE_LITERAL:
if (next_state->input == input)
return next_state;
case YR_ATOM_TYPE_CLASS:
if (_yr_ac_compare_classes(next_state->bitmap, bitmap))
return next_state;
break;
break;
case YR_ATOM_TYPE_ANY:
return next_state;
case YR_ATOM_TYPE_CLASS:
if (_yr_ac_compare_classes(next_state->bitmap, bitmap))
return next_state;
break;
}
}
next_state = next_state->siblings;
Expand Down Expand Up @@ -448,12 +447,11 @@ static bool _yr_ac_transitions_subset(YR_AC_STATE* s1, YR_AC_STATE* s2)
{
if (state->type == YR_ATOM_TYPE_LITERAL)
{
yr_bitmask_set(set, state->input);
yr_bitmask_set(set, state->input);
}
else
{
for (int i = 0; i < YR_BITMAP_SIZE; i++)
set[i] |= state->bitmap[i];
for (int i = 0; i < YR_BITMAP_SIZE; i++) set[i] |= state->bitmap[i];
}

state = state->siblings;
Expand Down Expand Up @@ -560,7 +558,8 @@ static int _yr_ac_find_suitable_transition_table_slot(
{
for (int k = 0; k < YR_BITMASK_SLOT_BITS; k++)
{
if (yr_bitmask_is_set(child_state->bitmap, i * YR_BITMASK_SLOT_BITS + k))
if (yr_bitmask_is_set(
child_state->bitmap, i * YR_BITMASK_SLOT_BITS + k))
yr_bitmask_set(state_bitmask, i * YR_BITMASK_SLOT_BITS + k + 1);
}
}
Expand Down Expand Up @@ -944,11 +943,16 @@ int yr_ac_add_string(
}
}

YR_AC_STATE* next_state = _yr_ac_next_state_typed(state, atom->atom.bytes[i], atom->atom.mask[i], atom->atom.bitmap[i]);
YR_AC_STATE* next_state = _yr_ac_next_state_typed(
state, atom->atom.bytes[i], atom->atom.mask[i], atom->atom.bitmap[i]);

if (next_state == NULL)
{
next_state = _yr_ac_state_create(state, atom->atom.bytes[i], atom->atom.mask[i], atom->atom.bitmap[i]);
next_state = _yr_ac_state_create(
state,
atom->atom.bytes[i],
atom->atom.mask[i],
atom->atom.bitmap[i]);

if (next_state == NULL)
return ERROR_INSUFFICIENT_MEMORY;
Expand Down
23 changes: 15 additions & 8 deletions libyara/atoms.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,10 @@ int _yr_atoms_trim(YR_ATOM* atom)
{
atom->bytes[i] = atom->bytes[trim_left + i];
atom->mask[i] = atom->mask[trim_left + i];
memcpy(atom->bitmap[i], atom->bitmap[trim_left + i], (sizeof(YR_BITMASK) * YR_BITMAP_SIZE));
memcpy(
atom->bitmap[i],
atom->bitmap[trim_left + i],
(sizeof(YR_BITMASK) * YR_BITMAP_SIZE));
}

return trim_left;
Expand Down Expand Up @@ -726,7 +729,6 @@ static int _yr_atoms_case_insensitive(
atom->atom.mask[i] = YR_ATOM_TYPE_CLASS;
}
}

}
atom = atom->next;
}
Expand Down Expand Up @@ -764,7 +766,8 @@ static int _yr_atoms_xor(
{
new_atom->atom.bytes[i] = atom->atom.bytes[i] ^ j;
new_atom->atom.mask[i] = 0xFF;
yr_bitmask_clear_all(new_atom->atom.bitmap[i], sizeof(new_atom->atom.bitmap[i]));
yr_bitmask_clear_all(
new_atom->atom.bitmap[i], sizeof(new_atom->atom.bitmap[i]));
yr_bitmask_set(new_atom->atom.bitmap[i], new_atom->atom.bytes[i]);
}

Expand Down Expand Up @@ -809,7 +812,8 @@ static int _yr_atoms_wide(
{
new_atom->atom.bytes[i] = 0;
new_atom->atom.mask[i] = 0xFF;
yr_bitmask_clear_all(new_atom->atom.bitmap[i], sizeof(new_atom->atom.bitmap[i]));
yr_bitmask_clear_all(
new_atom->atom.bitmap[i], sizeof(new_atom->atom.bitmap[i]));
yr_bitmask_set(new_atom->atom.bitmap[i], new_atom->atom.bytes[i]);
}

Expand All @@ -819,7 +823,10 @@ static int _yr_atoms_wide(
{
new_atom->atom.bytes[i * 2] = atom->atom.bytes[i];
new_atom->atom.mask[i * 2] = atom->atom.mask[i];
memcpy(new_atom->atom.bitmap[i * 2], atom->atom.bitmap[i], (sizeof(YR_BITMASK) * YR_BITMAP_SIZE));
memcpy(
new_atom->atom.bitmap[i * 2],
atom->atom.bitmap[i],
(sizeof(YR_BITMASK) * YR_BITMAP_SIZE));
}
else
break;
Expand All @@ -839,7 +846,6 @@ static int _yr_atoms_wide(
return ERROR_SUCCESS;
}


struct STACK_ITEM
{
RE_NODE* re_node;
Expand Down Expand Up @@ -1245,7 +1251,8 @@ static int _yr_atoms_expand_wildcards(YR_ATOM_LIST_ITEM* atoms)

new_atom->atom.bytes[i] = (uint8_t) a;
new_atom->atom.mask[i] = 0xFF;
yr_bitmask_clear_all(new_atom->atom.bitmap[i], sizeof(new_atom->atom.bitmap[i]));
yr_bitmask_clear_all(
new_atom->atom.bitmap[i], sizeof(new_atom->atom.bitmap[i]));
yr_bitmask_set(new_atom->atom.bitmap[i], new_atom->atom.bytes[i]);
new_atom->next = next_atom;
prev_atom->next = new_atom;
Expand Down Expand Up @@ -1418,7 +1425,7 @@ int yr_atoms_extract_from_string(
atom.length = YR_MAX_ATOM_LENGTH;
memcpy(atom.bytes, string + i - YR_MAX_ATOM_LENGTH + 1, atom.length);

for (int j = 0; j <atom.length; j++)
for (int j = 0; j < atom.length; j++)
{
yr_bitmask_clear_all(atom.bitmap[j], sizeof(atom.bitmap[j]));
yr_bitmask_set(atom.bitmap[j], atom.bytes[j]);
Expand Down

0 comments on commit daa7d07

Please sign in to comment.